forked from M-Labs/artiq
pc_rpc: id_parameters -> description
This commit is contained in:
parent
a6ab066c87
commit
998db5121b
|
@ -29,10 +29,10 @@ def get_argparser():
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def list_targets(target_names, id_parameters):
|
def list_targets(target_names, description):
|
||||||
print("Target(s): " + ", ".join(target_names))
|
print("Target(s): " + ", ".join(target_names))
|
||||||
if id_parameters is not None:
|
if description is not None:
|
||||||
print("Parameters: " + id_parameters)
|
print("Description: " + description)
|
||||||
|
|
||||||
|
|
||||||
def list_methods(remote):
|
def list_methods(remote):
|
||||||
|
@ -85,7 +85,7 @@ def main():
|
||||||
|
|
||||||
remote = Client(args.server, args.port, None)
|
remote = Client(args.server, args.port, None)
|
||||||
|
|
||||||
targets, id_parameters = remote.get_rpc_id()
|
targets, description = remote.get_rpc_id()
|
||||||
|
|
||||||
if args.action != "list-targets":
|
if args.action != "list-targets":
|
||||||
# If no target specified and remote has only one, then use this one.
|
# If no target specified and remote has only one, then use this one.
|
||||||
|
@ -99,7 +99,7 @@ def main():
|
||||||
remote.select_rpc_target(args.target)
|
remote.select_rpc_target(args.target)
|
||||||
|
|
||||||
if args.action == "list-targets":
|
if args.action == "list-targets":
|
||||||
list_targets(targets, id_parameters)
|
list_targets(targets, description)
|
||||||
elif args.action == "list-methods":
|
elif args.action == "list-methods":
|
||||||
list_methods(remote)
|
list_methods(remote)
|
||||||
elif args.action == "call":
|
elif args.action == "call":
|
||||||
|
|
|
@ -39,7 +39,7 @@ def main():
|
||||||
dev = Pdq2(url=args.device, dev=port)
|
dev = Pdq2(url=args.device, dev=port)
|
||||||
try:
|
try:
|
||||||
simple_server_loop({"pdq2": dev}, args.bind, args.port,
|
simple_server_loop({"pdq2": dev}, args.bind, args.port,
|
||||||
id_parameters="device=" + str(args.device))
|
description="device=" + str(args.device))
|
||||||
finally:
|
finally:
|
||||||
dev.close()
|
dev.close()
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class Client:
|
||||||
|
|
||||||
server_identification = self.__recv()
|
server_identification = self.__recv()
|
||||||
self.__target_names = server_identification["targets"]
|
self.__target_names = server_identification["targets"]
|
||||||
self.__id_parameters = server_identification["parameters"]
|
self.__description = server_identification["description"]
|
||||||
if target_name is not None:
|
if target_name is not None:
|
||||||
self.select_rpc_target(target_name)
|
self.select_rpc_target(target_name)
|
||||||
except:
|
except:
|
||||||
|
@ -94,9 +94,9 @@ class Client:
|
||||||
self.__socket.sendall((target_name + "\n").encode())
|
self.__socket.sendall((target_name + "\n").encode())
|
||||||
|
|
||||||
def get_rpc_id(self):
|
def get_rpc_id(self):
|
||||||
"""Returns a tuple (target_names, id_parameters) containing the
|
"""Returns a tuple (target_names, description) containing the
|
||||||
identification information of the server."""
|
identification information of the server."""
|
||||||
return (self.__target_names, self.__id_parameters)
|
return (self.__target_names, self.__description)
|
||||||
|
|
||||||
def close_rpc(self):
|
def close_rpc(self):
|
||||||
"""Closes the connection to the RPC server.
|
"""Closes the connection to the RPC server.
|
||||||
|
@ -157,7 +157,7 @@ class AsyncioClient:
|
||||||
self.__reader = None
|
self.__reader = None
|
||||||
self.__writer = None
|
self.__writer = None
|
||||||
self.__target_names = None
|
self.__target_names = None
|
||||||
self.__id_parameters = None
|
self.__description = None
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def connect_rpc(self, host, port, target_name):
|
def connect_rpc(self, host, port, target_name):
|
||||||
|
@ -170,7 +170,7 @@ class AsyncioClient:
|
||||||
self.__writer.write(_init_string)
|
self.__writer.write(_init_string)
|
||||||
server_identification = yield from self.__recv()
|
server_identification = yield from self.__recv()
|
||||||
self.__target_names = server_identification["targets"]
|
self.__target_names = server_identification["targets"]
|
||||||
self.__id_parameters = server_identification["parameters"]
|
self.__description = server_identification["description"]
|
||||||
if target_name is not None:
|
if target_name is not None:
|
||||||
self.select_rpc_target(target_name)
|
self.select_rpc_target(target_name)
|
||||||
except:
|
except:
|
||||||
|
@ -186,9 +186,9 @@ class AsyncioClient:
|
||||||
self.__writer.write((target_name + "\n").encode())
|
self.__writer.write((target_name + "\n").encode())
|
||||||
|
|
||||||
def get_rpc_id(self):
|
def get_rpc_id(self):
|
||||||
"""Returns a tuple (target_names, id_parameters) containing the
|
"""Returns a tuple (target_names, description) containing the
|
||||||
identification information of the server."""
|
identification information of the server."""
|
||||||
return (self.__target_names, self.__id_parameters)
|
return (self.__target_names, self.__description)
|
||||||
|
|
||||||
def close_rpc(self):
|
def close_rpc(self):
|
||||||
"""Closes the connection to the RPC server.
|
"""Closes the connection to the RPC server.
|
||||||
|
@ -199,7 +199,7 @@ class AsyncioClient:
|
||||||
self.__reader = None
|
self.__reader = None
|
||||||
self.__writer = None
|
self.__writer = None
|
||||||
self.__target_names = None
|
self.__target_names = None
|
||||||
self.__id_parameters = None
|
self.__description = None
|
||||||
|
|
||||||
def __send(self, obj):
|
def __send(self, obj):
|
||||||
line = pyon.encode(obj) + "\n"
|
line = pyon.encode(obj) + "\n"
|
||||||
|
@ -398,17 +398,17 @@ class Server(_AsyncioServer):
|
||||||
:param targets: A dictionary of objects providing the RPC methods to be
|
:param targets: A dictionary of objects providing the RPC methods to be
|
||||||
exposed to the client. Keys are names identifying each object.
|
exposed to the client. Keys are names identifying each object.
|
||||||
Clients select one of these objects using its name upon connection.
|
Clients select one of these objects using its name upon connection.
|
||||||
:param id_parameters: An optional human-readable string giving more
|
:param description: An optional human-readable string giving more
|
||||||
information about the server.
|
information about the server.
|
||||||
:param builtin_terminate: If set, the server provides a built-in
|
:param builtin_terminate: If set, the server provides a built-in
|
||||||
``terminate`` method that unblocks any tasks waiting on
|
``terminate`` method that unblocks any tasks waiting on
|
||||||
``wait_terminate``. This is useful to handle server termination
|
``wait_terminate``. This is useful to handle server termination
|
||||||
requests from clients.
|
requests from clients.
|
||||||
"""
|
"""
|
||||||
def __init__(self, targets, id_parameters=None, builtin_terminate=False):
|
def __init__(self, targets, description=None, builtin_terminate=False):
|
||||||
_AsyncioServer.__init__(self)
|
_AsyncioServer.__init__(self)
|
||||||
self.targets = targets
|
self.targets = targets
|
||||||
self.id_parameters = id_parameters
|
self.description = description
|
||||||
self.builtin_terminate = builtin_terminate
|
self.builtin_terminate = builtin_terminate
|
||||||
if builtin_terminate:
|
if builtin_terminate:
|
||||||
self._terminate_request = asyncio.Event()
|
self._terminate_request = asyncio.Event()
|
||||||
|
@ -422,7 +422,7 @@ class Server(_AsyncioServer):
|
||||||
|
|
||||||
obj = {
|
obj = {
|
||||||
"targets": sorted(self.targets.keys()),
|
"targets": sorted(self.targets.keys()),
|
||||||
"parameters": self.id_parameters
|
"description": self.description
|
||||||
}
|
}
|
||||||
line = pyon.encode(obj) + "\n"
|
line = pyon.encode(obj) + "\n"
|
||||||
writer.write(line.encode())
|
writer.write(line.encode())
|
||||||
|
@ -480,7 +480,7 @@ class Server(_AsyncioServer):
|
||||||
yield from self._terminate_request.wait()
|
yield from self._terminate_request.wait()
|
||||||
|
|
||||||
|
|
||||||
def simple_server_loop(targets, host, port, id_parameters=None):
|
def simple_server_loop(targets, host, port, description=None):
|
||||||
"""Runs a server until an exception is raised (e.g. the user hits Ctrl-C)
|
"""Runs a server until an exception is raised (e.g. the user hits Ctrl-C)
|
||||||
or termination is requested by a client.
|
or termination is requested by a client.
|
||||||
|
|
||||||
|
@ -488,7 +488,7 @@ def simple_server_loop(targets, host, port, id_parameters=None):
|
||||||
"""
|
"""
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
try:
|
try:
|
||||||
server = Server(targets, id_parameters, True)
|
server = Server(targets, description, True)
|
||||||
loop.run_until_complete(server.start(host, port))
|
loop.run_until_complete(server.start(host, port))
|
||||||
try:
|
try:
|
||||||
loop.run_until_complete(server.wait_terminate())
|
loop.run_until_complete(server.wait_terminate())
|
||||||
|
|
Loading…
Reference in New Issue