summaryrefslogtreecommitdiff
path: root/ACE/netsvcs/clients/Logger
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:30 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2006-07-24 15:50:30 +0000
commitc44379cc7d9c7aa113989237ab0f56db12aa5219 (patch)
tree66a84b20d47f2269d8bdc6e0323f338763424d3a /ACE/netsvcs/clients/Logger
parent3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff)
downloadATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz
Repo restructuring
Diffstat (limited to 'ACE/netsvcs/clients/Logger')
-rw-r--r--ACE/netsvcs/clients/Logger/Logger.mpc22
-rw-r--r--ACE/netsvcs/clients/Logger/Makefile.am58
-rw-r--r--ACE/netsvcs/clients/Logger/README18
-rw-r--r--ACE/netsvcs/clients/Logger/direct_logging.cpp84
-rw-r--r--ACE/netsvcs/clients/Logger/indirect_logging.cpp60
5 files changed, 242 insertions, 0 deletions
diff --git a/ACE/netsvcs/clients/Logger/Logger.mpc b/ACE/netsvcs/clients/Logger/Logger.mpc
new file mode 100644
index 00000000000..e4dbe0a0046
--- /dev/null
+++ b/ACE/netsvcs/clients/Logger/Logger.mpc
@@ -0,0 +1,22 @@
+// -*- MPC -*-
+// $Id$
+
+project(direct logging) : aceexe {
+ avoids += ace_for_tao
+ exename = direct_logging
+ libs += netsvcs
+ after += netsvcs
+ Source_Files {
+ direct_logging.cpp
+ }
+}
+
+project(indirect logging) : aceexe {
+ avoids += ace_for_tao
+ exename = indirect_logging
+ libs += netsvcs
+ after += netsvcs
+ Source_Files {
+ indirect_logging.cpp
+ }
+}
diff --git a/ACE/netsvcs/clients/Logger/Makefile.am b/ACE/netsvcs/clients/Logger/Makefile.am
new file mode 100644
index 00000000000..8c3ae8decb3
--- /dev/null
+++ b/ACE/netsvcs/clients/Logger/Makefile.am
@@ -0,0 +1,58 @@
+## Process this file with automake to create Makefile.in
+##
+## $Id$
+##
+## This file was generated by MPC. Any changes made directly to
+## this file will be lost the next time it is generated.
+##
+## MPC Command:
+## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu
+
+ACE_BUILDDIR = $(top_builddir)
+ACE_ROOT = $(top_srcdir)
+
+noinst_PROGRAMS =
+
+## Makefile.direct_logging.am
+
+if !BUILD_ACE_FOR_TAO
+noinst_PROGRAMS += direct_logging
+
+direct_logging_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR)
+
+direct_logging_SOURCES = \
+ direct_logging.cpp
+
+direct_logging_LDADD = \
+ $(top_builddir)/netsvcs/lib/libnetsvcs.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+endif !BUILD_ACE_FOR_TAO
+
+## Makefile.indirect_logging.am
+
+if !BUILD_ACE_FOR_TAO
+noinst_PROGRAMS += indirect_logging
+
+indirect_logging_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR)
+
+indirect_logging_SOURCES = \
+ indirect_logging.cpp
+
+indirect_logging_LDADD = \
+ $(top_builddir)/netsvcs/lib/libnetsvcs.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+endif !BUILD_ACE_FOR_TAO
+
+## Clean up template repositories, etc.
+clean-local:
+ -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.*
+ -rm -f gcctemp.c gcctemp so_locations *.ics
+ -rm -rf cxx_repository ptrepository ti_files
+ -rm -rf templateregistry ir.out
+ -rm -rf ptrepository SunWS_cache Templates.DB
diff --git a/ACE/netsvcs/clients/Logger/README b/ACE/netsvcs/clients/Logger/README
new file mode 100644
index 00000000000..87e324ab0d8
--- /dev/null
+++ b/ACE/netsvcs/clients/Logger/README
@@ -0,0 +1,18 @@
+This directory contains two sample logging applications that implement
+and test the ACE distributed logging service.
+
+ . indirect_logging.cpp
+
+ This program talks to the ACE Client Logging Daemon on
+ the localhost, which forwards the messages to Server
+ Logging Daemon. The Client Logging Daemon and Server
+ Logging Daemon both must be started before you can run
+ this test.
+
+ . direct_logging.cpp
+
+ This program talks directly to the Server Logging
+ Daemon. The Server Logging Daemon must be started
+ before you can run this test.
+
+To start these daemons, please check out the ../../servers/ directory.
diff --git a/ACE/netsvcs/clients/Logger/direct_logging.cpp b/ACE/netsvcs/clients/Logger/direct_logging.cpp
new file mode 100644
index 00000000000..4ed5e67aef3
--- /dev/null
+++ b/ACE/netsvcs/clients/Logger/direct_logging.cpp
@@ -0,0 +1,84 @@
+// $Id$
+
+// This program sends logging records directly to the server, rather
+// than going through the client logging daemon.
+
+#include "ace/SOCK_Connector.h"
+#include "ace/Log_Record.h"
+#include "ace/Log_Msg.h"
+#include "ace/OS_NS_time.h"
+#include "ace/OS_NS_stdlib.h"
+#include "ace/OS_NS_unistd.h"
+#include "ace/CDR_Stream.h"
+
+ACE_RCSID(Logger, direct_logging, "$Id$")
+
+static u_short LOGGER_PORT = ACE_DEFAULT_SERVER_PORT;
+static const ACE_TCHAR *const LOGGER_HOST = ACE_DEFAULT_SERVER_HOST;
+static const ACE_TCHAR *const DATA = ACE_TEXT ("hello world\n");
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv[])
+{
+ u_short logger_port = argc > 1 ? ACE_OS::atoi (argv[1]) : LOGGER_PORT;
+ const ACE_TCHAR *logger_host = argc > 2 ? argv[2] : LOGGER_HOST;
+
+ ACE_SOCK_Stream logger;
+ ACE_SOCK_Connector connector;
+ ACE_INET_Addr addr (logger_port, logger_host);
+ ACE_Log_Record log_record (LM_DEBUG,
+ ACE_OS::time ((time_t *) 0),
+ ACE_OS::getpid ());
+
+ if (connector.connect (logger, addr) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1);
+
+ log_record.msg_data (DATA);
+ const size_t max_payload_size =
+ 4 // type()
+ + 8 // timestamp
+ + 4 // process id
+ + 4 // data length
+ + ACE_Log_Record::MAXLOGMSGLEN // data
+ + ACE_CDR::MAX_ALIGNMENT; // padding;
+
+ // Insert contents of <log_record> into payload stream.
+ ACE_OutputCDR payload (max_payload_size);
+ payload << log_record;
+
+ // Get the number of bytes used by the CDR stream.
+ ACE_CDR::ULong length = payload.total_length ();
+
+ // Send a header so the receiver can determine the byte order and
+ // size of the incoming CDR stream.
+ ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8);
+ header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER);
+
+ // Store the size of the payload that follows
+ header << ACE_CDR::ULong (length);
+
+ // Use an iovec to send both buffer and payload simultaneously.
+ iovec iov[2];
+ iov[0].iov_base = header.begin ()->rd_ptr ();
+ iov[0].iov_len = 8;
+ iov[1].iov_base = payload.begin ()->rd_ptr ();
+ iov[1].iov_len = length;
+
+ if (logger.sendv_n (iov, 2) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send"), -1);
+ else if (logger.close () == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close"), -1);
+
+#if defined (ACE_WIN32)
+ // !!Important, Winsock is broken in that if you don't close
+ // down the connection before exiting main, you'll lose data.
+ // More over, your server might get "Access Violation" from
+ // within Winsock functions.
+
+ // Here we close down the connection to Logger by redirecting
+ // the logging destination back to stderr.
+ ACE_LOG_MSG->open (0, ACE_Log_Msg::STDERR, 0);
+#endif /* ACE_WIN32 */
+
+ return 0;
+}
diff --git a/ACE/netsvcs/clients/Logger/indirect_logging.cpp b/ACE/netsvcs/clients/Logger/indirect_logging.cpp
new file mode 100644
index 00000000000..40cd0d61e10
--- /dev/null
+++ b/ACE/netsvcs/clients/Logger/indirect_logging.cpp
@@ -0,0 +1,60 @@
+// $Id$
+
+// This is a simple test that sends logging records to the Client
+// Logging Daemon running on the localhost. This daemon then forwards
+// them to the Server Logging Daemon. If there is no Server Logging
+// Daemon, the logging records will be written to stderr.
+
+#include "ace/OS_NS_time.h"
+#include "ace/OS_NS_stdlib.h"
+#include "ace/Log_Msg.h"
+#include "ace/Log_Record.h"
+
+ACE_RCSID(Logger, indirect_logging, "$Id$")
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv[])
+{
+ const ACE_TCHAR *prog_name = argv[0];
+ int iterations = argc < 2 ? 10 : ACE_OS::atoi (argv[1]);
+ const ACE_TCHAR *logger_key = argc < 3 ? ACE_DEFAULT_LOGGER_KEY : argv[2];
+ int verbose = argc < 4 ? 0 : ACE_Log_Msg::VERBOSE;
+
+ ACE_OS::srand ((u_int) ACE_OS::time (0));
+
+ if (ACE_LOG_MSG->open (prog_name, ACE_Log_Msg::LOGGER, logger_key) == -1)
+ {
+ ACE_ERROR ((LM_ERROR, "Cannot open logger, using STDERR\n"));
+
+ if (ACE_LOG_MSG->open (prog_name, ACE_Log_Msg::STDERR | verbose) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "Cannot open logger\n"), -1);
+ }
+
+ ACE_DEBUG ((LM_STARTUP, "starting up the test\n"));
+
+ for (int i = 0; i < iterations; i++)
+ {
+ size_t priority = ACE_OS::rand () % int (LM_MAX);
+ ACE_POW (priority);
+ ACE_Log_Priority log_priority = ACE_Log_Priority (priority);
+ ACE_DEBUG ((log_priority,
+ "random message %s (%d)...\n",
+ ACE_Log_Record::priority_name (log_priority),
+ priority));
+ }
+
+ ACE_DEBUG ((LM_SHUTDOWN, "closing down the test\n"));
+
+#if defined (ACE_WIN32)
+ // !!Important, Winsock is broken in that if you don't close
+ // down the connection before exiting main, you'll lose data.
+ // More over, your server might get "Access Violation" from
+ // within Winsock functions.
+
+ // Here we close down the connection to Logger by redirecting
+ // the logging destination back to stderr.
+ ACE_LOG_MSG->open (0, ACE_Log_Msg::STDERR, 0);
+#endif /* ACE_WIN32 */
+
+ return 0;
+}