3 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_strings.h"
7 void replace (ACE_TCHAR
** a
, ACE_TCHAR
** b
)
15 Server::Server (int , ACE_TCHAR
* argv
[])
16 : init_ (false), shutdown_ (false)
19 ACE_ARGV
args_1 (argv
);
20 ACE_ARGV
args_2 (argv
);
23 for (int my_count = 0; my_count < args_1.argc(); my_count++) {
24 ACE_DEBUG ((LM_DEBUG, "<%d, %s> ", my_count, (args_1.argv())[my_count]));
26 ACE_DEBUG ((LM_DEBUG, "\n"));
29 ACE_TCHAR
** my_argv
= args_1
.argv ();
30 int my_argc
= args_1
.argc ();
32 for (count
= my_argc
-1; count
> -1; count
--) {
33 if (ACE_OS::strcasecmp (ACE_TEXT("-ORBEndpoint"), my_argv
[count
]) == 0) {
37 if (count
> my_argc
-2){
38 // check if less than 2-last position.
41 replace (&(my_argv
[count
]), &(my_argv
[my_argc
-2]));
42 replace (&(my_argv
[count
+1]), &(my_argv
[my_argc
-1]));
45 orb_
= CORBA::ORB_init (my_argc
, my_argv
, "Server");
46 if (CORBA::is_nil (orb_
.in())) {
47 ACE_ERROR ((LM_ERROR
, "Server::Server> ORB initialization failed.\n"));
51 my_argv
= args_2
.argv();
52 my_argc
= args_2
.argc();
53 for (count
= 0; count
< my_argc
; count
++) {
54 if (ACE_OS::strcasecmp (ACE_TEXT("-ORBEndpoint"), my_argv
[count
]) == 0) {
58 if (count
> my_argc
-2) {
59 // check if less than 2-last position.
62 replace (&(my_argv
[count
]), &(my_argv
[my_argc
-2]));
63 replace (&(my_argv
[count
+1]), &(my_argv
[my_argc
-1]));
65 // initialize management ORB
67 management_orb_
= CORBA::ORB_init (my_argc
, my_argv
, "Management");
68 if (CORBA::is_nil (orb_
.in())) {
69 ACE_ERROR ((LM_ERROR
, "Server::Server> Mgmt ORB initialization failed.\n"));
73 if (!this->parse_args (my_argc
, my_argv
))
76 CORBA::Object_var obj
= orb_
->resolve_initial_references ("RootPOA");
77 PortableServer::POA_var root_poa
=
78 PortableServer::POA::_narrow (obj
.in ());
79 PortableServer::POAManager_var poa_manager
= root_poa
->the_POAManager ();
81 test_i_
.reset (new Test_i (orb_
.in()));
82 PortableServer::ObjectId_var oid
=
83 root_poa
->activate_object (test_i_
.get());
84 obj
= root_poa
->id_to_reference (oid
.in());
85 Test_var test_obj
= Test::_narrow (obj
.in());
87 CORBA::String_var ior
= orb_
->object_to_string (test_obj
.in ());
88 obj
= orb_
->resolve_initial_references("IORTable");
89 IORTable::Table_var table
= IORTable::Table::_narrow (obj
.in());
90 table
->bind ("Test", ior
.in());
92 poa_manager
->activate ();
94 // initialize management objects
96 obj
= management_orb_
->resolve_initial_references ("RootPOA");
97 PortableServer::POA_var management_root_poa
=
98 PortableServer::POA::_narrow (obj
.in ());
99 PortableServer::POAManager_var management_poa_manager
=
100 management_root_poa
->the_POAManager ();
102 oid
= management_root_poa
->activate_object (test_i_
.get());
103 obj
= management_root_poa
->id_to_reference (oid
.in());
104 test_obj
= Test::_narrow (obj
.in());
106 ior
= orb_
->object_to_string (test_obj
.in ());
107 obj
= management_orb_
->resolve_initial_references("IORTable");
108 table
= IORTable::Table::_narrow (obj
.in());
109 table
->bind ("Management", ior
.in());
111 management_poa_manager
->activate ();
113 catch( CORBA::Exception
& ex
) {
114 ACE_ERROR ((LM_ERROR
, "(%P|%t) Server> Caught CORBA::Exception %s"
115 , ex
._info().c_str()));
128 Server::parse_args (int , ACE_TCHAR
* [])
131 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT(""));
134 while ((c = get_opts ()) != -1) {
138 ACE_ERROR_RETURN ((LM_ERROR, "Invalid option \'-%c\'\n", c)
148 Server::run (bool management
)
153 if (!management
&& !CORBA::is_nil (orb_
.in())) {
157 catch( CORBA::Exception
& ex
) {
158 ACE_ERROR ((LM_ERROR
, "(%P|%t) Server::run> Caught CORBA::Exception %s in worker ORB\n"
159 , ex
._info().c_str()));
164 if (management
&& !CORBA::is_nil (management_orb_
.in())) {
165 management_orb_
->run();
168 catch( CORBA::Exception
& ex
) {
169 ACE_ERROR ((LM_ERROR
, "(%P|%t) Server::run> Caught CORBA::Exception %s in management ORB\n"
170 , ex
._info().c_str()));
180 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
);
186 if (!CORBA::is_nil (management_orb_
.in())) {
187 management_orb_
->shutdown (true);
188 ACE_OS::sleep (1); // Let management thread clear out
190 test_i_
.reset ((Test_i
*)0);
192 if (!CORBA::is_nil (orb_
.in())) {
195 orb_
= CORBA::ORB::_nil();
196 if (!CORBA::is_nil (management_orb_
.in())) {
197 management_orb_
->destroy ();
199 management_orb_
= CORBA::ORB::_nil();
201 catch( CORBA::Exception
& ex
) {
202 ACE_ERROR ((LM_ERROR
, "(%P|%t) Server::run> Caught CORBA::Exception %s"
203 , ex
._info().c_str()));