Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Hang_Shutdown / server.cpp
blob9022362a9febbeea6c72185849c09b16e6db73d4
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[])
39 try
41 CORBA::ORB_var orb =
42 CORBA::ORB_init (argc, argv);
44 CORBA::Object_var poa_object =
45 orb->resolve_initial_references("RootPOA");
47 PortableServer::POA_var root_poa =
48 PortableServer::POA::_narrow (poa_object.in ());
50 if (CORBA::is_nil (root_poa.in ()))
51 ACE_ERROR_RETURN ((LM_ERROR,
52 " (%P|%t) Panic: nil RootPOA\n"),
53 1);
55 PortableServer::POAManager_var poa_manager =
56 root_poa->the_POAManager ();
58 if (parse_args (argc, argv) != 0)
59 return 1;
61 test_i *test_impl = 0;
62 ACE_NEW_RETURN (test_impl,
63 test_i (),
64 1);
65 PortableServer::ServantBase_var owner_transfer (test_impl);
67 PortableServer::ObjectId_var id =
68 root_poa->activate_object (test_impl);
70 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
72 Hang_var test =
73 Hang::_narrow (object.in ());
75 CORBA::String_var ior =
76 orb->object_to_string (test.in ());
78 // If the ior_output_file exists, output the ior to it
79 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
80 if (output_file == 0)
81 ACE_ERROR_RETURN ((LM_ERROR,
82 "Cannot open output file for writing IOR: %s",
83 ior_output_file),
84 1);
85 ACE_OS::fprintf (output_file, "%s", ior.in ());
86 ACE_OS::fclose (output_file);
88 poa_manager->activate ();
90 ACE_Time_Value tv (10);
92 orb->run (&tv);
94 ACE_DEBUG ((LM_DEBUG,
95 "(%P|%t) server - event loop finished\n"));
97 root_poa->destroy (true, true);
99 orb->destroy ();
101 catch (const CORBA::Exception& ex)
103 ex._tao_print_exception ("Caught CORBA exception\n");
104 return -1;
107 return 0;
112 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
114 return Test::try_main (argc, argv);