1 #include "ace/SString.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_stdio.h"
8 const ACE_TCHAR
*control_ior
= 0;
9 const ACE_TCHAR
*proxy_ior
= 0;
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("c:p:"));
17 while ((c
= get_opts ()) != -1)
21 control_ior
= get_opts
.opt_arg ();
24 proxy_ior
= get_opts
.opt_arg ();
27 // Indicates successful parsing of the command line
32 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
38 // Initilaize the ORB, POA etc.
39 manager
.init (argc
, argv
);
41 if (parse_args (argc
, argv
) == -1)
44 manager
.activate_servant ();
46 CORBA::ORB_var orb
= manager
.orb ();
47 CORBA::Object_var server_ref
= manager
.server ();
49 CORBA::String_var ior
=
50 orb
->object_to_string (server_ref
.in ());
52 FILE *output_file
= 0;
57 "Writing the servant locator object ref out to file %s\n",
59 output_file
= ACE_OS::fopen (proxy_ior
, "w");
61 ACE_ERROR_RETURN ((LM_ERROR
,
62 "Cannot open output file for writing IOR: %s",
65 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
66 ACE_OS::fclose (output_file
);
69 // this is only to shutdown the manager afterwards
70 Simple_Server_i
server_impl (orb
.in ());
72 Simple_Server_var server
= server_impl
._this ();
75 orb
->object_to_string (server
.in ());
77 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
79 // If the proxy_ior exists, output the ior to it
83 "Writing the root poa servant server IOR out to file %s\n",
85 output_file
= ACE_OS::fopen (control_ior
, "w");
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 "Cannot open output file for writing IOR: %s",
91 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
92 ACE_OS::fclose (output_file
);
97 catch (const CORBA::Exception
& ex
)
99 ex
._tao_print_exception ("Exception caught in manager:");
115 this->orb_
->destroy ();
121 return CORBA::ORB::_duplicate (this->orb_
.in ());
127 return CORBA::Object::_duplicate (this->server_
.in ());
131 Manager::init (int argc
, ACE_TCHAR
*argv
[])
133 this->orb_
= CORBA::ORB_init (argc
, argv
);
135 // Obtain the RootPOA.
136 CORBA::Object_var obj_var
=
137 this->orb_
->resolve_initial_references ("RootPOA");
139 // Get the POA_var object from Object_var.
140 PortableServer::POA_var root_poa_var
=
141 PortableServer::POA::_narrow (obj_var
.in ());
143 // Get the POAManager of the RootPOA.
144 PortableServer::POAManager_var poa_manager_var
=
145 root_poa_var
->the_POAManager ();
147 poa_manager_var
->activate ();
149 // Policies for the childPOA to be created.
150 CORBA::PolicyList
policies (4);
153 // The next two policies are common to both
154 // Id Assignment Policy
156 root_poa_var
->create_id_assignment_policy (PortableServer::USER_ID
);
160 root_poa_var
->create_lifespan_policy (PortableServer::PERSISTENT
);
162 // Tell the POA to use a servant manager
164 root_poa_var
->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER
);
166 // Servant Retention Policy -> Use a locator
168 root_poa_var
->create_servant_retention_policy (PortableServer::NON_RETAIN
);
170 ACE_CString name
= "newPOA";
173 root_poa_var
->create_POA (name
.c_str (),
174 poa_manager_var
.in (),
177 // Creation of childPOAs is over. Destroy the Policy objects.
178 for (CORBA::ULong i
= 0;
179 i
< policies
.length ();
182 CORBA::Policy_ptr policy
= policies
[i
];
190 Manager::activate_servant ()
192 Servant_Locator
*tmp
= 0;
194 ACE_NEW_THROW_EX (tmp
,
196 CORBA::NO_MEMORY ());
198 this->servant_locator_
= tmp
;
200 // Set ServantLocator object as the servant Manager of
202 this->new_poa_var_
->set_servant_manager (this->servant_locator_
.in ());
204 // Try to create a reference with user created ID in new_poa
205 // which uses ServantLocator.
206 PortableServer::ObjectId_var oid_var
=
207 PortableServer::string_to_ObjectId ("Simple_Server");
210 new_poa_var_
->create_reference_with_id (oid_var
.in (),
211 "IDL:Simple_Server:1.0");