diff options
author | Matthew Newhook <matthew@zeroc.com> | 2007-01-30 11:04:51 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2007-01-30 11:04:51 +0000 |
commit | fd675fdaff4dfa73678effd765a52209967567c7 (patch) | |
tree | 2943032021c6bf8329da6330b02af24ba6cad6bc /cpp/demo/IceStorm/clock/Subscriber.cpp | |
parent | cleanup IceStorm tests. (diff) | |
download | ice-fd675fdaff4dfa73678effd765a52209967567c7.tar.bz2 ice-fd675fdaff4dfa73678effd765a52209967567c7.tar.xz ice-fd675fdaff4dfa73678effd765a52209967567c7.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1711
Diffstat (limited to 'cpp/demo/IceStorm/clock/Subscriber.cpp')
-rw-r--r-- | cpp/demo/IceStorm/clock/Subscriber.cpp | 71 |
1 files changed, 64 insertions, 7 deletions
diff --git a/cpp/demo/IceStorm/clock/Subscriber.cpp b/cpp/demo/IceStorm/clock/Subscriber.cpp index c08173003ee..01b27870fd4 100644 --- a/cpp/demo/IceStorm/clock/Subscriber.cpp +++ b/cpp/demo/IceStorm/clock/Subscriber.cpp @@ -9,6 +9,7 @@ #include <Ice/Application.h> #include <IceStorm/IceStorm.h> +#include <IceUtil/Options.h> #include <Clock.h> @@ -42,9 +43,34 @@ main(int argc, char* argv[]) return app.main(argc, argv, "config.sub"); } +void +usage(const string& n) +{ + cerr << "Usage: " << n << " [--batch] [--datagram|--twoway|--ordered|--oneway] [topic]\n" << endl; +} + int Subscriber::run(int argc, char* argv[]) { + IceUtil::Options opts; + opts.addOpt("", "datagram"); + opts.addOpt("", "twoway"); + opts.addOpt("", "ordered"); + opts.addOpt("", "oneway"); + opts.addOpt("", "batch"); + + IceUtil::Options::StringVector remaining; + try + { + remaining = opts.parse(argc, argv); + } + catch(const IceUtil::BadOptException& e) + { + cerr << argv[0] << ": " << e.reason << endl; + usage(appName()); + return EXIT_FAILURE; + } + IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator()->propertyToProxy("IceStorm.TopicManager.Proxy")); if(!manager) @@ -54,9 +80,9 @@ Subscriber::run(int argc, char* argv[]) } string topicName = "time"; - if(argc != 1) + if(!remaining.empty()) { - topicName = argv[1]; + topicName = remaining.front(); } IceStorm::TopicPrx topic; @@ -82,15 +108,46 @@ Subscriber::run(int argc, char* argv[]) // // Add a Servant for the Ice Object. // + IceStorm::QoS qos; Ice::ObjectPrx subscriber = adapter->addWithUUID(new ClockI); - // - // This demo requires no quality of service, so it will use - // the defaults. + // Set up the proxy. // - IceStorm::QoS qos; + if(opts.isSet("datagram")) + { + subscriber = subscriber->ice_datagram(); + } + else if(opts.isSet("twoway")) + { + // Do nothing. + } + else if(opts.isSet("ordered")) + { + qos["reliability"] = "ordered"; + subscriber = subscriber->ice_datagram(); + } + else // default. + { + subscriber = subscriber->ice_oneway(); + } + if(opts.isSet("batch")) + { + if(opts.isSet("twoway") || opts.isSet("ordered")) + { + cerr << appName() << ": batch can only be set with oneway or datagram" << endl; + return EXIT_FAILURE; + } + if(opts.isSet("datagram")) + { + subscriber = subscriber->ice_batchDatagram(); + } + else + { + subscriber = subscriber->ice_batchOneway(); + } + } - topic->subscribe(qos, subscriber); + topic->subscribeAndGetPublisher(qos, subscriber); adapter->activate(); shutdownOnInterrupt(); |