1 #include "Scheduling_Service.h"
3 #include "ace/Get_Opt.h"
5 #include "ace/Argv_Type_Converter.h"
6 #include "orbsvcs/CosNamingC.h"
7 #include "ace/OS_main.h"
8 #include "ace/OS_NS_stdio.h"
9 #include "ace/OS_NS_strings.h"
10 #include "ace/OS_NS_unistd.h"
12 TAO_Scheduling_Service::TAO_Scheduling_Service ()
13 : scheduler_impl_ (0),
14 service_name_ ("ScheduleService"),
15 scheduler_type_ (CONFIG
)
19 // Constructor taking the command-line arguments.
20 TAO_Scheduling_Service::TAO_Scheduling_Service (int argc
, ACE_TCHAR
* argv
[])
21 : scheduler_impl_ (0),
22 service_name_ ("ScheduleService"),
23 scheduler_type_ (CONFIG
)
25 this->init (argc
, argv
);
28 TAO_Scheduling_Service::~TAO_Scheduling_Service ()
32 // Initialize the Scheduling Service with the arguments.
34 TAO_Scheduling_Service::init (int argc
, ACE_TCHAR
* argv
[])
38 PortableServer::POAManager_ptr poa_manager
;
42 // Copy command line parameter.
43 ACE_Argv_Type_Converter
command_line(argc
, argv
);
45 // Initialize ORB manager.
46 this->orb_manager_
.init (command_line
.get_argc(), command_line
.get_TCHAR_argv());
48 orb
= this->orb_manager_
.orb ();
50 poa_manager
= this->orb_manager_
.poa_manager ();
52 poa_manager
->activate ();
54 // Check the non-ORB arguments. this needs to come before we
55 // initialize the scheduler implementation so that we know which
56 // type of scheduler to use.
58 result
= this->parse_args (command_line
.get_argc(), command_line
.get_TCHAR_argv());
62 // Construct a scheduler implementation of the specified type.
63 switch (this->scheduler_type_
)
66 ACE_NEW_THROW_EX (scheduler_impl_
,
72 ACE_NEW_THROW_EX (scheduler_impl_
,
78 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
79 "TAO_Scheduling_Service::init: "
80 "unrecognized Scheduler_Type"), -1);
83 // Locate the naming service.
84 CORBA::Object_var naming_obj
=
85 orb
->resolve_initial_references ("NameService");
87 if (CORBA::is_nil (naming_obj
.in ()))
88 ORBSVCS_ERROR_RETURN ((LM_ERROR
,
89 " (%P|%t) Unable to locate the Naming Service.\n"),
91 CosNaming::NamingContext_var naming_context
=
92 CosNaming::NamingContext::_narrow (naming_obj
.in ());
94 RtecScheduler::Scheduler_var scheduler
=
95 this->scheduler_impl_
->_this ();
97 CORBA::String_var scheduler_ior_string
=
98 orb
->object_to_string (scheduler
.in ());
100 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT("The scheduler IOR is <%C>\n"),
101 scheduler_ior_string
.in ()));
103 // Register the servant with the Naming Context....
104 CosNaming::Name
schedule_name (1);
105 schedule_name
.length (1);
106 schedule_name
[0].id
= CORBA::string_dup (this->service_name_
.rep());
107 naming_context
->rebind (schedule_name
, scheduler
.in ());
109 if (this->ior_file_name_
.rep() != 0)
111 FILE *iorf
= ACE_OS::fopen (this->ior_file_name_
.rep(), "w");
114 ACE_OS::fprintf (iorf
,
116 scheduler_ior_string
.in ());
117 ACE_OS::fclose (iorf
);
121 if (this->pid_file_name_
.rep() != 0)
123 FILE *pidf
= ACE_OS::fopen (this->pid_file_name_
.rep(), "w");
126 ACE_OS::fprintf (pidf
,
128 static_cast<long> (ACE_OS::getpid ()));
129 ACE_OS::fclose (pidf
);
133 catch (const CORBA::Exception
& ex
)
135 ex
._tao_print_exception ("TAO_Scheduling_Service::init");
143 // Runs the TAO_Scheduling_Service.
146 TAO_Scheduling_Service::run ()
148 // Run the ORB manager.
149 return this->orb_manager_
.run ();
153 // Parses the command line arguments.
156 TAO_Scheduling_Service::parse_args (int argc
, ACE_TCHAR
* argv
[])
158 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("n:p:o:s:"));
161 while ((opt
= get_opt ()) != EOF
)
166 this->service_name_
= ACE_TEXT_ALWAYS_CHAR(get_opt
.opt_arg ());
170 this->pid_file_name_
= ACE_TEXT_ALWAYS_CHAR(get_opt
.opt_arg ());
174 this->ior_file_name_
= ACE_TEXT_ALWAYS_CHAR(get_opt
.opt_arg ());
178 if (ACE_OS::strcasecmp (ACE_TEXT("CONFIG"), get_opt
.optarg
) == 0)
180 this->scheduler_type_
= CONFIG
;
182 else if (ACE_OS::strcasecmp (ACE_TEXT("RECONFIG"), get_opt
.optarg
) == 0)
184 this->scheduler_type_
= RECONFIG
;
188 ORBSVCS_DEBUG ((LM_DEBUG
,
191 "[-p pid_file_name] "
192 "[-o ior_file_name] "
193 "[-s <CONFIG | reconfig>]"
204 ORBSVCS_DEBUG ((LM_DEBUG
,
207 "[-p pid_file_name] "
208 "[-o ior_file_name] "
209 "[-s <CONFIG | reconfig>]"
220 int ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
224 TAO_Scheduling_Service scheduling_service
;
226 ORBSVCS_DEBUG ((LM_DEBUG
,
227 "%s; initializing scheduling service\n", __FILE__
));
229 if (scheduling_service
.init (argc
, argv
) < 0)
230 ORBSVCS_ERROR_RETURN ((LM_ERROR
, "%p\n", "init"), 1);
232 ORBSVCS_DEBUG ((LM_DEBUG
,
233 "%s; running scheduling service\n", __FILE__
));
235 scheduling_service
.run ();
237 catch (const CORBA::Exception
& ex
)
239 ex
._tao_print_exception ("schedule_service");