diff options
Diffstat (limited to 'py/demo')
-rwxr-xr-x | py/demo/Glacier2/callback/Server.py | 2 | ||||
-rwxr-xr-x | py/demo/Ice/callback/Server.py | 2 | ||||
-rw-r--r-- | py/demo/Ice/protobuf/Client.py | 69 | ||||
-rw-r--r-- | py/demo/Ice/protobuf/Hello.ice | 28 | ||||
-rw-r--r-- | py/demo/Ice/protobuf/Person.proto | 16 | ||||
-rw-r--r-- | py/demo/Ice/protobuf/README | 39 | ||||
-rw-r--r-- | py/demo/Ice/protobuf/Server.py | 38 | ||||
-rw-r--r-- | py/demo/Ice/protobuf/config.client | 23 | ||||
-rw-r--r-- | py/demo/Ice/protobuf/config.server | 24 | ||||
-rwxr-xr-x | py/demo/Ice/protobuf/expect.py | 30 | ||||
-rwxr-xr-x | py/demo/Ice/value/Client.py | 10 | ||||
-rwxr-xr-x | py/demo/book/simple_filesystem/Server.py | 8 |
12 files changed, 279 insertions, 10 deletions
diff --git a/py/demo/Glacier2/callback/Server.py b/py/demo/Glacier2/callback/Server.py index 889d71b95c8..ea50ffec29f 100755 --- a/py/demo/Glacier2/callback/Server.py +++ b/py/demo/Glacier2/callback/Server.py @@ -17,7 +17,7 @@ class CallbackI(Demo.Callback): def initiateCallback(self, proxy, current=None): print "initiating callback to: " + current.adapter.getCommunicator().proxyToString(proxy) try: - proxy.callback(current.ctx) + proxy.callback() except: traceback.print_exc() diff --git a/py/demo/Ice/callback/Server.py b/py/demo/Ice/callback/Server.py index bc1b3233b95..b048c253fc7 100755 --- a/py/demo/Ice/callback/Server.py +++ b/py/demo/Ice/callback/Server.py @@ -17,7 +17,7 @@ class CallbackSenderI(Demo.CallbackSender): def initiateCallback(self, proxy, current=None): print "initiating callback" try: - proxy.callback(current.ctx) + proxy.callback() except: traceback.print_exc() diff --git a/py/demo/Ice/protobuf/Client.py b/py/demo/Ice/protobuf/Client.py new file mode 100644 index 00000000000..ca4b7e17b5c --- /dev/null +++ b/py/demo/Ice/protobuf/Client.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2008 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. +# +# ********************************************************************** + +import sys, traceback, Ice + +Ice.loadSlice('Hello.ice') +import Demo +from Person_pb2 import Person + +def menu(): + print """ +usage: +t: send greeting +s: shutdown server +x: exit +?: help +""" + +class Client(Ice.Application): + def run(self, args): + if len(args) > 1: + print self.appName() + ": too many arguments" + return 1 + + hello = Demo.HelloPrx.checkedCast(self.communicator().propertyToProxy('Hello.Proxy')) + if not hello: + print args[0] + ": invalid proxy" + return 1 + + menu() + + p = Person() + p.id = 1 + p.name = "Fred Jones" + p.email = "fred@jones.com" + + c = None + while c != 'x': + try: + c = raw_input("==> ") + if c == 't': + hello.sayHello(p) + elif c == 's': + hello.shutdown() + elif c == 'x': + pass # Nothing to do + elif c == '?': + menu() + else: + print "unknown command `" + c + "'" + menu() + except KeyboardInterrupt: + break + except EOFError: + break + except Ice.Exception, ex: + print ex + + return 0 + +app = Client() +sys.exit(app.main(sys.argv, "config.client")) diff --git a/py/demo/Ice/protobuf/Hello.ice b/py/demo/Ice/protobuf/Hello.ice new file mode 100644 index 00000000000..f987ad8da31 --- /dev/null +++ b/py/demo/Ice/protobuf/Hello.ice @@ -0,0 +1,28 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +#ifndef HELLO_ICE +#define HELLO_ICE + +module Demo +{ + +["cpp:protobuf:tutorial::Person", "java:protobuf:tutorial.PersonPB.Person", "python:protobuf:Person_pb2.Person"] +sequence<byte> Person; + +interface Hello +{ + idempotent void sayHello(Person p); + void shutdown(); +}; + +}; + + +#endif diff --git a/py/demo/Ice/protobuf/Person.proto b/py/demo/Ice/protobuf/Person.proto new file mode 100644 index 00000000000..b68990dbc48 --- /dev/null +++ b/py/demo/Ice/protobuf/Person.proto @@ -0,0 +1,16 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2008 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. +// +// ********************************************************************** + +package tutorial; + +message Person { + required int32 id = 1; + required string name = 2; + optional string email = 3; +} diff --git a/py/demo/Ice/protobuf/README b/py/demo/Ice/protobuf/README new file mode 100644 index 00000000000..91f1d18598f --- /dev/null +++ b/py/demo/Ice/protobuf/README @@ -0,0 +1,39 @@ +This demo shows how to integrate Google Protocol Buffers with Ice. + +The Protocol Buffers distribution and documentation can be found at + + http://code.google.com/apis/protocolbuffers/ + +This demo was tested with Protocol Buffers version 2.0.3. + +We have added new metadata that makes it possible for you to specify +protocol buffers message types in your Slice definitions, with Ice +handling the serialization chores for you automatically. The metadata, +which may only be used on a sequence<byte> type, has the following +syntax in Python: + + python:protobuf:protoc-generated-class + +For example: + + ["python:protobuf:Person_pb2.Person"] sequence<byte> Person; + +The type name specified in this example, Person_pb2.Person, +corresponds to the Python class generated by the Protocol Buffers +compiler (protoc) for the definition shown below: + + package tutorial; + message Person { ... }; + +Prior to running the demo, you must generate the Python code for +Person.proto by running the following command: + + $ protoc --python_out=. Person.proto + +To run the demo, first start the server: + + $ python Server.py + +In a separate window, start the client: + + $ python Client.py diff --git a/py/demo/Ice/protobuf/Server.py b/py/demo/Ice/protobuf/Server.py new file mode 100644 index 00000000000..0ccd8d6dbc5 --- /dev/null +++ b/py/demo/Ice/protobuf/Server.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2008 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. +# +# ********************************************************************** + +import sys, traceback, time, Ice + +Ice.loadSlice('Hello.ice') +import Demo +from Person_pb2 import Person + +class HelloI(Demo.Hello): + def sayHello(self, p, current=None): + print "Hello World from %s" % str(p) + + def shutdown(self, current=None): + current.adapter.getCommunicator().shutdown() + +class Server(Ice.Application): + def run(self, args): + if len(args) > 1: + print self.appName() + ": too many arguments" + return 1 + + adapter = self.communicator().createObjectAdapter("Hello") + adapter.add(HelloI(), self.communicator().stringToIdentity("hello")) + adapter.activate() + self.communicator().waitForShutdown() + return 0 + +sys.stdout.flush() +app = Server() +sys.exit(app.main(sys.argv, "config.server")) diff --git a/py/demo/Ice/protobuf/config.client b/py/demo/Ice/protobuf/config.client new file mode 100644 index 00000000000..a02cab0f4cb --- /dev/null +++ b/py/demo/Ice/protobuf/config.client @@ -0,0 +1,23 @@ +# +# The client reads this property to create the reference to the +# "hello" object in the server. +# +Hello.Proxy=hello:tcp -p 10000 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +#Ice.Trace.Network=1 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +#Ice.Trace.Protocol=1 diff --git a/py/demo/Ice/protobuf/config.server b/py/demo/Ice/protobuf/config.server new file mode 100644 index 00000000000..309db9731b2 --- /dev/null +++ b/py/demo/Ice/protobuf/config.server @@ -0,0 +1,24 @@ +# +# The server creates one single object adapter with the name +# "Hello". The following line sets the endpoints for this +# adapter. +# +Hello.Endpoints=tcp -p 10000 + +# +# Network Tracing +# +# 0 = no network tracing +# 1 = trace connection establishment and closure +# 2 = like 1, but more detailed +# 3 = like 2, but also trace data transfer +# +#Ice.Trace.Network=1 + +# +# Protocol Tracing +# +# 0 = no protocol tracing +# 1 = trace protocol messages +# +#Ice.Trace.Protocol=1 diff --git a/py/demo/Ice/protobuf/expect.py b/py/demo/Ice/protobuf/expect.py new file mode 100755 index 00000000000..6db9aa22652 --- /dev/null +++ b/py/demo/Ice/protobuf/expect.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2009 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. +# +# ********************************************************************** + +import sys, os + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "demoscript")) ] +if len(path) == 0: + raise "can't find toplevel directory!" +sys.path.append(path[0]) + +from demoscript import * +from demoscript.Ice import protobuf + +server = Util.spawn('Server.py --Ice.PrintAdapterReady --Ice.Warn.Connections=0') +server.expect('.* ready') +client = Util.spawn('Client.py --Ice.Warn.Connections=0') +client.expect('.*==>') + +protobuf.run(client, server) diff --git a/py/demo/Ice/value/Client.py b/py/demo/Ice/value/Client.py index e5b89c773da..0dbdeed4376 100755 --- a/py/demo/Ice/value/Client.py +++ b/py/demo/Ice/value/Client.py @@ -15,10 +15,10 @@ import Demo, Printer class ObjectFactory(Ice.ObjectFactory): def create(self, type): - if type == "::Demo::Printer": + if type == Demo.Printer.ice_staticId(): return Printer.PrinterI() - if type == "::Demo::DerivedPrinter": + if type == Demo.DerivedPrinter.ice_staticId(): return Printer.DerivedPrinterI() assert(False) @@ -70,7 +70,7 @@ class Client(Ice.Application): raw_input() factory = ObjectFactory() - self.communicator().addObjectFactory(factory, "::Demo::Printer") + self.communicator().addObjectFactory(factory, Demo.Printer.ice_staticId()) printer, printerProxy = initial.getPrinter() print "==> " + printer.message @@ -102,7 +102,7 @@ class Client(Ice.Application): derivedAsBase = initial.getDerivedPrinter() print "==> The type ID of the received object is \"" + derivedAsBase.ice_id() + "\"" - assert(derivedAsBase.ice_id() == "::Demo::Printer") + assert(derivedAsBase.ice_id() == Demo.Printer.ice_staticId()) print '\n'\ "Now we install a factory for the derived class, and try again.\n"\ @@ -111,7 +111,7 @@ class Client(Ice.Application): "[press enter]" raw_input() - self.communicator().addObjectFactory(factory, "::Demo::DerivedPrinter") + self.communicator().addObjectFactory(factory, Demo.DerivedPrinter.ice_staticId()) derived = initial.getDerivedPrinter() print "==> The type ID of the received object is \"" + derived.ice_id() + "\"" diff --git a/py/demo/book/simple_filesystem/Server.py b/py/demo/book/simple_filesystem/Server.py index ea408b2fbbd..75982f0b70b 100755 --- a/py/demo/book/simple_filesystem/Server.py +++ b/py/demo/book/simple_filesystem/Server.py @@ -21,10 +21,11 @@ class DirectoryI(Filesystem.Directory): # Create an identity. The root directory has the fixed identity "RootDir" # + self._id = Ice.Identity() if self._parent: - self._id = communicator.stringToIdentity(Ice.generateUUID()) + self._id.name = Ice.generateUUID() else: - self._id = communicator.stringToIdentity("RootDir") + self._id.name = "RootDir" # Slice Node::name() operation @@ -59,7 +60,8 @@ class FileI(Filesystem.File): # Create an identity # - self._id = communicator.stringToIdentity(Ice.generateUUID()) + self._id = Ice.Identity() + self._id.name = Ice.generateUUID() # Slice Node::name() operation |