Use message factory for slam streamer
This commit is contained in:
@@ -1,25 +1,7 @@
|
||||
import zmq
|
||||
|
||||
|
||||
class MessageFactory():
|
||||
|
||||
def getZmqPubSubStreamer(self, topic):
|
||||
'''
|
||||
Not thread-safe. Always get this inside the thread/process where you intend
|
||||
to use it.
|
||||
'''
|
||||
return ZmqPubSubStreamer(topic)
|
||||
|
||||
|
||||
class Streamer():
|
||||
def send_message(self, message_bytes):
|
||||
raise NotImplementedError
|
||||
|
||||
def send_message_topic(self, topic, message_bytes):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class ZmqPubSubStreamer(Streamer):
|
||||
class ZmqPubSubStreamer:
|
||||
'''
|
||||
Not thread-safe. Always get this inside the thread/process where you intend
|
||||
to use it.
|
||||
@@ -29,7 +11,9 @@ class ZmqPubSubStreamer(Streamer):
|
||||
# Should create the socket here always, since zmq is not thread safe.
|
||||
# Hopefully whoever uses this is not stupid enough to create it then
|
||||
# pass it into a thread.
|
||||
pass
|
||||
self._socket = zmq.Context.instance().socket(zmq.PUB)
|
||||
print('Starting socket with address: ' + 'tcp://*:' + str(port))
|
||||
self._socket.bind("tcp://*:" + str(port))
|
||||
|
||||
def send_message(self, message):
|
||||
'''
|
||||
@@ -37,15 +21,23 @@ class ZmqPubSubStreamer(Streamer):
|
||||
----
|
||||
message: A message type that has the serialise() method.
|
||||
'''
|
||||
pass
|
||||
self.send_message_topic("", message)
|
||||
|
||||
def send_message_topic(self, topic, message):
|
||||
pass
|
||||
self._socket.send_multipart([bytes(topic), message.serialise()])
|
||||
|
||||
|
||||
class BluetoothStreamer(Streamer):
|
||||
class BluetoothStreamer:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def send_message(self, message_bytes):
|
||||
pass
|
||||
|
||||
|
||||
def getZmqPubSubStreamer(port):
|
||||
'''
|
||||
Not thread-safe. Always get this inside the thread/process where you intend
|
||||
to use it.
|
||||
'''
|
||||
return ZmqPubSubStreamer(port)
|
||||
|
||||
@@ -23,8 +23,8 @@ class PackMessage(Message):
|
||||
|
||||
class ProtoMessage(Message):
|
||||
|
||||
def __init__(self, proto_type, message=None):
|
||||
Message(message)
|
||||
def __init__(self, proto_type=None, message=None):
|
||||
super().__init__(message)
|
||||
self._type = proto_type
|
||||
|
||||
def serialise(self):
|
||||
|
||||
Reference in New Issue
Block a user