1 #include "Messenger_i.h"
4 #include "ace/Get_Opt.h"
6 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("messenger.ior");
9 parse_args (int argc
, ACE_TCHAR
*argv
[])
11 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
14 while ((c
= get_opts ()) != -1)
18 ior_output_file
= get_opts
.opt_arg ();
23 ACE_ERROR_RETURN ((LM_ERROR
,
30 // Indicates successful parsing of the command line
35 PortableServer::POA_ptr
36 createPersistentPOA(PortableServer::POA_ptr root_poa
,
39 CORBA::PolicyList policies
;
42 policies
[0] = root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
43 policies
[1] = root_poa
->create_id_assignment_policy(PortableServer::USER_ID
);
45 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
46 PortableServer::POA_var poa
=
47 root_poa
->create_POA(poa_name
, mgr
.in(), policies
);
49 policies
[0]->destroy();
50 policies
[1]->destroy();
56 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
59 CORBA::ORB_var orb
= CORBA::ORB_init(argc
, argv
);
61 if (parse_args (argc
, argv
) != 0)
64 CORBA::Object_var obj
= orb
->resolve_initial_references("RootPOA");
65 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow(obj
.in());
67 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager();
69 const char* poa_name
= "MessengerService";
71 PortableServer::POA_var poa
= createPersistentPOA(root_poa
.in(), poa_name
);
73 PortableServer::Servant_var
<Messenger_i
> servant
= new Messenger_i
;
75 PortableServer::ObjectId_var object_id
=
76 PortableServer::string_to_ObjectId("object");
78 poa
->activate_object_with_id(object_id
.in(), servant
.in());
80 obj
= poa
->id_to_reference(object_id
.in());
81 CORBA::String_var ior
= orb
->object_to_string(obj
.in());
83 // If the ior_output_file exists, output the ior to it
84 if (ior_output_file
!= 0)
86 FILE *output_file
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file
), "w");
88 ACE_ERROR_RETURN ((LM_ERROR
,
89 "Cannot open output file for writing IOR: %s",
92 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
93 ACE_OS::fclose (output_file
);
98 std::cout
<< "Messenger server ready." << std::endl
;
102 std::cout
<< "Messenger server shutting down." << std::endl
;
104 root_poa
->destroy(1,1);
108 } catch(const CORBA::Exception
& ex
) {
109 std::cerr
<< "Server main() Caught Exception" << ex
<< std::endl
;