diff options
Diffstat (limited to 'cpp/demo/IceStorm/clock/Subscriber.cpp')
-rw-r--r-- | cpp/demo/IceStorm/clock/Subscriber.cpp | 124 |
1 files changed, 81 insertions, 43 deletions
diff --git a/cpp/demo/IceStorm/clock/Subscriber.cpp b/cpp/demo/IceStorm/clock/Subscriber.cpp index 8a0500add41..848e9a500ba 100644 --- a/cpp/demo/IceStorm/clock/Subscriber.cpp +++ b/cpp/demo/IceStorm/clock/Subscriber.cpp @@ -8,7 +8,6 @@ // ********************************************************************** #include <IceUtil/IceUtil.h> -#include <IceUtil/Options.h> #include <Ice/Ice.h> #include <IceStorm/IceStorm.h> @@ -53,29 +52,82 @@ usage(const string& n) int Subscriber::run(int argc, char* argv[]) { - IceUtilInternal::Options opts; - opts.addOpt("", "datagram"); - opts.addOpt("", "twoway"); - opts.addOpt("", "ordered"); - opts.addOpt("", "oneway"); - opts.addOpt("", "batch"); - - IceUtilInternal::Options::StringVector remaining; - try - { - remaining = opts.parse(argc, (const char**)argv); - } - catch(const IceUtilInternal::BadOptException& e) + bool batch = false; + + enum Option { Datagram, Twoway, Oneway, Ordered}; + Option option = Oneway; + + string topicName = "time"; + + if(argc > 4) { - 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; + int argIndex = 1; + string optionString = argv[argIndex]; + + if(optionString == "--batch") + { + batch = true; + if(argc >= 3) + { + argIndex++; + optionString = argv[argIndex]; + } + else + { + optionString = ""; + } + } + + if(optionString == "") + { + // done + } + else if(optionString == "--datagram") + { + option = Datagram; + } + else if(optionString == "--twoway") + { + option = Twoway; + } + else if(optionString == "--oneway") + { + option = Oneway; + } + else if(optionString == "--ordered") + { + option = Ordered; + } + else if(argIndex == argc - 2) + { + cerr << appName() << ": too many arguments" << endl; + usage(appName()); + return EXIT_FAILURE; + } + else + { + topicName = optionString; + } + + argIndex++; + if(argIndex < argc) + { + topicName = argv[argIndex]; + } + + if(topicName[0] == '-') + { + cerr << appName() << ": invalid topic name" << endl; + usage(appName()); + return EXIT_FAILURE; + } } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( @@ -86,12 +138,6 @@ Subscriber::run(int argc, char* argv[]) return EXIT_FAILURE; } - string topicName = "time"; - if(!remaining.empty()) - { - topicName = remaining.front(); - } - IceStorm::TopicPrx topic; try { @@ -120,43 +166,35 @@ Subscriber::run(int argc, char* argv[]) // // Set up the proxy. // - int optsSet = 0; - if(opts.isSet("datagram")) + + if(option == Datagram) { subscriber = subscriber->ice_datagram(); - ++optsSet; } - if(opts.isSet("twoway")) + else if(option == Twoway) { // Do nothing to the subscriber proxy. Its already twoway. - ++optsSet; + } - if(opts.isSet("ordered")) + else if(option == Ordered) { qos["reliability"] = "ordered"; // Do nothing to the subscriber proxy. Its already twoway. - ++optsSet; + } - if(opts.isSet("oneway") || optsSet == 0) + else if(option == Oneway) { subscriber = subscriber->ice_oneway(); - ++optsSet; - } - - if(optsSet != 1) - { - usage(appName()); - return EXIT_FAILURE; } - if(opts.isSet("batch")) + if(batch) { - if(opts.isSet("twoway") || opts.isSet("ordered")) + if(option == Twoway || option == Ordered) { cerr << appName() << ": batch can only be set with oneway or datagram" << endl; return EXIT_FAILURE; } - if(opts.isSet("datagram")) + if(option == Datagram) { subscriber = subscriber->ice_batchDatagram(); } |