1 #include "Naming_Service.h"
3 #include "orbsvcs/Naming/Naming_Server.h"
4 #include "orbsvcs/Log_Macros.h"
5 #include "orbsvcs/Daemon_Utilities.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Argv_Type_Converter.h"
10 // Default Constructor.
11 TAO_Naming_Service::TAO_Naming_Service ()
17 // Constructor taking command-line arguments.
18 TAO_Naming_Service::TAO_Naming_Service (int argc
, ACE_TCHAR
* argv
[])
22 this->init (argc
, argv
);
26 // Initialize the state of the TAO_Naming_Service object
28 TAO_Naming_Service::init (int argc
, ACE_TCHAR
* argv
[])
32 // Check if -ORBDaemon is specified and if so, daemonize at this moment,
33 // -ORBDaemon in the ORB core is faulty, see bugzilla 3335
34 TAO_Daemon_Utility::check_for_daemon (argc
, argv
);
37 this->orb_
= CORBA::ORB_init (argc
, argv
);
39 // Parse the args for '-t' option. If '-t' option is passed, do
40 // the needful and then remove the option from the list of
42 this->parse_args (argc
, argv
);
44 // This function call initializes the naming service and returns
45 // '-1' in case of an exception.
46 int const result
= this->my_naming_server_
.init_with_orb (argc
,
53 catch (const CORBA::Exception
& ex
)
55 ex
._tao_print_exception ("TAO_Naming_Service::init");
63 TAO_Naming_Service::parse_args (int &argc
, ACE_TCHAR
* argv
[])
65 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("-t:n:"));
68 while ((c
= get_opts ()) != -1)
74 int const time
= ACE_OS::atoi (get_opts
.opt_arg ());
78 // Remove the option '-t' from argv []
79 // to avoid any confusion that might result.
80 for (int i
= get_opts
.opt_ind (); i
!= argc
; ++i
)
81 argv
[i
-2 ] = argv
[i
];
83 // Decrement the value of argc to reflect the removal
90 int const nt
= ACE_OS::atoi (get_opts
.opt_arg ());
92 this->num_threads_
= nt
;
94 // Remove the option '-n' from argv []
95 // to avoid any confusion that might result.
96 for (int i
= get_opts
.opt_ind (); i
!= argc
; ++i
)
97 argv
[i
-2 ] = argv
[i
];
99 // Decrement the value of argc to reflect the removal
107 // Don't do anything. The TAO_Naming_Server::parse_args ()
108 // takes care of indicating an error in case of error.
115 // Run the ORB event loop.
117 class ORB_Runner
: public ACE_Task_Base
120 ORB_Runner (CORBA::ORB_ptr o
, long t
)
121 : orb_(CORBA::ORB::_duplicate (o
)),
127 if (!CORBA::is_nil (orb_
.in ()))
135 ACE_Time_Value
tv (time_
);
136 this->orb_
->run (tv
);
149 TAO_Naming_Service::run ()
151 ORB_Runner
runner (this->orb_
.in(), time_
);
152 if (this->num_threads_
== 1)
156 int grpid
= runner
.activate ( THR_NEW_LWP
| THR_JOINABLE
| THR_INHERIT_SCHED
,
160 ORBSVCS_ERROR ((LM_ERROR
,
161 ACE_TEXT ("Naming_Service(%P)::run %p\n"),
162 ACE_TEXT ("thread acitvation")));
171 TAO_Naming_Service::shutdown ()
173 if (!CORBA::is_nil (orb_
.in ()))
175 this->orb_
->shutdown (false);
180 TAO_Naming_Service::fini ()
182 this->my_naming_server_
.fini();
186 // destroy implies shutdown
187 if (!CORBA::is_nil (orb_
.in ()))
189 this->orb_
->destroy ();
192 catch (const CORBA::Exception
& ex
)
194 ex
._tao_print_exception ("TAO_Naming_Service::fini");
201 TAO_Naming_Service::~TAO_Naming_Service ()