Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / Naming_Service / Naming_Service.cpp
blobbbda4aa95c8de65a869113a5b0f0a99ad761c916
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"
8 #include "ace/Task.h"
10 // Default Constructor.
11 TAO_Naming_Service::TAO_Naming_Service ()
12 : time_ (0),
13 num_threads_ (1)
17 // Constructor taking command-line arguments.
18 TAO_Naming_Service::TAO_Naming_Service (int argc, ACE_TCHAR* argv[])
19 : time_ (0),
20 num_threads_ (1)
22 this->init (argc, argv);
26 // Initialize the state of the TAO_Naming_Service object
27 int
28 TAO_Naming_Service::init (int argc, ACE_TCHAR* argv[])
30 try
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);
36 // Initialize the ORB
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
41 // arguments.
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,
47 argv,
48 this->orb_.in ());
50 if (result == -1)
51 return result;
53 catch (const CORBA::Exception& ex)
55 ex._tao_print_exception ("TAO_Naming_Service::init");
56 return -1;
59 return 0;
62 int
63 TAO_Naming_Service::parse_args (int &argc, ACE_TCHAR* argv[])
65 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("-t:n:"));
66 int c;
68 while ((c = get_opts ()) != -1)
70 switch (c)
72 case 't':
74 int const time = ACE_OS::atoi (get_opts.opt_arg ());
75 if (time >= 0)
76 this->time_ = time;
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
84 // of '-t' option.
85 argc = argc - 2;
86 break;
88 case 'n':
90 int const nt = ACE_OS::atoi (get_opts.opt_arg ());
91 if (nt >= 1)
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
100 // of '-n' option.
101 argc = argc - 2;
102 break;
105 case '?':
106 default:
107 // Don't do anything. The TAO_Naming_Server::parse_args ()
108 // takes care of indicating an error in case of error.
109 break;
112 return 0;
115 // Run the ORB event loop.
117 class ORB_Runner : public ACE_Task_Base
119 public:
120 ORB_Runner (CORBA::ORB_ptr o, long t)
121 : orb_(CORBA::ORB::_duplicate (o)),
122 time_(t)
125 int svc ()
127 if (!CORBA::is_nil (orb_.in ()))
129 if (time_ == 0)
131 this->orb_->run ();
133 else
135 ACE_Time_Value tv (time_);
136 this->orb_->run (tv);
140 return 0;
143 private:
144 CORBA::ORB_var orb_;
145 long time_;
149 TAO_Naming_Service::run ()
151 ORB_Runner runner (this->orb_.in(), time_);
152 if (this->num_threads_ == 1)
153 return runner.svc();
154 else
156 int grpid = runner.activate ( THR_NEW_LWP | THR_JOINABLE | THR_INHERIT_SCHED,
157 this->num_threads_);
158 if (grpid == -1)
160 ORBSVCS_ERROR ((LM_ERROR,
161 ACE_TEXT ("Naming_Service(%P)::run %p\n"),
162 ACE_TEXT ("thread acitvation")));
163 return -1;
165 runner.wait();
167 return 0;
170 void
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");
195 return -1;
197 return 0;
200 // Destructor.
201 TAO_Naming_Service::~TAO_Naming_Service ()