More tests update
[ACE_TAO.git] / TAO / tests / Hang_Shutdown / server.cpp
blob03193adec64059dc4f2ffb83009120a619e85b6e
1 #include "test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 namespace Test
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("server.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.optarg;
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 static int
36 try_main (int argc,
37 ACE_TCHAR *argv[])
40 try
42 CORBA::ORB_var orb =
43 CORBA::ORB_init (argc, argv);
45 CORBA::Object_var poa_object =
46 orb->resolve_initial_references("RootPOA");
48 PortableServer::POA_var root_poa =
49 PortableServer::POA::_narrow (poa_object.in ());
51 if (CORBA::is_nil (root_poa.in ()))
52 ACE_ERROR_RETURN ((LM_ERROR,
53 " (%P|%t) Panic: nil RootPOA\n"),
54 1);
56 PortableServer::POAManager_var poa_manager =
57 root_poa->the_POAManager ();
59 if (parse_args (argc, argv) != 0)
60 return 1;
62 test_i *test_impl = 0;
63 ACE_NEW_RETURN (test_impl,
64 test_i (),
65 1);
66 PortableServer::ServantBase_var owner_transfer (test_impl);
68 PortableServer::ObjectId_var id =
69 root_poa->activate_object (test_impl);
71 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
73 Hang_var test =
74 Hang::_narrow (object.in ());
76 CORBA::String_var ior =
77 orb->object_to_string (test.in ());
79 // If the ior_output_file exists, output the ior to it
80 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
81 if (output_file == 0)
82 ACE_ERROR_RETURN ((LM_ERROR,
83 "Cannot open output file for writing IOR: %s",
84 ior_output_file),
85 1);
86 ACE_OS::fprintf (output_file, "%s", ior.in ());
87 ACE_OS::fclose (output_file);
89 poa_manager->activate ();
91 ACE_Time_Value tv (10);
93 orb->run (&tv);
95 ACE_DEBUG ((LM_DEBUG,
96 "(%P|%t) server - event loop finished\n"));
98 root_poa->destroy (1, 1);
100 orb->destroy ();
102 catch (const CORBA::Exception& ex)
104 ex._tao_print_exception ("Caught CORBA exception\n");
105 return -1;
108 return 0;
113 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
115 return Test::try_main (argc, argv);