Commit 5b588263 authored by legoc's avatar legoc

First python tests and examples

parent 10747e01
......@@ -340,10 +340,14 @@
</application>
<!-- Python apps -->
<application name="startsimplepy" starting_time="0" stopping_time="1" output_stream="yes" multiple="no" restart="no" environment="python.properties">
<application name="startsimplepy" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no" environment="python.properties">
<start executable="src/startsimple.py"/>
</application>
<application name="startstoppy" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no" environment="python.properties">
<start executable="src/startstop.py"/>
</application>
<!-- test apps -->
<application name="responder-server" starting_time="0" stopping_time="1" output_stream="yes" log_directory="logs" multiple="no" restart="no">
<start executable="build/bin/testresponderserver"/>
......
PYTHONPATH=/usr/local/lib/python3.7/site-packages
\ No newline at end of file
......@@ -21,15 +21,6 @@
<start executable="build/bin/subscriber"/>
</application>
<!-- Python -->
<application name="responderpy" starting_time="0" retries="0" stopping_time="1" output_stream="yes" multiple="no" restart="no" environment="python.properties">
<start executable="src/examples/responderapplication.py"/>
</application>
<application name="requesterpy" starting_time="0" retries="0" stopping_time="1" output_stream="yes" multiple="no" restart="no" environment="python.properties">
<start executable="src/examples/requesterapplication.py"/>
</application>
</applications>
</config>
#!/usr/bin/python3 -u
import sys
import cameopy
import time
this = cameopy.This
this.init(sys.argv)
publisher = cameopy.Publisher.create("the-publisher")
print("Created publisher:", publisher.getName())
this.setRunning()
i = 0
while True:
message = "a message " + str(i)
publisher.send(message)
i += 1
time.sleep(1.000)
<?xml version="1.0" encoding="UTF-8"?>
<config port="11000" max_applications="20" log_directory="logs" log_level="fine" polling_time="100">
<applications>
<!-- Python -->
<application name="responderpy" starting_time="0" retries="0" stopping_time="1" output_stream="yes" multiple="no" restart="no" environment="python.properties">
<start executable="responderapplication.py"/>
</application>
<application name="requesterpy" starting_time="0" retries="0" stopping_time="1" output_stream="yes" multiple="no" restart="no" environment="python.properties">
<start executable="requesterapplication.py"/>
</application>
<application name="publisherpy" starting_time="0" retries="0" stopping_time="1" output_stream="yes" multiple="no" restart="no" environment="python.properties">
<start executable="publisherapplication.py"/>
</application>
<application name="subscriberpy" starting_time="0" retries="0" stopping_time="1" output_stream="yes" multiple="no" restart="no" environment="python.properties">
<start executable="subscriberapplication.py"/>
</application>
</applications>
</config>
LD_LIBRARY_PATH=/users/legoc/cameo-master/local-test/lib/
PYTHONPATH=/usr/local/lib/python3.7/site-packages
\ No newline at end of file
#!/usr/bin/python3
import sys
#!/usr/bin/python3 -u
import sys
import cameopy
t = cameopy.This
t.init(sys.argv)
numberOfTimes = 1 if len(sys.argv) < 3 else int(sys.argv[1])
print("Number of times:", numberOfTimes)
server = cameopy.Server("tcp://localhost:11000")
this = cameopy.This
this.init(sys.argv)
responderServer = server.connect("responderpy", cameopy.NONE)
server = this.getServer()
responderApp = server.connect("responderpy", 0)
print("Connected :", responderServer.getNameId())
print("Connected:", responderApp.getNameId())
requester = cameopy.Requester.create(responderServer, "the-responder")
requester = cameopy.Requester.create(responderApp, "the-responder")
for i in range(6):
s = "request-" + str(i)
requester.send(s)
for i in range(numberOfTimes):
request = "request-" + str(i)
requester.send(request)
print("Sent request")
requester.receive(s)
print("Response :", s)
response = requester.receive()
print("Response:", response)
#!/usr/bin/python3
import sys
#!/usr/bin/python3 -u
import sys
import cameopy
t = cameopy.This
t.init(sys.argv)
this = cameopy.This
this.init(sys.argv)
responder = cameopy.Responder.create("the-responder")
print("Created responder:", responder.getName())
t.setRunning()
this.setRunning()
i = 0
while i < 6:
while True:
request = responder.receive();
print(request.getBinary())
request.replyBinary("this is a text message")
if request:
requestStr = request.get()
print("received request:", requestStr)
response = "processed " + requestStr
request.reply(response)
else:
print("canceled")
i += 1
#!/usr/bin/python3 -u
import sys
import cameopy
this = cameopy.This
this.init(sys.argv)
server = this.getServer()
publisherApp = server.connect("publisherpy", 0)
print("Connected:", publisherApp.getNameId())
subscriber = cameopy.Subscriber.create(publisherApp, "the-publisher")
while True:
message = subscriber.receive()
if message:
print("Received", message)
else:
print("Canceled")
#!/usr/bin/python3
import sys
numberOfTimes = 1 if len(sys.argv) < 3 else sys.argv[1]
print("Number of times: ", numberOfTimes)
#!/usr/bin/python3 -u
import sys
import cameopy
t = cameopy.This
t.init(sys.argv);
numberOfTimes = 1 if len(sys.argv) < 3 else int(sys.argv[1])
print("Number of times:", numberOfTimes)
this = cameopy.This
this.init(sys.argv)
server = this.getServer()
server = t.getServer();
for i in range(numberOfTimes):
app = server.start("simplecpp", cameopy.NONE);
state = app.waitFor();
print( "finished the application ", app.getName,
" with state ", toString(state),
" and code ", app.getExitCode()
app = server.start("simplecpp", 0)
state = app.waitFor()
print("finished the application", app.getNameId(),
"with state", state,
"and code", app.getExitCode()
)
#!/usr/bin/python3 -u
import sys
import cameopy
import time
numberOfTimes = 1 if len(sys.argv) < 3 else int(sys.argv[1])
print("Number of times:", numberOfTimes)
this = cameopy.This
this.init(sys.argv)
server = this.getServer()
for i in range(numberOfTimes):
app = server.start("stopcpp", 0);
print("waiting 100ms...")
time.sleep(0.100)
print("stopping application", app.getNameId())
app.stop()
result = app.getResult()
# The variable result can be None
if result:
print("result", result)
else:
print("no result")
print("finished the application")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment