feat(rcf): Append get set

This commit is contained in:
Swann
2019-04-08 18:21:48 +02:00
parent 333f0980bf
commit 92f9070bd9
3 changed files with 38 additions and 43 deletions

View File

@ -43,31 +43,6 @@ class State(Enum):
SYNCING = 2
ACTIVE = 3
class RCFStore(collections.MutableMapping, dict):
def __init__(self):
super().__init__()
def __getitem__(self, key):
return dict.__getitem__(self, key)
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
def __delitem__(self, key):
dict.__delitem__(self, key)
def __iter__(self):
return dict.__iter__(self)
def __len__(self):
return dict.__len__(self)
def __contains__(self, x):
return dict.__contains__(self, x)
class RCFMessage(object):
"""
Message is formatted on wire as 2 frames:
@ -138,7 +113,6 @@ class RCFMessage(object):
data=data,
))
class RCFClient(object):
ctx = None
pipe = None
@ -158,10 +132,24 @@ class RCFClient(object):
def set(self, key, value):
"""Set new value in distributed hash table
Sends [SET][key][value][ttl] to the agent
Sends [SET][key][value] to the agent
"""
self.pipe.send_multipart([b"SET", umsgpack.packb(key), umsgpack.packb(value)])
def get(self, key):
"""Lookup value in distributed hash table
Sends [GET][key] to the agent and waits for a value response
If there is no clone available, will eventually return None.
"""
self.pipe.send_multipart([b"GET", umsgpack.packb(key)])
try:
reply = self.pipe.recv_multipart()
except KeyboardInterrupt:
return
else:
return umsgpack.unpackb(reply[0])
def exit(self):
if self.agent.is_alive():
global stop
@ -186,7 +174,6 @@ class RCFServer(object):
self.subscriber.linger = 0
print("connected on tcp://{}:{}".format(address.decode(), port))
class RCFClientAgent(object):
ctx = None
pipe = None
@ -199,7 +186,7 @@ class RCFClientAgent(object):
def __init__(self, ctx, pipe):
self.ctx = ctx
self.pipe = pipe
self.property_map = RCFStore()
self.property_map = {}
self.id = b"test"
self.state = State.INITIAL
self.server = None
@ -232,6 +219,11 @@ class RCFClientAgent(object):
rcfmsg.send(self.publisher)
elif command == b"GET":
key = umsgpack.unpackb(msg[0])
value = self.property_map.get(key)
self.pipe.send(umsgpack.packb(value.body) if value else b'')
def rcf_client_agent(ctx, pipe):
agent = RCFClientAgent(ctx, pipe)
server = None

View File

@ -714,6 +714,7 @@ class session_add_property(bpy.types.Operator):
global client
client.set('key', 1)
print(client.get('key'))
# item = resolve_bpy_path(self.property_path)
# print(item)

View File

@ -126,7 +126,8 @@ class SessionPropertiesPanel(bpy.types.Panel):
@classmethod
def poll(cls, context):
if net_operators.client:
return net_operators.client.status == net_components.RCFStatus.CONNECTED
return net_operators.client.agent.is_alive()
# return net_operators.client.status == net_components.RCFStatus.CONNECTED
return False
def draw(self, context):
@ -149,18 +150,18 @@ class SessionPropertiesPanel(bpy.types.Panel):
row = layout.row()
# Property area
area_msg = row.box()
if len(net_operators.client.property_map) > 0:
for key, values in net_operators.client.property_map.items():
item_box = area_msg.box()
detail_item_box = item_box.row()
# detail_item_box = item_box.row()
# if len(net_operators.client.property_map) > 0:
# for key, values in net_operators.client.property_map.items():
# item_box = area_msg.box()
# detail_item_box = item_box.row()
# # detail_item_box = item_box.row()
detail_item_box.label(text="{} ({}) {} ".format(
key, values.mtype, values.id.decode()))
detail_item_box.operator(
"session.remove_prop", text="", icon="X").property_path = key
else:
area_msg.label(text="Empty")
# detail_item_box.label(text="{} ({}) {} ".format(
# key, values.mtype, values.id.decode()))
# detail_item_box.operator(
# "session.remove_prop", text="", icon="X").property_path = key
# else:
# area_msg.label(text="Empty")
class SessionTaskPanel(bpy.types.Panel):
"""Creates a Panel in the scene context of the properties editor"""
@ -173,7 +174,8 @@ class SessionTaskPanel(bpy.types.Panel):
@classmethod
def poll(cls, context):
if net_operators.client:
return net_operators.client.status == net_components.RCFStatus.CONNECTED
return net_operators.client.agent.is_alive()
# return net_operators.client.status == net_components.RCFStatus.CONNECTED
return False
def draw(self, context):
@ -199,7 +201,7 @@ class SessionTaskPanel(bpy.types.Panel):
classes = (
SessionSettingsPanel,
# SessionUsersPanel,
# SessionPropertiesPanel,
SessionPropertiesPanel,
# SessionTaskPanel,
)