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 (void)
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
,
55 catch (const CORBA::Exception
& ex
)
57 ex
._tao_print_exception ("TAO_FT_Naming_Service::init");
65 TAO_FT_Naming_Service::parse_args (int &argc
, ACE_TCHAR
* argv
[])
67 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("-t:n:"));
70 while ((c
= get_opts ()) != -1)
76 int const time
= ACE_OS::atoi (get_opts
.opt_arg ());
80 // Remove the option '-t' from argv []
81 // to avoid any confusion that might result.
82 for (int i
= get_opts
.opt_ind (); i
!= argc
; ++i
)
83 argv
[i
-2 ] = argv
[i
];
85 // Decrement the value of argc to reflect the removal
92 int const nt
= ACE_OS::atoi (get_opts
.opt_arg ());
94 this->num_threads_
= nt
;
96 // Remove the option '-n' from argv []
97 // to avoid any confusion that might result.
98 for (int i
= get_opts
.opt_ind (); i
!= argc
; ++i
)
99 argv
[i
-2 ] = argv
[i
];
101 // Decrement the value of argc to reflect the removal
109 // Don't do anything. The TAO_Naming_Server::parse_args ()
110 // takes care of indicating an error in case of error.
117 // Run the ORB event loop.
119 class ORB_Runner
: public ACE_Task_Base
122 ORB_Runner (CORBA::ORB_ptr o
, long t
)
123 : orb_(CORBA::ORB::_duplicate (o
)),
129 if (!CORBA::is_nil (orb_
.in ()))
137 ACE_Time_Value
tv (time_
);
138 this->orb_
->run (tv
);
151 TAO_FT_Naming_Service::run (void)
153 ORB_Runner
runner (this->orb_
.in(), time_
);
154 if (this->num_threads_
== 1)
158 int grpid
= runner
.activate ( THR_NEW_LWP
| THR_JOINABLE
| THR_INHERIT_SCHED
,
162 ORBSVCS_ERROR ((LM_ERROR
,
163 ACE_TEXT ("FT_Naming_Service(%P)::run %p\n"),
164 ACE_TEXT ("thread acitvation")));
173 TAO_FT_Naming_Service::shutdown (void)
175 if (!CORBA::is_nil (orb_
.in ()))
177 this->orb_
->shutdown (0);
182 TAO_FT_Naming_Service::fini (void)
184 this->my_naming_server_
.fini();
188 // destroy implies shutdown
189 if (!CORBA::is_nil (orb_
.in ()))
191 this->orb_
->destroy ();
194 catch (const CORBA::Exception
& ex
)
196 ex
._tao_print_exception ("TAO_FT_Naming_Service::fini");
203 TAO_FT_Naming_Service::~TAO_FT_Naming_Service (void)