diff options
author | Mark Spruiell <mes@zeroc.com> | 2002-04-01 20:41:28 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2002-04-01 20:41:28 +0000 |
commit | f5452c64777343b5b854629f600e1734ef6f9008 (patch) | |
tree | e4a76b4a6214ad9544470031848405acd0bc4197 /cpp | |
parent | adding IceBox (diff) | |
download | ice-f5452c64777343b5b854629f600e1734ef6f9008.tar.bz2 ice-f5452c64777343b5b854629f600e1734ef6f9008.tar.xz ice-f5452c64777343b5b854629f600e1734ef6f9008.zip |
initial check-in
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/demo/IceBox/Makefile | 22 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/.depend | 4 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/Client.cpp | 193 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/Hello.ice | 20 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/HelloI.cpp | 32 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/HelloI.h | 30 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/HelloServiceI.cpp | 54 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/HelloServiceI.h | 37 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/Makefile | 54 | ||||
-rw-r--r-- | cpp/demo/IceBox/hello/config | 78 | ||||
-rw-r--r-- | cpp/slice/IceBox/IceBox.ice | 142 | ||||
-rw-r--r-- | cpp/src/IceBox/.depend | 5 | ||||
-rw-r--r-- | cpp/src/IceBox/Admin.cpp | 120 | ||||
-rw-r--r-- | cpp/src/IceBox/Exception.cpp | 23 | ||||
-rw-r--r-- | cpp/src/IceBox/Makefile | 69 | ||||
-rw-r--r-- | cpp/src/IceBox/Server.cpp | 54 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.cpp | 320 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.h | 48 |
18 files changed, 1305 insertions, 0 deletions
diff --git a/cpp/demo/IceBox/Makefile b/cpp/demo/IceBox/Makefile new file mode 100644 index 00000000000..cc73ca32bed --- /dev/null +++ b/cpp/demo/IceBox/Makefile @@ -0,0 +1,22 @@ +# ********************************************************************** +# +# Copyright (c) 2002 +# MutableRealms, Inc. +# Huntsville, AL, USA +# +# All Rights Reserved +# +# ********************************************************************** + +top_srcdir = ../.. + +include $(top_srcdir)/config/Make.rules + +SUBDIRS = hello + +$(EVERYTHING):: + @for subdir in $(SUBDIRS); \ + do \ + echo "making $@ in $$subdir"; \ + ( cd $$subdir && $(MAKE) $@ ) || exit 1; \ + done diff --git a/cpp/demo/IceBox/hello/.depend b/cpp/demo/IceBox/hello/.depend new file mode 100644 index 00000000000..aead70e14e4 --- /dev/null +++ b/cpp/demo/IceBox/hello/.depend @@ -0,0 +1,4 @@ +Hello.o: Hello.cpp ../../../include/Ice/Stream.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/IceUtil/Config.h ../../../include/Ice/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalException.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/StreamF.h ../../../include/Ice/BuiltinSequences.h Hello.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/EndpointF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Current.h ../../../include/Ice/Identity.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/Ice/BasicStream.h ../../../include/Ice/InstanceF.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h ../../../include/Ice/Direct.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/ObjectFactory.h +Client.o: Client.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/IceUtil/Config.h ../../../include/Ice/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalException.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/StreamF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/Properties.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/LoggerF.h ../../../include/Ice/Communicator.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/EndpointF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Current.h ../../../include/Ice/Identity.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h ../../../include/Ice/Direct.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/SystemF.h ../../../include/Ice/SslExtensionF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/IdentityUtil.h Hello.h +HelloI.o: HelloI.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/IceUtil/Config.h ../../../include/Ice/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalException.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/StreamF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/Properties.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/LoggerF.h ../../../include/Ice/Communicator.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/EndpointF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Current.h ../../../include/Ice/Identity.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h ../../../include/Ice/Direct.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/SystemF.h ../../../include/Ice/SslExtensionF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/IdentityUtil.h HelloI.h Hello.h +HelloServiceI.o: HelloServiceI.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/IceUtil/Config.h ../../../include/Ice/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalException.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/StreamF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/Properties.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/LoggerF.h ../../../include/Ice/Communicator.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/EndpointF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Current.h ../../../include/Ice/Identity.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h ../../../include/Ice/Direct.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/SystemF.h ../../../include/Ice/SslExtensionF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/IdentityUtil.h HelloServiceI.h ../../../include/IceBox/IceBox.h HelloI.h Hello.h diff --git a/cpp/demo/IceBox/hello/Client.cpp b/cpp/demo/IceBox/hello/Client.cpp new file mode 100644 index 00000000000..fc0b25c6e0e --- /dev/null +++ b/cpp/demo/IceBox/hello/Client.cpp @@ -0,0 +1,193 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <Hello.h> + +using namespace std; + +void +menu() +{ + cout << + "usage:\n" + "t: send greeting as twoway\n" + "o: send greeting as oneway\n" + "O: send greeting as batch oneway\n" + "d: send greeting as datagram\n" + "D: send greeting as batch datagram\n" + "f: flush all batch requests\n" + "T: set a timeout\n" + "S: switch secure mode on/off\n" + "x: exit\n" + "?: help\n"; +} + +int +run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) +{ + Ice::PropertiesPtr properties = communicator->getProperties(); + const char* refProperty = "Hello.Hello"; + std::string ref = properties->getProperty(refProperty); + if (ref.empty()) + { + cerr << argv[0] << ": property `" << refProperty << "' not set" << endl; + return EXIT_FAILURE; + } + + Ice::ObjectPrx base = communicator->stringToProxy(ref); + HelloPrx twoway = HelloPrx::checkedCast(base->ice_twoway()->ice_timeout(-1)->ice_secure(false)); + if (!twoway) + { + cerr << argv[0] << ": invalid object reference" << endl; + return EXIT_FAILURE; + } + HelloPrx oneway = HelloPrx::uncheckedCast(twoway->ice_oneway()); + HelloPrx batchOneway = HelloPrx::uncheckedCast(twoway->ice_batchOneway()); + HelloPrx datagram = HelloPrx::uncheckedCast(twoway->ice_datagram()); + HelloPrx batchDatagram = HelloPrx::uncheckedCast(twoway->ice_batchDatagram()); + + bool secure = false; + int timeout = -1; + + menu(); + + char c; + do + { + try + { + cout << "==> "; + cin >> c; + if (c == 't') + { + twoway->hello(); + } + else if (c == 'o') + { + oneway->hello(); + } + else if (c == 'O') + { + batchOneway->hello(); + } + else if (c == 'd') + { + datagram->hello(); + } + else if (c == 'D') + { + batchDatagram->hello(); + } + else if (c == 'f') + { + batchOneway->ice_flush(); + batchDatagram->ice_flush(); + } + else if (c == 'T') + { + if (timeout == -1) + { + timeout = 2000; + } + else + { + timeout = -1; + } + + twoway = HelloPrx::uncheckedCast(twoway->ice_timeout(timeout)); + oneway = HelloPrx::uncheckedCast(oneway->ice_timeout(timeout)); + batchOneway = HelloPrx::uncheckedCast(batchOneway->ice_timeout(timeout)); + + if (timeout == -1) + { + cout << "timeout is now switched off" << endl; + } + else + { + cout << "timeout is now set to 2000ms" << endl; + } + } + else if (c == 'S') + { + secure = !secure; + + twoway = HelloPrx::uncheckedCast(twoway->ice_secure(secure)); + oneway = HelloPrx::uncheckedCast(oneway->ice_secure(secure)); + batchOneway = HelloPrx::uncheckedCast(batchOneway->ice_secure(secure)); + datagram = HelloPrx::uncheckedCast(datagram->ice_secure(secure)); + batchDatagram = HelloPrx::uncheckedCast(batchDatagram->ice_secure(secure)); + + if (secure) + { + cout << "secure mode is now on" << endl; + } + else + { + cout << "secure mode is now off" << endl; + } + } + else if (c == 'x') + { + // Nothing to do + } + else if (c == '?') + { + menu(); + } + else + { + cout << "unknown command `" << c << "'" << endl; + menu(); + } + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + } + } + while (cin.good() && c != 'x'); + + return EXIT_SUCCESS; +} + +int +main(int argc, char* argv[]) +{ + int status; + Ice::CommunicatorPtr communicator; + + try + { + Ice::PropertiesPtr properties = Ice::createPropertiesFromFile(argc, argv, "config"); + communicator = Ice::initializeWithProperties(properties); + status = run(argc, argv, communicator); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if (communicator) + { + try + { + communicator->destroy(); + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/demo/IceBox/hello/Hello.ice b/cpp/demo/IceBox/hello/Hello.ice new file mode 100644 index 00000000000..d0bf7f4b664 --- /dev/null +++ b/cpp/demo/IceBox/hello/Hello.ice @@ -0,0 +1,20 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef HELLO_ICE +#define HELLO_ICE + +class Hello +{ + void hello(); + void shutdown(); +}; + +#endif diff --git a/cpp/demo/IceBox/hello/HelloI.cpp b/cpp/demo/IceBox/hello/HelloI.cpp new file mode 100644 index 00000000000..a0b5969f726 --- /dev/null +++ b/cpp/demo/IceBox/hello/HelloI.cpp @@ -0,0 +1,32 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <HelloI.h> + +using namespace std; + +HelloI::HelloI(const Ice::CommunicatorPtr& communicator) : + _communicator(communicator) +{ +} + +void +HelloI::hello(const Ice::Current&) +{ + cout << "Hello World!" << endl; +} + +void +HelloI::shutdown(const Ice::Current&) +{ + cout << "Shutting down..." << endl; + _communicator->shutdown(); +} diff --git a/cpp/demo/IceBox/hello/HelloI.h b/cpp/demo/IceBox/hello/HelloI.h new file mode 100644 index 00000000000..88801bbcd8b --- /dev/null +++ b/cpp/demo/IceBox/hello/HelloI.h @@ -0,0 +1,30 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef HELLO_I_H +#define HELLO_I_H + +#include <Hello.h> + +class HelloI : public Hello +{ +public: + + HelloI(const Ice::CommunicatorPtr&); + + virtual void hello(const Ice::Current&); + virtual void shutdown(const Ice::Current&); + +private: + + Ice::CommunicatorPtr _communicator; +}; + +#endif diff --git a/cpp/demo/IceBox/hello/HelloServiceI.cpp b/cpp/demo/IceBox/hello/HelloServiceI.cpp new file mode 100644 index 00000000000..b7596d539e2 --- /dev/null +++ b/cpp/demo/IceBox/hello/HelloServiceI.cpp @@ -0,0 +1,54 @@ +#include <Ice/Ice.h> +#include <HelloServiceI.h> +#include <HelloI.h> + +using namespace std; + +extern "C" +{ + +// +// Factory function +// +::IceBox::ServicePtr +create(::Ice::CommunicatorPtr communicator) +{ + return new HelloServiceI; +} + +} + +HelloServiceI::HelloServiceI() +{ + cout << "HelloServiceI()" << endl; +} + +HelloServiceI::~HelloServiceI() +{ + cout << "~HelloServiceI()" << endl; +} + +void +HelloServiceI::init(const string& name, + const ::Ice::CommunicatorPtr& communicator, + const ::Ice::PropertiesPtr& properties, + const ::Ice::StringSeq& args) +{ + _adapter = communicator->createObjectAdapter(name + "Adapter"); + ::Ice::ObjectPtr object = new HelloI(communicator); + _adapter->add(object, ::Ice::stringToIdentity("hello")); + _adapter->activate(); +} + +void +HelloServiceI::start() +{ + cout << "HelloServiceI::start" << endl; +} + +void +HelloServiceI::stop() +{ + cout << "HelloServiceI::stop" << endl; + _adapter->deactivate(); +} diff --git a/cpp/demo/IceBox/hello/HelloServiceI.h b/cpp/demo/IceBox/hello/HelloServiceI.h new file mode 100644 index 00000000000..015b532c6aa --- /dev/null +++ b/cpp/demo/IceBox/hello/HelloServiceI.h @@ -0,0 +1,37 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef HELLO_SERVICE_I_H +#define HELLO_SERVICE_I_H + +#include <IceBox/IceBox.h> + +class HelloServiceI : public ::IceBox::Service +{ +public: + + HelloServiceI(); + virtual ~HelloServiceI(); + + virtual void init(const ::std::string&, + const ::Ice::CommunicatorPtr&, + const ::Ice::PropertiesPtr&, + const ::Ice::StringSeq&); + + virtual void start(); + + virtual void stop(); + +private: + + ::Ice::ObjectAdapterPtr _adapter; +}; + +#endif diff --git a/cpp/demo/IceBox/hello/Makefile b/cpp/demo/IceBox/hello/Makefile new file mode 100644 index 00000000000..237bce322d5 --- /dev/null +++ b/cpp/demo/IceBox/hello/Makefile @@ -0,0 +1,54 @@ +# ********************************************************************** +# +# Copyright (c) 2002 +# MutableRealms, Inc. +# Huntsville, AL, USA +# +# All Rights Reserved +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client + +NAME = libHelloService.so +VERSIONED_NAME = $(NAME).$(VERSION) + +TARGETS = $(CLIENT) $(NAME) $(VERSIONED_NAME) + +OBJS = Hello.o + +COBJS = Client.o + +SOBJS = HelloI.o \ + HelloServiceI.o + +SRCS = $(OBJS:.o=.cpp) \ + $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. $(CPPFLAGS) + +$(VERSIONED_NAME): $(OBJS) $(SOBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) $(SOBJS) + +$(NAME): $(VERSIONED_NAME) + rm -f $@ + ln -s $(VERSIONED_NAME) $@ + +$(CLIENT): $(OBJS) $(COBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(COBJS) $(LIBS) + +Hello.h Hello.cpp: Hello.ice $(SLICE2CPP) + rm -f Hello.h Hello.cpp + $(SLICE2CPP) Hello.ice + +clean:: + rm -f Hello.h Hello.cpp + +include .depend diff --git a/cpp/demo/IceBox/hello/config b/cpp/demo/IceBox/hello/config new file mode 100644 index 00000000000..a41c0094ec0 --- /dev/null +++ b/cpp/demo/IceBox/hello/config @@ -0,0 +1,78 @@ +# +# The IceBox server endpoint configuration +# +IceBox.ServiceManager.Endpoints=tcp -p 9998#:ssl -p 9999 + +# +# The hello service +# +IceBox.Service.Hello=libHelloService.so:create + +# +# The client reads this property to create the reference to the +# "hello" object in the server. +# +Hello.Hello=hello:tcp -p 10000:udp -p 10000#:ssl -p 10001#:sudp -p 10001 + +# +# The server creates one single object adapter with the name +# "helloadapater". The following line sets the endpoints for this +# adapter +# +Ice.Adapter.HelloAdapter.Endpoints=tcp -p 10000:udp -p 10000#:ssl -p 10001#:sudp -p 10001 + +# +# Warn about connection exceptions +# +Ice.ConnectionWarnings=1 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +Ice.Trace.Network=1 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +#Ice.Trace.Protocol=1 + +# +# Security Tracing +# +# 0 = no security tracing +# 1 = trace warning messages +# 2 = config file parsing warnings +# +#Ice.Trace.Security=4 + +# +# SSL Configuration File +# +# An XML based file that specifies the certificates, keys, SSL version +# and other pertinent information for creating an SSL connection. +# +Ice.Ssl.Client.CertPath=../../../certs +Ice.Ssl.Client.Config=sslconfig.xml +Ice.Ssl.Server.CertPath=../../../certs +Ice.Ssl.Server.Config=sslconfig.xml + +# +# Glacier settings +# +Glacier.Router.Endpoints=default -p 10005 +Glacier.Client.Endpoints=tcp:udp:ssl#:sudp +Glacier.Trace.Client=2 +Glacier.Trace.RoutingTable=1 + +# +# Uncomment the following lines if you want to run this demo with Glacier +# +#Ice.DefaultRouter=Glacier/router:default -p 10005 diff --git a/cpp/slice/IceBox/IceBox.ice b/cpp/slice/IceBox/IceBox.ice new file mode 100644 index 00000000000..90b6cdefbe3 --- /dev/null +++ b/cpp/slice/IceBox/IceBox.ice @@ -0,0 +1,142 @@ +// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef ICE_BOX_SERVICE_ICE
+#define ICE_BOX_SERVICE_ICE
+
+#include <Ice/BuiltinSequences.ice>
+#include <Ice/CommunicatorF.ice>
+#include <Ice/PropertiesF.ice>
+
+module IceBox
+{
+
+/**
+ *
+ * Used by a service to indicate failure.
+ // ML: How about adding a "reason" field?
+ *
+ **/
+local exception ServiceFailureException
+{
+};
+
+/**
+ *
+ * An application service managed by a [ServiceManager]. The
+ * [ServiceManager] will invoke [init] on all services prior to
+ * calling [start], and will invoke [stop] on all services when
+ * [ServiceManager::shutdown] is called. The order in which the
+ * services are invoked is not defined. The service lifecycle
+ * operations are described below:
+ *
+ * <itemizedlist>
+ *
+ * <listitem><para>[init] - This is the opportunity for the service to
+ * create a Communicator or Object Adapter, register servants,
+ * etc.</para></listitem>
+ *
+ * <listitem><para>[start] - Perform any client-side activities which
+ * might result in an invocation on a collocated service.
+ * </para></listitem>
+ *
+ * <listitem><para>[stop] - Destroy Communicators, deactivate Object
+ * Adapters, clean up resources, etc. The [ServiceManager] guarantees
+ * that [stop] will be invoked on all services whose [init] has been
+ * invoked.</para></listitem>
+ *
+ * </itemizedlist>
+ *
+ * <note><para>If the service requires an Object Adapter, it should be
+ * created and activated in [init]. However, the service should
+ * refrain from any client-side activities which might result in an
+ * invocation on a collocated service, because the order of service
+ * configuration is not defined and therefore the target service may
+ * not be active yet. Client-side activities can be safely performed
+ * in [start], as the [ServiceManager] guarantees that all services
+ * will be configured before [start] is invoked. </para></note>
+ *
+ * @see ServiceManager
+ *
+ **/
+local interface Service
+{
+ /**
+ *
+ * Initialize the service. The given Communicator is created by
+ * the [ServiceManager]. The service may use this instance, or may
+ * create its own as needed. The advantage of using this
+ * Communicator instance is that invocations between collocated
+ * services are optimized.
+ *
+ * <note><para>The [ServiceManager] owns this Communicator, and is
+ * responsible for destroying it.</para></note>
+ *
+ * @param name The service's name, as determined by the
+ * configuration.
+ *
+ * @param communicator The [ServiceManager]'s Communicator
+ * instance.
+ *
+ * @param properties The property set representing the service's
+ * command-line arguments of the form
+ * [--<replaceable>name</replaceable>.key=value].
+ *
+ * @param args The service arguments which were not converted into
+ * properties.
+ *
+ * @throws ServiceFailureException Raised if [init] failed.
+ *
+ * @see start
+ *
+ **/
+ void init(string name, Ice::Communicator communicator, Ice::Properties properties, Ice::StringSeq args)
+ throws ServiceFailureException;
+
+ /**
+ *
+ * Start the service.
+ *
+ * @throws ServiceFailureException Raised if [start] failed.
+ *
+ **/
+ void start()
+ throws ServiceFailureException;
+
+ /**
+ *
+ * Stop the service.
+ *
+ **/
+ void stop();
+};
+
+/**
+ *
+ * Administers a set of [Service] instances.
+ // ML: Additional operations to initialize services programatically instead of properties only?
+ *
+ * @see Service
+ *
+ **/
+interface ServiceManager
+{
+ /**
+ *
+ * Shutdown all services. This will cause [Service::stop] to be
+ * invoked on all configured services.
+ *
+ **/
+ void shutdown();
+};
+
+};
+
+#endif
diff --git a/cpp/src/IceBox/.depend b/cpp/src/IceBox/.depend new file mode 100644 index 00000000000..1b8329277ee --- /dev/null +++ b/cpp/src/IceBox/.depend @@ -0,0 +1,5 @@ +IceBox.o: IceBox.cpp ../../include/Ice/Stream.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/BuiltinSequences.h ../../include/IceBox/IceBox.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../../include/Ice/ObjectFactory.h +Exception.o: Exception.cpp ../../include/IceBox/IceBox.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../../include/Ice/Stream.h +ServiceManagerI.o: ServiceManagerI.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/Ice/DynamicLibrary.h ../../include/Ice/DynamicLibraryF.h ../IceBox/ServiceManagerI.h ../../include/IceBox/IceBox.h +Server.o: Server.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../IceBox/ServiceManagerI.h ../../include/IceBox/IceBox.h ../../include/Ice/DynamicLibraryF.h +Admin.o: Admin.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IceBox/IceBox.h diff --git a/cpp/src/IceBox/Admin.cpp b/cpp/src/IceBox/Admin.cpp new file mode 100644 index 00000000000..657f881a5a2 --- /dev/null +++ b/cpp/src/IceBox/Admin.cpp @@ -0,0 +1,120 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Application.h> +#include <IceBox/IceBox.h> + +using namespace std; +using namespace Ice; + +class Client : public Application +{ +public: + + void usage(); + virtual int run(int, char*[]); +}; + +int +main(int argc, char* argv[]) +{ + addArgumentPrefix("IceBox"); + + Client app; + int rc = app.main(argc, argv); + + return rc; +} + +void +Client::usage() +{ + cerr << "Usage: " << appName() << " [options] [command...]\n"; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + "\n" + "Commands:\n" + "shutdown Shutdown the server.\n" + ; +} + +int +Client::run(int argc, char* argv[]) +{ + vector<string> commands; + + int idx = 1; + while (idx < argc) + { + if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) + { + usage(); + return EXIT_SUCCESS; + } + else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + else if (argv[idx][0] == '-') + { + cerr << appName() << ": unknown option `" << argv[idx] << "'" << endl; + usage(); + return EXIT_FAILURE; + } + else + { + commands.push_back(argv[idx]); + ++idx; + } + } + + if (commands.empty()) + { + usage(); + return EXIT_SUCCESS; + } + + PropertiesPtr properties = communicator()->getProperties(); + const char* managerEndpointsProperty = "IceBox.ServiceManager.Endpoints"; + string managerEndpoints = properties->getProperty(managerEndpointsProperty); + if (managerEndpoints.empty()) + { + cerr << appName() << ": property `" << managerEndpointsProperty << "' is not set" << endl; + return EXIT_FAILURE; + } + + ObjectPrx base = communicator()->stringToProxy("ServiceManager:" + managerEndpoints); + IceBox::ServiceManagerPrx manager = IceBox::ServiceManagerPrx::checkedCast(base); + if (!manager) + { + cerr << appName() << ": `" << managerEndpoints << "' is not running" << endl; + return EXIT_FAILURE; + } + + vector<string>::const_iterator r; + for (r = commands.begin(); r != commands.end(); ++r) + { + if ((*r) == "shutdown") + { + manager->shutdown(); + } + else + { + cerr << appName() << ": unknown command `" << *r << "'" << endl; + usage(); + return EXIT_FAILURE; + } + } + + return EXIT_SUCCESS; +} diff --git a/cpp/src/IceBox/Exception.cpp b/cpp/src/IceBox/Exception.cpp new file mode 100644 index 00000000000..342349c4b1d --- /dev/null +++ b/cpp/src/IceBox/Exception.cpp @@ -0,0 +1,23 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <IceBox/IceBox.h> +#include <Ice/Stream.h> + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +void +IceBox::ServiceFailureException::ice_print(ostream& out) const +{ + Exception::ice_print(out); + out << ":\nservice failure exception"; +} diff --git a/cpp/src/IceBox/Makefile b/cpp/src/IceBox/Makefile new file mode 100644 index 00000000000..7a7d381449c --- /dev/null +++ b/cpp/src/IceBox/Makefile @@ -0,0 +1,69 @@ +#********************************************************************** +# +# Copyright (c) 2002 +# MutableRealms, Inc. +# Huntsville, AL, USA +# +# All Rights Reserved +# +# ********************************************************************** + +top_srcdir = ../.. + +BASE = libIceBox.so +VERSIONED_BASE = $(BASE).$(VERSION) + +NAME = $(top_srcdir)/lib/$(BASE) +VERSIONED_NAME = $(top_srcdir)/lib/$(VERSIONED_BASE) + +SERVER = $(top_srcdir)/bin/icebox +ADMIN = $(top_srcdir)/bin/iceboxadmin + +TARGETS = $(NAME) $(VERSIONED_NAME) $(SERVER) $(ADMIN) + +OBJS = IceBox.o \ + Exception.o + +SOBJS = ServiceManagerI.o \ + Server.o + +AOBJS = Admin.o + +SRCS = $(OBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) \ + $(AOBJS:.o=.cpp) + +HDIR = $(includedir)/IceBox +SDIR = $(slicedir)/IceBox +SLICECMD = $(SLICE2CPP) --include-dir IceBox -I$(slicedir) -I.. +SLICE2FREEZECMD = $(SLICE2FREEZE) --include-dir IceBox -I$(slicedir) -I.. + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I.. $(CPPFLAGS) + +$(VERSIONED_NAME): $(OBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -shared -o $@ $(OBJS) + +$(NAME): $(VERSIONED_NAME) + rm -f $@ + ln -s $(VERSIONED_BASE) $@ + +$(SERVER): $(SOBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(SOBJS) -lIceBox $(LIBS) + +$(ADMIN): $(AOBJS) + rm -f $@ + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(AOBJS) -lIceBox $(LIBS) + +$(HDIR)/IceBox.h IceBox.cpp: $(SDIR)/IceBox.ice $(SLICE2CPP) + rm -f $(HDIR)/IceBox.h IceBox.cpp + $(SLICECMD) --dll-export ICE_STORM_API $(SDIR)/IceBox.ice + mv IceBox.h $(HDIR) + +clean:: + rm -f $(HDIR)/IceBox.h IceBox.cpp + +include .depend diff --git a/cpp/src/IceBox/Server.cpp b/cpp/src/IceBox/Server.cpp new file mode 100644 index 00000000000..13c18d746df --- /dev/null +++ b/cpp/src/IceBox/Server.cpp @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceBox/ServiceManagerI.h> + +using namespace std; +using namespace Ice; +using namespace IceBox; + +int +main(int argc, char* argv[]) +{ + CommunicatorPtr communicator; + ServiceManagerPtr serviceManager; + int status; + + addArgumentPrefix("IceBox"); + + try + { + communicator = initialize(argc, argv); + ServiceManagerI* serviceManagerImpl = new ServiceManagerI(communicator); + serviceManager = serviceManagerImpl; + status = serviceManagerImpl->run(argc, argv); + } + catch (const Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + + if (communicator) + { + try + { + communicator->destroy(); + } + catch (const Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } + } + + return status; +} diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp new file mode 100644 index 00000000000..99ae44a9735 --- /dev/null +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -0,0 +1,320 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <Ice/DynamicLibrary.h> +#include <IceBox/ServiceManagerI.h> + +using namespace Ice; +using namespace IceInternal; +using namespace std; + +typedef IceBox::ServicePtr (*SERVICE_FACTORY)(CommunicatorPtr); + +IceBox::ServiceManagerI::ServiceManagerI(CommunicatorPtr communicator) + : _communicator(communicator) +{ +} + +IceBox::ServiceManagerI::~ServiceManagerI() +{ +} + +void +IceBox::ServiceManagerI::shutdown(const Current& current) +{ + _communicator->shutdown(); +} + +int +IceBox::ServiceManagerI::run(int& argc, char* argv[]) +{ + try + { + _logger = _communicator->getLogger(); + + ServiceManagerPtr obj = this; + + // + // Create an object adapter. Services probably should NOT share + // this object adapter, as the endpoint(s) for this object adapter + // will most likely need to be firewalled for security reasons. + // + ObjectAdapterPtr adapter = _communicator->createObjectAdapterFromProperty("ServiceManagerAdapter", + "IceBox.ServiceManager.Endpoints"); + adapter->add(obj, stringToIdentity("ServiceManager")); + + // + // Load and initialize the services. + // + if (!initServices(argc, argv)) + { + stopServices(); + return EXIT_FAILURE; + } + + // + // Invoke start() on the services. + // + if (!startServices()) + { + stopServices(); + return EXIT_FAILURE; + } + + // + // Start request dispatching after we've started the services. + // + adapter->activate(); + + _communicator->waitForShutdown(); + + // + // Invoke stop() on the services. + // + stopServices(); + } + catch (const Exception& ex) + { + Error out(_logger); + out << "ServiceManager: " << ex; + stopServices(); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} + +bool +IceBox::ServiceManagerI::initServices(int& argc, char* argv[]) +{ + // + // Retrieve all properties with the prefix "IceBox.Service.". + // These properties should have the following format: + // + // IceBox.Service.Foo=Package.Foo [args] + // + const string prefix = "IceBox.Service."; + PropertiesPtr properties = _communicator->getProperties(); + StringSeq allOptions = properties->getCommandLineOptions(); + StringSeq arr = properties->getProperties(prefix); + for (StringSeq::size_type i = 0; i < arr.size(); i += 2) + { + string name = arr[i].substr(prefix.size()); + string value = arr[i + 1]; + + // + // Separate the factory function from the arguments. + // + string factoryFunc; + StringSeq args; + string::size_type pos = value.find_first_of(" \t\n"); + if (pos == string::npos) + { + factoryFunc = value; + } + else + { + factoryFunc = value.substr(0, pos); + string::size_type beg = value.find_first_not_of(" \t\n", pos); + while (beg != string::npos) + { + string::size_type end = value.find_first_of(" \t\n", beg); + if (end == string::npos) + { + args.push_back(value.substr(beg)); + beg = end; + } + else + { + args.push_back(value.substr(beg, end - beg)); + beg = value.find_first_not_of(" \t\n", end); + } + } + } + + // + // Now we need to create a property set to pass to init(). + // The property set is populated from a number of sources. + // The precedence order (from lowest to highest) is: + // + // 1. Properties defined in the server property set (e.g., + // that were defined in the server's configuration file) + // 2. Service arguments + // 3. Server arguments + // + // We'll compose an array of arguments in the above order. + // + vector<string> l; + StringSeq::size_type j; + int k; + for (j = 0; j < allOptions.size(); j++) + { + if (allOptions[j].find("--" + name + ".") == 0) + { + l.push_back(allOptions[j]); + } + } + for (j = 0; j < args.size(); j++) + { + l.push_back(args[j]); + } + for (k = 1; k < argc; k++) + { + string s = argv[k]; + if (s.find("--" + name + ".") == 0) + { + l.push_back(s); + } + } + + // + // Create the service property set. + // + addArgumentPrefix(name); + int serviceArgc = static_cast<int>(l.size() + 1); + char** serviceArgv = new char*[serviceArgc + 1]; + serviceArgv[0] = argv[0]; + for (k = 1; k < serviceArgc; k++) + { + serviceArgv[k] = const_cast<char*>(l[k - 1].c_str()); + } + PropertiesPtr serviceProperties = createProperties(serviceArgc, serviceArgv); + StringSeq serviceArgs; + for (k = 1; k < serviceArgc; k++) + { + serviceArgs.push_back(serviceArgv[k]); + } + delete[] serviceArgv; + + // + // Load the dynamic library. + // + string::size_type colon = factoryFunc.rfind(':'); + if (colon == string::npos || colon == factoryFunc.size() - 1) + { + Error out(_logger); + out << "ServiceManager: invalid factory function `" << factoryFunc << "'"; + return false; + } + string libName = factoryFunc.substr(0, colon); + string funcName = factoryFunc.substr(colon + 1); + DynamicLibraryPtr library = new DynamicLibrary(); + if (!library->load(libName)) + { + string msg = library->getErrorMessage(); + Error out(_logger); + out << "ServiceManager: unable to load library `" << libName << "'"; + if (!msg.empty()) + { + out << ": " << msg; + } + return false; + } + + // + // Lookup the factory function and invoke it. + // + DynamicLibrary::symbol_type sym = library->getSymbol(funcName); + if (sym == 0) + { + string msg = library->getErrorMessage(); + Error out(_logger); + out << "ServiceManager: unable to load symbol `" << funcName << "'"; + if (!msg.empty()) + { + out << ": " << msg; + } + return false; + } + SERVICE_FACTORY factory = (SERVICE_FACTORY)sym; + ServicePtr service; + try + { + service = factory(_communicator); + } + catch (const Exception& ex) + { + Error out(_logger); + out << "ServiceManager: exception in factory function `" << funcName << "': " << ex; + return false; + } + + // + // Invoke Service::init(). + // + try + { + service->init(name, _communicator, serviceProperties, serviceArgs); + _services[name] = service; + _libraries.push_back(library); + } + catch (const ServiceFailureException& ex) + { + Error out(_logger); + out << "ServiceManager: initialization failed for service " << name; + return false; + } + catch (const Exception& ex) + { + Error out(_logger); + out << "ServiceManager: exception while initializing service " << name << ": " << ex; + return false; + } + } + + return true; +} + +bool +IceBox::ServiceManagerI::startServices() +{ + map<string,ServicePtr>::const_iterator r; + for (r = _services.begin(); r != _services.end(); ++r) + { + try + { + (*r).second->start(); + } + catch (const ServiceFailureException& ex) + { + Error out(_logger); + out << "ServiceManager: start failed for service " << (*r).first; + return false; + } + catch (const Exception& ex) + { + Error out(_logger); + out << "ServiceManager: exception in start for service " << (*r).first << ": " << ex; + return false; + } + } + + return true; +} + +void +IceBox::ServiceManagerI::stopServices() +{ + map<string,ServicePtr>::const_iterator r; + for (r = _services.begin(); r != _services.end(); ++r) + { + try + { + (*r).second->stop(); + } + catch (const Exception& ex) + { + Error out(_logger); + out << "ServiceManager: exception in stop for service " << (*r).first << ": " << ex; + } + } + _services.clear(); +} diff --git a/cpp/src/IceBox/ServiceManagerI.h b/cpp/src/IceBox/ServiceManagerI.h new file mode 100644 index 00000000000..8a84d5aff22 --- /dev/null +++ b/cpp/src/IceBox/ServiceManagerI.h @@ -0,0 +1,48 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef SERVICE_MANAGER_I_H +#define SERVICE_MANAGER_I_H + +#include <IceBox/IceBox.h> +#include <Ice/LoggerF.h> +#include <Ice/CommunicatorF.h> +#include <Ice/DynamicLibraryF.h> +#include <map> + +namespace IceBox +{ + +class ServiceManagerI : public ServiceManager +{ +public: + + ServiceManagerI(::Ice::CommunicatorPtr); + virtual ~ServiceManagerI(); + + virtual void shutdown(const ::Ice::Current&); + + int run(int&, char*[]); + +private: + + bool initServices(int&, char*[]); + bool startServices(); + void stopServices(); + + ::Ice::CommunicatorPtr _communicator; + ::Ice::LoggerPtr _logger; + std::map<std::string, ServicePtr> _services; + std::vector< ::IceInternal::DynamicLibraryPtr > _libraries; +}; + +} + +#endif |