summaryrefslogtreecommitdiff
path: root/cpp/demo/IceStorm/clock/Publisher.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2008-01-09 18:09:32 -0500
committerBernard Normier <bernard@zeroc.com>2008-01-09 18:09:32 -0500
commit27ed1dbf26ed4d3fe715bbbdf1ed635cda385a60 (patch)
treebf9c5d505bea08035b592d39eaff1b665c223e08 /cpp/demo/IceStorm/clock/Publisher.cpp
parentMerge branch 'master' of ssh://cvs.zeroc.com/home/git/ice (diff)
downloadice-27ed1dbf26ed4d3fe715bbbdf1ed635cda385a60.tar.bz2
ice-27ed1dbf26ed4d3fe715bbbdf1ed635cda385a60.tar.xz
ice-27ed1dbf26ed4d3fe715bbbdf1ed635cda385a60.zip
Removed IceUtilInternal calls from demos
Diffstat (limited to 'cpp/demo/IceStorm/clock/Publisher.cpp')
-rw-r--r--cpp/demo/IceStorm/clock/Publisher.cpp84
1 files changed, 50 insertions, 34 deletions
diff --git a/cpp/demo/IceStorm/clock/Publisher.cpp b/cpp/demo/IceStorm/clock/Publisher.cpp
index 314ce50e14a..22a83124cbb 100644
--- a/cpp/demo/IceStorm/clock/Publisher.cpp
+++ b/cpp/demo/IceStorm/clock/Publisher.cpp
@@ -8,7 +8,6 @@
// **********************************************************************
#include <IceUtil/IceUtil.h>
-#include <IceUtil/Options.h>
#include <Ice/Ice.h>
#include <IceStorm/IceStorm.h>
@@ -40,29 +39,60 @@ usage(const string& n)
int
Publisher::run(int argc, char* argv[])
{
- IceUtilInternal::Options opts;
- opts.addOpt("", "datagram");
- opts.addOpt("", "twoway");
- opts.addOpt("", "oneway");
+ enum Option { Datagram, Twoway, Oneway };
+ Option option = Oneway;
- IceUtilInternal::Options::StringVector remaining;
- try
- {
- remaining = opts.parse(argc, (const char**)argv);
- }
- catch(const IceUtilInternal::BadOptException& e)
+ string topicName = "time";
+
+ if(argc > 3)
{
- cerr << argv[0] << ": " << e.reason << endl;
+ cerr << appName() << ": too many arguments" << endl;
usage(appName());
return EXIT_FAILURE;
}
- if(remaining.size() > 1)
+
+ if(argc >= 2)
{
- cerr << appName() << ": too many arguments" << endl;
- usage(appName());
- return EXIT_FAILURE;
+ string optionString = argv[1];
+ if(optionString == "--datagram")
+ {
+ option = Datagram;
+ }
+ else if(optionString == "--twoway")
+ {
+ option = Twoway;
+ }
+ else if(optionString == "--oneway")
+ {
+ option = Oneway;
+ }
+ else if(argc == 3)
+ {
+ cerr << appName() << ": too many arguments" << endl;
+ usage(appName());
+ return EXIT_FAILURE;
+ }
+ else
+ {
+ topicName = optionString;
+ }
+
+ if(argc == 3)
+ {
+ topicName = argv[2];
+ }
+
+ if(topicName[0] == '-')
+ {
+ cerr << appName() << ": invalid topic name" << endl;
+ usage(appName());
+ return EXIT_FAILURE;
+ }
}
+
+
+
IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(
communicator()->propertyToProxy("IceStorm.TopicManager.Proxy"));
if(!manager)
@@ -71,12 +101,6 @@ Publisher::run(int argc, char* argv[])
return EXIT_FAILURE;
}
- string topicName = "time";
- if(!remaining.empty())
- {
- topicName = remaining.front();
- }
-
//
// Retrieve the topic.
//
@@ -103,27 +127,19 @@ Publisher::run(int argc, char* argv[])
// the mode specified as an argument of this application.
//
Ice::ObjectPrx publisher = topic->getPublisher();
- int optsSet = 0;
- if(opts.isSet("datagram"))
+ if(option == Datagram)
{
publisher = publisher->ice_datagram();
- ++optsSet;
}
- else if(opts.isSet("twoway"))
+ else if(option == Twoway)
{
// Do nothing.
- ++optsSet;
}
- else if(opts.isSet("oneway") || optsSet == 0)
+ else if(option == Oneway)
{
publisher = publisher->ice_oneway();
- ++optsSet;
- }
- if(optsSet != 1)
- {
- usage(appName());
- return EXIT_FAILURE;
}
+
ClockPrx clock = ClockPrx::uncheckedCast(publisher);
cout << "publishing tick events. Press ^C to terminate the application." << endl;