Merge pull request #2218 from jwillemsen/jwi-pthreadsigmask
[ACE_TAO.git] / TAO / examples / CSD_Strategy / ThreadPool2 / FooServantList.cpp
blobbaf65e459b6a940784b49f2c647a14e6090994ff
1 #include "FooServantList.h"
2 #include "Foo_i.h"
3 #include "OrbShutdownTask.h"
5 FooServantList::FooServantList(const ACE_TCHAR* prefix,
6 unsigned num_servants,
7 unsigned num_clients,
8 CORBA::ORB_ptr orb)
9 : prefix_(prefix),
10 num_servants_(num_servants),
11 num_clients_(num_clients),
12 orb_ (CORBA::ORB::_duplicate(orb))
14 this->servants_ = new PortableServer::ServantBase_var[num_servants];
18 FooServantList::~FooServantList()
20 delete [] this->servants_;
24 void
25 FooServantList::create_and_activate(PortableServer::POA_ptr poa)
27 for (unsigned i = 0; i < this->num_servants_; i++)
29 ACE_TCHAR buf[32];
30 ACE_OS::sprintf(buf, ACE_TEXT("%02d"), i + 1);
31 ACE_TString servant_name = this->prefix_ + ACE_TEXT("_") + buf;
33 this->servants_[i] = new Foo_i(servant_name.c_str(),this);
35 PortableServer::ObjectId_var id =
36 PortableServer::string_to_ObjectId(ACE_TEXT_ALWAYS_CHAR(servant_name.c_str()));
38 poa->activate_object_with_id(id.in(),
39 this->servants_[i].in());
41 CORBA::Object_var obj = poa->id_to_reference(id.in());
43 if (CORBA::is_nil(obj.in()))
45 ACE_ERROR((LM_ERROR,
46 "(%P|%t) Failed to activate servant (%s).\n",
47 servant_name.c_str()));
48 throw TestException();
51 CORBA::String_var ior
52 = this->orb_->object_to_string(obj.in());
54 ACE_TString filename = servant_name + ACE_TEXT(".ior");
55 FILE* ior_file = ACE_OS::fopen(filename.c_str(), "w");
57 if (ior_file == 0)
59 ACE_ERROR((LM_ERROR,
60 "(%P|%t) Cannot open output file (%s) for writing IOR.",
61 filename.c_str()));
62 throw TestException();
65 ACE_OS::fprintf(ior_file, "%s", ior.in());
66 ACE_OS::fclose(ior_file);
71 void
72 FooServantList::client_done()
74 unsigned num_left = --this->num_clients_;
76 if (num_left == 0)
78 if (TheOrbShutdownTask::instance()->open(0) != 0)
80 ACE_ERROR((LM_ERROR, "(%P|%t)FooServantList::client_done: "
81 "failed to create orb shutdown thread.\n"));