summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/async/Publisher.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2006-11-16 17:31:10 +0000
committerDwayne Boone <dwayne@zeroc.com>2006-11-16 17:31:10 +0000
commit51b5c23482df36ac145c82d58e9ccdef9728f935 (patch)
tree15a62e43b132ebdd721ec13a0d6b664133d00e3a /cpp/demo/Ice/async/Publisher.cpp
parentRemove debug code (diff)
downloadice-51b5c23482df36ac145c82d58e9ccdef9728f935.tar.bz2
ice-51b5c23482df36ac145c82d58e9ccdef9728f935.tar.xz
ice-51b5c23482df36ac145c82d58e9ccdef9728f935.zip
Added async demo
Diffstat (limited to 'cpp/demo/Ice/async/Publisher.cpp')
-rw-r--r--cpp/demo/Ice/async/Publisher.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/cpp/demo/Ice/async/Publisher.cpp b/cpp/demo/Ice/async/Publisher.cpp
new file mode 100644
index 00000000000..ca9e3fc6e8b
--- /dev/null
+++ b/cpp/demo/Ice/async/Publisher.cpp
@@ -0,0 +1,109 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2006 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <Ice/Application.h>
+#include <Queue.h>
+
+using namespace std;
+using namespace Demo;
+
+class QueuePublisher : public Ice::Application
+{
+public:
+
+ virtual int run(int, char*[]);
+
+private:
+
+ void menu();
+ string trim(const string& s);
+};
+
+int
+main(int argc, char* argv[])
+{
+ QueuePublisher app;
+ return app.main(argc, argv, "config.client");
+}
+
+int
+QueuePublisher::run(int argc, char* argv[])
+{
+ Ice::PropertiesPtr properties = communicator()->getProperties();
+ const char* proxyProperty = "Queue.Proxy";
+ string proxy = properties->getProperty(proxyProperty);
+ if(proxy.empty())
+ {
+ cerr << argv[0] << ": property `" << proxyProperty << "' not set" << endl;
+ return EXIT_FAILURE;
+ }
+
+ QueuePrx queue = QueuePrx::checkedCast(communicator()->stringToProxy(proxy));
+ if(!queue)
+ {
+ cerr << argv[0] << ": invalid proxy" << endl;
+ return EXIT_FAILURE;
+ }
+
+ cout << "Type a message and hit return to queue a message." << endl;
+ menu();
+
+ try
+ {
+ do
+ {
+ string s;
+ cout << "==> ";
+ getline(cin, s);
+ s = trim(s);
+ if(!s.empty())
+ {
+ if(s[0] == '/')
+ {
+ if(s == "/quit")
+ {
+ break;
+ }
+ menu();
+ }
+ else
+ {
+ queue->add(s);
+ }
+ }
+ }
+ while(cin.good());
+ }
+ catch(const Ice::Exception& ex)
+ {
+ cerr << ex << endl;
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+void
+QueuePublisher::menu()
+{
+ cout << "Enter /quit to exit." << endl;
+}
+
+string
+QueuePublisher::trim(const string& s)
+{
+ static const string delims = "\t\r\n ";
+ string::size_type last = s.find_last_not_of(delims);
+ if(last != string::npos)
+ {
+ return s.substr(s.find_first_not_of(delims), last+1);
+ }
+ return s;
+}
+