More tests update
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / ORB_Shutdown / server.cpp
blob3b7edf15ccd3d6c48b6c2e2b0651b7a2fb548c80
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "Server_ORBInitializer.h"
4 #include "Server_Request_Interceptor.h"
5 #include "tao/ORBInitializer_Registry.h"
6 #include "ace/OS_NS_stdio.h"
9 const ACE_TCHAR *ior_file = 0;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_file = get_opts.opt_arg ();
22 break;
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "Usage: %s "
26 "-o IOR\n",
27 argv[0]),
28 -1);
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 #if TAO_HAS_INTERCEPTORS == 1
40 bool destroy_called = false;
42 Server_ORBInitializer *temp_initializer = 0;
43 ACE_NEW_RETURN (temp_initializer,
44 Server_ORBInitializer (destroy_called),
45 -1); // No exceptions yet!
46 PortableInterceptor::ORBInitializer_var orb_initializer =
47 temp_initializer;
49 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
50 #endif /* TAO_HAS_INTERCEPTORS == 1 */
52 CORBA::ORB_var orb =
53 CORBA::ORB_init (argc, argv, "Server ORB");
55 CORBA::Object_var poa_object =
56 orb->resolve_initial_references ("RootPOA");
58 if (CORBA::is_nil (poa_object.in ()))
59 ACE_ERROR_RETURN ((LM_ERROR,
60 " (%P|%t) Unable to initialize the POA.\n"),
61 1);
63 PortableServer::POA_var root_poa =
64 PortableServer::POA::_narrow (poa_object.in ());
66 PortableServer::POAManager_var poa_manager =
67 root_poa->the_POAManager ();
69 poa_manager->activate ();
71 if (::parse_args (argc, argv) != 0)
72 return -1;
74 test_i servant (orb.in ());
76 PortableServer::ObjectId_var id =
77 root_poa->activate_object (&servant);
79 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
81 CORBA::Object_var obj =
82 CORBA::Object::_narrow (object.in ());
84 CORBA::String_var ior =
85 orb->object_to_string (obj.in ());
87 ACE_DEBUG ((LM_DEBUG,
88 "test servant: <%C>\n",
89 ior.in ()));
91 // Write IOR to a file.
92 FILE *output_file= ACE_OS::fopen (ior_file, "w");
93 if (output_file == 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot open output file <%s> for writing "
96 "IOR: %C",
97 ior_file,
98 ior.in ()),
99 1);
100 ACE_OS::fprintf (output_file, "%s", ior.in ());
101 ACE_OS::fclose (output_file);
103 // Run the ORB event loop.
104 orb->run ();
106 root_poa->destroy (1, 1);
108 orb->destroy ();
110 #if TAO_HAS_INTERCEPTORS == 1
111 ACE_TEST_ASSERT (destroy_called == true);
112 #endif
114 ACE_DEBUG ((LM_DEBUG, "Event loop finished.\n"));
116 catch (const CORBA::Exception& ex)
118 ex._tao_print_exception ("Caught exception:");
119 return -1;
122 return 0;