summaryrefslogtreecommitdiff
path: root/cpp/demo/IceStorm/clock/Publisher.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/demo/IceStorm/clock/Publisher.cpp')
-rw-r--r--cpp/demo/IceStorm/clock/Publisher.cpp52
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;