summaryrefslogtreecommitdiff
path: root/trunk/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'trunk/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp')
-rw-r--r--trunk/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp269
1 files changed, 269 insertions, 0 deletions
diff --git a/trunk/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp b/trunk/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp
new file mode 100644
index 00000000000..fa49a6952ed
--- /dev/null
+++ b/trunk/TAO/orbsvcs/Logging_Service/RTEvent_Logging_Service/RTEvent_Logging_Service.cpp
@@ -0,0 +1,269 @@
+#include "RTEvent_Logging_Service.h"
+#include "tao/IORTable/IORTable.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$")
+
+
+RTEvent_Logging_Service::RTEvent_Logging_Service (void)
+ : service_name_ ("RTEventLogFactory"),
+ ior_file_name_ (0),
+ pid_file_name_ (0),
+ bind_to_naming_service_ (true),
+ nthreads_ (0)
+{
+ // No-Op.
+}
+
+RTEvent_Logging_Service::~RTEvent_Logging_Service (void)
+{
+ // No-Op.
+}
+
+void
+RTEvent_Logging_Service::init_ORB (int& argc, char *argv[]
+ ACE_ENV_ARG_DECL)
+{
+ 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;
+}
+
+
+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;
+
+ while ((opt = get_opt ()) != EOF)
+ {
+ switch (opt)
+ {
+ case 'n':
+ this->service_name_ = get_opt.opt_arg ();
+ break;
+
+ case 'o':
+ this->ior_file_name_ = get_opt.opt_arg ();
+ break;
+
+ case 'p':
+ this->pid_file_name_ = get_opt.opt_arg ();
+ break;
+
+ case 't':
+ this->nthreads_ = ACE_OS::atoi (get_opt.opt_arg ());
+ break;
+
+ case 'x':
+ this->bind_to_naming_service_ = false;
+ break;
+
+ 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);
+ }
+
+ RTEventLogAdmin::EventLogFactory_var obj =
+ this->rtevent_log_factory_->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
+ ACE_CHECK_RETURN (-1);
+
+ CORBA::String_var ior =
+ this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (-1);
+
+ if (true)
+ {
+ 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);
+ }
+
+ if (this->ior_file_name_ != 0)
+ {
+ 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 (this->pid_file_name_ != 0)
+ {
+ FILE* pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("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 (this->service_name_);
+
+ this->naming_->rebind (name,
+ obj.in ()
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (-1);
+ }
+
+ return 0;
+}
+
+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;
+}
+
+int
+RTEvent_Logging_Service::run (ACE_ENV_SINGLE_ARG_DECL)
+{
+ if (this->nthreads_ > 0)
+ {
+ if (this->activate ((THR_NEW_LWP | THR_JOINABLE), this->nthreads_) != 0)
+ return -1;
+
+ this->thr_mgr ()->wait ();
+ return 0;
+ }
+
+ this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER);
+ ACE_CHECK_RETURN (-1);
+
+ return 0;
+}
+
+int
+RTEvent_Logging_Service::svc (void)
+{
+ ACE_DECLARE_NEW_CORBA_ENV;
+ ACE_TRY
+ {
+ this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER);
+ ACE_TRY_CHECK;
+ }
+ ACE_CATCHANY
+ {
+ return -1;
+ }
+ ACE_ENDTRY;
+
+ return 0;
+}
+
+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_);
+
+ this->naming_->unbind (name
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK;
+ }
+
+ // shutdown the ORB.
+ if (!CORBA::is_nil (this->orb_.in ()))
+ this->orb_->shutdown ();
+}