00001
00002
00003
00004
00005
00006 import time
00007 from threading import *
00008 from debug import *
00009
00010 from pydim import DimRpc, DimRpcInfo, dis_start_serving
00011
00012
00013
00014 e = Event()
00015
00016
00017
00018
00019
00020
00021
00022 class PyRpc (DimRpc):
00023 def __init__(self):
00024 DimRpc.__init__(self, 'testRpc', 'I', 'I')
00025 self.counter = 0
00026
00027 def rpcHandler(self):
00028 SAY('Server side funciton called. Getting parameters...')
00029 i = self.getInt()
00030 SAY("getInt - received: ", i)
00031 i = self.getData()
00032 SAY("getData - received: ", i)
00033 self.counter += i
00034 SAY('Setting response data ', self.counter+1)
00035 self.setData(self.counter+1)
00036
00037
00038 class PyRpcInfo(DimRpcInfo):
00039 def __init__(self):
00040 DimRpcInfo.__init__(self, 'testRpc', 'I', 'I', None)
00041 self.value = 1
00042
00043 def rpcHandler(self):
00044 SAY("Non blocking RPC call executed")
00045 i = getInt()
00046 SAY("Received value %d", i)
00047
00048 def run(self):
00049 DEBUG("Calling thread started")
00050 while not e.isSet():
00051 SAY('Calling server function')
00052 self.setData(self.value)
00053 if self.value % 2:
00054
00055 SAY("Getting return value as int: ", self.getInt())
00056 else:
00057
00058 pass
00059 time.sleep(1)
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 if __name__ == '__main__':
00071 DEBUG("Creating PyDimRpc ...")
00072 myrpc = PyRpc()
00073 DEBUG("Creating PyDimRpcInfo ...")
00074 myrpcCaller = PyRpcInfo()
00075
00076 DEBUG("Starting DIM ...")
00077 dis_start_serving()
00078
00079 t = Thread(target = myrpcCaller.run)
00080 t.start()
00081
00082 try:
00083 while True:
00084 time.sleep(1)
00085 except:
00086 DEBUG("Stopping test")
00087 e.set()
00088
00089