def logon(self, name): """Handles device logon.""" Controller.logon(self, name) self.connected.add(name) if name == cfg.CAMERA_NAME: self.set_frame_rate(self.throughput_constraint()) else: self.processors.add(name) return
def stringReceived(self, data): rpc = Rpc() rpc.ParseFromString(data) for serializedRequest in rpc.request: service = self._services[serializedRequest.method.split('.')[0]] if not service: self.sendError(serializedRequest.id, RpcErrors.SERVICE_NOT_FOUND) return method = service.GetDescriptor().FindMethodByName( serializedRequest.method.split('.')[1]) if not method: self.sendError(serializedRequest.id, RpcErrors.METHOD_NOT_FOUND) return request = service.GetRequestClass(method)() request.ParseFromString(serializedRequest.serialized_request) controller = Controller(peer=self.transport.getPeer()) d = Deferred() d.addCallback(self.serialize_response, serializedRequest, controller) d.addCallback(self.serialize_rpc) d.addCallback(lambda rpc: self.sendString(rpc.SerializeToString())) service.CallMethod(method, controller, request, d.callback) for serializedResponse in rpc.response: _id = serializedResponse.id if _id in self._pending: self._pending[_id].callback(serializedResponse)
def __init__(self): Controller.__init__(self) self.running = threading.Event() self.avg_fps = AvgItem(cfg.EWMA_ALPHA) self.avg_tput = AvgItem(cfg.EWMA_ALPHA) self.metrics = {} self.values = {} self.values[self.VAL_T_0] = cfg.T_o self.values[self.VAL_M_0] = cfg.M_o self.values[self.VAL_AVG_FPS] = 0.0 self.values[self.VAL_AVG_TPUT] = 0.0 self.values[self.VAL_PIPELINE] = 0 self.connected = set() self.values['connected'] = self.connected self.processors = set() self.constraint_lock = threading.Lock() return
class UdpChannel(BaseChannel, DatagramProtocol): def __init__(self, host=None, port=None): self._host = host self._port = port self.connected = False BaseChannel.__init__(self) def startProtocol(self): if self._host and self._port: self.transport.connect(self._host, self._port) self.connected = True def datagramReceived(self, data, (host, port)): rpc = Rpc() rpc.ParseFromString(data) for serializedRequest in rpc.request: service = self._services[serializedRequest.method.split('.')[0]] if not service: self.sendError(serializedRequest.id, RpcErrors.SERVICE_NOT_FOUND, host, port) return method = service.GetDescriptor().FindMethodByName( serializedRequest.method.split('.')[1]) if not method: self.sendError(serializedRequest.id, RpcErrors.METHOD_NOT_FOUND, host, port) return request = service.GetRequestClass(method)() request.ParseFromString(serializedRequest.serialized_request) controller = Controller() d = Deferred() d.addCallback(self.serialize_response, serializedRequest) d.addCallback(self.serialize_rpc) d.addCallback(lambda rpc: self.send_string(rpc.SerializeToString(), host, port)) service.CallMethod(method, controller, request, d.callback) for serializedResponse in rpc.response: id = serializedResponse.id if self._pending.has_key(id): self._pending[id].callback(serializedResponse)
def __init__(self, model, view): Controller.__init__(self, model, view)
def call(method, request): d = Deferred() controller = Controller() method(controller, request, d) return d
def start(self): """Starts controller thread.""" self.running.set() Controller.start(self) return
def logoff(self, name): """Handles device logoff.""" Controller.logoff(self, name) self.processors.discard(name) self.connected.discard(name) return