1 #include "Messenger_i.h"
3 #include "tao/ImR_Client/ImR_Client.h"
5 #include "ace/SString.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/OS_NS_string.h"
8 #include "ace/OS_NS_stdio.h"
9 #include "ace/Get_Opt.h"
11 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("messenger.ior");
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
19 while ((c
= get_opts ()) != -1)
23 ior_output_file
= get_opts
.opt_arg ();
28 ACE_ERROR_RETURN ((LM_ERROR
,
35 // Indicates successful parsing of the command line
39 PortableServer::POA_ptr
40 createPersistentPOA (PortableServer::POA_ptr root_poa
, const char *poa_name
)
42 CORBA::PolicyList policies
;
45 policies
[0] = root_poa
->create_lifespan_policy (PortableServer::PERSISTENT
);
47 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
49 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager ();
51 PortableServer::POA_var poa
= root_poa
->create_POA (poa_name
, mgr
.in (),
53 policies
[0]->destroy ();
54 policies
[1]->destroy ();
60 writeIORFile (const char* ior
)
62 FILE *out
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file
), "w");
65 ACE_OS::fprintf (out
, "%s", ior
);
71 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
75 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
77 if (parse_args (argc
, argv
) != 0)
80 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Server Process started\n")));
82 CORBA::Object_var obj
= orb
->resolve_initial_references ("RootPOA");
83 PortableServer::POA_var root_poa
=
84 PortableServer::POA::_narrow (obj
.in ());
86 PortableServer::POAManager_var mgr
= root_poa
->the_POAManager ();
88 const char* poa_name
= "MessengerService";
90 PortableServer::POA_var poa
= createPersistentPOA (root_poa
.in (),
92 Messenger_i
servant (orb
.in ());
94 PortableServer::ObjectId_var object_id
=
95 PortableServer::string_to_ObjectId ("object");
97 poa
->activate_object_with_id (object_id
.in (), &servant
);
98 obj
= poa
->id_to_reference (object_id
.in ());
99 CORBA::String_var ior
= orb
->object_to_string (obj
.in ());
101 writeIORFile (ior
.in ());
104 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Messenger server ready.\n")));
108 // the following 1 second of sleep is needed to help
109 // Windows with "server shutdown too quickly so the
110 // client cannot get the reply" issue.
112 ACE_DEBUG ((LM_DEBUG
,
113 ACE_TEXT ("(%P|%t) Messenger server shutting down.\n")));
114 root_poa
->destroy (1, 1);
118 catch (const CORBA::Exception
&ex
)
120 ACE_CString str
= ex
._info ();
121 ACE_ERROR ((LM_ERROR
, ACE_TEXT ("Server main() caught: %C\n"),