summaryrefslogtreecommitdiff
path: root/cpp/demo/IceStorm/clock/Subscriber.cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2001-11-26 15:53:00 +0000
committerMatthew Newhook <matthew@zeroc.com>2001-11-26 15:53:00 +0000
commit021c6615fd0b299d7742c82f7d6b76f4a813f397 (patch)
treeaf38dfba0fc3204ce8a0572777b92883e6e657f8 /cpp/demo/IceStorm/clock/Subscriber.cpp
parentBlobject (diff)
downloadice-021c6615fd0b299d7742c82f7d6b76f4a813f397.tar.bz2
ice-021c6615fd0b299d7742c82f7d6b76f4a813f397.tar.xz
ice-021c6615fd0b299d7742c82f7d6b76f4a813f397.zip
Initial version of IceStorm.
Diffstat (limited to 'cpp/demo/IceStorm/clock/Subscriber.cpp')
-rw-r--r--cpp/demo/IceStorm/clock/Subscriber.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/cpp/demo/IceStorm/clock/Subscriber.cpp b/cpp/demo/IceStorm/clock/Subscriber.cpp
new file mode 100644
index 00000000000..7756aace6bc
--- /dev/null
+++ b/cpp/demo/IceStorm/clock/Subscriber.cpp
@@ -0,0 +1,89 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Ice/Ice.h>
+#include <IceStorm/IceStorm.h>
+
+#include <ClockI.h>
+
+using namespace std;
+
+int
+run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator)
+{
+ Ice::PropertiesPtr properties = communicator->getProperties();
+ const char* refProperty = "IceStorm.TopicManager";
+ std::string ref = properties->getProperty(refProperty);
+ if (ref.empty())
+ {
+ cerr << argv[0] << ": property `" << refProperty << "' not set" << endl;
+ return EXIT_FAILURE;
+ }
+
+ Ice::ObjectPrx base = communicator->stringToProxy(ref);
+ IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base);
+ if (!manager)
+ {
+ cerr << argv[0] << ": invalid object reference" << endl;
+ return EXIT_FAILURE;
+ }
+
+ Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("ClockAdapter", "tcp");
+ Ice::ObjectPtr clock = new ClockI();
+ const char* id = "events#time";
+ adapter->add(clock, id);
+
+ Ice::ObjectPrx object = adapter->createProxy(id);
+
+ IceStorm::StringSeq topics;
+ topics.push_back("time");
+ IceStorm::QoS qos;
+ qos["reliability"] = "batch";
+ manager->subscribe(object, "events", qos, topics);
+
+ adapter->activate();
+
+ communicator->waitForShutdown();
+ return EXIT_SUCCESS;
+}
+
+int
+main(int argc, char* argv[])
+{
+ int status;
+ Ice::CommunicatorPtr communicator;
+
+ try
+ {
+ Ice::PropertiesPtr properties = Ice::createPropertiesFromFile(argc, argv, "config");
+ communicator = Ice::initializeWithProperties(properties);
+ status = run(argc, argv, communicator);
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = EXIT_FAILURE;
+ }
+
+ if (communicator)
+ {
+ try
+ {
+ communicator->destroy();
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ status = EXIT_FAILURE;
+ }
+ }
+
+ return status;
+}