summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormjb2 <mjb2@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-07-22 02:34:39 +0000
committermjb2 <mjb2@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-07-22 02:34:39 +0000
commit4115ce1c192044d4244d03e1a1df4eb6c061a7c6 (patch)
tree04191376e8f1c11bf2a7f93c64991e04310b5cba
parent9c58665b67dd651b44133d01afedb4ece37804c8 (diff)
downloadATCD-4115ce1c192044d4244d03e1a1df4eb6c061a7c6.tar.gz
See Tue Jul 21 21:12:31 1998 Matthew J Braun <mjb2@cec.wustl.edu>
-rw-r--r--TAO/ChangeLog-98c26
-rw-r--r--TAO/orbsvcs/orbsvcs/Log/Logger_i.cpp18
-rw-r--r--TAO/orbsvcs/orbsvcs/Log/Logger_i.h8
-rw-r--r--TAO/orbsvcs/orbsvcs/Logger.idl2
-rw-r--r--TAO/orbsvcs/tests/Logger/README45
-rw-r--r--TAO/orbsvcs/tests/Logger/client.cpp368
-rw-r--r--TAO/orbsvcs/tests/Logger/client_i.cpp295
-rw-r--r--TAO/orbsvcs/tests/Logger/client_i.h95
-rwxr-xr-xTAO/orbsvcs/tests/Logger/run_test.pl82
-rw-r--r--TAO/orbsvcs/tests/Logger/server.cpp144
-rw-r--r--TAO/orbsvcs/tests/Logger/server_i.cpp129
-rw-r--r--TAO/orbsvcs/tests/Logger/server_i.h87
12 files changed, 814 insertions, 485 deletions
diff --git a/TAO/ChangeLog-98c b/TAO/ChangeLog-98c
index 74fa6f87865..93957ad7f7a 100644
--- a/TAO/ChangeLog-98c
+++ b/TAO/ChangeLog-98c
@@ -1,3 +1,29 @@
+Tue Jul 21 21:12:31 1998 Matthew J Braun <mjb2@cec.wustl.edu>
+
+ * orbsvcs/orbsvcs/Log/Logger_i.{h,cpp}:Added 2 new methods to get and
+ set the verbosity level
+
+ * orbsvcs/orbsvcs/Logger.idl: Enabled the verbosity method
+
+ * orbsvcs/tests/Logger/run_test.pl: Renamed from
+ runtests.pl. Removed nameservice code
+
+ * orbsvcs/tests/Logger/README: Edited to provide more detail
+
+ * orbsvcs/tests/Logger/client_i.{h,cpp}: New files. Interface and
+ implementation of the <Logger_Client> class
+
+ * orbsvcs/tests/Logger/server_i.{h,cpp}: New files. Interface and
+ implementation of the <Logger_Server> class.
+
+ * orbsvcs/tests/Logger/client.cpp: Restructured the code. Moved
+ most of the work onto the <Logger_Client> class defined in
+ client_i.h. main () is now rather stripped down
+
+ * orbsvcs/tests/Logger/server.cpp: Restructured the code. Moved
+ most of the work onto the <Logger_Server> class defined in
+ server_i.h. main () is now rather stripped down.
+
Tue Jul 21 17:29:15 1998 Darrell Brunsch <brunsch@cs.wustl.edu>
* orbsvcs/orbsvcs/orbsvcs_lib.dsp:
diff --git a/TAO/orbsvcs/orbsvcs/Log/Logger_i.cpp b/TAO/orbsvcs/orbsvcs/Log/Logger_i.cpp
index 8c6310fe296..d0d8a004fc8 100644
--- a/TAO/orbsvcs/orbsvcs/Log/Logger_i.cpp
+++ b/TAO/orbsvcs/orbsvcs/Log/Logger_i.cpp
@@ -24,7 +24,8 @@ Logger_Factory_i::Logger_Factory_i (void)
}
Logger_i::Logger_i (const char *name)
- : name_ (ACE_OS::strdup (name))
+ : name_ (ACE_OS::strdup (name)),
+ verbosity_level_ (Logger::VERBOSE)
{
// Do nothing
}
@@ -100,10 +101,21 @@ Logger_i::log (const Logger::Log_Record &log_rec,
MAXHOSTNAMELEN);
rec.print (namebuf,
- this->verbosity_level_,
+ this->verbosity_conversion (this->verbosity_level_),
stderr);
// Print out the logging message to stderr with the given level of
// verbosity
}
-// @@ Matt, please add the method for verbosity().
+Logger::Verbosity_Level
+Logger_i::verbosity (void) const
+{
+ return verbosity_level_;
+}
+
+void
+Logger_i::verbosity (Logger::Verbosity_Level level, CORBA::Environment &env)
+{
+ ACE_UNUSED_ARG (env);
+ verbosity_level_ = level;
+}
diff --git a/TAO/orbsvcs/orbsvcs/Log/Logger_i.h b/TAO/orbsvcs/orbsvcs/Log/Logger_i.h
index 99c954bccf2..4049a13680d 100644
--- a/TAO/orbsvcs/orbsvcs/Log/Logger_i.h
+++ b/TAO/orbsvcs/orbsvcs/Log/Logger_i.h
@@ -36,6 +36,7 @@ public:
// Currently, <name> is unused.
};
+
class Logger_i : public virtual POA_Logger
{
// = TITLE
@@ -51,7 +52,12 @@ public:
CORBA::Environment &_env);
// Writes the <log_rec> to the standard output.
- // @@ Matt, please add the method for verbosity().
+ Logger::Verbosity_Level verbosity (void) const;
+ // Gets the verbosity level
+
+ void verbosity (Logger::Verbosity_Level level, CORBA::Environment &env);
+ // Sets the verbosity level. Valid values are {VERBOSE, VERBOSE_LITE
+ // and SILENT}. Defaults to VERBOSE
private:
ACE_Log_Priority priority_conversion (Logger::Log_Priority priority);
diff --git a/TAO/orbsvcs/orbsvcs/Logger.idl b/TAO/orbsvcs/orbsvcs/Logger.idl
index e5dff99eddf..751838caeb7 100644
--- a/TAO/orbsvcs/orbsvcs/Logger.idl
+++ b/TAO/orbsvcs/orbsvcs/Logger.idl
@@ -85,7 +85,7 @@ interface Logger
oneway void log (in Log_Record log_rec);
// Transmit a Log_Record to the logging server.
- // void verbosity (in Verbosity_Level verbosity_level);
+ oneway void verbosity (in Verbosity_Level level);
// Change the state of the <verbosity_level>. This controls how
// much logging information is displayed by the server.
};
diff --git a/TAO/orbsvcs/tests/Logger/README b/TAO/orbsvcs/tests/Logger/README
new file mode 100644
index 00000000000..e0d6f19ff60
--- /dev/null
+++ b/TAO/orbsvcs/tests/Logger/README
@@ -0,0 +1,45 @@
+$ID$
+
+This example tests the TAO logging service. It generates SII stubs and
+skeletons using the TAO IDL compiler. You can either run the client
+and server as seperate processes in the same, or different windows (or
+machines), or you may run the "runtests.pl" script which will start
+both executables.
+
+By default, the client and server use the Naming Service. The
+log_server has its own NamingServer implementation, so it doesn't
+require you to start the NamingService before starting the client and
+server.
+
+The test demonstrates the functionality of the logging
+service. The client program will generate 2 logging messages which
+will be logged to the screen. First message will be in the
+"verbose_lite" format. The second will be a fully verbose message.
+
+server:
+------
+
+% server [-d]
+
+client:
+-------
+
+% client [-d]
+
+Options:
+-------
+-d Debug flag. It is an additive flag, so more -d's will increase
+the debugging level. Only one flag is necessary to enable the
+debugging output from the executables, but the debug level
+affects how the utilized TAO methods act (including mysterious
+debugging messages).
+
+
+
+That's all there is to it. If you desire, feel free to change the
+logging priorities, verbosity levels and messages in the client
+program but note that the maximum length of the message is 1023 characters.
+
+-Matt Braun
+mjb2@cec.wustl.edu
+Monday July 06, 1998
diff --git a/TAO/orbsvcs/tests/Logger/client.cpp b/TAO/orbsvcs/tests/Logger/client.cpp
index 95a85da7912..5ee03137ebd 100644
--- a/TAO/orbsvcs/tests/Logger/client.cpp
+++ b/TAO/orbsvcs/tests/Logger/client.cpp
@@ -1,363 +1,6 @@
// $Id$
-#include "ace/INET_Addr.h"
-#include "ace/SOCK_Dgram_Mcast.h"
-#include "ace/OS.h"
-#include "orbsvcs/CosNamingC.h"
-#include "orbsvcs/LoggerC.h"
-#include "client.h"
-
-// Constructor
-Logger_Client::Logger_Client (void)
- : test_nesting_ (0)
-{
- // Do nothing
-}
-
-// Parses the command line arguments and returns an error status.
-int
-Logger_Client::parse_args (void)
-{
- ACE_Get_Opt get_opts (argc_, argv_, "dn");
- int c;
-
- while ((c = get_opts ()) != -1)
- switch (c)
- {
- case 'd': // debug flag
- TAO_debug_level++;
- break;
- case 'n':
- this->test_nesting_++;
- break;
- case '?':
- default:
- ACE_ERROR_RETURN ((LM_ERROR,
- "usage: %s"
- " [-d]"
- " [-n]"
- "\n"
- " -d: increase debug level\n"
- " -n: test nesting in Naming Service\n",
- this->argv_ [0]),
- -1);
- }
-
- // Indicates successful parsing of command line.
- return 0;
-}
-
-void
-Logger_Client::init_record (Logger::Log_Record &newrec,
- Logger::Log_Priority lp,
- const char *msg)
-{
- // Copy the message data into newrec.
- newrec.msg_data = CORBA::string_copy (msg);
-
- // Assign the log priority.
- newrec.type = lp;
-
- // Create and assign the timestamp.
- ACE_Time_Value time (ACE_OS::gettimeofday ());
- newrec.time = time.sec ();
-
- // Get and store the PID of the calling process.
- pid_t pid = ACE_OS::getpid ();
- newrec.app_id = pid;
-
- char name[MAXHOSTNAMELEN];
- ACE_OS::hostname (name, MAXHOSTNAMELEN);
- hostent *he = ACE_OS::gethostbyname (name);
-
- // Get and store the IP of the local host .
- newrec.host_addr =
- (ACE_reinterpret_cast (in_addr *,
- he->h_addr_list[0])->s_addr);
-}
-
-void
-Logger_Client::show_record (Logger::Log_Record &newrec)
-{
- in_addr address;
- address.s_addr = newrec.host_addr;
-
- ACE_DEBUG ((LM_DEBUG,
- " Log Priority: %d\n"
- " Time: %d\n"
- " PID: %d\n"
- " Host Address: %s\n"
- " Message: %s\n",
- newrec.type,
- newrec.time,
- newrec.app_id,
- inet_ntoa (address),
- newrec.msg_data.in ()));
-}
-
-CORBA::Object_var
-Logger_Client::resolve_name (CosNaming::Name &name,
- char *namestring,
- CosNaming::NamingContext_var context,
- CORBA::Environment &env)
-{
- name.length(1);
- name[0].id = CORBA::string_dup (namestring);
-
- return context->resolve (name, env);
-}
-
-int
-Logger_Client::nesting_test (CosNaming::Name &nested,
- char *contextstring,
- CosNaming::NamingContext_var context,
- CORBA::Environment &env)
-{
- nested.length (1);
- nested[0].id = CORBA::string_dup (contextstring);
-
- CosNaming::NamingContext_var nc1 =
- context->bind_new_context (nested, env);
-
- if (CORBA::is_nil (nc1.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- "nil nested context"),
- -1);
- ACE_DEBUG ((LM_DEBUG,
- "Nested naming context created\n"));
-
- CosNaming::Name logger1_name (1);
- logger1_name.length (1);
- logger1_name[0].id = CORBA::string_dup ("logger_1_");
- nc1->bind (logger1_name,
- this->logger_1_.in (),
- env);
-
- ACE_DEBUG ((LM_DEBUG,
- "Bind in nested context succeded\n"));
-
- nc1->unbind (logger1_name,
- env);
-
- ACE_DEBUG ((LM_DEBUG,
- "Unbind in nested context succeded\n"));
-
- // destroy the naming context created above.
- nc1->destroy (env);
-
- ACE_DEBUG ((LM_DEBUG,
- "destroy of nested context succeded\n"));
-
- return 0;
-}
-
-// Execute client example code.
-
-int
-Logger_Client::run (void)
-{
- TAO_TRY
- {
- // Create 2 Log_Records for the test
- Logger::Log_Record rec1;
- Logger::Log_Record rec2;
-
- // Setup the first log record
- this->init_record (rec1,
- Logger::LM_DEBUG,
- "Logging at logger 1\n");
-
- // Setup the second log record
- this->init_record (rec2,
- Logger::LM_ERROR,
- "Logging at logger 2\n");
-
- // If debugging, output the new log records
- if (TAO_debug_level > 0)
- {
- ACE_DEBUG ((LM_DEBUG,
- "First Log_Record created. Contents:\n"));
- this->show_record (rec1);
-
- ACE_DEBUG ((LM_DEBUG,
- "Second Log_Record created. Contents:\n"));
- this->show_record (rec2);
- }
-
- // @@ Matt, I recommend that you make a couple of calls to
- // log(), using different verbosity levels each time. Log the
- // first Log_Record, i.e.,
- // this->logger_1_->verbosity (foo1);
-
- this->logger_1_->log (rec1, TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- // Log the second Log_Record.
- this->logger_2_->log (rec2, TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- }
- TAO_CATCHANY
- {
- TAO_TRY_ENV.print_exception ("run");
- return -1;
- }
- TAO_ENDTRY;
- return 0;
-}
-
-Logger_Client::~Logger_Client (void)
-{
- // Do nothing
-}
-
-int
-Logger_Client::init (int argc, char **argv)
-{
- this->argc_ = argc;
- this->argv_ = argv;
-
- // @@ Matt, this method is rather long. Can you please break it
- // into several smaller (private) methods?
-
- TAO_TRY
- {
- // Initialize ORB.
- this->orb_ = CORBA::ORB_init (argc,
- argv,
- "internet",
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- // @@ Somewhere around here is where we want to initialize the
- // new TAO_Naming_Client.
-
- CORBA::Object_var naming_obj =
- this->orb_->resolve_initial_references ("NameService");
-
- if (CORBA::is_nil (naming_obj.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- " (%P|%t) Unable to initialize the POA.\n"),
- -1);
-
- CosNaming::NamingContext_var naming_context =
- CosNaming::NamingContext::_narrow (naming_obj.in (),
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- if (TAO_debug_level > 0)
- ACE_DEBUG ((LM_DEBUG,
- "Obtained naming_context\n"));
-
- // Parse command line and verify parameters.
- if (this->parse_args () == -1)
- return -1;
-
- CosNaming::Name factory_name (1);
- CORBA::Object_var factory_ref =
- this->resolve_name (factory_name,
- "logger_factory",
- naming_context,
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- // The following code must fail with an exception.
- CosNaming::Name factory_name2 (1);
- this->resolve_name (factory_name2,
- "logger_factory2",
- naming_context,
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- if (TAO_TRY_ENV.exception () && TAO_debug_level > 0)
- {
- CosNaming::NamingContext::NotFound_ptr ex =
- CosNaming::NamingContext::NotFound::_narrow (TAO_TRY_ENV.exception ());
- if (ex != 0)
- TAO_TRY_ENV.print_exception
- ("Negative test case for name not found, succeeded\n");
- else
- TAO_TRY_ENV.print_exception
- ("Negative test case for name not found, FAILED!\n");
- TAO_TRY_ENV.clear ();
- }
-
- if (CORBA::is_nil (factory_ref.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- "resolved to nil object"),
- -1);
-
- if (TAO_debug_level > 0)
- ACE_DEBUG ((LM_DEBUG,
- "\nLogger_Factory resolved\n"));
-
- Logger_Factory_var factory =
- Logger_Factory::_narrow (factory_ref.in (),
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- if (CORBA::is_nil (factory.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- "narrow returned nil"),
- -1);
- if (TAO_debug_level > 0)
- ACE_DEBUG ((LM_DEBUG,
- "\nLogger_Factory narrowed\n"));
-
- CORBA::String_var str =
- this->orb_->object_to_string (factory.in (),
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- if (TAO_debug_level > 0)
- ACE_DEBUG ((LM_DEBUG,
- "The factory IOR is <%s>\n",
- str.in ()));
-
- // Now retrieve the Logger obj ref corresponding to key1 and
- // key2.
- this->logger_1_ = factory->make_logger ("key1",
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
- this->logger_2_ = factory->make_logger ("key2",
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- if (TAO_debug_level > 0)
- {
-
- if (CORBA::is_nil (this->logger_1_.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- "nil logger1"),
- -1);
-
- if (CORBA::is_nil (this->logger_2_.in ()))
- ACE_ERROR_RETURN ((LM_ERROR,
- "nil logger2"),
- -1);
-
- ACE_DEBUG ((LM_DEBUG,
- "Created two loggers\n"));
- }
-
- if (this->test_nesting_)
- {
- CosNaming::Name nested (1);
- this->nesting_test (nested,
- "my_naming_context_1",
- naming_context,
- TAO_TRY_ENV);
- }
- }
- TAO_CATCHANY
- {
- TAO_TRY_ENV.print_exception ("init");
- return -1;
- }
- TAO_ENDTRY;
-
- return 0;
-}
+#include "client_i.h"
// This function runs the test.
@@ -366,8 +9,13 @@ main (int argc, char **argv)
{
Logger_Client logger_client;
- if (logger_client.init (argc, argv) != 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "\n \t IDL_Logger: client \n\n"));
+
+ if (logger_client.init (argc, argv) == -1)
return 1;
- return logger_client.run ();
+ int retval = logger_client.run ();
+
+ return retval;
}
diff --git a/TAO/orbsvcs/tests/Logger/client_i.cpp b/TAO/orbsvcs/tests/Logger/client_i.cpp
new file mode 100644
index 00000000000..39f92b7737d
--- /dev/null
+++ b/TAO/orbsvcs/tests/Logger/client_i.cpp
@@ -0,0 +1,295 @@
+// $Id$
+
+#include "ace/INET_Addr.h"
+#include "ace/SOCK_Dgram_Mcast.h"
+#include "ace/OS.h"
+#include "orbsvcs/CosNamingC.h"
+#include "orbsvcs/LoggerC.h"
+#include "client_i.h"
+
+// Constructor
+Logger_Client::Logger_Client (void)
+{
+ // Do nothing
+}
+
+// Destructor
+Logger_Client::~Logger_Client (void)
+{
+ // Do nothing
+}
+
+int
+Logger_Client::init (int argc, char **argv)
+{
+ this->argc_ = argc;
+ this->argv_ = argv;
+
+ TAO_TRY
+ {
+ // Initialize the ORB
+ orb_ = CORBA::ORB_init (argc,
+ argv,
+ "internet",
+ TAO_TRY_ENV);
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "\nTrying to initialize orb\n"));
+
+ TAO_CHECK_ENV;
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "\nOrb initialized successfully\n"));
+
+ // Parse command line and verify parameters.
+ if (this->parse_args () == -1)
+ return -1;
+
+ // Initialize the naming service
+ if (this->init_naming_service (TAO_TRY_ENV) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Unable to initialize naming"
+ "services.\n"),
+ -1);
+ // Create the logger instances
+ if (this->init_loggers (TAO_TRY_ENV) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Unable to initialize logger"
+ "instances.\n"),
+ -1);
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("init");
+ return -1;
+ }
+ TAO_ENDTRY;
+
+ return 0;
+
+}
+
+
+int
+Logger_Client::init_naming_service (CORBA::Environment &env)
+{
+ // Initialize the naming services
+ if (my_name_client_.init (orb_, argc_, argv_) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Unable to initialize "
+ "the TAO_Naming_Client. \n"),
+ -1);
+
+ // Resolve an instance of the Logger_Factory
+ CosNaming::Name factory_name (1);
+ factory_name.length (1);
+ factory_name[0].id = CORBA::string_dup ("logger_factory");
+
+ CORBA::Object_var factory_ref =
+ my_name_client_->resolve (factory_name,
+ env);
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "\nFactory_ref resolved\n"));
+
+ if (CORBA::is_nil (factory_ref.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "resolved to nil object"),
+ -1);
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "\nLogger_Factory resolved\n"));
+
+ // Narrow the factory and check the success
+ factory_ =
+ Logger_Factory::_narrow (factory_ref.in (),
+ env);
+
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "\nFactory narrowed\n"));
+ if (CORBA::is_nil (factory_.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "narrow returned nil"),
+ -1);
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "\nLogger_Factory narrowed\n"));
+
+ // If debugging, get the factory's IOR
+ CORBA::String_var str =
+ orb_->object_to_string (factory_.in (),
+ env);
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "The factory IOR is <%s>\n",
+ str.in ()));
+ return 0;
+}
+
+
+int
+Logger_Client::init_loggers (CORBA::Environment &env)
+{
+ // Retrieve the Logger obj ref corresponding to key1 and
+ // key2.
+ this->logger_1_ = factory_->make_logger ("key1",
+ env);
+ this->logger_2_ = factory_->make_logger ("key2",
+ env);
+
+ if (CORBA::is_nil (this->logger_1_.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "nil logger1"),
+ -1);
+
+ if (CORBA::is_nil (this->logger_2_.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "nil logger2"),
+ -1);
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "Created two loggers\n"));
+ return 0;
+}
+
+
+// Execute client example code.
+
+int
+Logger_Client::run (void)
+{
+ TAO_TRY
+ {
+ // @@ Matt, for fun, you might try having an array of
+ // Log_Records (e.g., of size 2 to start out with) and then put
+ // the following code in a loop.
+
+ // Create 2 Log_Records for the test
+ Logger::Log_Record rec1;
+ Logger::Log_Record rec2;
+
+ // Setup the first log record
+ this->init_record (rec1,
+ Logger::LM_DEBUG,
+ "Praise Bob! (1)\n");
+
+ // Setup the second log record
+ this->init_record (rec2,
+ Logger::LM_ERROR,
+ "Beware The Stark Fist of Removal. (2)\n");
+
+ // If debugging, output the new log records
+ if (TAO_debug_level > 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "First Log_Record created. Contents:\n"));
+ this->show_record (rec1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "Second Log_Record created. Contents:\n"));
+ this->show_record (rec2);
+ }
+
+ // Change the verbosity
+ this->logger_1_->verbosity (Logger::VERBOSE_LITE, TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Log the first Log_Record
+ this->logger_1_->log (rec1, TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Change the verbosity again
+ this->logger_2_->verbosity (Logger::VERBOSE, TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Log the second Log_Record.
+ this->logger_2_->log (rec2, TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("run");
+ return -1;
+ }
+ TAO_ENDTRY;
+ return 0;
+}
+
+
+// Parses the command line arguments and returns an error status.
+
+int
+Logger_Client::parse_args (void)
+{
+ ACE_Get_Opt get_opts (argc_, argv_, "d");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'd': // debug flag
+ TAO_debug_level++;
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s"
+ " [-d]"
+ "\n"
+ " -d: increase debug level\n",
+ this->argv_ [0]),
+ -1);
+ }
+
+ // Indicates successful parsing of command line.
+ return 0;
+}
+
+
+void
+Logger_Client::init_record (Logger::Log_Record &newrec,
+ Logger::Log_Priority lp,
+ const char *msg)
+{
+ // Copy the message data into newrec.
+ newrec.msg_data = CORBA::string_copy (msg);
+
+ // Assign the log priority.
+ newrec.type = lp;
+
+ // Create and assign the timestamp.
+ ACE_Time_Value time (ACE_OS::gettimeofday ());
+ newrec.time = time.sec ();
+
+ // Get and store the PID of the calling process.
+ pid_t pid = ACE_OS::getpid ();
+ newrec.app_id = pid;
+
+ // Get and store the IP of the local host .
+ char name[MAXHOSTNAMELEN];
+ ACE_OS::hostname (name, MAXHOSTNAMELEN);
+ hostent *he = ACE_OS::gethostbyname (name);
+ newrec.host_addr =
+ (ACE_reinterpret_cast (in_addr *,
+ he->h_addr_list[0])->s_addr);
+}
+
+void
+Logger_Client::show_record (Logger::Log_Record &newrec)
+{
+ in_addr address;
+ address.s_addr = newrec.host_addr;
+
+ ACE_DEBUG ((LM_DEBUG,
+ " Log Priority: %d\n"
+ " Time: %d\n"
+ " PID: %d\n"
+ " Host Address: %s\n"
+ " Message: %s\n",
+ newrec.type,
+ newrec.time,
+ newrec.app_id,
+ inet_ntoa (address),
+ newrec.msg_data.in ()));
+}
diff --git a/TAO/orbsvcs/tests/Logger/client_i.h b/TAO/orbsvcs/tests/Logger/client_i.h
new file mode 100644
index 00000000000..8d52d865681
--- /dev/null
+++ b/TAO/orbsvcs/tests/Logger/client_i.h
@@ -0,0 +1,95 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/tests/Logger
+//
+// = FILENAME
+// client_i.h
+//
+// = DESCRIPTION
+// This class implements a simple logger CORBA client for the Logger
+// example using stubs generated by the TAO ORB IDL compiler
+//
+// = AUTHORS
+// Sergio Flores-Gaitan <sergio@cs.wustl.edu>
+// Matt Braun <mjb2@cec.wustl.edu>
+//
+// ============================================================================
+
+#include "ace/Get_Opt.h"
+#include "tao/corba.h"
+#include "orbsvcs/CosNamingC.h"
+#include "orbsvcs/LoggerC.h"
+#include "orbsvcs/Naming/Naming_Utils.h"
+
+class Logger_Client
+{
+ // = TITLE
+ // Defines a class that encapsulates behaviour of the Logger
+ // client example. Provides a better understanding of the logic
+ // in an object oriented way.
+ //
+ // = DESCRIPTION
+ // This class declares an interface to run the example client for
+ // Logger CORBA server. All the complexity for initializing the
+ // server is hidden in the class. Just the <run> interface is
+ // needed.
+public:
+ // = Initialization and termination methods.
+
+ Logger_Client (void);
+ // Constructor.
+
+ ~Logger_Client (void);
+ // Destructor.
+
+ int init (int argc, char **argv);
+ // Initialize the client communication endpoint with server.
+
+ int run (void);
+ // Execute client example code.
+
+private:
+ int parse_args (void);
+ // Parses the arguments passed on the command line.
+
+ void init_record (Logger::Log_Record &newrec,
+ Logger::Log_Priority lp,
+ const char *msg);
+ // Prepares the <Log_Record> for logging.
+
+ int init_naming_service (CORBA::Environment &env);
+ // Initialises the name server and resolves the logger_factory
+
+ int init_loggers (CORBA::Environment &env);
+ // Instantiates the 2 logger member variables
+
+ void show_record (Logger::Log_Record &newrec);
+ // Shows contents of the record (for debugging purposes).
+
+ TAO_Naming_Client my_name_client_;
+ // An instance of the name client used for resolving the factory
+ // objects.
+
+ CORBA::ORB_var orb_;
+ // Keep a pointer to the ORB for easy access
+
+ int argc_;
+ // # of arguments on the command line.
+
+ char **argv_;
+ // arguments from command line.
+
+ Logger_Factory_var factory_;
+ // A pointer to the Logger_Factory; used in init_loggers
+
+ Logger_var logger_1_;
+ // Logger obj ref.
+
+ Logger_var logger_2_;
+ // Logger obj ref.
+};
+
diff --git a/TAO/orbsvcs/tests/Logger/run_test.pl b/TAO/orbsvcs/tests/Logger/run_test.pl
new file mode 100755
index 00000000000..9d330474be6
--- /dev/null
+++ b/TAO/orbsvcs/tests/Logger/run_test.pl
@@ -0,0 +1,82 @@
+# $Id$
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
+ & eval 'exec perl -S $0 $argv:q'
+ if 0;
+
+# This is a Perl script that runs the client and all the other servers that
+# are needed
+
+unshift @INC, '../../../../bin';
+require Process;
+
+# amount of delay between running the servers
+$sleeptime = 3;
+
+# Get the userid (or ip on NT)
+if ($^O eq "MSWin32")
+{
+ system ("ipconfig | find \"Address\">ipnum");
+
+ open (IPNUM, "ipnum");
+
+ read (IPNUM, $line, 80);
+
+ ($junk, $ip1, $ip2, $ip3, $ip4) = split (/: (\d+)\.(\d+)\.(\d+)\.(\d+)/, $line);
+
+ close IPNUM;
+
+ system ("del /q ipnum");
+
+ $uid = $ip4;
+}
+else
+{
+ $uid = getpwnam (getlogin ());
+}
+
+# variables for parameters
+
+$svport = 0;
+
+# other variables
+
+$n = 1;
+$leave = 1;
+$ior = 0;
+$done = "";
+$debug = "";
+$cm = "";
+$sm = "";
+$other = "";
+$c_conf = "client.conf";
+$s_conf = "server.conf";
+
+sub server
+{
+ my $args = "";
+ my $prog = "server".$Process::EXE_EXT;
+
+ $SV = Process::Create ($prog, $args);
+}
+
+sub client
+{
+ my $args = "";
+ my $prog = "client".$Process::EXE_EXT;
+
+ $CL = Process::Create ($prog, $args);
+}
+
+server ();
+
+sleep $sleeptime;
+
+client ();
+
+sleep $sleeptime;
+if ($leave)
+{
+ $SV->Kill ();
+ $NS->Kill ();
+ $CL->Kill ();
+}
diff --git a/TAO/orbsvcs/tests/Logger/server.cpp b/TAO/orbsvcs/tests/Logger/server.cpp
index 6596bf9e58d..3170ce37f62 100644
--- a/TAO/orbsvcs/tests/Logger/server.cpp
+++ b/TAO/orbsvcs/tests/Logger/server.cpp
@@ -1,134 +1,38 @@
// $Id$
-#include "orbsvcs/CosNamingC.h"
-#include "orbsvcs/Log/Logger_i.h"
-#include "tao/TAO.h"
+#include "server_i.h"
-// Parses the command line arguments and returns an error status
-
-static int
-parse_args (int argc_, char** argv_)
-{
- ACE_Get_Opt get_opts (argc_, argv_, "d");
- int c;
-
- while ((c = get_opts ()) != -1)
- switch (c)
- {
- case 'd': // debug flag
- TAO_debug_level++;
- break;
- case '?':
- default:
- ACE_ERROR_RETURN ((LM_ERROR,
- "usage: %s"
- " [-d]"
- "\n"
- " -d: increase debug level\n",
- argv_ [0]),
- -1);
- }
-
- // Indicates successful parsing of command line.
- return 0;
-}
-
-// @@ Matt, please replace all of this code with the TAO_Naming_Server
-// stuff, e.g., as it's defined in the TAO IDL_Cubit example.
-
-static void
-setup_naming (CORBA::ORB_var orb,
- CosNaming::NamingContext_var naming_context,
- CORBA::Environment &env)
-{
- CORBA::Object_var naming_obj =
- orb->resolve_initial_references ("NameService");
-
- naming_context =
- CosNaming::NamingContext::_narrow (naming_obj.in (), env);
-}
-
int
-main (int argc, char ** argv)
+main (int argc, char *argv[])
{
- // Get command line information.
- parse_args (argc, argv);
-
+ Logger_Server log_server;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\n\tIDL_Logger:SERVER\n\n"));
TAO_TRY
{
- // Set up the ORB.
- TAO_ORB_Manager orb_manager;
- orb_manager.init (argc, argv, TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- // Get access to the underlying ORB and POA
- CORBA::ORB_var orb = orb_manager.orb ();
- PortableServer::POA_var poa = orb_manager.root_poa ();
-
- // Setup the interaction with the naming service
- CosNaming::NamingContext_var naming_context;
- setup_naming (orb, naming_context, TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- // Create a factory implementation for the Logger.
- Logger_Factory_i factory_impl;
- Logger_Factory_var factory = factory_impl._this (TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- // If debugging, output the factory IOR
- if (TAO_debug_level > 0)
- {
- CORBA::String_var str =
- orb.in ()->object_to_string (factory.in (),
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
- ACE_DEBUG ((LM_DEBUG,
- "The factory IOR is <%s>\n",
- str.in ()));
- }
-
- // Register the servant with the Naming Context....
- CosNaming::Name factory_name (1);
- factory_name.length (1);
- factory_name[0].id = CORBA::string_dup ("logger_factory");
- naming_context->bind (factory_name,
- factory.in (),
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- if (TAO_TRY_ENV.exception () != 0)
- {
- TAO_TRY_ENV.print_exception ("bind: name already bound\n");
- return -1;
- }
-
- PortableServer::POAManager_var poa_manager =
- poa->the_POAManager(TAO_TRY_ENV);
-
- // Activate the servant
- poa_manager->activate (TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- if (TAO_debug_level > 0)
- ACE_DEBUG ((LM_DEBUG,
- "running logging service\n"));
-
- orb_manager.run (TAO_TRY_ENV);
- TAO_CHECK_ENV;
-
- // Unbind the logger factory name.
- naming_context->unbind (factory_name,
- TAO_TRY_ENV);
- TAO_CHECK_ENV;
+ if (log_server.init (argc, argv, TAO_TRY_ENV) == -1)
+ return 1;
+ else
+ {
+ log_server.run (TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+ }
+ }
+ TAO_CATCH (CORBA::SystemException, sysex)
+ {
+ ACE_UNUSED_ARG (sysex);
+ TAO_TRY_ENV.print_exception ("System Exception");
+ return -1;
}
-
- TAO_CATCHANY
+ TAO_CATCH (CORBA::UserException, userex)
{
- TAO_TRY_ENV.print_exception ("logger_service");
+ ACE_UNUSED_ARG (userex);
+ TAO_TRY_ENV.print_exception ("User Exception");
+ return -1;
}
-
TAO_ENDTRY;
-
return 0;
}
+
diff --git a/TAO/orbsvcs/tests/Logger/server_i.cpp b/TAO/orbsvcs/tests/Logger/server_i.cpp
new file mode 100644
index 00000000000..96f3809147a
--- /dev/null
+++ b/TAO/orbsvcs/tests/Logger/server_i.cpp
@@ -0,0 +1,129 @@
+// $Id$
+
+#include "server_i.h"
+
+Logger_Server::Logger_Server (void)
+{
+ // Do nothing
+}
+
+int
+Logger_Server::parse_args (void)
+{
+ ACE_Get_Opt get_opts (argc_, argv_, "d");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'd': // debug flag.
+ TAO_debug_level++;
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s"
+ " [-d]"
+ "\n",
+ argv_ [0]),
+ -1);
+ }
+
+ // Indicates successful parsing of command line.
+ return 0;
+}
+
+int
+Logger_Server::init (int argc,
+ char** argv,
+ CORBA::Environment& env)
+{
+ this->argc_ = argc;
+ this->argv_ = argv;
+
+ // Call the init of <TAO_ORB_Manager> to initialize the ORB and
+ // create a child POA under the root POA.
+ if (this->orb_manager_.init_child_poa (argc,
+ argv,
+ "child_poa",
+ env) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "init_child_poa"),
+ -1);
+
+ TAO_CHECK_ENV_RETURN (env,-1);
+
+ // Parse the command line arguments
+ if (this->parse_args () != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "parse_args"),
+ -1);
+
+ // Activate the logger_factory
+ CORBA::String_var str =
+ this->orb_manager_.activate_under_child_poa ("logger_factory",
+ &this->factory_impl_,
+ env);
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "The IOR is: <%s>\n",
+ str.in ()));
+
+ // Initialize the naming service
+ if (this->init_naming_service (env) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "init_naming_service"),
+ -1);
+ else
+ return 0;
+}
+
+
+// Initialisation of Naming Service and register IDL_Logger Context
+// and logger_factory object.
+
+int
+Logger_Server::init_naming_service (CORBA::Environment& env)
+{
+ // Get pointers to the ORB and child POA
+ CORBA::ORB_var orb = this->orb_manager_.orb ();
+ PortableServer::POA_var child_poa = this->orb_manager_.child_poa ();
+
+ // Initialize the naming service
+ if (this->my_name_server_.init (orb.in (),
+ child_poa.in ()) == -1)
+ return -1;
+
+ // Create an instance of the Logger_Factory
+ Logger_Factory_var factory = this->factory_impl_._this (env);
+ TAO_CHECK_ENV_RETURN (env, -1);
+
+ //Register the logger_factory
+ CosNaming::Name factory_name (1);
+ factory_name.length (1);
+ factory_name[0].id = CORBA::string_dup ("logger_factory");
+ this->my_name_server_->bind (factory_name,
+ factory.in (),
+ env);
+ TAO_CHECK_ENV_RETURN (env,-1);
+
+ return 0;
+}
+
+int
+Logger_Server::run (CORBA::Environment& env)
+{
+ if (this->orb_manager_.run (env) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Logger_Server::run"),
+ -1);
+ return 0;
+}
+
+Logger_Server::~Logger_Server (void)
+{
+ // Do nothing
+}
diff --git a/TAO/orbsvcs/tests/Logger/server_i.h b/TAO/orbsvcs/tests/Logger/server_i.h
new file mode 100644
index 00000000000..94b95ae1d6a
--- /dev/null
+++ b/TAO/orbsvcs/tests/Logger/server_i.h
@@ -0,0 +1,87 @@
+// -*- c++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/tests/Logger
+//
+// = FILENAME
+// server_i.h
+//
+// = DESCRIPTION
+// This class implements a simple "logger" CORBA server for the Logger
+// example using skeletons generated by the TAO ORB IDL compiler.
+//
+// = AUTHORS
+// Nagarajan Surendran <naga@cs.wustl.edu>
+// Matthew Braun <mjb2@cec.wustl.edu>
+//
+// ============================================================================
+
+#if !defined (_C_SERVER_H)
+#define _C_SERVER_H
+
+#include "ace/Get_Opt.h"
+#include "ace/Log_Msg.h"
+#include "tao/TAO.h"
+#include "orbsvcs/CosNamingC.h"
+#include "orbsvcs/Naming/Naming_Utils.h"
+#include "orbsvcs/Log/Logger_i.h"
+#include "orbsvcs/LoggerS.h"
+
+class Logger_Server
+{
+ // = TITLE
+ // Defines a Logger_Server class that implements the functionality
+ // of a server process as an object.
+ //
+ // = DESCRIPTION
+ // The interface is quite simple. A server program has to call
+ // init to initialize the logger_server's state and then call run
+ // to run the orb.
+public:
+ // = Initialization and termination methods.
+ Logger_Server (void);
+ // Constructor.
+
+ ~Logger_Server (void);
+ // Destructor.
+
+ int init (int argc,
+ char **argv,
+ CORBA::Environment& env);
+ // Initialize the Logger_Server state - parsing arguments and ...
+
+ int run (CORBA::Environment& env);
+ // Run the ORB.
+
+private:
+ int parse_args (void);
+ // Parses the commandline arguments.
+
+ int init_naming_service (CORBA::Environment &env);
+ // Initialises the name server and registers logger_factory with the
+ // name server.
+
+ TAO_ORB_Manager orb_manager_;
+ // The ORB manager.
+
+ TAO_Naming_Server my_name_server_;
+ // An instance of the name server used for registering the factory
+ // objects.
+
+ Logger_Factory_i factory_impl_;
+ // Implementation object of the Logger_Factory.
+
+ Logger_Factory_var factory_;
+ // Factory_var to register with NamingService.
+
+ int argc_;
+ // Number of commandline arguments.
+
+ char **argv_;
+ // commandline arguments.
+};
+
+#endif /* _C_SERVER_H */