diff options
author | Mark Spruiell <mes@zeroc.com> | 2013-06-12 15:57:57 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2013-06-12 15:57:57 -0700 |
commit | 3f3bf46c8a62b26c51ca52800657186cfbc8a799 (patch) | |
tree | 39733798f3581a1f09e737a4eef02ea8fc6a4427 /py/demo/Ice/optional/Server.py | |
parent | removing extraneous semicolon in UserExceptionFactory.h (diff) | |
download | ice-3f3bf46c8a62b26c51ca52800657186cfbc8a799.tar.bz2 ice-3f3bf46c8a62b26c51ca52800657186cfbc8a799.tar.xz ice-3f3bf46c8a62b26c51ca52800657186cfbc8a799.zip |
ICE-5349 - add optional demo for php/py/rb
Diffstat (limited to 'py/demo/Ice/optional/Server.py')
-rw-r--r-- | py/demo/Ice/optional/Server.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/py/demo/Ice/optional/Server.py b/py/demo/Ice/optional/Server.py new file mode 100644 index 00000000000..bac205826c0 --- /dev/null +++ b/py/demo/Ice/optional/Server.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2013 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, threading + +Ice.loadSlice("Contact.ice") +import Demo + +class ContactDBI(Demo.ContactDB): + def __init__(self): + self._contacts = {} + + def addContact(self, name, type, number, dialGroup, current = None): + contact = Demo.Contact() + contact.name = name + if type != Ice.Unset: + contact.type = type + if number != Ice.Unset: + contact.number = number + if dialGroup != Ice.Unset: + contact.dialGroup = dialGroup + self._contacts[name] = contact + + def updateContact(self, name, type, number, dialGroup, current = None): + if name in self._contacts: + contact = self._contacts[name] + if type != Ice.Unset: + contact.type = type + if number != Ice.Unset: + contact.number = number + if dialGroup != Ice.Unset: + contact.dialGroup = dialGroup + + def query(self, name, current = None): + if name in self._contacts: + return self._contacts[name] + return None + + def queryNumber(self, name, current = None): + if name in self._contacts: + return self._contacts[name].number + return Ice.Unset + + def queryDialgroup(self, name, current = None): + if name in self._contacts: + return self._contacts[name].dialGroup + return Ice.Unset + + def shutdown(self, current = None): + print("Shutting down...") + current.adapter.getCommunicator().shutdown(); + +class ContactServer(Ice.Application): + def run(self, args): + if len(args) > 1: + print(self.appName() + ": too many arguments") + return 1 + + adapter = self.communicator().createObjectAdapter("ContactDB") + adapter.add(ContactDBI(), self.communicator().stringToIdentity("contactdb")) + adapter.activate() + self.communicator().waitForShutdown() + return 0 + +sys.stdout.flush() +app = ContactServer() +sys.exit(app.main(sys.argv, "config.server")) |