示例#1
0
    def open(self, *args):
        try:
            logging.debug("BulkIOWebsocketHandler open kind=%s, path=%s",
                          self.kind, args)
            obj, path = yield self.redhawk.get_object_by_path(
                args, path_type=self.kind)
            logging.debug("Found object %s", dir(obj))

            for p in obj.ports:
                if p.name == path[0]:
                    if p._direction == 'Uses':
                        data_type = p._using.name
                        namespace = p._using.nameSpace

                        if namespace == 'BULKIO':
                            self.port = obj.getPort(str(path[0]))
                            logging.debug("Found port %s", self.port)

                            self.converter = self.data_conversion_map[
                                data_type]

                            bulkio_poa = getattr(BULKIO__POA, data_type)
                            logging.debug(bulkio_poa)

                            self.async_port = AsyncPort(
                                bulkio_poa, self._pushSRI, self._pushPacket)
                            self._portname = 'myport%s' % id(self)
                            self.port.connectPort(self.async_port.getPort(),
                                                  self._portname)

                            break
                        else:
                            raise ValueError("Port '%s' is not a BULKIO port" %
                                             path[0])
                    else:
                        raise ValueError("Port '%s' is not a uses" % path[0])
            else:
                raise ValueError("Could not find port of name '%s'" % path[0])

        except ResourceNotFound, e:
            self.write_message(dict(error='ResourceNotFound', message=str(e)))
            self.close()