diff options
author | Matthew Newhook <matthew@zeroc.com> | 2006-11-15 13:31:33 +0000 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2006-11-15 13:31:33 +0000 |
commit | 709152f1ce6f82cbadfaea5e8fdbd22be6f8fd4c (patch) | |
tree | a09c44e0aa4263fe90a26bed3049551b9cf66363 /cpp/demo/IceStorm/clock/Publisher.cpp | |
parent | Added NullPermissionsVerifiers to Glacier2 (diff) | |
download | ice-709152f1ce6f82cbadfaea5e8fdbd22be6f8fd4c.tar.bz2 ice-709152f1ce6f82cbadfaea5e8fdbd22be6f8fd4c.tar.xz ice-709152f1ce6f82cbadfaea5e8fdbd22be6f8fd4c.zip |
http://bugzilla.zeroc.com/bugzilla/show_bug.cgi?id=1547. Demo cleanup.
Diffstat (limited to 'cpp/demo/IceStorm/clock/Publisher.cpp')
-rw-r--r-- | cpp/demo/IceStorm/clock/Publisher.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/cpp/demo/IceStorm/clock/Publisher.cpp b/cpp/demo/IceStorm/clock/Publisher.cpp index 527a180f899..5e7d96a77eb 100644 --- a/cpp/demo/IceStorm/clock/Publisher.cpp +++ b/cpp/demo/IceStorm/clock/Publisher.cpp @@ -42,45 +42,63 @@ Publisher::run(int argc, char* argv[]) return EXIT_FAILURE; } - Ice::ObjectPrx base = communicator()->stringToProxy(proxy); - IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); + IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( + communicator()->stringToProxy(proxy)); if(!manager) { cerr << appName() << ": invalid proxy" << endl; return EXIT_FAILURE; } + string topicName = "time"; + if(argc != 1) + { + topicName = argv[1]; + } + // // Retrieve the topic named "time". // IceStorm::TopicPrx topic; try { - topic = manager->retrieve("time"); + topic = manager->retrieve(topicName); } catch(const IceStorm::NoSuchTopic& e) { - cerr << appName() << ": " << e << " name: " << e.name << endl; - return EXIT_FAILURE; + try + { + topic = manager->create(topicName); + } + catch(const IceStorm::TopicExists& e) + { + cerr << appName() << ": temporary failure. try again." << endl; + return EXIT_FAILURE; + } } - assert(topic); // - // Get the topic's publisher object, verify that it supports - // the Clock type, and create a oneway Clock proxy (for efficiency - // reasons). + // Get the topic's publisher object, the Clock type, and create a + // oneway Clock proxy (for efficiency reasons). // - Ice::ObjectPrx obj = topic->getPublisher(); - if(!obj->ice_isDatagram()) + ClockPrx clock = ClockPrx::uncheckedCast(topic->getPublisher()->ice_oneway()); + + cout << "publishing tick events. Press ^C to terminate the application." << endl; + try { - obj = obj->ice_oneway(); + while(true) + { + clock->tick(IceUtil::Time::now().toString()); +#ifdef WIN32 + Sleep(1000); +#else + sleep(1); +#endif + } } - ClockPrx clock = ClockPrx::uncheckedCast(obj); - - cout << "publishing 10 tick events" << endl; - for(int i = 0; i < 10; ++i) + catch(const Ice::CommunicatorDestroyedException&) { - clock->tick(); + // Ignore } return EXIT_SUCCESS; |