1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
10 #include <IceUtil/Options.h>
12 #include <Ice/Service.h>
13 #include <IceBox/ServiceManagerI.h>
17 using namespace IceBox
;
22 class IceBoxService
: public Ice::Service
30 virtual bool start(int, char*[], int&);
35 void usage(const std::string
&);
36 ServiceManagerIPtr _serviceManager
;
41 IceBox::IceBoxService::IceBoxService()
46 IceBox::IceBoxService::start(int argc
, char* argv
[], int& status
)
48 // Run through the command line arguments removing all the service
50 vector
<string
> args
= Ice::argsToStringSeq(argc
, argv
);
51 PropertiesPtr properties
= communicator()->getProperties();
52 const string prefix
= "IceBox.Service.";
53 PropertyDict services
= properties
->getPropertiesForPrefix(prefix
);
54 for(PropertyDict::const_iterator p
= services
.begin(); p
!= services
.end(); ++p
)
56 string name
= p
->first
.substr(prefix
.size());
57 StringSeq::iterator q
= args
.begin();
58 while(q
!= args
.end())
60 if(q
->find("--" + name
+ ".") == 0)
69 IceUtilInternal::Options opts
;
70 opts
.addOpt("h", "help");
71 opts
.addOpt("v", "version");
75 args
= opts
.parse(args
);
77 catch(const IceUtilInternal::BadOptException
& e
)
84 if(opts
.isSet("help"))
87 status
= EXIT_SUCCESS
;
90 if(opts
.isSet("version"))
92 print(ICE_STRING_VERSION
);
93 status
= EXIT_SUCCESS
;
103 _serviceManager
= new ServiceManagerI(communicator(), argc
, argv
);
105 return _serviceManager
->start();
109 IceBox::IceBoxService::stop()
113 _serviceManager
->stop();
120 IceBox::IceBoxService::usage(const string
& appName
)
124 "-h, --help Show this message.\n"
125 "-v, --version Display the Ice version.";
130 "--daemon Run as a daemon.\n"
131 "--pidfile FILE Write process ID into FILE.\n"
132 "--noclose Do not close open file descriptors.\n"
133 "--nochdir Do not change the current working directory."
136 print("Usage: " + appName
+ " [options]\n" + options
);
139 //COMPILERFIX: Borland C++ 2010 doesn't support wmain for console applications.
140 #if defined(_WIN32 ) && !defined(__BCPLUSPLUS__)
143 wmain(int argc
, wchar_t* argv
[])
148 main(int argc
, char* argv
[])
152 IceBox::IceBoxService svc
;
154 InitializationData initData
;
155 initData
.properties
= createProperties();
156 initData
.properties
->setProperty("Ice.Admin.DelayCreation", "1");
157 return svc
.main(argc
, argv
, initData
);