Skip to content

Commit

Permalink
Buffers now moved from protocol into buffer manager. Fix typos.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhananjaysathe committed May 16, 2013
1 parent 7059dea commit feca7d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
13 changes: 11 additions & 2 deletions rce-comm/rce/comm/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ def __init__(self, consumer, protocol):
self.consumer = consumer
self.protocol = protocol
self._paused = False
self._binary_buff = deque(maxlen=10)

def push_data(self, data):
""" Method to push data into the buffer manager from the protocol
@param data: Data to be sent and accompanying message
@type data: tuple - (uriBinary, msgURI)
"""
self._binary_buff.append(data)

def resumeProducing(self):
self._paused = False
while not self._paused:
try:
uriBinary, msgURI = self.protocol._binary_buff.popleft()
WebSocketServerProtocol.sendMessage(self, json.dumps(msgURI))
uriBinary, msgURI = self._binary_buff.popleft()
WebSocketProtocol.sendMessage(self, json.dumps(msgURI))
for data in uriBinary:
msg = data[0] + data[1].getvalue()
WebSocketProtocol.sendMessage(self.protocol, msg, binary=True)
Expand Down
4 changes: 1 addition & 3 deletions rce-comm/rce/comm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from urllib import urlencode
from urllib2 import urlopen, HTTPError
from hashlib import sha256
from collections import deque

# zope specific imports
from zope.interface import implements
Expand Down Expand Up @@ -73,7 +72,6 @@ def __init__(self, conn):
self._connection = conn
self._assembler = MessageAssembler(self, 60)
self._registered = False
self._binary_buff = deque(maxlen=10)

def connectionMade(self):
WebSocketClientProtocol.connectionMade(self)
Expand Down Expand Up @@ -111,7 +109,7 @@ def send(msg):
if not uriBinary :
WebSocketClientProtocol.sendMessage(self, json.dumps(msgURI))
else:
self._binary_buff.append((uriBinary, msgURI))
self._buffermanager.push_data((uriBinary, msgURI))


if isInIOThread():
Expand Down
5 changes: 1 addition & 4 deletions rce-comm/rce/comm/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

# Python specific imports
import json
from collections import deque


try:
from cStringIO import StringIO
Expand Down Expand Up @@ -196,7 +194,6 @@ def __init__(self, realm):
self._realm = realm
self._assembler = MessageAssembler(self, self.MSG_QUEUE_TIMEOUT)
self._avatar = None
self._binary_buff = deque(maxlen=10)

def connectionMade(self):
WebSocketServerProtocol.connectionMade(self)
Expand Down Expand Up @@ -449,7 +446,7 @@ def sendMessage(self, msg):
if not uriBinary :
WebSocketServerProtocol.sendMessage(self, json.dumps(msgURI))
else:
self._binary_buff.append((uriBinary, msgURI))
self._buffermanager.push_data((uriBinary, msgURI))

def sendDataMessage(self, iTag, clsName, msgID, msg):
""" Callback for Connection object to send a data message to the robot
Expand Down

0 comments on commit feca7d4

Please sign in to comment.