diff options
author | jtc <jtc@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2006-12-14 09:11:57 +0000 |
---|---|---|
committer | jtc <jtc@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2006-12-14 09:11:57 +0000 |
commit | a0bd52b900a61c23810c46b7865aebe1a45807c9 (patch) | |
tree | 7d271525649f968510f2256dad689f96ed11d281 /TAO/orbsvcs/Logging_Service | |
parent | cc5f2bd3005c0a835feb4abda293ef12901e48e2 (diff) | |
download | ATCD-a0bd52b900a61c23810c46b7865aebe1a45807c9.tar.gz |
ChangeLogTag: Thu Dec 14 08:47:25 UTC 2006 J.T. Conklin <jtc@acorntoolworks.com>
Diffstat (limited to 'TAO/orbsvcs/Logging_Service')
9 files changed, 412 insertions, 442 deletions
diff --git a/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.cpp b/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.cpp index e782bb204f7..54f2829e160 100644 --- a/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.cpp +++ b/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.cpp @@ -14,7 +14,7 @@ Basic_Logging_Service::Basic_Logging_Service (void) : service_name_ ("BasicLogFactory"), ior_file_name_ (0), pid_file_name_ (0), - bind_to_naming_service_ (1), + bind_to_naming_service_ (true), nthreads_ (0) { // No-Op. @@ -26,8 +26,8 @@ Basic_Logging_Service::~Basic_Logging_Service (void) } void -Basic_Logging_Service::init_ORB (int& argc, char *argv [] - ACE_ENV_ARG_DECL) +Basic_Logging_Service::init_ORB (int& argc, char *argv [] + ACE_ENV_ARG_DECL) { this->orb_ = CORBA::ORB_init (argc, argv, @@ -35,7 +35,7 @@ Basic_Logging_Service::init_ORB (int& argc, char *argv [] ACE_ENV_ARG_PARAMETER); ACE_CHECK; - CORBA::Object_var poa_object = + CORBA::Object_var poa_object = this->orb_->resolve_initial_references("RootPOA" ACE_ENV_ARG_PARAMETER); ACE_CHECK; @@ -64,23 +64,23 @@ Basic_Logging_Service::parse_args (int argc, char *argv[]) switch (opt) { case 'n': - service_name_ = get_opt.opt_arg(); + this->service_name_ = get_opt.opt_arg (); break; case 'o': - ior_file_name_ = get_opt.opt_arg(); + this->ior_file_name_ = get_opt.opt_arg (); break; case 'p': - pid_file_name_ = get_opt.opt_arg(); + this->pid_file_name_ = get_opt.opt_arg (); break; case 't': - nthreads_ = ACE_OS::atoi (get_opt.opt_arg ()); + this->nthreads_ = ACE_OS::atoi (get_opt.opt_arg ()); break; case 'x': - bind_to_naming_service_ = 0; + this->bind_to_naming_service_ = false; break; case '?': @@ -104,7 +104,7 @@ Basic_Logging_Service::parse_args (int argc, char *argv[]) int Basic_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) { - // initalize the ORB. + // initialize the ORB. this->init_ORB (argc, argv ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); @@ -113,7 +113,6 @@ Basic_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) return -1; // Activate the basic log factory - // CORBA::Object_var obj = DsLogAdmin::BasicLogFactory_var obj = this->basic_log_factory_.activate (this->orb_.in (), this->poa_.in () @@ -140,23 +139,24 @@ Basic_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) ACE_CHECK_RETURN (-1); } - if (ior_file_name_ != 0) + if (this->ior_file_name_ != 0) { - FILE* iorf = ACE_OS::fopen (ior_file_name_, ACE_TEXT("w")); - if (iorf == 0) { - ACE_ERROR_RETURN ((LM_ERROR, - "Cannot open output file for writing IOR: %s", - ior_file_name_), - -1); - } + FILE* iorf = ACE_OS::fopen (this->ior_file_name_, ACE_TEXT("w")); + if (iorf == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->ior_file_name_), + -1); + } ACE_OS::fprintf (iorf, "%s\n", ior.in ()); ACE_OS::fclose (iorf); } - if (pid_file_name_ != 0) + if (this->pid_file_name_ != 0) { - FILE* pidf = ACE_OS::fopen (pid_file_name_, ACE_TEXT("w")); + FILE* pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("w")); if (pidf != 0) { ACE_OS::fprintf (pidf, @@ -166,15 +166,12 @@ Basic_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) } } - if (bind_to_naming_service_) + if (this->bind_to_naming_service_) { // Resolve the naming service. this->resolve_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK_RETURN (-1); - // Register the Basic Log Factory. - ACE_ASSERT(!CORBA::is_nil (this->naming_.in ())); - CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (this->service_name_); @@ -225,7 +222,7 @@ Basic_Logging_Service::run (ACE_ENV_SINGLE_ARG_DECL) } int -Basic_Logging_Service::svc () +Basic_Logging_Service::svc (void) { ACE_DECLARE_NEW_CORBA_ENV; ACE_TRY @@ -245,32 +242,18 @@ Basic_Logging_Service::svc () void Basic_Logging_Service::shutdown (ACE_ENV_SINGLE_ARG_DECL) { - // @@ JTC - factory object isn't activated on root poa. -#if 0 - // Deactivate. - PortableServer::ObjectId_var oid = - this->poa_->servant_to_id (&this->basic_log_factory_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // Deactivate from the poa. - this->poa_->deactivate_object (oid.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -#endif - - if (bind_to_naming_service_) + if (this->bind_to_naming_service_) { - // Unbind from the naming service. CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (this->service_name_); this->naming_->unbind (name ACE_ENV_ARG_PARAMETER); + ACE_CHECK; } - // Shutdown the ORB. + // shutdown the ORB. if (!CORBA::is_nil (this->orb_.in ())) this->orb_->shutdown (); } diff --git a/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.h b/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.h index 57066ebf020..91af3e22296 100644 --- a/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.h +++ b/TAO/orbsvcs/Logging_Service/Basic_Logging_Service/Basic_Logging_Service.h @@ -87,7 +87,7 @@ protected: const char* pid_file_name_; // The name of the file where we output the process id. - int bind_to_naming_service_; + bool bind_to_naming_service_; // If true, bind to naming service int nthreads_; diff --git a/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.cpp b/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.cpp index be47a102d7c..6020302f152 100644 --- a/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.cpp +++ b/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.cpp @@ -15,7 +15,7 @@ Event_Logging_Service::Event_Logging_Service (void) : service_name_ ("EventLogFactory"), ior_file_name_ (0), pid_file_name_ (0), - bind_to_naming_service_ (1), + bind_to_naming_service_ (true), nthreads_ (0) { // No-Op. @@ -27,8 +27,8 @@ Event_Logging_Service::~Event_Logging_Service (void) } void -Event_Logging_Service::init_ORB (int& argc, char *argv [] - ACE_ENV_ARG_DECL) +Event_Logging_Service::init_ORB (int& argc, char *argv [] + ACE_ENV_ARG_DECL) { this->orb_ = CORBA::ORB_init (argc, argv, @@ -36,7 +36,7 @@ Event_Logging_Service::init_ORB (int& argc, char *argv [] ACE_ENV_ARG_PARAMETER); ACE_CHECK; - CORBA::Object_var poa_object = + CORBA::Object_var poa_object = this->orb_->resolve_initial_references("RootPOA" ACE_ENV_ARG_PARAMETER); ACE_CHECK; @@ -65,23 +65,23 @@ Event_Logging_Service::parse_args (int argc, char *argv[]) switch (opt) { case 'n': - service_name_ = get_opt.opt_arg(); + this->service_name_ = get_opt.opt_arg (); break; case 'o': - ior_file_name_ = get_opt.opt_arg(); + this->ior_file_name_ = get_opt.opt_arg (); break; case 'p': - pid_file_name_ = get_opt.opt_arg(); + this->pid_file_name_ = get_opt.opt_arg (); break; case 't': - nthreads_ = ACE_OS::atoi (get_opt.opt_arg ()); + this->nthreads_ = ACE_OS::atoi (get_opt.opt_arg ()); break; case 'x': - bind_to_naming_service_ = 0; + this->bind_to_naming_service_ = false; break; case '?': @@ -105,7 +105,7 @@ Event_Logging_Service::parse_args (int argc, char *argv[]) int Event_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) { - // initalize the ORB. + // initialize the ORB. this->init_ORB (argc, argv ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); @@ -118,7 +118,6 @@ Event_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) TAO_EventLogFactory_i (), CORBA::NO_MEMORY ()); - // CORBA::Object_var obj = DsEventLogAdmin::EventLogFactory_var obj = this->event_log_factory_->activate (this->orb_.in (), this->poa_.in () @@ -145,23 +144,23 @@ Event_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) ACE_CHECK_RETURN (-1); } - if (ior_file_name_ != 0) + if (this->ior_file_name_ != 0) { - FILE* iorf = ACE_OS::fopen (ior_file_name_, ACE_TEXT("w")); - if (iorf == 0) { - ACE_ERROR_RETURN ((LM_ERROR, - "Cannot open output file for writing IOR: %s", - ior_file_name_), - -1); - } - + FILE* iorf = ACE_OS::fopen (this->ior_file_name_, ACE_TEXT("w")); + if (iorf == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->ior_file_name_), + -1); + } ACE_OS::fprintf (iorf, "%s\n", ior.in ()); ACE_OS::fclose (iorf); } - if (pid_file_name_ != 0) + if (this->pid_file_name_ != 0) { - FILE* pidf = ACE_OS::fopen (pid_file_name_, ACE_TEXT("w")); + FILE* pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("w")); if (pidf != 0) { ACE_OS::fprintf (pidf, @@ -171,15 +170,13 @@ Event_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) } } - if (bind_to_naming_service_) + if (this->bind_to_naming_service_) { // Resolve the naming service. this->resolve_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK_RETURN (-1); // Register the Event Log Factory. - ACE_ASSERT(!CORBA::is_nil (this->naming_.in ())); - CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (this->service_name_); @@ -250,29 +247,15 @@ Event_Logging_Service::svc (void) void Event_Logging_Service::shutdown (ACE_ENV_SINGLE_ARG_DECL) { - // @@ JTC - factory object isn't activated on root poa. -#if 0 - // Deactivate. - PortableServer::ObjectId_var oid = - this->poa_->servant_to_id (this->event_log_factory_ - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // deactivate from the poa. - this->poa_->deactivate_object (oid.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -#endif - - if (bind_to_naming_service_) + if (this->bind_to_naming_service_) { - // Unbind from the naming service. CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (this->service_name_); this->naming_->unbind (name ACE_ENV_ARG_PARAMETER); + ACE_CHECK; } // shutdown the ORB. diff --git a/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.h b/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.h index de98deb20f9..36be03ed34d 100644 --- a/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.h +++ b/TAO/orbsvcs/Logging_Service/Event_Logging_Service/Event_Logging_Service.h @@ -88,7 +88,7 @@ protected: const char* pid_file_name_; // The name of the file where we output the process id. - int bind_to_naming_service_; + bool bind_to_naming_service_; // If true, bind to naming service int nthreads_; diff --git a/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.cpp b/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.cpp index 12b4c5d8d87..00f6f2e038d 100644 --- a/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.cpp +++ b/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.cpp @@ -16,7 +16,7 @@ Notify_Logging_Service::Notify_Logging_Service (void) : service_name_ (NOTIFY_KEY), ior_file_name_ (0), pid_file_name_ (0), - bind_to_naming_service_ (1), + bind_to_naming_service_ (true), nthreads_ (0) { // No-Op. @@ -45,18 +45,18 @@ Notify_Logging_Service::init_ORB (int& argc, char *argv [] return -1; } - CORBA::Object_var poa_obj = + CORBA::Object_var poa_object = this->orb_->resolve_initial_references("RootPOA" ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); - if (CORBA::is_nil (poa_obj.in ())) + if (CORBA::is_nil (poa_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to resolve the RootPOA.\n"), -1); this->poa_ = - PortableServer::POA::_narrow (poa_obj.in () + PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); @@ -81,23 +81,23 @@ Notify_Logging_Service::parse_args (int argc, char *argv[]) switch (opt) { case 'n': - service_name_ = get_opt.opt_arg(); + this->service_name_ = get_opt.opt_arg (); break; case 'o': - ior_file_name_ = get_opt.opt_arg(); + this->ior_file_name_ = get_opt.opt_arg (); break; case 'p': - pid_file_name_ = get_opt.opt_arg(); + this->pid_file_name_ = get_opt.opt_arg (); break; case 't': - nthreads_ = ACE_OS::atoi (get_opt.opt_arg ()); + this->nthreads_ = ACE_OS::atoi (get_opt.opt_arg ()); break; case 'x': - bind_to_naming_service_ = 0; + this->bind_to_naming_service_ = false; break; case '?': @@ -107,6 +107,7 @@ Notify_Logging_Service::parse_args (int argc, char *argv[]) "-n service_name " "-o ior_file_name " "-p pid_file_name " + "-t threads " "-x [disable naming service bind] " "\n", argv[0])); @@ -121,7 +122,7 @@ int Notify_Logging_Service::init (int argc, char *argv[] ACE_ENV_ARG_DECL) { - // initalize the ORB. + // initialize the ORB. if (this->init_ORB (argc, argv ACE_ENV_ARG_PARAMETER) != 0) return -1; @@ -167,14 +168,14 @@ Notify_Logging_Service::init (int argc, char *argv[] ACE_CHECK_RETURN (-1); } - if (ior_file_name_ != 0) + if (this->ior_file_name_ != 0) { - FILE* iorf = ACE_OS::fopen (ior_file_name_, ACE_TEXT("w")); + FILE* iorf = ACE_OS::fopen (this->ior_file_name_, ACE_TEXT("w")); if (iorf == 0) { ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: %s", - ior_file_name_), + this->ior_file_name_), -1); } @@ -182,9 +183,9 @@ Notify_Logging_Service::init (int argc, char *argv[] ACE_OS::fclose (iorf); } - if (pid_file_name_ != 0) + if (this->pid_file_name_ != 0) { - FILE* pidf = ACE_OS::fopen (pid_file_name_, ACE_TEXT("w")); + FILE* pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("w")); if (pidf != 0) { ACE_OS::fprintf (pidf, @@ -194,19 +195,15 @@ Notify_Logging_Service::init (int argc, char *argv[] } } - if (bind_to_naming_service_) + if (this->bind_to_naming_service_) { // Resolve the naming service. - resolve_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER); + this->resolve_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_CHECK_RETURN (-1); - // Register the Factory - ACE_ASSERT (!CORBA::is_nil (this->naming_.in ())); - CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (this->service_name_); - ACE_CHECK_RETURN (-1); this->naming_->rebind (name, obj.in () @@ -231,7 +228,7 @@ Notify_Logging_Service::resolve_naming_service (ACE_ENV_SINGLE_ARG_DECL) this->naming_ = CosNaming::NamingContext::_narrow (naming_obj.in () - ACE_ENV_ARG_PARAMETER); + ACE_ENV_ARG_PARAMETER); ACE_CHECK; } @@ -254,7 +251,7 @@ Notify_Logging_Service::run (ACE_ENV_SINGLE_ARG_DECL) } int -Notify_Logging_Service::svc () +Notify_Logging_Service::svc (void) { ACE_DECLARE_NEW_CORBA_ENV; ACE_TRY @@ -274,26 +271,11 @@ Notify_Logging_Service::svc () void Notify_Logging_Service::shutdown (ACE_ENV_SINGLE_ARG_DECL) { - // @@ JTC - factory object isn't activated on root poa. -#if 0 - // Deactivate. - PortableServer::ObjectId_var oid = - this->poa_->reference_to_id (this->notify_log_factory_.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - - // deactivate from the poa. - this->poa_->deactivate_object (oid.in () - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; -#endif - - if (bind_to_naming_service_) + if (this->bind_to_naming_service_) { CosNaming::Name name (1); name.length (1); name[0].id = CORBA::string_dup (this->service_name_); - ACE_CHECK; this->naming_->unbind (name ACE_ENV_ARG_PARAMETER); diff --git a/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.h b/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.h index c6d5f3a459b..ed1202bcd9b 100644 --- a/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.h +++ b/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.h @@ -98,7 +98,7 @@ protected: const char* pid_file_name_; // The name of the file where we output the process id. - int bind_to_naming_service_; + bool bind_to_naming_service_; // If true, bind to naming service int nthreads_; diff --git a/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Server.cpp b/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Server.cpp new file mode 100644 index 00000000000..5b3ba58a51d --- /dev/null +++ b/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Server.cpp @@ -0,0 +1,82 @@ +#include "RTEvent_Logging_Service.h" +#include "orbsvcs/Event/EC_Default_Factory.h" +#include "ace/OS_main.h" + +#include "orbsvcs/Shutdown_Utilities.h" +#include "tao/debug.h" + +ACE_RCSID (RTEvent_Logging_Service, + RTEvent_Logging_Server, + "$Id$") + + +class Logging_Svc_Shutdown + : public Shutdown_Functor +{ +public: + Logging_Svc_Shutdown (RTEvent_Logging_Service& svc); + + void operator() (int which_signal); + +private: + RTEvent_Logging_Service& svc_; +}; + +Logging_Svc_Shutdown::Logging_Svc_Shutdown (RTEvent_Logging_Service& svc) + : svc_ (svc) +{ +} + +void +Logging_Svc_Shutdown::operator() (int which_signal) +{ + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + "RTEvent_Logging_Service: shutting down on signal %d\n", + which_signal)); + + ACE_DECLARE_NEW_CORBA_ENV; + (void) this->svc_.shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); +} + +// Driver function for the RTEvent_Logging_Service + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + TAO_EC_Default_Factory::init_svcs (); + + RTEvent_Logging_Service service; + + Logging_Svc_Shutdown killer (service); + Service_Shutdown kill_contractor (killer); + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + int rc; + + rc = service.init (argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (rc == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Failed to initialize the Telecom Log Service.\n"), + 1); + + rc = service.run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + if (rc == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Failed to start the Telecom Log Service.\n"), + 1); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Failed to start the Telecom Log Service.\n"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp b/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp index 02dce835e2e..fa49a6952ed 100644 --- a/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp +++ b/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp @@ -1,341 +1,269 @@ #include "RTEvent_Logging_Service.h" -#include "ace/Get_Opt.h" -#include "ace/Auto_Ptr.h" -#include "orbsvcs/CosNamingC.h" -#include "orbsvcs/Event_Utilities.h" -#include "orbsvcs/Sched/Config_Scheduler.h" -#include "orbsvcs/Event/EC_Default_Factory.h" -#include "orbsvcs/Event/EC_Event_Channel.h" #include "tao/IORTable/IORTable.h" -#include "ace/OS_main.h" -#include "ace/OS_NS_strings.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_unistd.h" ACE_RCSID (RTEvent_Logging_Service, RTEvent_Logging_Service, "$Id$") -int -ACE_TMAIN (int argc, ACE_TCHAR *argv[]) -{ - TAO_EC_Default_Factory::init_svcs (); - - RTEvent_Logging_Service event_service; - return event_service.run (argc, argv); -} - -// **************************************************************** RTEvent_Logging_Service::RTEvent_Logging_Service (void) - : sched_impl_ (0), - // ec_impl_ (0), - service_name_ (0), + : service_name_ ("RTEventLogFactory"), ior_file_name_ (0), pid_file_name_ (0), - global_scheduler_ (0), - rtevent_log_factory_name_ ("RTEventLogFactory"), - child_poa_name_ ("RTEventLog_ChildPOA"), - factory_servant_ (0) + bind_to_naming_service_ (true), + nthreads_ (0) { + // No-Op. } RTEvent_Logging_Service::~RTEvent_Logging_Service (void) { - //delete this->ec_impl_; - //this->ec_impl_ = 0; - //delete this->sched_impl_; - //this->sched_impl_ = 0; + // No-Op. } -int -RTEvent_Logging_Service::run (int argc, char* argv[]) +void +RTEvent_Logging_Service::init_ORB (int& argc, char *argv[] + ACE_ENV_ARG_DECL) { - ACE_TRY_NEW_ENV - { - // Initialize ORB. - this->orb_ = - CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - if (this->parse_args (argc, argv) == -1) - return 1; - - ACE_NEW_RETURN (factory_servant_, - TAO_RTEventLogFactory_i (), - -1); - - CORBA::Object_var poa_object = - this->orb_->resolve_initial_references("RootPOA" - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - if (CORBA::is_nil (poa_object.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - " (%P|%t) Unable to initialize the POA.\n"), - 1); - - this->root_poa_ = - PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - PortableServer::POAManager_var poa_manager = - this->root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - CORBA::Object_var naming_obj = - this->orb_->resolve_initial_references ("NameService" ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; + this->orb_ = CORBA::ORB_init (argc, + argv, + "" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Object_var poa_object = + this->orb_->resolve_initial_references("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->poa_ = + PortableServer::POA::_narrow (poa_object.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + PortableServer::POAManager_var poa_manager = + this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; +} - if (CORBA::is_nil (naming_obj.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - " (%P|%t) Unable to initialize the Naming Service.\n"), - 1); - CosNaming::NamingContext_var context = - CosNaming::NamingContext::_narrow (naming_obj.in () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; +int +RTEvent_Logging_Service::parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("n:o:p:t:x")); + int opt; -// Alternative way to get NamingContext. -/* if (naming_client_.init (orb_.in ()) != 0) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) Unable to initialize " - "the TAO_Naming_Client. \n"), - 1); + while ((opt = get_opt ()) != EOF) + { + switch (opt) + { + case 'n': + this->service_name_ = get_opt.opt_arg (); + break; - CosNaming::NamingContext_var context = - naming_client_.get_context (); -*/ + case 'o': + this->ior_file_name_ = get_opt.opt_arg (); + break; - RtecScheduler::Scheduler_var scheduler; - // This is the name we (potentially) register the Scheduling - // Service in the Naming Service. + case 'p': + this->pid_file_name_ = get_opt.opt_arg (); + break; - CosNaming::Name schedule_name (1); - schedule_name.length (1); - schedule_name[0].id = CORBA::string_dup ("ScheduleService"); + case 't': + this->nthreads_ = ACE_OS::atoi (get_opt.opt_arg ()); + break; + case 'x': + this->bind_to_naming_service_ = false; + break; - if (1) // this->event_service_type_ == ES_OLD_REACTIVE - // || this->event_service_type_ == ES_OLD_MT) - { - // We must find the scheduler object reference... - - if (this->global_scheduler_ == 0) - { - ACE_NEW_RETURN (this->sched_impl_, - ACE_Config_Scheduler, - 1); - - scheduler = this->sched_impl_->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - // Register the servant with the Naming Context.... - context->rebind (schedule_name, scheduler.in () - ACE_ENV_ARG_PARAMETER); - - ACE_TRY_CHECK; - } - else - { - CORBA::Object_var tmp = - context->resolve (schedule_name ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - scheduler = RtecScheduler::Scheduler::_narrow (tmp.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } + case '?': + default: + ACE_DEBUG ((LM_DEBUG, + "Usage: %s " + "-n service_name " + "-o ior_file_name " + "-p pid_file_name " + "-t threads " + "-x [disable naming service bind] " + "\n", + argv[0])); + return -1; } + } + return 0; +} +int +RTEvent_Logging_Service::init (int argc, char* argv[] ACE_ENV_ARG_DECL) +{ + // initialize the ORB. + this->init_ORB (argc, argv + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + if (this->parse_args (argc, argv) == -1) + return -1; + + // Activate the rtevent log factory + ACE_NEW_THROW_EX (this->rtevent_log_factory_, + TAO_RTEventLogFactory_i (), + CORBA::NO_MEMORY ()); + + if (this->rtevent_log_factory_->init (orb_.in (), + poa_.in () + ACE_ENV_ARG_PARAMETER) != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Unable to initialize " + "the factory. \n"), + -1); + } -/* - TAO_EC_Event_Channel_Attributes attr (root_poa.in (), - root_poa.in ()); - TAO_EC_Event_Channel* ec; - ACE_NEW_RETURN (ec, - TAO_EC_Event_Channel (attr), - 1); - this->ec_impl_ = ec; - ec->activate (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; -*/ - // Notice that we activate *this* object with the POA, but we - // forward all the requests to the underlying EC - // implementation. -/* - RtecEventChannelAdmin::EventChannel_var ec = - this->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - - CORBA::String_var str = - this->orb_->object_to_string (ec.in () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - + RTEventLogAdmin::EventLogFactory_var obj = + this->rtevent_log_factory_->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); - ACE_DEBUG ((LM_DEBUG, - "The EC IOR is <%s>\n", str.in ())); + CORBA::String_var ior = + this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); - CosNaming::Name channel_name (1); - channel_name.length (1); - channel_name[0].id = CORBA::string_dup (this->service_name_); - naming_context->rebind (channel_name, ec.in () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; -*/ - - if (factory_servant_->init (orb_.in (), - root_poa_.in () - ACE_ENV_ARG_PARAMETER) != 0) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) Unable to initialize " - "the factory. \n"), - 1); - - // activate the factory in the root poa. - factory_ = factory_servant_->_this (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; + if (true) + { + CORBA::Object_var table_object = + this->orb_->resolve_initial_references ("IORTable" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); - // Give the ownership to the POA. - factory_servant_->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); + IORTable::Table_var adapter = + IORTable::Table::_narrow (table_object.in ()); + ACE_CHECK_RETURN (-1); - ACE_TRY_CHECK; - CORBA::String_var - ior = orb_->object_to_string (factory_.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; + adapter->bind("RTEventLogService", ior.in ()); + ACE_CHECK_RETURN (-1); + } - if (true) + if (this->ior_file_name_ != 0) + { + FILE* iorf = ACE_OS::fopen (this->ior_file_name_, ACE_TEXT("w")); + if (iorf == 0) { - CORBA::Object_var table_object = - this->orb_->resolve_initial_references ("IORTable" - ACE_ENV_ARG_PARAMETER); - ACE_CHECK_RETURN (-1); - - IORTable::Table_var adapter = - IORTable::Table::_narrow (table_object.in ()); - ACE_CHECK_RETURN (-1); - - adapter->bind("RTEventLogService", ior.in ()); - ACE_CHECK_RETURN (-1); + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->ior_file_name_), + -1); } + ACE_OS::fprintf (iorf, "%s\n", ior.in ()); + ACE_OS::fclose (iorf); + } - if (this->ior_file_name_ != 0) + if (this->pid_file_name_ != 0) + { + FILE* pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("w")); + if (pidf != 0) { - FILE *output_file= ACE_OS::fopen (this->ior_file_name_, "w"); - if (output_file == 0) - ACE_ERROR_RETURN ((LM_ERROR, - "Cannot open output file for writing IOR: %s", - this->ior_file_name_), - 1); - ACE_OS::fprintf (output_file, "%s", ior.in ()); - ACE_OS::fclose (output_file); + ACE_OS::fprintf (pidf, + "%ld\n", + static_cast<long> (ACE_OS::getpid ())); + ACE_OS::fclose (pidf); } + } - if (this->pid_file_name_ != 0) - { - FILE *pidf = fopen (this->pid_file_name_, "w"); - if (pidf != 0) - { - ACE_OS::fprintf (pidf, - "%ld\n", - static_cast<long> (ACE_OS::getpid ())); - ACE_OS::fclose (pidf); - } - } + if (this->bind_to_naming_service_) + { + // Resolve the naming service. + this->resolve_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); CosNaming::Name name (1); name.length (1); - name[0].id = CORBA::string_dup (rtevent_log_factory_name_); - context->rebind (name, - factory_.in () - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; + name[0].id = CORBA::string_dup (this->service_name_); - this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; + this->naming_->rebind (name, + obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + } - context->unbind (name ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; + return 0; +} - if (!CORBA::is_nil (scheduler.in ())) - { - context->unbind (schedule_name ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - } +void +RTEvent_Logging_Service::resolve_naming_service (ACE_ENV_SINGLE_ARG_DECL) +{ + CORBA::Object_var naming_obj = + this->orb_->resolve_initial_references ("NameService" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + // Need to check return value for errors. + if (CORBA::is_nil (naming_obj.in ())) + ACE_THROW (CORBA::UNKNOWN ()); + + this->naming_ = + CosNaming::NamingContext::_narrow (naming_obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} - } - ACE_CATCHANY +int +RTEvent_Logging_Service::run (ACE_ENV_SINGLE_ARG_DECL) +{ + if (this->nthreads_ > 0) { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "EC"); + if (this->activate ((THR_NEW_LWP | THR_JOINABLE), this->nthreads_) != 0) + return -1; + + this->thr_mgr ()->wait (); + return 0; } - ACE_ENDTRY; + this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); return 0; } int -RTEvent_Logging_Service::parse_args (int argc, char *argv []) +RTEvent_Logging_Service::svc (void) { - // default values... - this->service_name_ = "EventService"; - - ACE_Get_Opt get_opt (argc, argv, "n:o:p:s:"); - int opt; - - while ((opt = get_opt ()) != EOF) + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY { - switch (opt) - { - case 'n': - this->service_name_ = get_opt.opt_arg (); - break; - - case 'o': - this->ior_file_name_ = get_opt.opt_arg (); - break; + this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + return -1; + } + ACE_ENDTRY; - case 'p': - this->pid_file_name_ = get_opt.opt_arg (); - break; + return 0; +} - case 's': - // It could be just a flag (i.e. no "global" or "local" - // argument, but this is consistent with the EC_Multiple - // test and also allows for a runtime scheduling service. - - if (ACE_OS::strcasecmp (get_opt.opt_arg (), "global") == 0) - { - this->global_scheduler_ = 1; - } - else if (ACE_OS::strcasecmp (get_opt.opt_arg (), "local") == 0) - { - this->global_scheduler_ = 0; - } - else - { - ACE_DEBUG ((LM_DEBUG, - "Unknown scheduling type <%s> " - "defaulting to local\n", - get_opt.opt_arg ())); - this->global_scheduler_ = 0; - } - break; +void +RTEvent_Logging_Service::shutdown (ACE_ENV_SINGLE_ARG_DECL) +{ + if (this->bind_to_naming_service_) + { + CosNaming::Name name (1); + name.length (1); + name[0].id = CORBA::string_dup (this->service_name_); - case '?': - default: - ACE_DEBUG ((LM_DEBUG, - "Usage: %s " - "-n service_name " - "-o ior_file_name " - "-p pid_file_name " - "-s <global|local> " - "\n", - argv[0])); - return -1; - } + this->naming_->unbind (name + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; } - return 0; + // shutdown the ORB. + if (!CORBA::is_nil (this->orb_.in ())) + this->orb_->shutdown (); } diff --git a/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.h b/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.h index 629155423b4..535fea9fbe0 100644 --- a/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.h +++ b/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.h @@ -17,68 +17,80 @@ #ifndef RTEVENT_LOGGING_SERVICE_H #define RTEVENT_LOGGING_SERVICE_H -#include "orbsvcs/RtecEventChannelAdminS.h" -#include "orbsvcs/RtecSchedulerS.h" - -#include "orbsvcs/RTEventLogAdminS.h" - -#include "orbsvcs/Log/RTEventLogFactory_i.h" - +#include "ace/Task.h" #include "orbsvcs/CosNamingC.h" -#include "orbsvcs/Naming/Naming_Client.h" - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ +#include "orbsvcs/Log/RTEventLogFactory_i.h" class RTEvent_Logging_Service + : public ACE_Task_Base { + // = TITLE + // RTEvent_Logging_Service + // + // = DESCRIPTION + // Implementation of the Telecom Log Service + public: + // = Initialization and termination methods. RTEvent_Logging_Service (void); + // Constructor. + virtual ~RTEvent_Logging_Service (void); + // Destructor. - int run (int argc, char* argv[]); - // Run the event service. + int init (int argc, char* argv[]); + // Initializes the Telecom Log Service. -private: - int parse_args (int argc, char* argv[]); - // parse the command line args + int run (ACE_ENV_SINGLE_ARG_DECL); + // Run the Telecom Log Service. + // Returns 0 on success, -1 on error. -private: - POA_RtecScheduler::Scheduler *sched_impl_; - // The Scheduler implementation. + void shutdown (ACE_ENV_SINGLE_ARG_DECL); + // Shutdown the Telecom Log Service. + // Returns 0 on success, -1 on error. - const char* service_name_; - // The name we use to bind with the NameService - - const char* ior_file_name_; - // The name of the file were we output the Event_Service IOR. +protected: + void init_ORB (int& argc, char *argv [] + ACE_ENV_ARG_DECL); + // initializes the ORB. - const char* pid_file_name_; - // The name of a file where the process stores its pid - - int global_scheduler_; - // Should we use a global scheduler or a local one? + int parse_args (int argc, char* argv[]); + // parse the command line args - const char* rtevent_log_factory_name_; - // The name of the factory registered with the naming service. + void resolve_naming_service (ACE_ENV_SINGLE_ARG_DECL); + // Resolve the naming service. - const char* child_poa_name_; - // The name of the Child POA. + int svc (); + // Run worker threads. - TAO_RTEventLogFactory_i *factory_servant_; - // The factory servant. +private: + // = Data members + TAO_RTEventLogFactory_i *rtevent_log_factory_; + // The RTEvent Log Factory. CORBA::ORB_var orb_; // The ORB that we use. - PortableServer::POA_var root_poa_; + PortableServer::POA_var poa_; // Reference to the root poa. - RTEventLogAdmin::EventLogFactory_var factory_; - // The corba object after activation. + CosNaming::NamingContext_var naming_; + // A naming context. + + const char* service_name_; + // The name we use to bind with the NameService + + const char* ior_file_name_; + // The name of the file were we output the factory IOR. + + const char* pid_file_name_; + // The name of a file where the process stores its pid - TAO_Naming_Client naming_client_; + bool bind_to_naming_service_; + // If true, bind to naming service + + int nthreads_; + // Number of worker threads. }; #endif /* RTEVENT_LOGGING_SERVICE_H */ |