feat(client): append serial agent to client API (#74)
This commit is contained in:
parent
757be4bc44
commit
64a5d8e56c
44
client.py
44
client.py
@ -10,19 +10,19 @@ from random import randint
|
|||||||
import copy
|
import copy
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
import zmq
|
# import zmq
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from .libs import umsgpack
|
from .libs import umsgpack
|
||||||
# from .libs import zmq
|
from .libs import zmq
|
||||||
from .libs import dump_anything
|
from .libs import dump_anything
|
||||||
from . import helpers
|
from . import helpers
|
||||||
from . import message
|
from . import message
|
||||||
except:
|
except:
|
||||||
# Server import
|
# Server import
|
||||||
from libs import umsgpack
|
from libs import umsgpack
|
||||||
# from libs import zmq
|
from libs import zmq
|
||||||
from libs import dump_anything
|
from libs import dump_anything
|
||||||
import helpers
|
import helpers
|
||||||
import message
|
import message
|
||||||
@ -63,28 +63,36 @@ class State(Enum):
|
|||||||
class RCFClient(object):
|
class RCFClient(object):
|
||||||
ctx = None
|
ctx = None
|
||||||
pipe = None
|
pipe = None
|
||||||
agent = None
|
net_agent = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ctx = zmq.Context()
|
self.ctx = zmq.Context()
|
||||||
self.pipe, peer = zpipe(self.ctx)
|
self.pipe, peer = zpipe(self.ctx)
|
||||||
self.queue = queue.Queue()
|
self.serial_pipe, serial_peer = zpipe(self.ctx)
|
||||||
self.agent = threading.Thread(
|
serial_in, net_in = zpipe(self.ctx)
|
||||||
target=rcf_client_agent, args=(self.ctx, peer, self.queue), name="net-agent")
|
self.tasks = queue.Queue()
|
||||||
self.agent.daemon = True
|
|
||||||
self.agent.start()
|
# Database and connexion agent
|
||||||
# self.sync_agent = threading.Thread(
|
self.net_agent = threading.Thread(
|
||||||
# target=rcf_sync_agent, args=(self.ctx, self.pipe), name="sync-agent")
|
target=rcf_client_agent, args=(self.ctx, peer, self.tasks), name="net-agent")
|
||||||
# self.sync_agent.daemon = True
|
self.net_agent.daemon = True
|
||||||
# self.sync_agent.start()
|
self.net_agent.start()
|
||||||
|
|
||||||
|
# Local data translation agent
|
||||||
|
self.serial_agent = threading.Thread(
|
||||||
|
target=serialization_agent, args=(self.ctx, serial_peer, self.tasks), name="serial-agent")
|
||||||
|
self.serial_agent.daemon = True
|
||||||
|
self.serial_agent.start()
|
||||||
|
|
||||||
|
|
||||||
def connect(self, id, address, port):
|
def connect(self, id, address, port):
|
||||||
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
self.pipe.send_multipart([b"CONNECT", (id.encode() if isinstance(
|
||||||
id, str) else id), (address.encode() if isinstance(
|
id, str) else id), (address.encode() if isinstance(
|
||||||
address, str) else address), b'%d' % port])
|
address, str) else address), b'%d' % port])
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""Set new value in distributed hash table
|
"""
|
||||||
Sends [SET][key][value] to the agent
|
Scene initialisation
|
||||||
"""
|
"""
|
||||||
self.pipe.send_multipart(
|
self.pipe.send_multipart(
|
||||||
[b"INIT"])
|
[b"INIT"])
|
||||||
@ -100,6 +108,7 @@ class RCFClient(object):
|
|||||||
"""Set new value in distributed hash table
|
"""Set new value in distributed hash table
|
||||||
Sends [SET][key][value] to the agent
|
Sends [SET][key][value] to the agent
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.pipe.send_multipart(
|
self.pipe.send_multipart(
|
||||||
[b"SET", umsgpack.packb(key), (umsgpack.packb(value) if value else umsgpack.packb('None')),umsgpack.packb(override)])
|
[b"SET", umsgpack.packb(key), (umsgpack.packb(value) if value else umsgpack.packb('None')),umsgpack.packb(override)])
|
||||||
|
|
||||||
@ -125,7 +134,7 @@ class RCFClient(object):
|
|||||||
return umsgpack.unpackb(reply[0])
|
return umsgpack.unpackb(reply[0])
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
if self.agent.is_alive():
|
if self.net_agent.is_alive():
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
# Disconnect time
|
# Disconnect time
|
||||||
@ -476,7 +485,7 @@ class SerializationAgent(object):
|
|||||||
self.pipe.send_multipart([b"DONE"])
|
self.pipe.send_multipart([b"DONE"])
|
||||||
|
|
||||||
|
|
||||||
def serialization_agent(ctx, pipe):
|
def serialization_agent(ctx, pipe, tasks):
|
||||||
agent = SerializationAgent(ctx, pipe)
|
agent = SerializationAgent(ctx, pipe)
|
||||||
|
|
||||||
global stop
|
global stop
|
||||||
@ -496,6 +505,7 @@ def serialization_agent(ctx, pipe):
|
|||||||
if agent.pipe in items:
|
if agent.pipe in items:
|
||||||
agent.control_message()
|
agent.control_message()
|
||||||
|
|
||||||
|
# TODO : Fill tasks
|
||||||
|
|
||||||
class RCFSyncAgent(object):
|
class RCFSyncAgent(object):
|
||||||
ctx = None
|
ctx = None
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 14 KiB |
@ -563,7 +563,7 @@ def depsgraph_update(scene):
|
|||||||
global client_instance
|
global client_instance
|
||||||
global client_keys
|
global client_keys
|
||||||
|
|
||||||
if client_instance and client_instance.agent.is_alive():
|
if client_instance and client_instance.net_agent.is_alive():
|
||||||
updates = bpy.context.depsgraph.updates
|
updates = bpy.context.depsgraph.updates
|
||||||
username = bpy.context.scene.session_settings.username
|
username = bpy.context.scene.session_settings.username
|
||||||
update_selected_object(bpy.context)
|
update_selected_object(bpy.context)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user