summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.cpp')
-rw-r--r--TAO/orbsvcs/Logging_Service/Notify_Logging_Service/Notify_Logging_Service.cpp145
1 files changed, 117 insertions, 28 deletions
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 f3b735e39db..70d68573c51 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
@@ -4,8 +4,9 @@
#include "ace/Arg_Shifter.h"
#include "ace/Get_Opt.h"
#include "tao/debug.h"
-#include "tao/IORTable/IORTable.h"
#include "orbsvcs/Notify/Service.h"
+#include "ace/OS_NS_stdio.h"
+#include "ace/OS_NS_unistd.h"
ACE_RCSID (Notify_Logging_Service,
Notify_Logging_Service,
@@ -13,7 +14,10 @@ ACE_RCSID (Notify_Logging_Service,
Notify_Logging_Service::Notify_Logging_Service (void)
-: notify_factory_name_ (NOTIFY_KEY)
+ : service_name_ (NOTIFY_KEY),
+ ior_file_name_ (0),
+ pid_file_name_ (0),
+ bind_to_naming_service_ (1)
{
// No-Op.
}
@@ -67,6 +71,49 @@ Notify_Logging_Service::init_ORB (int& argc, char *argv []
}
int
+Notify_Logging_Service::parse_args (int argc, char *argv[])
+{
+ ACE_Get_Opt get_opt (argc, argv, ACE_LIB_TEXT("n:o:p:x"));
+ int opt;
+
+ while ((opt = get_opt ()) != EOF)
+ {
+ switch (opt)
+ {
+ case 'n':
+ service_name_ = get_opt.opt_arg();
+ break;
+
+ case 'o':
+ ior_file_name_ = get_opt.opt_arg();
+ break;
+
+ case 'p':
+ pid_file_name_ = get_opt.opt_arg();
+ break;
+
+ case 'x':
+ bind_to_naming_service_ = 0;
+ break;
+
+ case '?':
+ default:
+ ACE_DEBUG ((LM_DEBUG,
+ "Usage: %s "
+ "-n service_name "
+ "-o ior_file_name "
+ "-p pid_file_name "
+ "-x [disable naming service bind] "
+ "\n",
+ argv[0]));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int
Notify_Logging_Service::init (int argc, char *argv[]
ACE_ENV_ARG_DECL)
{
@@ -75,11 +122,10 @@ Notify_Logging_Service::init (int argc, char *argv[]
ACE_ENV_ARG_PARAMETER) != 0)
return -1;
- this->notify_service_->init (this->orb_.in () ACE_ENV_ARG_PARAMETER);
- ACE_CHECK_RETURN (-1);
+ if (this->parse_args (argc, argv) == -1)
+ return -1;
- // Resolve the naming service.
- resolve_naming_service (ACE_ENV_SINGLE_ARG_PARAMETER);
+ this->notify_service_->init (this->orb_.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
ACE_DEBUG ((LM_DEBUG,
@@ -99,23 +145,63 @@ Notify_Logging_Service::init (int argc, char *argv[]
ACE_CHECK_RETURN (-1);
- // Register the Factory
- ACE_ASSERT (!CORBA::is_nil (this->naming_.in ()));
-
- CosNaming::Name_var name =
- this->naming_->to_name (this->notify_factory_name_.c_str ()
- ACE_ENV_ARG_PARAMETER);
+ CORBA::String_var str =
+ this->orb_->object_to_string (obj.in () ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
+ ACE_DEBUG ((LM_DEBUG,
+ "The Notify Log Factory IOR is <%s>\n", str.in()));
- this->naming_->rebind (name.in (),
- obj.in ()
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK_RETURN (-1);
+ if (ior_file_name_ != 0)
+ {
+ FILE* iorf = ACE_OS::fopen (ior_file_name_, ACE_LIB_TEXT("w"));
+ if (iorf == 0)
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot open output file for writing IOR: %s",
+ ior_file_name_),
+ -1);
+ }
+
+ ACE_OS::fprintf (iorf, "%s\n", str.in ());
+ ACE_OS::fclose (iorf);
+ }
- ACE_DEBUG ((LM_DEBUG,
- "Registered with the naming service as: %s\n",
- this->notify_factory_name_.c_str()));
+ if (pid_file_name_ != 0)
+ {
+ FILE* pidf = ACE_OS::fopen (pid_file_name_, ACE_LIB_TEXT("w"));
+ if (pidf != 0)
+ {
+ ACE_OS::fprintf (pidf,
+ "%ld\n",
+ static_cast<long> (ACE_OS::getpid ()));
+ ACE_OS::fclose (pidf);
+ }
+ }
+
+ if (bind_to_naming_service_)
+ {
+ // Resolve the naming service.
+ 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 ()
+ ACE_ENV_ARG_PARAMETER);
+ ACE_CHECK_RETURN (-1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "Registered with the naming service as: %s\n",
+ this->service_name_));
+ }
return 0;
}
@@ -133,7 +219,7 @@ Notify_Logging_Service::resolve_naming_service (ACE_ENV_SINGLE_ARG_DECL)
ACE_THROW (CORBA::UNKNOWN ());
this->naming_ =
- CosNaming::NamingContextExt::_narrow (naming_obj.in ()
+ CosNaming::NamingContext::_narrow (naming_obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
}
@@ -174,14 +260,17 @@ Notify_Logging_Service::shutdown (ACE_ENV_SINGLE_ARG_DECL)
ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
- CosNaming::Name_var name =
- this->naming_->to_name (this->notify_factory_name_.c_str ()
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK;
-
- this->naming_->unbind (name.in ()
- ACE_ENV_ARG_PARAMETER);
- ACE_CHECK;
+ if (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);
+ ACE_CHECK;
+ }
// shutdown the ORB.
if (!CORBA::is_nil (this->orb_.in ()))