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/DisableWarnings.h>
11 #include <IceUtil/Options.h>
12 #include <Ice/Application.h>
13 #include <Ice/SliceChecksums.h>
14 #include <IceStorm/Parser.h>
18 using namespace IceStorm
;
20 class Client
: public Application
25 virtual int run(int, char*[]);
28 //COMPILERFIX: Borland C++ 2010 doesn't support wmain for console applications.
29 #if defined(_WIN32 ) && !defined(__BCPLUSPLUS__)
32 wmain(int argc
, wchar_t* argv
[])
37 main(int argc
, char* argv
[])
42 Ice::InitializationData id
;
43 Ice::StringSeq args
= Ice::argsToStringSeq(argc
, argv
);
44 id
.properties
= Ice::createProperties(args
);
46 // We don't want to load DB plug-ins with icestormadmin, as this will
47 // cause FileLock issues when run with the same configuration file
48 // used by the service.
50 id
.properties
->setProperty("Ice.Plugin.DB", "");
51 int rc
= app
.main(argc
, argv
, id
);
58 cerr
<< "Usage: " << appName() << " [options]\n";
61 "-h, --help Show this message.\n"
62 "-v, --version Display the Ice version.\n"
63 "-e COMMANDS Execute COMMANDS.\n"
64 "-d, --debug Print debug messages.\n"
69 Client::run(int argc
, char* argv
[])
74 IceUtilInternal::Options opts
;
75 opts
.addOpt("h", "help");
76 opts
.addOpt("v", "version");
77 opts
.addOpt("e", "", IceUtilInternal::Options::NeedArg
, "", IceUtilInternal::Options::Repeat
);
78 opts
.addOpt("d", "debug");
83 args
= opts
.parse(argc
, (const char**)argv
);
85 catch(const IceUtilInternal::BadOptException
& e
)
87 cerr
<< e
.reason
<< endl
;
93 cerr
<< argv
[0] << ": too many arguments" << endl
;
98 if(opts
.isSet("help"))
103 if(opts
.isSet("version"))
105 cout
<< ICE_STRING_VERSION
<< endl
;
110 vector
<string
> optargs
= opts
.argVec("e");
111 for(vector
<string
>::const_iterator i
= optargs
.begin(); i
!= optargs
.end(); ++i
)
113 commands
+= *i
+ ";";
116 debug
= opts
.isSet("debug");
118 // The complete set of Ice::Identity -> manager proxies.
119 map
<Ice::Identity
, IceStorm::TopicManagerPrx
> managers
;
120 PropertiesPtr properties
= communicator()->getProperties();
121 IceStorm::TopicManagerPrx defaultManager
;
123 Ice::PropertyDict props
= communicator()->getProperties()->getPropertiesForPrefix("IceStormAdmin.TopicManager.");
125 for(Ice::PropertyDict::const_iterator p
= props
.begin(); p
!= props
.end(); ++p
)
128 // Ignore proxy property settings. eg IceStormAdmin.TopicManager.*.LocatorCacheTimeout
130 if(p
->first
.find('.', strlen("IceStormAdmin.TopicManager.")) == string::npos
)
134 IceStorm::TopicManagerPrx manager
= IceStorm::TopicManagerPrx::uncheckedCast(
135 communicator()->propertyToProxy(p
->first
));
136 managers
.insert(map
<Ice::Identity
, IceStorm::TopicManagerPrx
>::value_type(
137 manager
->ice_getIdentity(), manager
));
139 catch(const Ice::ProxyParseException
&)
141 cerr
<< appName() << ": malformed proxy: " << p
->second
<< endl
;
147 string managerProxy
= properties
->getProperty("IceStormAdmin.TopicManager.Default");
148 if(!managerProxy
.empty())
150 defaultManager
= IceStorm::TopicManagerPrx::uncheckedCast(
151 communicator()->stringToProxy(managerProxy
));
153 else if(!managers
.empty())
155 defaultManager
= managers
.begin()->second
;
161 cerr
<< appName() << ": no manager proxies configured" << endl
;
165 ParserPtr p
= Parser::createParser(communicator(), defaultManager
, managers
);
166 int status
= EXIT_SUCCESS
;
168 if(!commands
.empty()) // Commands were given
170 int parseStatus
= p
->parse(commands
, debug
);
171 if(parseStatus
== EXIT_FAILURE
)
173 status
= EXIT_FAILURE
;
176 else // No commands, let's use standard input
180 int parseStatus
= p
->parse(stdin
, debug
);
181 if(parseStatus
== EXIT_FAILURE
)
183 status
= EXIT_FAILURE
;