summaryrefslogtreecommitdiff
path: root/py/demo/IceGrid/simple/Client.py
blob: c0dad5d49b496ba97fad74367078d067c0732354 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2007 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, IceGrid

Ice.loadSlice('Hello.ice')
import Demo


def menu():
    print """
usage:
t: send greeting as twoway
s: shutdown server
x: exit
?: help
"""

class Client(Ice.Application):
    def run(self, args):
        hello = None
	try:
	    hello = Demo.HelloPrx.checkedCast(self.communicator().stringToProxy("hello"))
	except Ice.NotRegisteredException:
	    query = IceGrid.QueryPrx.checkedCast(self.communicator().stringToProxy("DemoIceGrid/Query"))
	    hello = Demo.HelloPrx.checkedCast(query.findObjectByType("::Demo::Hello"))

	if not hello:
	    print self.appName() + ": couldn't find a `::Demo::Hello' object."
	    return False

	menu()

	c = None
	while c != 'x':
	    try:
		c = raw_input("==> ")
		if c == 't':
		    hello.sayHello()
		elif c == 's':
		    hello.shutdown()
		elif c == 'x':
		    pass # Nothing to do
		elif c == '?':
		    menu()
		else:
		    print "unknown command `" + c + "'"
		    menu()
	    except EOFError:
		break
            except KeyboardInterrupt:
                break

	return True

app = Client()
sys.exit(app.main(sys.argv, "config.client"))