summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-03-17 14:10:35 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-03-17 14:10:35 +0000
commit3e3dd221a3b5a11b6715fdb8443203dac704b356 (patch)
tree6bf5750c529ab12bd713b28e22901069c878ff65 /cpp/src
parentstarted to add evictor (diff)
downloadice-3e3dd221a3b5a11b6715fdb8443203dac704b356.tar.bz2
ice-3e3dd221a3b5a11b6715fdb8443203dac704b356.tar.xz
ice-3e3dd221a3b5a11b6715fdb8443203dac704b356.zip
Made IceBox a Ice::Service
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceBox/Makefile2
-rw-r--r--cpp/src/IceBox/Server.cpp88
-rw-r--r--cpp/src/IceBox/Service.cpp144
-rw-r--r--cpp/src/IceBox/ServiceManagerI.cpp55
-rw-r--r--cpp/src/IceBox/ServiceManagerI.h11
-rw-r--r--cpp/src/IceBox/iceboxS.dsp2
6 files changed, 173 insertions, 129 deletions
diff --git a/cpp/src/IceBox/Makefile b/cpp/src/IceBox/Makefile
index cbd5b2d7d8e..3d616795891 100644
--- a/cpp/src/IceBox/Makefile
+++ b/cpp/src/IceBox/Makefile
@@ -23,7 +23,7 @@ OBJS = IceBox.o \
Exception.o
SOBJS = ServiceManagerI.o \
- Server.o
+ Service.o
AOBJS = Admin.o
diff --git a/cpp/src/IceBox/Server.cpp b/cpp/src/IceBox/Server.cpp
deleted file mode 100644
index 97c6cb2e975..00000000000
--- a/cpp/src/IceBox/Server.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-// **********************************************************************
-//
-// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
-//
-// This copy of Ice is licensed to you under the terms described in the
-// ICE_LICENSE file included in this distribution.
-//
-// **********************************************************************
-
-#include <IceUtil/Options.h>
-#include <Ice/Ice.h>
-#include <IceBox/ServiceManagerI.h>
-
-using namespace std;
-using namespace Ice;
-using namespace IceBox;
-
-namespace IceBox
-{
-
-class Server : public Application
-{
-public:
-
- void usage();
- virtual int run(int, char*[]);
-};
-
-}
-
-int
-main(int argc, char* argv[])
-{
- Server server;
- return server.main(argc, argv);
-}
-
-void
-Server::usage()
-{
- cerr << "Usage: " << appName() << " [options] --Ice.Config=<file>\n";
- cerr <<
- "Options:\n"
- "-h, --help Show this message.\n"
- "-v, --version Display the Ice version.\n"
- ;
-}
-
-int
-Server::run(int argc, char* argv[])
-{
- IceUtil::Options opts;
- opts.addOpt("h", "help");
- opts.addOpt("v", "version");
-
- vector<string> args;
- try
- {
- args = opts.parse(argc, argv);
- }
- catch(const IceUtil::Options::BadOpt& e)
- {
- cerr << e.reason << endl;
- usage();
- return EXIT_FAILURE;
- }
-
- if(opts.isSet("h") || opts.isSet("help"))
- {
- usage();
- return EXIT_SUCCESS;
- }
- if(opts.isSet("v") || opts.isSet("version"))
- {
- cout << ICE_STRING_VERSION << endl;
- return EXIT_SUCCESS;
- }
-
- if(!args.empty())
- {
- usage();
- return EXIT_FAILURE;
- }
-
- ServiceManagerI* serviceManagerImpl = new ServiceManagerI(this, argc, argv);
- ServiceManagerPtr serviceManager = serviceManagerImpl;
- return serviceManagerImpl->run();
-}
diff --git a/cpp/src/IceBox/Service.cpp b/cpp/src/IceBox/Service.cpp
new file mode 100644
index 00000000000..96e401290de
--- /dev/null
+++ b/cpp/src/IceBox/Service.cpp
@@ -0,0 +1,144 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceUtil/Options.h>
+#include <Ice/Ice.h>
+#include <Ice/Service.h>
+#include <IceBox/ServiceManagerI.h>
+
+using namespace std;
+using namespace Ice;
+using namespace IceBox;
+
+namespace IceBox
+{
+
+class IceBoxService : public Ice::Service
+{
+public:
+
+ IceBoxService();
+
+protected:
+
+ virtual bool start(int, char*[]);
+ virtual bool stop();
+
+private:
+
+ void usage(const std::string&);
+ ServiceManagerIPtr _serviceManager;
+};
+
+}
+
+IceBox::IceBoxService::IceBoxService()
+{
+}
+
+bool
+IceBox::IceBoxService::start(int argc, char* argv[])
+{
+ IceUtil::Options opts;
+ opts.addOpt("h", "help");
+ opts.addOpt("v", "version");
+
+ vector<string> args;
+ try
+ {
+ args = opts.parse(argc, argv);
+ }
+ catch(const IceUtil::Options::BadOpt& e)
+ {
+ error(e.reason);
+ usage(argv[0]);
+ return false;
+ }
+
+ if(opts.isSet("h") || opts.isSet("help"))
+ {
+ usage(argv[0]);
+ return false;
+ }
+ if(opts.isSet("v") || opts.isSet("version"))
+ {
+ print(ICE_STRING_VERSION);
+ return false;
+ }
+
+ if(!args.empty())
+ {
+ usage(argv[0]);
+ return false;
+ }
+
+ _serviceManager = new ServiceManagerI(communicator(), argc, argv);
+ return _serviceManager->start();
+}
+
+bool
+IceBox::IceBoxService::stop()
+{
+ if(_serviceManager)
+ {
+ _serviceManager->stop();
+ _serviceManager = 0;
+ }
+ return true;
+}
+
+void
+IceBox::IceBoxService::usage(const string& appName)
+{
+ string options =
+ "Options:\n"
+ "-h, --help Show this message.\n"
+ "-v, --version Display the Ice version.";
+#ifdef _WIN32
+ if(checkSystem())
+ {
+ options.append(
+ "\n"
+ "\n"
+ "--service NAME Run as the Windows service NAME.\n"
+ "\n"
+ "--install NAME [--display DISP] [--executable EXEC] [args]\n"
+ " Install as Windows service NAME. If DISP is\n"
+ " provided, use it as the display name,\n"
+ " otherwise NAME is used. If EXEC is provided,\n"
+ " use it as the service executable, otherwise\n"
+ " this executable is used. Any additional\n"
+ " arguments are passed unchanged to the\n"
+ " service at startup.\n"
+ "--uninstall NAME Uninstall Windows service NAME.\n"
+ "--start NAME [args] Start Windows service NAME. Any additional\n"
+ " arguments are passed unchanged to the\n"
+ " service.\n"
+ "--stop NAME Stop Windows service NAME."
+ );
+ }
+#else
+ options.append(
+ "\n"
+ "\n"
+ "--daemon Run as a daemon.\n"
+ "--noclose Do not close open file descriptors.\n"
+ "--nochdir Do not change the current working directory."
+ );
+#endif
+ print("Usage: " + appName + " [options]\n" + options);
+}
+
+int
+main(int argc, char* argv[])
+{
+ IceBox::IceBoxService svc;
+ return svc.main(argc, argv);
+}
+
diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp
index 07012497dd1..f60df6ad3c2 100644
--- a/cpp/src/IceBox/ServiceManagerI.cpp
+++ b/cpp/src/IceBox/ServiceManagerI.cpp
@@ -20,15 +20,10 @@ using namespace std;
typedef IceBox::Service* (*SERVICE_FACTORY)(CommunicatorPtr);
-IceBox::ServiceManagerI::ServiceManagerI(Application* server, int& argc, char* argv[])
- : _server(server)
+IceBox::ServiceManagerI::ServiceManagerI(CommunicatorPtr communicator, int& argc, char* argv[])
+ : _communicator(communicator)
{
- _logger = _server->communicator()->getLogger();
-
- if(argc > 0)
- {
- _progName = argv[0];
- }
+ _logger = _communicator->getLogger();
for(int i = 1; i < argc; i++)
{
@@ -49,11 +44,11 @@ IceBox::ServiceManagerI::getSliceChecksums(const Current&) const
void
IceBox::ServiceManagerI::shutdown(const Current& current)
{
- _server->communicator()->shutdown();
+ _communicator->shutdown();
}
-int
-IceBox::ServiceManagerI::run()
+bool
+IceBox::ServiceManagerI::start()
{
try
{
@@ -64,9 +59,9 @@ IceBox::ServiceManagerI::run()
// this object adapter, as the endpoint(s) for this object adapter
// will most likely need to be firewalled for security reasons.
//
- ObjectAdapterPtr adapter = _server->communicator()->createObjectAdapter("IceBox.ServiceManager");
+ ObjectAdapterPtr adapter = _communicator->createObjectAdapter("IceBox.ServiceManager");
- PropertiesPtr properties = _server->communicator()->getProperties();
+ PropertiesPtr properties = _communicator->getProperties();
string identity = properties->getProperty("IceBox.ServiceManager.Identity");
if(identity.empty())
{
@@ -147,14 +142,6 @@ IceBox::ServiceManagerI::run()
cout << bundleName << " ready" << endl;
}
- //
- // Don't move after the adapter activation. This allows
- // applications to wait for the service manager to be
- // reachable before sending a signal to shutdown the
- // IceBox.
- //
- _server->shutdownOnInterrupt();
-
try
{
adapter->activate();
@@ -165,31 +152,29 @@ IceBox::ServiceManagerI::run()
// Expected if the communicator has been shutdown.
//
}
-
- _server->communicator()->waitForShutdown();
- _server->ignoreInterrupt();
-
- //
- // Invoke stop() on the services.
- //
- stopAll();
}
catch(const FailureException& ex)
{
Error out(_logger);
out << ex.reason;
stopAll();
- return EXIT_FAILURE;
+ return false;
}
catch(const Exception& ex)
{
Error out(_logger);
out << "ServiceManager: " << ex;
stopAll();
- return EXIT_FAILURE;
+ return false;
}
- return EXIT_SUCCESS;
+ return true;
+}
+
+void
+IceBox::ServiceManagerI::stop()
+{
+ stopAll();
}
void
@@ -270,7 +255,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
ServiceInfo info;
try
{
- info.service = factory(_server->communicator());
+ info.service = factory(_communicator);
}
catch(const Exception& ex)
{
@@ -297,7 +282,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
// add the service properties to the shared commnunicator
// property set.
//
- PropertiesPtr properties = _server->communicator()->getProperties();
+ PropertiesPtr properties = _communicator->getProperties();
if(properties->getPropertyAsInt("IceBox.UseSharedCommunicator." + service) > 0)
{
PropertiesPtr fileProperties = createProperties(serviceArgs);
@@ -358,7 +343,7 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
delete[] argv;
}
- CommunicatorPtr communicator = info.communicator ? info.communicator : _server->communicator();
+ CommunicatorPtr communicator = info.communicator ? info.communicator : _communicator;
//
// Start the service.
diff --git a/cpp/src/IceBox/ServiceManagerI.h b/cpp/src/IceBox/ServiceManagerI.h
index bac6ff31385..829e4dbb1d3 100644
--- a/cpp/src/IceBox/ServiceManagerI.h
+++ b/cpp/src/IceBox/ServiceManagerI.h
@@ -14,7 +14,6 @@
#include <Ice/LoggerF.h>
#include <Ice/CommunicatorF.h>
#include <Ice/DynamicLibraryF.h>
-#include <Ice/Application.h>
#include <map>
namespace IceBox
@@ -24,7 +23,7 @@ class ServiceManagerI : public ServiceManager
{
public:
- ServiceManagerI(::Ice::Application*, int&, char*[]);
+ ServiceManagerI(Ice::CommunicatorPtr, int&, char*[]);
virtual ~ServiceManagerI();
virtual Ice::SliceChecksumDict getSliceChecksums(const Ice::Current&) const;
@@ -41,19 +40,23 @@ public:
::std::string envName;
};
+ bool start();
+ void stop();
+
private:
void load(const std::string&, const std::string&);
void start(const std::string&, const std::string&, const ::Ice::StringSeq&);
void stopAll();
- ::Ice::Application* _server;
+ ::Ice::CommunicatorPtr _communicator;
::Ice::LoggerPtr _logger;
- std::string _progName; // argv[0]
::Ice::StringSeq _argv; // Filtered server argument vector, not including program name
std::map<std::string, ServiceInfo> _services;
};
+typedef IceUtil::Handle<ServiceManagerI> ServiceManagerIPtr;
+
}
#endif
diff --git a/cpp/src/IceBox/iceboxS.dsp b/cpp/src/IceBox/iceboxS.dsp
index 20bda1ff583..d1f6e751766 100644
--- a/cpp/src/IceBox/iceboxS.dsp
+++ b/cpp/src/IceBox/iceboxS.dsp
@@ -103,7 +103,7 @@ PostBuild_Cmds=copy $(OutDir)\$(TargetName).exe ..\..\bin copy $(OutDir)\$(Targe
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
-SOURCE=.\Server.cpp
+SOURCE=.\Service.cpp
# End Source File
# Begin Source File