Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / DSI_AMI_Gateway / gateway.cpp
blob3fa496dd2dd6e578ce08d7a96e7cd1d05c86df90
1 #include "test_dsi.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
6 int niterations = 5;
7 int do_shutdown = 0;
8 const ACE_TCHAR *ior_output_file = ACE_TEXT("gateway.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("xk:i:o:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'x':
20 do_shutdown = 1;
21 break;
23 case 'k':
24 ior = get_opts.opt_arg ();
25 break;
27 case 'i':
28 niterations = ACE_OS::atoi (get_opts.opt_arg ());
29 break;
31 case 'o':
32 ior_output_file = get_opts.opt_arg ();
33 break;
35 case '?':
36 default:
37 ACE_ERROR_RETURN ((LM_ERROR,
38 "usage: %s "
39 "-x "
40 "-k <ior> "
41 "-i <niterations> "
42 "-o <iorfile> "
43 "\n",
44 argv [0]),
45 -1);
48 // Indicates successful parsing of the command line
49 return 0;
52 int
53 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
55 try
57 CORBA::ORB_var orb =
58 CORBA::ORB_init (argc, argv);
60 CORBA::Object_var poa_object =
61 orb->resolve_initial_references("RootPOA");
63 if (CORBA::is_nil (poa_object.in ()))
65 ACE_ERROR_RETURN ((LM_ERROR,
66 " (%P|%t) Unable to initialize the POA.\n"),
67 1);
70 PortableServer::POA_var root_poa =
71 PortableServer::POA::_narrow (poa_object.in ());
73 PortableServer::POAManager_var poa_manager =
74 root_poa->the_POAManager ();
76 poa_manager->activate ();
78 if (parse_args (argc, argv) != 0)
80 return 1;
83 CORBA::Object_var object =
84 orb->string_to_object (ior);
86 DSI_Simple_Server server_impl (orb.in (),
87 object.in (),
88 root_poa.in ());
89 PortableServer::ObjectId_var oid =
90 root_poa->activate_object (&server_impl);
92 CORBA::Object_var server =
93 root_poa->id_to_reference (oid.in ());
95 CORBA::String_var ior =
96 orb->object_to_string (server.in ());
98 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
100 // If the ior_output_file exists, output the ior to it
101 if (ior_output_file != 0)
103 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
105 if (output_file == 0)
107 ACE_ERROR_RETURN (
108 (LM_ERROR,
109 "Cannot open output file for writing IOR: %s",
110 ior_output_file),
114 ACE_OS::fprintf (output_file, "%s", ior.in ());
115 ACE_OS::fclose (output_file);
118 orb->run ();
120 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
122 catch (const CORBA::Exception& ex)
124 ex._tao_print_exception ("Gateway: exception caught - ");
125 return 1;
128 return 0;