2 // This version uses the Implementation Repository.
5 #include "ace/Get_Opt.h"
6 #include "ace/streams.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "ace/OS_NS_stdio.h"
10 PortableServer::POA_ptr
11 createPOA (PortableServer::POA_ptr root_poa
, const ACE_TCHAR
* poa_name
)
13 PortableServer::LifespanPolicy_var life
=
14 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
16 PortableServer::IdAssignmentPolicy_var assign
=
17 root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
19 CORBA::PolicyList pols
;
21 pols
[0] = PortableServer::LifespanPolicy::_duplicate(life
.in());
22 pols
[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign
.in());
24 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
25 PortableServer::POA_var poa
=
26 root_poa
->create_POA(ACE_TEXT_ALWAYS_CHAR (poa_name
), mgr
.in(), pols
);
35 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
39 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
41 const ACE_TCHAR
*ior_file_name
= ACE_TEXT ("test.ior");
42 const ACE_TCHAR
*poa_name
= ACE_TEXT ("manual_test");
43 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("o:p:"));
46 while ((c
= get_opts ()) != -1)
51 ior_file_name
= get_opts
.opt_arg ();
54 poa_name
= get_opts
.opt_arg ();
61 CORBA::Object_var obj
= orb
->resolve_initial_references ("RootPOA");
62 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow (obj
.in ());
64 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager ();
65 PortableServer::POA_var test_poa
= createPOA (root_poa
.in(), poa_name
);
67 Test_i
*impl
= new Test_i ();
68 PortableServer::Servant_var
<Test_i
> test_servant
= impl
;
70 PortableServer::ObjectId_var object_id
=
71 PortableServer::string_to_ObjectId ("test_object");
73 test_poa
->activate_object_with_id (object_id
.in(), test_servant
.in());
75 obj
= test_poa
->id_to_reference (object_id
.in ());
76 CORBA::String_var test_ior
= orb
->object_to_string (obj
.in ());
77 FILE *f
= ACE_OS::fopen (ior_file_name
, ACE_TEXT ("w"));
78 ACE_OS::fprintf (f
, "%s", test_ior
.in ());
84 ACE_TEXT ("(%P|%t) Started Server <%s>\n"),
87 ACE_Time_Value
tv (1,0);
89 root_poa
->destroy(1,1);
92 ACE_TEXT ("(%P|%t) Server <%s> orb destroyed\n"),
95 catch(const CORBA::Exception
& ex
) {
96 ex
._tao_print_exception (ACE_TEXT ("Server main()"));