feat(rcf): code cleanup
This commit is contained in:
16
__init__.py
16
__init__.py
@ -1,16 +1,3 @@
|
|||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
# General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
bl_info = {
|
bl_info = {
|
||||||
"name" : "rcf",
|
"name" : "rcf",
|
||||||
"author" : "CUBE",
|
"author" : "CUBE",
|
||||||
@ -33,5 +20,6 @@ def register():
|
|||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bsyncio.unregister()
|
bsyncio.unregister()
|
||||||
net_operators.unregister()
|
|
||||||
net_ui.unregister()
|
net_ui.unregister()
|
||||||
|
net_operators.unregister()
|
||||||
|
|
@ -11,23 +11,25 @@ logging.basicConfig(level=logging.INFO)
|
|||||||
|
|
||||||
|
|
||||||
class RCFTranslation():
|
class RCFTranslation():
|
||||||
def get(self,data):
|
def get(self, data):
|
||||||
"""
|
"""
|
||||||
local program > rcf
|
local program > rcf
|
||||||
|
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def set(self,data):
|
def set(self, data):
|
||||||
"""
|
"""
|
||||||
rcf > local program
|
rcf > local program
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class RCFMsgFactory():
|
class RCFMsgFactory():
|
||||||
"""
|
"""
|
||||||
Abstract basic data bridge
|
Abstract basic data bridge
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
@ -39,7 +41,7 @@ class RCFMsgFactory():
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def unload(self,data):
|
def unload(self, data):
|
||||||
"""
|
"""
|
||||||
rcf > local program
|
rcf > local program
|
||||||
"""
|
"""
|
||||||
@ -66,6 +68,7 @@ class RCFMessage(object):
|
|||||||
self.mtype = mtype
|
self.mtype = mtype
|
||||||
self.body = body
|
self.body = body
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
||||||
self.factory = factory
|
self.factory = factory
|
||||||
|
|
||||||
def store(self, dikt):
|
def store(self, dikt):
|
||||||
@ -75,7 +78,6 @@ class RCFMessage(object):
|
|||||||
if self.key is not None and self.body is not None:
|
if self.key is not None and self.body is not None:
|
||||||
dikt[self.key] = self
|
dikt[self.key] = self
|
||||||
|
|
||||||
|
|
||||||
def send(self, socket):
|
def send(self, socket):
|
||||||
"""Send key-value message to socket; any empty frames are sent as such."""
|
"""Send key-value message to socket; any empty frames are sent as such."""
|
||||||
key = ''.encode() if self.key is None else self.key.encode()
|
key = ''.encode() if self.key is None else self.key.encode()
|
||||||
@ -115,10 +117,10 @@ class RCFMessage(object):
|
|||||||
|
|
||||||
|
|
||||||
class Client():
|
class Client():
|
||||||
def __init__(self, context=zmq.Context(), id="default", on_recv=None,on_post_init=None,is_admin=False):
|
def __init__(self, context=zmq.Context(), id="default", on_recv=None, on_post_init=None, is_admin=False):
|
||||||
self.is_admin = is_admin
|
self.is_admin = is_admin
|
||||||
|
|
||||||
#0MQ vars
|
# 0MQ vars
|
||||||
self.context = context
|
self.context = context
|
||||||
self.pull_sock = None
|
self.pull_sock = None
|
||||||
self.req_sock = None
|
self.req_sock = None
|
||||||
@ -161,7 +163,7 @@ class Client():
|
|||||||
self.poller = zmq.Poller()
|
self.poller = zmq.Poller()
|
||||||
self.poller.register(self.pull_sock, zmq.POLLIN)
|
self.poller.register(self.pull_sock, zmq.POLLIN)
|
||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(0.1)
|
||||||
|
|
||||||
async def main(self):
|
async def main(self):
|
||||||
logger.info("{} client syncing".format(id))
|
logger.info("{} client syncing".format(id))
|
||||||
@ -230,7 +232,6 @@ class Server():
|
|||||||
# Main client loop registration
|
# Main client loop registration
|
||||||
self.task = asyncio.ensure_future(self.main())
|
self.task = asyncio.ensure_future(self.main())
|
||||||
|
|
||||||
|
|
||||||
logger.info("{} client initialized".format(id))
|
logger.info("{} client initialized".format(id))
|
||||||
|
|
||||||
def bind_ports(self):
|
def bind_ports(self):
|
||||||
@ -276,13 +277,14 @@ class Server():
|
|||||||
logger.info("Bad snapshot request")
|
logger.info("Bad snapshot request")
|
||||||
break
|
break
|
||||||
|
|
||||||
for k,v in self.property_map.items():
|
for k, v in self.property_map.items():
|
||||||
logger.info("Sending {} snapshot to {}".format(k,identity))
|
logger.info(
|
||||||
self.request_sock.send(identity,zmq.SNDMORE)
|
"Sending {} snapshot to {}".format(k, identity))
|
||||||
|
self.request_sock.send(identity, zmq.SNDMORE)
|
||||||
v.send(self.request_sock)
|
v.send(self.request_sock)
|
||||||
|
|
||||||
msg_end_snapshot = RCFMessage(key="SNAPSHOT_END",id=identity)
|
msg_end_snapshot = RCFMessage(key="SNAPSHOT_END", id=identity)
|
||||||
self.request_sock.send(identity,zmq.SNDMORE)
|
self.request_sock.send(identity, zmq.SNDMORE)
|
||||||
msg_end_snapshot.send(self.request_sock)
|
msg_end_snapshot.send(self.request_sock)
|
||||||
logger.info("done")
|
logger.info("done")
|
||||||
elif self.collector_sock in socks:
|
elif self.collector_sock in socks:
|
||||||
|
@ -203,7 +203,7 @@ class session_join(bpy.types.Operator):
|
|||||||
|
|
||||||
client = net_components.Client(
|
client = net_components.Client(
|
||||||
id=username, on_recv=recv_callbacks, on_post_init=post_init_callbacks)
|
id=username, on_recv=recv_callbacks, on_post_init=post_init_callbacks)
|
||||||
time.sleep(1)
|
# time.sleep(1)
|
||||||
|
|
||||||
bpy.ops.asyncio.loop()
|
bpy.ops.asyncio.loop()
|
||||||
bpy.app.timers.register(observer)
|
bpy.app.timers.register(observer)
|
||||||
@ -347,7 +347,7 @@ def register():
|
|||||||
bpy.types.Scene.session_settings = bpy.props.PointerProperty(
|
bpy.types.Scene.session_settings = bpy.props.PointerProperty(
|
||||||
type=session_settings)
|
type=session_settings)
|
||||||
|
|
||||||
bpy.app.handlers.depsgraph_update_post.append(on_scene_evalutation)
|
# bpy.app.handlers.depsgraph_update_post.append(on_scene_evalutation)
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
@ -355,9 +355,11 @@ def unregister():
|
|||||||
for cls in reversed(classes):
|
for cls in reversed(classes):
|
||||||
unregister_class(cls)
|
unregister_class(cls)
|
||||||
|
|
||||||
|
# bpy.app.handlers.depsgraph_update_post.remove(on_scene_evalutation)
|
||||||
|
|
||||||
del bpy.types.Scene.session_settings
|
del bpy.types.Scene.session_settings
|
||||||
bpy.app.handlers.depsgraph_update_post.remove(on_scene_evalutation)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
register()
|
register()
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class SessionPanel(bpy.types.Panel):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(scene.session_settings,"username",text="")
|
row.prop(scene.session_settings,"username",text="username:")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.operator("session.join")
|
row.operator("session.join")
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
|
Reference in New Issue
Block a user