def Parse(cls, s): r = Response.Parse(s) if not (r and r.name == 'read_var'): return r var = SharedVar(r) m = SharedVar._rx.match(var.params) if not m: print 'read_var received but failed to parse:' print var.params return None var.svType = m.group('type') + ('[]' if m.group('array') else '') var.size = -1 if not m.group('size') else int(m.group('size')) var.varName = m.group('name') var.data = m.group('data') var.report = m.group('report') var.subscription = m.group('subscription') var.writer = m.group('writer') var.isNotification = not not var.report var.data = SharedVar._ProcessReadVar(var) return var
def _parsingThread(self): while True: data = BB._incomingMessages.get() el = SharedVar.Parse(data) if el and el.isNotification: handler = None BB._subscriptionHandlersLock.acquire() if el.varName in BB._subscriptionHandlers: handler = BB._subscriptionHandlers[el.varName] BB._subscriptionHandlersLock.release() if not handler: print 'ERROR: No handler for shared variable: ' + el.varName continue try: handler(el) except: print 'Handler for shared var: "' + el.varName + '" crashed.' continue if not el: el = Response.Parse(data) if el: print "Something that wasn't supposed to happen happened" if el: BB._commandsLock.acquire() if el in BB._sentCommands: BB._responsesLock.acquire() BB._receivedResponses[el] = el BB._responsesLock.release() elif self._asyncHandler: self._asyncHandler(el) else: print 'Response without awaiting command: ' + repr(el) BB._commandsLock.release() continue el = Command.Parse(data) if el: BB._receivedCommands.put(el) continue print 'Invalid message received: ' + data + '_len(' + str( len(data)) + ')'