summaryrefslogtreecommitdiff
path: root/ACE/examples/Service_Configurator/Misc
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/examples/Service_Configurator/Misc
parent3aff90f4a822fcf5d902bbfbcc9fa931d6191a8c (diff)
downloadATCD-c44379cc7d9c7aa113989237ab0f56db12aa5219.tar.gz
Repo restructuring
Diffstat (limited to 'ACE/examples/Service_Configurator/Misc')
-rw-r--r--ACE/examples/Service_Configurator/Misc/.cvsignore1
-rw-r--r--ACE/examples/Service_Configurator/Misc/Makefile.am50
-rw-r--r--ACE/examples/Service_Configurator/Misc/README23
-rw-r--r--ACE/examples/Service_Configurator/Misc/Service_Configurator_Misc.mpc18
-rw-r--r--ACE/examples/Service_Configurator/Misc/Timer_Service.cpp135
-rw-r--r--ACE/examples/Service_Configurator/Misc/Timer_Service.h71
-rw-r--r--ACE/examples/Service_Configurator/Misc/main.cpp80
-rw-r--r--ACE/examples/Service_Configurator/Misc/svc.conf18
-rw-r--r--ACE/examples/Service_Configurator/Misc/svc.conf28
9 files changed, 394 insertions, 0 deletions
diff --git a/ACE/examples/Service_Configurator/Misc/.cvsignore b/ACE/examples/Service_Configurator/Misc/.cvsignore
new file mode 100644
index 00000000000..ba2906d0666
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/.cvsignore
@@ -0,0 +1 @@
+main
diff --git a/ACE/examples/Service_Configurator/Misc/Makefile.am b/ACE/examples/Service_Configurator/Misc/Makefile.am
new file mode 100644
index 00000000000..f0de4232add
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/Makefile.am
@@ -0,0 +1,50 @@
+## 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)
+
+## Makefile.Service_Configurator_Misc_Timer.am
+
+noinst_LTLIBRARIES = libtimer.la
+
+libtimer_la_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR) \
+ -DACE_BUILD_SVC_DLL
+
+libtimer_la_SOURCES = \
+ Timer_Service.cpp
+
+noinst_HEADERS = \
+ Timer_Service.h
+
+## Makefile.Service_Configurator_Misc_Main.am
+noinst_PROGRAMS = main
+
+main_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR)
+
+main_SOURCES = \
+ main.cpp \
+ Timer_Service.h
+
+main_LDADD = \
+ libtimer.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+## 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/examples/Service_Configurator/Misc/README b/ACE/examples/Service_Configurator/Misc/README
new file mode 100644
index 00000000000..c3b22759926
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/README
@@ -0,0 +1,23 @@
+This directory contains an example that illustrates how the ACE
+Service Configurator can configure static and dynamic services, both
+from the command-line and from a svc.config file. We define several
+instances, i.e., Timer_Service_1 and Timer_Service_2 of the SAME
+service just to exercise different configuration options. A "real"
+application would usually define different services.
+
+Windows CE:
+-----------
+
+When using Windows CE (WCE) emulator, make sure that you use the
+following command to copy the svc.conf files into the top-level
+directory in CE emulator.
+
+ empfile -c svc.conf1 wce:\svc.conf1
+ empfile -c svc.conf2 wce:\svc.conf2
+
+The command "empfile" moves the files to emulator's root directory and
+resigters the files with CE emulator's object store.
+
+Also make sure you type in at least one argument (which is argv[0],)
+when the program dialog box requests you to key in the program
+arguments. Otherwise, the program won't run at all.
diff --git a/ACE/examples/Service_Configurator/Misc/Service_Configurator_Misc.mpc b/ACE/examples/Service_Configurator/Misc/Service_Configurator_Misc.mpc
new file mode 100644
index 00000000000..9c9744fd601
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/Service_Configurator_Misc.mpc
@@ -0,0 +1,18 @@
+// -*- MPC -*-
+// $Id$
+
+project(*Timer) : acelib {
+ sharedname = timer
+ dynamicflags += ACE_BUILD_SVC_DLL
+ Source_Files {
+ Timer_Service.cpp
+ }
+}
+project(*Main) : aceexe {
+ exename = main
+ after += Service_Configurator_Misc_Timer
+ libs += timer
+ Source_Files {
+ main.cpp
+ }
+}
diff --git a/ACE/examples/Service_Configurator/Misc/Timer_Service.cpp b/ACE/examples/Service_Configurator/Misc/Timer_Service.cpp
new file mode 100644
index 00000000000..82ace8f657c
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/Timer_Service.cpp
@@ -0,0 +1,135 @@
+// $Id$
+
+#include "ace/OS_NS_string.h"
+#include "Timer_Service.h"
+#include "ace/Log_Msg.h"
+
+ACE_RCSID(Misc, Timer_Service, "$Id$")
+
+Timer_Service_1::Timer_Service_1 (void)
+{
+ ACE_OS::strcpy (this->name_,
+ ACE_TEXT ("Timer_Service_1"));
+}
+
+int
+Timer_Service_1::init (int argc, ACE_TCHAR *argv[])
+{
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("in Timer_Service::init, argv[0] = %s, argc == %d\n"),
+ argv[0], argc));
+
+ // Printout the <argv> values for sanity's sake.
+ for (int i = 0; i < argc; i++)
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("argv[%d] = %s\n"),
+ i, argv[i]));
+
+ int interval = Timer_Service_1::TIMEOUT;
+
+ if (argc > 1)
+ {
+ // If the second argument exists use this as the interval for
+ // the periodic timer. Otherwise, go off every TIMEOUT seconds.
+
+ interval = ACE_OS::atoi (argv[1]);
+
+ if (interval == 0)
+ interval = Timer_Service_1::TIMEOUT;
+ }
+
+ if (argc > 2)
+ {
+ // If the third argument exists use it to control the maximum
+ // number of timeouts.
+ this->max_timeouts_ = ACE_OS::atoi (argv[2]);
+
+ if (this->max_timeouts_ == 0)
+ this->max_timeouts_ = Timer_Service_1::MAX_TIMEOUTS;
+ }
+
+ this->cur_timeouts_ = 0;
+
+ // If the fourth argument exists take this as an indication to
+ // enable tracing.
+#if defined (ACE_HAS_TRACE)
+ if (argc > 3)
+ ACE_Trace::start_tracing ();
+ else
+ ACE_Trace::stop_tracing ();
+#endif /* ACE_HAS_TRACE */
+
+ // Register the timer to go off in 1 second, and then to go off
+ // every <interval> seconds.
+ if (ACE_Reactor::instance ()->schedule_timer
+ (this,
+ 0,
+ ACE_Time_Value (1),
+ ACE_Time_Value (interval)) == -1)
+ return -1;
+ else
+ return 0;
+}
+
+int
+Timer_Service_1::handle_timeout (const ACE_Time_Value &tv,
+ const void *)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%x) in %s::handle_timeout sec = %d, usec = %d")
+ ACE_TEXT (" cur_timeouts = %d, max_timeouts = %d\n"),
+ this,
+ this->name_,
+ tv.sec (),
+ tv.usec (),
+ this->cur_timeouts_,
+ this->max_timeouts_));
+
+ this->cur_timeouts_++;
+
+ if (this->cur_timeouts_ == this->max_timeouts_)
+ // Shutdown the test.
+ return -1;
+ else
+ return 0;
+}
+
+int
+Timer_Service_1::handle_close (ACE_HANDLE,
+ ACE_Reactor_Mask)
+{
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("closing down the timer test\n")));
+
+ // Remove ourselves from the timer queue.
+ ACE_Reactor::instance ()->cancel_timer (this);
+
+ ACE_Reactor::end_event_loop();
+ return 0;
+}
+
+Timer_Service_2::Timer_Service_2 (void)
+{
+ ACE_OS::strcpy (this->name_,
+ ACE_TEXT ("Timer_Service_2"));
+}
+
+Timer_Service_3::Timer_Service_3 (void)
+{
+ ACE_OS::strcpy (this->name_,
+ ACE_TEXT ("Timer_Service_3"));
+}
+
+// Define the object that describes the service.
+ACE_STATIC_SVC_DEFINE (Timer_Service_1,
+ ACE_TEXT ("Timer_Service_1"),
+ ACE_SVC_OBJ_T,
+ &ACE_SVC_NAME (Timer_Service_1),
+ ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
+ 0)
+
+// The following are "Factories" used by the <ACE_Service_Config> and
+// svc.conf file to dynamically initialize the state of the Timer
+// Services.
+ACE_SVC_FACTORY_DEFINE (Timer_Service_1)
+ACE_SVC_FACTORY_DEFINE (Timer_Service_2)
+ACE_SVC_FACTORY_DEFINE (Timer_Service_3)
diff --git a/ACE/examples/Service_Configurator/Misc/Timer_Service.h b/ACE/examples/Service_Configurator/Misc/Timer_Service.h
new file mode 100644
index 00000000000..01aa77b7317
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/Timer_Service.h
@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//
+// $Id$
+
+#include "ace/svc_export.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ace/Service_Config.h"
+#include "ace/Reactor.h"
+#include "ace/Service_Object.h"
+
+
+class ACE_Svc_Export Timer_Service_1 : public ACE_Service_Object
+{
+ // = TITLE
+ // Demonstrates a simple timer service that can be configured
+ // statically.
+public:
+ Timer_Service_1 (void);
+ // Default constructor.
+
+ virtual int init (int argc, ACE_TCHAR *argv[]);
+ // Initialization hook.
+
+ virtual int handle_timeout (const ACE_Time_Value &,
+ const void *);
+ // Timeout hook.
+
+ virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask);
+ // Close hook.
+
+protected:
+ ACE_TCHAR name_[BUFSIZ];
+ // Keep track of which service this is!
+
+private:
+ enum
+ {
+ TIMEOUT = 4, // Wait 4 seconds between timeouts
+ MAX_TIMEOUTS = 10 // Don't timeout for more than 10 times.
+ };
+
+ int max_timeouts_;
+ // Maximum number of timeouts before shutting down the test.
+
+ int cur_timeouts_;
+ // Current number of timeouts.
+};
+
+class ACE_Svc_Export Timer_Service_2 : public Timer_Service_1
+{
+public:
+ Timer_Service_2 (void);
+ // Default constructor.
+};
+
+class ACE_Svc_Export Timer_Service_3 : public Timer_Service_1
+{
+public:
+ Timer_Service_3 (void);
+ // Default constructor.
+};
+
+// Declare both static and dynamic services.
+ACE_STATIC_SVC_DECLARE_EXPORT (ACE_Svc, Timer_Service_1)
+ACE_SVC_FACTORY_DECLARE (Timer_Service_1)
+ACE_SVC_FACTORY_DECLARE (Timer_Service_2)
+ACE_SVC_FACTORY_DECLARE (Timer_Service_3)
diff --git a/ACE/examples/Service_Configurator/Misc/main.cpp b/ACE/examples/Service_Configurator/Misc/main.cpp
new file mode 100644
index 00000000000..a7ff6c9da26
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/main.cpp
@@ -0,0 +1,80 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// examples/Service_Configurator/Misc
+//
+// = FILENAME
+// main.cpp
+//
+// = DESCRIPTION
+// This directory contains an example that illustrates how the ACE
+// Service Configurator can configure static and dynamic services,
+// both from the command-line and from a svc.config file.
+//
+// = AUTHOR
+// Doug Schmidt <schmidt@cs.wustl.edu>
+//
+// ============================================================================
+
+#include "ace/OS_main.h"
+#include "ace/Service_Config.h"
+#include "ace/ARGV.h"
+#include "ace/Log_Msg.h"
+#include "Timer_Service.h"
+
+ACE_RCSID(Misc, main, "$Id$")
+
+// Create an object that will insert the <Timer_Service> into the list
+// of statically linked services that the <ACE_Service_Config> will
+// process at run-time.
+ACE_STATIC_SVC_REQUIRE (Timer_Service_1)
+
+int
+ACE_TMAIN (int, ACE_TCHAR *argv[])
+{
+ // Set up an argument vector that we can add entries to!
+ ACE_ARGV args;
+
+ // Manufacture a "fake" svc.conf entry to demonstrate the -S option
+ // that allows us to pass these entries via the "command-line"
+ // rather than the svc.conf file.
+ args.add (argv[0]);
+ args.add (ACE_TEXT ("-y"));
+ args.add (ACE_TEXT ("-d"));
+ args.add (ACE_TEXT ("-S"));
+ args.add (ACE_TEXT ("\"static Timer_Service_1 'timer 1 10 $TRACE'\""));
+ args.add (ACE_TEXT ("-S"));
+ args.add (ACE_TEXT ("\"dynamic Timer_Service_2 Service_Object * ./Timer:_make_Timer_Service_2() 'timer 2 10 $TRACE'\""));
+ // Test the -f option!
+ args.add (ACE_TEXT ("-fsvc.conf1"));
+ args.add (ACE_TEXT ("-fsvc.conf2"));
+
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("argc = %d\n"),
+ args.argc ()));
+
+ // Print the contents of the combined <ACE_ARGV>.
+ for (int i = 0; i < args.argc (); i++)
+ ACE_DEBUG ((LM_DEBUG,
+ ACE_TEXT ("(%d) %s\n"),
+ i,
+ args.argv ()[i]));
+
+ int result = ACE_Service_Config::open (args.argc (),
+ args.argv (),
+ ACE_DEFAULT_LOGGER_KEY,
+ 0);
+ if (result != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ACE_TEXT ("%p\n"),
+ ACE_TEXT ("open")),
+ 1);
+
+ // Run forever, performing the configured services until we
+ // shutdown.
+
+ ACE_Reactor::run_event_loop ();
+ return 0;
+}
diff --git a/ACE/examples/Service_Configurator/Misc/svc.conf1 b/ACE/examples/Service_Configurator/Misc/svc.conf1
new file mode 100644
index 00000000000..d0f552caa6e
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/svc.conf1
@@ -0,0 +1,8 @@
+# Dynamically configure the Timer_Service into the application process
+# and pass in up to 4 arguments. The final 3 arguments are retrieved
+# from environment variables, so they can be set by changing your
+# environment before running the main program. If you don't have
+# these variables set they are ignored.
+dynamic Timer_Service_3 Service_Object *
+ ./Timer:_make_Timer_Service_3()
+ "timer $INTERVAL $MAX_TIMEOUTS $TRACE"
diff --git a/ACE/examples/Service_Configurator/Misc/svc.conf2 b/ACE/examples/Service_Configurator/Misc/svc.conf2
new file mode 100644
index 00000000000..1bef63e8d48
--- /dev/null
+++ b/ACE/examples/Service_Configurator/Misc/svc.conf2
@@ -0,0 +1,8 @@
+# Statically configure the Timer_Service, which must have been linked
+# statically into the application process. Up to 4 arguments are
+# passed in. The final 3 arguments are retrieved from environment
+# variables, so they can be set by changing your environment before
+# running the main program. If you don't have these variables set
+# they are ignored.
+static Timer_Service_1
+ "timer $INTERVAL $MAX_TIMEOUTS $TRACE"