=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / ORB_Local_Config / Two_DLL_ORB / server.cpp
blob9425ff57850edb1ba2307ff27be36a44ff8684d8
1 #include "Test_i.h"
2 #include "ORB_DLL.h"
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"))
15 const ACE_TCHAR *
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));
28 int
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); )
34 switch (c)
36 case 'o':
37 this->ior_file_ = get_opts.opt_arg ();
38 break;
41 // Indicates successful parsing of the command line
42 return 0;
46 int
47 Server_Worker::test_main (int argc, ACE_TCHAR *argv[])
49 try
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")),
65 1);
67 PortableServer::POAManager_var poa_manager =
68 root_poa->the_POAManager ();
70 if (parse_args (argc, argv) != 0)
71 return 1;
73 Hello *hello_impl;
74 ACE_NEW_RETURN (hello_impl,
75 Hello (orb.in ()),
76 1);
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");
98 if (output_file == 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 ACE_TEXT ("(%P|%t) Cannot open output file %s for writing IOR: %C"),
101 ior_file_.c_str (),
102 ior.in ()),
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")));
109 orb->run ();
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);
120 orb->destroy ();
122 catch (const ::CORBA::Exception &e)
124 e._tao_print_exception("Server_Worker::test_main");
125 return 1;
128 return 0;