def register(self, socket, *args, **kwargs): # type: (SocketWrapper, Tuple[Any, ...], Dict[str, Any]) -> None """Registers a SocketWrapper object. Every SocketWrapper describes to a python-can bus object. This python-can bus object can only exist once. In case this object already exists in this SocketsPool, organized by a SocketMapper object, the new SocketWrapper is inserted in the list of subscribers of the SocketMapper. Otherwise a new python-can Bus object is created from the provided args and kwargs and inserted, encapsulated in a SocketMapper, into this SocketsPool. :param socket: SocketWrapper object which needs to be registered. :param args: Arguments for the python-can Bus object :param kwargs: Keyword arguments for the python-can Bus object """ k = str(kwargs.get("bustype", "unknown_bustype")) + "_" + \ str(kwargs.get("channel", "unknown_channel")) with self.pool_mutex: if k in self.pool: t = self.pool[k] t.sockets.append(socket) filters = [s.filters for s in t.sockets if s.filters is not None] if filters: t.bus.set_filters(reduce(add, filters)) socket.name = k else: bus = can_Bus(*args, **kwargs) socket.name = k self.pool[k] = SocketMapper(bus, [socket])
def register(self, socket, *args, **kwargs): k = str( str(kwargs.get("bustype", "unknown_bustype")) + "_" + str(kwargs.get("channel", "unknown_channel"))) with self.pool_mutex: if k in self.pool: t = self.pool[k] t.sockets.append(socket) filters = [ s.filters for s in t.sockets if s.filters is not None ] if filters: t.bus.set_filters(reduce(add, filters)) socket.name = k else: bus = can_Bus(*args, **kwargs) socket.name = k self.pool[k] = SocketMapper(bus, [socket])