diff --git a/.gitattributes b/.gitattributes index 41b64ee9d0027b4ae215464a27c346c27403b188..e247d46a4f696240d8177d5ee9806a3be75d6f0e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2545,6 +2545,9 @@ LCS/MessageBus/python/common/CMakeLists.txt -text LCS/MessageBus/python/common/__init__.py -text LCS/MessageBus/python/common/factory.py -text LCS/MessageBus/python/common/util.py -text +LCS/MessageBus/python/examples/ToUpperClient -text +LCS/MessageBus/python/examples/ToUpperMapClient -text +LCS/MessageBus/python/examples/ToUpperService -text LCS/MessageBus/python/messaging/CMakeLists.txt -text LCS/MessageBus/python/messaging/RPC.py -text LCS/MessageBus/python/messaging/Service.py -text diff --git a/LCS/MessageBus/python/examples/ToUpperClient b/LCS/MessageBus/python/examples/ToUpperClient new file mode 100755 index 0000000000000000000000000000000000000000..ff4bc97f020c33eecd4c7b55e7c86beeeebc4c26 --- /dev/null +++ b/LCS/MessageBus/python/examples/ToUpperClient @@ -0,0 +1,24 @@ +#!/usr/bin/python + +from messaging.RPC import RPC + +# Simple RPC client for Service 'ToUpper' + +# Used settings +ServiceName="ToUpper" +BusName="simpletest" +NumRequests=10 +Test="Hello World ToUpper " + +# Initialize a Remote Procedure Call object +RPCService=RPC(BusName,ServiceName,timeout=10) + +# 'with' tells the RPC object to connect to the bus +with RPCService: + for requestnr in range(NumRequests): + # execute the RPC Service + replymessage=RPCService(Test+str(requestnr)) + + # show the result from the RPC client + print replymessage + diff --git a/LCS/MessageBus/python/examples/ToUpperMapClient b/LCS/MessageBus/python/examples/ToUpperMapClient new file mode 100755 index 0000000000000000000000000000000000000000..65a73aad4e816857f9a1876d83b95b701b37285b --- /dev/null +++ b/LCS/MessageBus/python/examples/ToUpperMapClient @@ -0,0 +1,26 @@ +#!/usr/bin/python + +#from messagebus.RPC import RPC +from messaging.RPC import RPC + +# Simple RPC client for Service 'ToUpper' + +# Used settings +ServiceName="ToUpper" +BusName="simpletest" +NumRequests=10 +Test={} +Test["One"]="Hello World ToUpper" +Test["Two"]="Bla " + +RPCService=RPC(BusName,ServiceName,timeout=10) + +# loop forever +with RPCService: + for requestnr in range(NumRequests): + # send to the RPC Service + Test["sequence"]="nr:"+str(requestnr) + replymessage=RPCService(Test) + + # show the result from the RPC client + print replymessage diff --git a/LCS/MessageBus/python/examples/ToUpperService b/LCS/MessageBus/python/examples/ToUpperService new file mode 100755 index 0000000000000000000000000000000000000000..89e3faaae9e82500d7874a38bf588d4598ec3e36 --- /dev/null +++ b/LCS/MessageBus/python/examples/ToUpperService @@ -0,0 +1,39 @@ +#!/usr/bin/python + +from messaging.Service import Service + +# Simple RPC server 'ToUpper' + +# create service function: + +def ToUpper( Text ): + if (isinstance(Text,dict)): + ret={} + for name,value in Text.iteritems(): + ret[name]=str(value).upper() + return ret + if (isinstance(Text,str)): + print "ToUpper : %s" %(Text) + return str(Text).upper() + ret="Failed to convert to upper" + try: + ret="Cannot conver to upper object:" + str(Text) + except Exception as e: + ret="Cannot conver to upper object:" + str(e) + return ret + +# Used settings +ServiceName="ToUpper" +BusName="simpletest" + +# Register function as a service handler listeneing at Bus BusName and ServiceName +myserv = Service(BusName,ServiceName,ToUpper,numthreads=4) + +# 'with' sets up the connection context and defines the scope of the service. +with myserv: + # Start listening in the background. This will start as many threads as defined by the instance + myserv.StartListening() + # wait for control-C or kill + myserv.WaitForInterrupt() + # Tell all background listener threads to stop and wait for them to finish. + myserv.StopListening()