1 #include "ace/Get_Opt.h"
2 #include "tao/IORTable/IORTable.h"
4 #include "Server_Worker.h"
6 const ACE_TCHAR
*ior_output_file
= 0;
7 ACE_TCHAR
*another_output_file
= 0;
8 ACE_CString ior_table_name
= "";
9 char *another_table_name
= 0;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("i:o:n:"));
18 while ((c
= get_opts ()) != -1)
23 ior_table_name
= ACE_TEXT_ALWAYS_CHAR(get_opts
.opt_arg ());
24 int len
= ACE_OS::strlen(ior_table_name
.c_str ()) + 1;
25 another_table_name
= new char[len
+ 1];
26 ACE_OS::strcpy(another_table_name
, ior_table_name
.c_str ());
27 another_table_name
[len
-1] = '1';
28 another_table_name
[len
] = '\0';
33 ior_output_file
= get_opts
.opt_arg ();
34 int len
= ACE_OS::strlen(ior_output_file
) + 1;
35 another_output_file
= new ACE_TCHAR
[len
+ 1];
36 ACE_OS::strcpy(another_output_file
, ior_output_file
);
37 another_output_file
[len
-1] = '1';
38 another_output_file
[len
] = '\0';
42 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
47 ACE_ERROR_RETURN ((LM_ERROR
,
49 "[-i <iortable name>]"
55 // Indicates successful parsing of the command line
61 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
67 CORBA::ORB_init (argc
, argv
);
69 CORBA::Object_var poa_object
=
70 orb
->resolve_initial_references("RootPOA");
72 if (CORBA::is_nil (poa_object
.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR
,
74 " (%P|%t) Unable to initialize the POA.\n"),
77 // Get a Root POA reference
78 PortableServer::POA_var root_poa
=
79 PortableServer::POA::_narrow (poa_object
.in ());
81 PortableServer::POAManager_var poa_manager
=
82 root_poa
->the_POAManager ();
84 if (parse_args (argc
, argv
) != 0)
87 Simple_Server_i
server_impl (orb
.in ());
88 Another_One_i
another_one_impl (orb
.in());
90 Simple_Server_var server
=
93 Another_One_var another_one
=
94 another_one_impl
._this ();
96 CORBA::String_var ior
=
97 orb
->object_to_string (server
.in ());
99 CORBA::String_var another_ior
=
100 orb
->object_to_string (another_one
.in ());
102 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Activated as <%C>\n"), ior
.in ()));
104 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Activated another one as <%C>\n"),
107 if (ior_table_name
.length () != 0)
109 CORBA::Object_var table_object
=
110 orb
->resolve_initial_references ("IORTable");
112 IORTable::Table_var adapter
=
113 IORTable::Table::_narrow (table_object
.in ());
115 if (CORBA::is_nil (adapter
.in ()))
117 ACE_ERROR ((LM_ERROR
, "Nil IORTable\n"));
121 adapter
->bind ( ior_table_name
.c_str (), ior
.in ());
122 adapter
->bind ( another_table_name
, another_ior
.in());
126 // If the ior_output_file exists, output the ior to it
127 if (ior_output_file
!= 0)
129 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
130 if (output_file
== 0)
131 ACE_ERROR_RETURN ((LM_ERROR
,
132 "Cannot open output file for writing IOR: %s",
135 ACE_DEBUG ((LM_DEBUG
,"Wrote ior to %s\n",
137 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
138 ACE_OS::fclose (output_file
);
139 output_file
= ACE_OS::fopen (another_output_file
, "w");
140 if (output_file
== 0)
141 ACE_ERROR_RETURN ((LM_ERROR
,
142 "Cannot open output file for writing IOR: %s",
143 another_output_file
),
145 ACE_DEBUG ((LM_DEBUG
,"Wrote another ior to %s\n",
146 another_output_file
));
147 ACE_OS::fprintf (output_file
, "%s", another_ior
.in ());
148 ACE_OS::fclose (output_file
);
151 poa_manager
->activate ();
153 Server_Worker
worker (orb
.in ());
154 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
156 ACE_ERROR_RETURN ((LM_ERROR
,
157 "Cannot activate client threads\n"),
160 worker
.thr_mgr ()->wait ();
162 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
166 catch (const CORBA::Exception
& ex
)
168 ex
._tao_print_exception ("Exception caught:");