1 #include "FT_Naming_Service.h"
2 #include "orbsvcs/Naming/FaultTolerant/FT_Naming_Server.h"
3 #include "orbsvcs/Naming/Persistent_Naming_Context_Factory.h"
4 #include "orbsvcs/Daemon_Utilities.h"
5 #include "orbsvcs/Log_Macros.h"
7 #include "ace/Get_Opt.h"
8 #include "ace/Argv_Type_Converter.h"
11 // Default Constructor.
12 TAO_FT_Naming_Service::TAO_FT_Naming_Service ()
18 // Constructor taking command-line arguments.
19 TAO_FT_Naming_Service::TAO_FT_Naming_Service (int argc
, ACE_TCHAR
* argv
[])
23 this->init (argc
, argv
);
27 // Initialize the state of the TAO_FT_Naming_Service object
29 TAO_FT_Naming_Service::init (int argc
, ACE_TCHAR
* argv
[])
33 // Check if -ORBDaemon is specified and if so, daemonize at this moment,
34 // -ORBDaemon in the ORB core is faulty, see bugzilla 3335
35 TAO_Daemon_Utility::check_for_daemon (argc
, argv
);
38 this->orb_
= CORBA::ORB_init (argc
, argv
);
40 // Parse the args for '-t' option. If '-t' option is passed, do
41 // the needful and then remove the option from the list of
43 this->parse_args (argc
, argv
);
45 // This function call initializes the naming service and returns
46 // '-1' in case of an exception.
47 int const result
= this->my_naming_server_
.init_with_orb (argc
,
54 catch (const CORBA::Exception
& ex
)
56 ex
._tao_print_exception ("TAO_FT_Naming_Service::init");
64 TAO_FT_Naming_Service::parse_args (int &argc
, ACE_TCHAR
* argv
[])
66 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("-t:n:"));
69 while ((c
= get_opts ()) != -1)
75 int const time
= ACE_OS::atoi (get_opts
.opt_arg ());
79 // Remove the option '-t' from argv []
80 // to avoid any confusion that might result.
81 for (int i
= get_opts
.opt_ind (); i
!= argc
; ++i
)
82 argv
[i
-2 ] = argv
[i
];
84 // Decrement the value of argc to reflect the removal
91 int const nt
= ACE_OS::atoi (get_opts
.opt_arg ());
93 this->num_threads_
= nt
;
95 // Remove the option '-n' from argv []
96 // to avoid any confusion that might result.
97 for (int i
= get_opts
.opt_ind (); i
!= argc
; ++i
)
98 argv
[i
-2 ] = argv
[i
];
100 // Decrement the value of argc to reflect the removal
108 // Don't do anything. The TAO_Naming_Server::parse_args ()
109 // takes care of indicating an error in case of error.
116 // Run the ORB event loop.
118 class ORB_Runner
: public ACE_Task_Base
121 ORB_Runner (CORBA::ORB_ptr o
, long t
)
122 : orb_(CORBA::ORB::_duplicate (o
)),
128 if (!CORBA::is_nil (orb_
.in ()))
136 ACE_Time_Value
tv (time_
);
137 this->orb_
->run (tv
);
150 TAO_FT_Naming_Service::run ()
152 ORB_Runner
runner (this->orb_
.in(), time_
);
153 if (this->num_threads_
== 1)
157 int grpid
= runner
.activate ( THR_NEW_LWP
| THR_JOINABLE
| THR_INHERIT_SCHED
,
161 ORBSVCS_ERROR ((LM_ERROR
,
162 ACE_TEXT ("FT_Naming_Service(%P)::run %p\n"),
163 ACE_TEXT ("thread acitvation")));
172 TAO_FT_Naming_Service::shutdown ()
174 if (!CORBA::is_nil (orb_
.in ()))
176 this->orb_
->shutdown (false);
181 TAO_FT_Naming_Service::fini ()
183 this->my_naming_server_
.fini();
187 // destroy implies shutdown
188 if (!CORBA::is_nil (orb_
.in ()))
190 this->orb_
->destroy ();
193 catch (const CORBA::Exception
& ex
)
195 ex
._tao_print_exception ("TAO_FT_Naming_Service::fini");
202 TAO_FT_Naming_Service::~TAO_FT_Naming_Service ()