4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
6 #include "ace/OS_NS_unistd.h"
7 #include "ace/Argv_Type_Converter.h"
9 Server_Worker::Server_Worker ()
10 : Abstract_Worker (ACE_TEXT ("test.ior"))
16 Server_Worker::kind () const
18 return ACE_TEXT ("Server");
22 Server_Worker::~Server_Worker ()
24 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) %@ Server::<dtor>\n", this));
29 Server_Worker::parse_args (int argc
, ACE_TCHAR
*argv
[])
31 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"),0);
33 for( int c
= 0; ((c
= get_opts ()) != -1); )
37 this->ior_file_
= get_opts
.opt_arg ();
41 // Indicates successful parsing of the command line
47 Server_Worker::test_main (int argc
, ACE_TCHAR
*argv
[])
51 // Making sure there are no stale ior files to confuse a client
52 ACE_OS::unlink (ior_file_
.c_str ());
54 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
56 CORBA::Object_var poa_object
=
57 orb
->resolve_initial_references ("RootPOA");
59 PortableServer::POA_var root_poa
=
60 PortableServer::POA::_narrow (poa_object
.in ());
62 if (CORBA::is_nil (root_poa
.in ()))
63 ACE_ERROR_RETURN ((LM_ERROR
,
64 ACE_TEXT ("(%P|%t) Panic: nil RootPOA\n")),
67 PortableServer::POAManager_var poa_manager
=
68 root_poa
->the_POAManager ();
70 if (parse_args (argc
, argv
) != 0)
74 ACE_NEW_RETURN (hello_impl
,
78 PortableServer::ServantBase_var
owner_transfer (hello_impl
);
80 PortableServer::ObjectId_var id
=
81 root_poa
->activate_object (hello_impl
);
83 CORBA::Object_var hello_obj
=
84 root_poa
->id_to_reference (id
.in ());
86 Test::Hello_var hello
=
87 Test::Hello::_narrow (hello_obj
.in ());
89 CORBA::String_var ior
=
90 orb
->object_to_string (hello
.in ());
92 poa_manager
->activate ();
94 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Server activated POA manager\n")));
96 // Output the IOR to the <ior_output_file>
97 FILE *output_file
= ACE_OS::fopen (ior_file_
.c_str (), "w");
99 ACE_ERROR_RETURN ((LM_ERROR
,
100 ACE_TEXT ("(%P|%t) Cannot open output file %s for writing IOR: %C"),
104 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
105 ACE_OS::fclose (output_file
);
107 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Server entering the event loop\n")));
111 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) Server exiting the event loop\n")));
113 root_poa
->destroy (true, true);
115 // During normal test execution the ORB would have been destroyed
116 // by a request from the client.
118 // orb->shutdown (false);
122 catch (const ::CORBA::Exception
&e
)
124 e
._tao_print_exception("Server_Worker::test_main");