feat(rcf): Append get set
This commit is contained in:
@ -43,31 +43,6 @@ class State(Enum):
|
|||||||
SYNCING = 2
|
SYNCING = 2
|
||||||
ACTIVE = 3
|
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):
|
class RCFMessage(object):
|
||||||
"""
|
"""
|
||||||
Message is formatted on wire as 2 frames:
|
Message is formatted on wire as 2 frames:
|
||||||
@ -138,7 +113,6 @@ class RCFMessage(object):
|
|||||||
data=data,
|
data=data,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
class RCFClient(object):
|
class RCFClient(object):
|
||||||
ctx = None
|
ctx = None
|
||||||
pipe = None
|
pipe = None
|
||||||
@ -158,10 +132,24 @@ class RCFClient(object):
|
|||||||
|
|
||||||
def set(self, key, value):
|
def set(self, key, value):
|
||||||
"""Set new value in distributed hash table
|
"""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)])
|
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):
|
def exit(self):
|
||||||
if self.agent.is_alive():
|
if self.agent.is_alive():
|
||||||
global stop
|
global stop
|
||||||
@ -186,7 +174,6 @@ class RCFServer(object):
|
|||||||
self.subscriber.linger = 0
|
self.subscriber.linger = 0
|
||||||
print("connected on tcp://{}:{}".format(address.decode(), port))
|
print("connected on tcp://{}:{}".format(address.decode(), port))
|
||||||
|
|
||||||
|
|
||||||
class RCFClientAgent(object):
|
class RCFClientAgent(object):
|
||||||
ctx = None
|
ctx = None
|
||||||
pipe = None
|
pipe = None
|
||||||
@ -199,7 +186,7 @@ class RCFClientAgent(object):
|
|||||||
def __init__(self, ctx, pipe):
|
def __init__(self, ctx, pipe):
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
self.pipe = pipe
|
self.pipe = pipe
|
||||||
self.property_map = RCFStore()
|
self.property_map = {}
|
||||||
self.id = b"test"
|
self.id = b"test"
|
||||||
self.state = State.INITIAL
|
self.state = State.INITIAL
|
||||||
self.server = None
|
self.server = None
|
||||||
@ -232,6 +219,11 @@ class RCFClientAgent(object):
|
|||||||
|
|
||||||
rcfmsg.send(self.publisher)
|
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):
|
def rcf_client_agent(ctx, pipe):
|
||||||
agent = RCFClientAgent(ctx, pipe)
|
agent = RCFClientAgent(ctx, pipe)
|
||||||
server = None
|
server = None
|
||||||
|
@ -714,6 +714,7 @@ class session_add_property(bpy.types.Operator):
|
|||||||
global client
|
global client
|
||||||
|
|
||||||
client.set('key', 1)
|
client.set('key', 1)
|
||||||
|
print(client.get('key'))
|
||||||
# item = resolve_bpy_path(self.property_path)
|
# item = resolve_bpy_path(self.property_path)
|
||||||
|
|
||||||
# print(item)
|
# print(item)
|
||||||
|
28
net_ui.py
28
net_ui.py
@ -126,7 +126,8 @@ class SessionPropertiesPanel(bpy.types.Panel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
if net_operators.client:
|
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
|
return False
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
@ -149,18 +150,18 @@ class SessionPropertiesPanel(bpy.types.Panel):
|
|||||||
row = layout.row()
|
row = layout.row()
|
||||||
# Property area
|
# Property area
|
||||||
area_msg = row.box()
|
area_msg = row.box()
|
||||||
if len(net_operators.client.property_map) > 0:
|
# if len(net_operators.client.property_map) > 0:
|
||||||
for key, values in net_operators.client.property_map.items():
|
# for key, values in net_operators.client.property_map.items():
|
||||||
item_box = area_msg.box()
|
# item_box = area_msg.box()
|
||||||
detail_item_box = item_box.row()
|
|
||||||
# detail_item_box = item_box.row()
|
# detail_item_box = item_box.row()
|
||||||
|
# # detail_item_box = item_box.row()
|
||||||
|
|
||||||
detail_item_box.label(text="{} ({}) {} ".format(
|
# detail_item_box.label(text="{} ({}) {} ".format(
|
||||||
key, values.mtype, values.id.decode()))
|
# key, values.mtype, values.id.decode()))
|
||||||
detail_item_box.operator(
|
# detail_item_box.operator(
|
||||||
"session.remove_prop", text="", icon="X").property_path = key
|
# "session.remove_prop", text="", icon="X").property_path = key
|
||||||
else:
|
# else:
|
||||||
area_msg.label(text="Empty")
|
# area_msg.label(text="Empty")
|
||||||
|
|
||||||
class SessionTaskPanel(bpy.types.Panel):
|
class SessionTaskPanel(bpy.types.Panel):
|
||||||
"""Creates a Panel in the scene context of the properties editor"""
|
"""Creates a Panel in the scene context of the properties editor"""
|
||||||
@ -173,7 +174,8 @@ class SessionTaskPanel(bpy.types.Panel):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
if net_operators.client:
|
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
|
return False
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
@ -199,7 +201,7 @@ class SessionTaskPanel(bpy.types.Panel):
|
|||||||
classes = (
|
classes = (
|
||||||
SessionSettingsPanel,
|
SessionSettingsPanel,
|
||||||
# SessionUsersPanel,
|
# SessionUsersPanel,
|
||||||
# SessionPropertiesPanel,
|
SessionPropertiesPanel,
|
||||||
# SessionTaskPanel,
|
# SessionTaskPanel,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user