2 // This version uses the Implementation Repository.
6 #include "tao/PortableServer/Root_POA.h"
7 #include "tao/ImR_Client/ImR_Client.h"
9 #include "ace/Get_Opt.h"
10 #include "ace/streams.h"
11 #include "ace/OS_NS_unistd.h"
13 PortableServer::POA_var root_poa
;
14 PortableServer::POA_var poa_a
;
15 PortableServer::POA_var poa_b
;
16 PortableServer::POA_var poa_c
;
19 createPOAs (ACE_CString
&base
)
21 PortableServer::LifespanPolicy_var life
=
22 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
24 PortableServer::IdAssignmentPolicy_var assign
=
25 root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
27 CORBA::PolicyList pols
;
29 pols
[0] = PortableServer::LifespanPolicy::_duplicate(life
.in());
30 pols
[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign
.in());
32 PortableServer::POAManager_var mgr
= PortableServer::POAManager::_nil();
34 ACE_CString poa_name
= base
+ ACE_CString ("_a");
35 poa_a
= root_poa
->create_POA(poa_name
.c_str(), mgr
.in(), pols
);
36 poa_name
= base
+ ACE_CString ("_b");
37 poa_b
= root_poa
->create_POA(poa_name
.c_str(), mgr
.in(), pols
);
38 poa_name
= base
+ ACE_CString ("_c");
39 poa_c
= root_poa
->create_POA(poa_name
.c_str(), mgr
.in(), pols
);
45 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager ();
47 mgr
= poa_a
->the_POAManager ();
49 mgr
= poa_b
->the_POAManager ();
51 mgr
= poa_c
->the_POAManager ();
56 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
59 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
61 bool write_iors
= false;
63 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("d:w"));
66 while ((c
= get_opts ()) != -1)
70 delay
= ACE_OS::atoi (get_opts
.opt_arg ());
78 "-d <seconds to delay before initializing POA> "
85 CORBA::Object_var obj
= orb
->resolve_initial_references ("RootPOA");
86 root_poa
= PortableServer::POA::_narrow (obj
.in ());
88 ACE_CString base
= ACE_CString ("TestObject");
92 ACE_CString status_file
= base
+ ACE_CString(".status");
93 ofstream
out(status_file
.c_str (), ios_base::app
);
96 ACE_DEBUG ((LM_DEBUG
, "server did not get good bit from %s\n", status_file
.c_str()));
98 out
<< ACE_OS::getpid () << endl
;
102 ACE_OS::sleep (delay
);
106 PortableServer::Servant_var
<Test_i
> test_servant
= new Test_i
;
108 PortableServer::ObjectId_var object_id
=
109 PortableServer::string_to_ObjectId (base
.c_str());
111 poa_a
->activate_object_with_id (object_id
.in(), test_servant
.in ());
112 obj
= poa_a
->id_to_reference (object_id
.in());
113 Test_var tva
= Test::_narrow (obj
.in());
115 poa_b
->activate_object_with_id (object_id
.in(), test_servant
.in ());
116 obj
= poa_b
->id_to_reference (object_id
.in());
117 Test_var tvb
= Test::_narrow (obj
.in());
119 poa_c
->activate_object_with_id (object_id
.in(), test_servant
.in ());
120 obj
= poa_c
->id_to_reference (object_id
.in());
121 Test_var tvc
= Test::_narrow (obj
.in());
125 ACE_DEBUG ((LM_DEBUG
, "(%P) writing IOR files\n"));
126 CORBA::String_var iorstr
= orb
->object_to_string (tva
.in ());
127 ACE_CString filename
= base
+ "_a.ior";
128 FILE *iorf
= ACE_OS::fopen (filename
.c_str(), "w");
129 ACE_OS::fprintf (iorf
, "%s", iorstr
.in ());
130 ACE_OS::fclose (iorf
);
132 iorstr
= orb
->object_to_string (tvb
.in ());
133 filename
= base
+ "_b.ior";
134 iorf
= ACE_OS::fopen (filename
.c_str(), "w");
135 ACE_OS::fprintf (iorf
, "%s", iorstr
.in ());
136 ACE_OS::fclose (iorf
);
138 iorstr
= orb
->object_to_string (tvc
.in ());
139 filename
= base
+ "_c.ior";
140 iorf
= ACE_OS::fopen (filename
.c_str(), "w");
141 ACE_OS::fprintf (iorf
, "%s", iorstr
.in ());
142 ACE_OS::fclose (iorf
);
147 ACE_DEBUG ((LM_DEBUG
, "Started Server %s \n", base
.c_str()));
150 root_poa
->destroy(1,1);
153 catch(const CORBA::Exception
& ex
) {
154 ex
._tao_print_exception ("Server main()");