summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/invoke/PrinterI.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2004-10-19 02:27:18 +0000
committerMark Spruiell <mes@zeroc.com>2004-10-19 02:27:18 +0000
commit4ee06da3e23c279897cef5b2b51487875b4486b7 (patch)
treee2080691778256ebf32ceabc7d8edce6e869fbad /cpp/demo/Ice/invoke/PrinterI.cpp
parentupdating dependencies (diff)
downloadice-4ee06da3e23c279897cef5b2b51487875b4486b7.tar.bz2
ice-4ee06da3e23c279897cef5b2b51487875b4486b7.tar.xz
ice-4ee06da3e23c279897cef5b2b51487875b4486b7.zip
adding streaming API
Diffstat (limited to 'cpp/demo/Ice/invoke/PrinterI.cpp')
-rw-r--r--cpp/demo/Ice/invoke/PrinterI.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/cpp/demo/Ice/invoke/PrinterI.cpp b/cpp/demo/Ice/invoke/PrinterI.cpp
new file mode 100644
index 00000000000..13092ceeb71
--- /dev/null
+++ b/cpp/demo/Ice/invoke/PrinterI.cpp
@@ -0,0 +1,161 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2004 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/Ice.h>
+#include <PrinterI.h>
+
+using namespace std;
+
+static ostream&
+operator<<(ostream& out, Demo::Color c)
+{
+ switch(c)
+ {
+ case Demo::red:
+ out << "red";
+ break;
+ case Demo::green:
+ out << "green";
+ break;
+ case Demo::blue:
+ out << "blue";
+ break;
+ }
+ return out;
+}
+
+bool
+PrinterI::ice_invoke(const vector<Ice::Byte>& inParams, vector<Ice::Byte>& outParams, const Ice::Current& current)
+{
+ Ice::CommunicatorPtr communicator = current.adapter->getCommunicator();
+
+ Ice::InputStreamPtr in;
+ if(inParams.size() > 0)
+ {
+ in = Ice::createInputStream(communicator, inParams);
+ }
+
+ if(current.operation == "printString")
+ {
+ string message = in->readString();
+ in->finished();
+ cout << "Printing string `" << message << "'" << endl;
+ return true;
+ }
+ else if(current.operation == "printStringSequence")
+ {
+ Demo::StringSeq seq = in->readStringSeq();
+ in->finished();
+ cout << "Printing string sequence {";
+ for(Demo::StringSeq::iterator p = seq.begin(); p != seq.end(); ++p)
+ {
+ if(p != seq.begin())
+ {
+ cout << ", ";
+ }
+ cout << "'" << *p << "'";
+ }
+ cout << "}" << endl;
+ return true;
+ }
+ else if(current.operation == "printDictionary")
+ {
+ Demo::StringDict dict;
+ Demo::ice_readStringDict(in, dict);
+ in->finished();
+ cout << "Printing dictionary {";
+ for(Demo::StringDict::iterator p = dict.begin(); p != dict.end(); ++p)
+ {
+ if(p != dict.begin())
+ {
+ cout << ", ";
+ }
+ cout << p->first << "=" << p->second;
+ }
+ cout << "}" << endl;
+ return true;
+ }
+ else if(current.operation == "printEnum")
+ {
+ Demo::Color c;
+ Demo::ice_readColor(in, c);
+ in->finished();
+ cout << "Printing enum " << c << endl;
+ return true;
+ }
+ else if(current.operation == "printStruct")
+ {
+ Demo::Structure s;
+ Demo::ice_readStructure(in, s);
+ in->finished();
+ cout << "Printing struct: name=" << s.name << ", value=" << s.value << endl;
+ return true;
+ }
+ else if(current.operation == "printStructSequence")
+ {
+ Demo::StructureSeq seq;
+ Demo::ice_readStructureSeq(in, seq);
+ in->finished();
+ cout << "Printing struct sequence: {";
+ for(Demo::StructureSeq::iterator p = seq.begin(); p != seq.end(); ++p)
+ {
+ if(p != seq.begin())
+ {
+ cout << ", ";
+ }
+ cout << p->name << "=" << p->value;
+ }
+ cout << "}" << endl;
+ return true;
+ }
+ else if(current.operation == "printClass")
+ {
+ Demo::CPtr c;
+ Demo::ice_readC(in, c);
+ in->finished();
+ cout << "Printing class: s.name=" << c->s.name << ", s.value=" << c->s.value << endl;
+ return true;
+ }
+ else if(current.operation == "getValues")
+ {
+ Demo::CPtr c = new Demo::C;
+ c->s.name = "green";
+ c->s.value = Demo::green;
+ Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
+ Demo::ice_writeC(out, c);
+ out->writeString("hello");
+ out->finished(outParams);
+ return true;
+ }
+ else if(current.operation == "throwPrintFailure")
+ {
+ cout << "Throwing PrintFailure" << endl;
+ Demo::PrintFailure ex;
+ ex.reason = "paper tray empty";
+ Ice::OutputStreamPtr out = Ice::createOutputStream(communicator);
+ out->writeException(ex);
+ out->finished(outParams);
+ return false;
+ }
+ else if(current.operation == "shutdown")
+ {
+ current.adapter->getCommunicator()->shutdown();
+ return true;
+ }
+ else
+ {
+ Ice::OperationNotExistException ex(__FILE__, __LINE__);
+ ex.id = current.id;
+ ex.facet = current.facet;
+ ex.operation = current.operation;
+ throw ex;
+ }
+
+ return false;
+}