示例#1
0
    def ConfigureDevice(self, device_alias, request_data, callback):
        """Send a device config request.

    Args:
      device_alias: the alias of the device to configure
      request_data: the request to send to the device
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a response.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.DeviceConfigRequest()
        request.device_alias = device_alias
        request.data = request_data
        done = lambda x, y: self._ConfigureDeviceComplete(callback, x, y)
        try:
            self._stub.ConfigureDevice(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#2
0
    def RegisterUniverse(self, universe, action, data_callback, callback=None):
        """Register to receive dmx updates for a universe.

    Args:
      universe: the universe to register to
      action: OlaClient.REGISTER or OlaClient.UNREGISTER
      data_callback: the function to be called when there is new data, passed
        a single argument of type array.
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.RegisterDmxRequest()
        request.universe = universe
        request.action = action
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        try:
            self._stub.RegisterForDmx(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        if action == self.PATCH:
            self._universe_callbacks[universe] = data_callback
        elif universe in self._universe_callbacks:
            del self._universe_callbacks[universe]
        return True
示例#3
0
    def _HandleRequest(self, message):
        """Handle a Request message.

    Args:
      message: The RpcMessage object.
    """
        if not self._service:
            logging.warning('No service registered')
            return

        descriptor = self._service.GetDescriptor()
        method = descriptor.FindMethodByName(message.name)
        if not method:
            logging.warning('Failed to get method descriptor for %s',
                            message.name)
            self._SendNotImplemented(message.id)
            return

        request_pb = self._service.GetRequestClass(method)()
        request_pb.ParseFromString(message.buffer)
        controller = SimpleRpcController()
        request = OutstandingRequest(message.id, controller)

        if message.id in self._outstanding_requests:
            logging.warning('Duplicate request for %d', message.id)
            self._SendRequestFailed(message.id)

        self._outstanding_requests[message.id] = request
        callback = lambda x: self.RequestComplete(request, x)
        self._service.CallMethod(method, request.controller, request_pb,
                                 callback)
示例#4
0
    def RunRDMDiscovery(self, universe, full, callback):
        """Triggers RDM discovery for a universe.

    Args:
      universe: The universe to run discovery for.
      full: true to use full discovery, false for incremental (if supported)
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.DiscoveryRequest()
        request.universe = universe
        request.full = full
        done = lambda x, y: self._FetchUIDsComplete(callback, x, y)
        try:
            self._stub.ForceDiscovery(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#5
0
    def SendDmx(self, universe, data, callback=None):
        """Send DMX data to the server

    Args:
      universe: the universe to send the data for
      data: An array object with the DMX data
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.DmxData()
        request.universe = universe
        request.data = data.tostring()
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        try:
            self._stub.UpdateDmxData(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#6
0
 def _RDMMessage(self,
                 universe,
                 uid,
                 sub_device,
                 param_id,
                 callback,
                 data,
                 include_frames,
                 set=False):
     controller = SimpleRpcController()
     request = Ola_pb2.RDMRequest()
     request.universe = universe
     request.uid.esta_id = uid.manufacturer_id
     request.uid.device_id = uid.device_id
     request.sub_device = sub_device
     request.param_id = param_id
     request.data = data
     request.is_set = set
     request.include_raw_response = include_frames
     done = lambda x, y: self._RDMCommandComplete(callback, x, y)
     try:
         self._stub.RDMCommand(controller, request, done)
     except socket.error:
         raise OLADNotRunningException()
     return True
示例#7
0
    def SetUniverseMergeMode(self, universe, merge_mode, callback=None):
        """Set the merge mode of a universe.

    Args:
      universe: the universe to set the merge mode of
      merge_mode: either Universe.HTP or Universe.LTP
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.MergeModeRequest()
        request.universe = universe
        request.merge_mode = merge_mode
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        try:
            self._stub.SetMergeMode(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#8
0
  def PatchPort(self, device_alias, port, is_output, action, universe,
                callback=None):
    """Patch a port to a universe.

    Args:
      device_alias: the alias of the device of which to patch a port
      port: the id of the port
      is_output: select the input or output port
      action: OlaClient.PATCH or OlaClient.UNPATCH
      universe: the universe to set the name of
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
    if self._socket is None:
      return False

    controller = SimpleRpcController()
    request = Ola_pb2.PatchPortRequest()
    request.device_alias = device_alias
    request.port_id = port
    request.action = action
    request.is_output = is_output
    request.universe = universe
    try:
      self._stub.PatchPort(
          controller, request,
          lambda x, y: self._AckMessageComplete(callback, x, y))
    except socket.error:
      raise OLADNotRunningException()
    return True
示例#9
0
    def SetUniverseName(self, universe, name, callback=None):
        """Set the name of a universe.

    Args:
      universe: the universe to set the name of
      name: the new name for the universe
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.UniverseNameRequest()
        request.universe = universe
        request.name = name
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        try:
            self._stub.SetUniverseName(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#10
0
    def GetCandidatePorts(self, callback, universe=None):
        """Send a GetCandidatePorts request. The result is similar to FetchDevices
    (GetDeviceInfo), except that returned devices will only contain ports
    available for patching to the given universe. If universe is None, then the
    devices will list their ports available for patching to a potential new
    universe.

    Args:
      callback: The function to call once complete, takes a RequestStatus
        object and a list of Device objects.
      universe: The universe to get the candidate ports for. If unspecified,
        return the candidate ports for a new universe.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.OptionalUniverseRequest()

        if universe is not None:
            request.universe = universe

        # GetCandidatePorts works very much like GetDeviceInfo, so we can re-use
        # its complete method.
        done = lambda x, y: self._DeviceInfoComplete(callback, x, y)
        try:
            self._stub.GetCandidatePorts(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()

        return True
示例#11
0
    def FetchUniverses(self, callback):
        """Fetch a list of universes from the server

    Args:
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a list of Universe objects.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.UniverseInfoRequest()
        done = lambda x, y: self._UniverseInfoComplete(callback, x, y)
        self._stub.GetUniverseInfo(controller, request, done)
示例#12
0
    def FetchDmx(self, universe, callback):
        """Fetch a list of universes from the server

    Args:
      universe: the universe to fetch the data for
      callback: The function to call once complete, takes three arguments, a
        RequestStatus object, a universe number and a list of dmx data.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.UniverseInfoRequest()
        request.universe = universe
        done = lambda x, y: self._GetDmxComplete(callback, x, y)
        self._stub.GetDmx(controller, request, done)
示例#13
0
    def FetchDevices(self, callback, plugin_filter=Plugin.OLA_PLUGIN_ALL):
        """Fetch a list of devices from the server.

    Args:
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a list of Device objects.
      filter: a plugin id to filter by
    """
        controller = SimpleRpcController()
        request = Ola_pb2.DeviceInfoRequest()
        request.plugin_id = plugin_filter
        done = lambda x, y: self._DeviceInfoComplete(callback, x, y)
        self._stub.GetDeviceInfo(controller, request, done)
示例#14
0
    def ConfigureDevice(self, device_alias, request_data, callback):
        """Send a device config request.

    Args:
      device_alias: the alias of the device to configure
      request_data: the request to send to the device
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a response.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.DeviceConfigRequest()
        request.device_alias = device_alias
        request.data = request_data
        done = lambda x, y: self._ConfigureDeviceComplete(callback, x, y)
        self._stub.ConfigureDevice(controller, request, done)
示例#15
0
    def SetUniverseMergeMode(self, universe, merge_mode, callback=None):
        """Set the merge_mode of a universe.

    Args:
      universe: the universe to set the name of
      merge_mode: either Universe.HTP or Universe.LTP
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.MergeModeRequest()
        request.universe = universe
        request.merge_mode = merge_mode
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        self._stub.SetMergeMode(controller, request, done)
示例#16
0
    def SetUniverseName(self, universe, name, callback=None):
        """Set the name of a universe.

    Args:
      universe: the universe to set the name of
      name: the new name for the universe
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.UniverseNameRequest()
        request.universe = universe
        request.name = name
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        self._stub.SetUniverseName(controller, request, done)
示例#17
0
    def SendDmx(self, universe, data, callback=None):
        """Send DMX data to the server

    Args:
      universe: the universe to fetch the data for
      data: An array object with the DMX data
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.DmxData()
        request.universe = universe
        request.data = data.tostring()
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        self._stub.UpdateDmxData(controller, request, done)
示例#18
0
    def FetchPlugins(self,
                     callback,
                     plugin_filter=Plugin.OLA_PLUGIN_ALL,
                     include_description=False):
        """Fetch the list of plugins.

    Args:
      callback: the function to call once complete, takes two arguments, a
        RequestStatus object and a list of Plugin objects
      filter: the id of the plugin if you want to filter the results
      include_description: whether to include the plugin description or not
    """
        controller = SimpleRpcController()
        request = Ola_pb2.PluginInfoRequest()
        request.plugin_id = plugin_filter
        request.include_description = include_description
        done = lambda x, y: self._PluginInfoComplete(callback, x, y)
        self._stub.GetPluginInfo(controller, request, done)
示例#19
0
    def PatchPort(self, device_alias, port, action, universe, callback=None):
        """Patch a port to a universe.

    Args:
      device_alias: the alias of the device to configure
      port: the id of the port
      action: OlaClient.PATCH or OlcClient.UNPATCH
      universe: the universe to set the name of
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.PatchPortRequest()
        request.device_alias = device_alias
        request.port_id = port
        request.action = action
        request.universe = universe
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        self._stub.PatchPort(controller, request, done)
示例#20
0
    def SendRawRDMDiscovery(self,
                            universe,
                            uid,
                            sub_device,
                            param_id,
                            callback,
                            data='',
                            include_frames=False):
        """Send an RDM Discovery command. Unless you're writing RDM tests you
      shouldn't need to use this.

    Args:
      universe: The universe to get the UID list for.
      uid: A UID object
      sub_device: The sub device index
      param_id: the param ID
      callback: The function to call once complete, takes a RDMResponse object
      data: the data to send
      include_frames: True if the response should include the raw frame data.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.RDMDiscoveryRequest()
        request.universe = universe
        request.uid.esta_id = uid.manufacturer_id
        request.uid.device_id = uid.device_id
        request.sub_device = sub_device
        request.param_id = param_id
        request.data = data
        request.include_raw_response = True
        request.include_raw_response = include_frames
        try:
            self._stub.RDMDiscoveryCommand(
                controller, request,
                lambda x, y: self._RDMCommandComplete(callback, x, y))
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#21
0
    def RegisterUniverse(self, universe, action, data_callback, callback=None):
        """Register to receive dmx updates for a universe.

    Args:
      universe: the universe to set the name of
      action: OlaClient.REGISTER or OlaClient.UNREGISTER
      data_callback: the function to be called when there is new data, passed
        a single argument of type array.
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.
    """
        controller = SimpleRpcController()
        request = Ola_pb2.RegisterDmxRequest()
        request.universe = universe
        request.action = action
        done = lambda x, y: self._AckMessageComplete(callback, x, y)
        self._stub.RegisterForDmx(controller, request, done)
        if action == self.PATCH:
            self._universe_callbacks[universe] = data_callback
        elif universe in self._universe_callbacks:
            del self._universe_callbacks[universe]
示例#22
0
    def FetchUniverses(self, callback):
        """Fetch a list of universes from the server

    Args:
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a list of Universe objects.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.OptionalUniverseRequest()
        done = lambda x, y: self._UniverseInfoComplete(callback, x, y)
        try:
            self._stub.GetUniverseInfo(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#23
0
    def FetchPlugins(self, callback):
        """Fetch the list of plugins.

    Args:
      callback: the function to call once complete, takes two arguments, a
        RequestStatus object and a list of Plugin objects

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.PluginListRequest()
        done = lambda x, y: self._GetPluginsComplete(callback, x, y)
        try:
            self._stub.GetPlugins(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#24
0
    def SendTimeCode(self,
                     time_code_type,
                     hours,
                     minutes,
                     seconds,
                     frames,
                     callback=None):
        """Send Time Code Data.

    Args:
      time_code_type: One of OlaClient.TIMECODE_FILM, OlaClient.TIMECODE_EBU,
        OlaClient.TIMECODE_DF or OlaClient.TIMECODE_SMPTE
      hours: the hours
      minutes: the minutes
      seconds: the seconds
      frames: the frame count
      callback: The function to call once complete, takes one argument, a
        RequestStatus object.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.TimeCode()
        request.type = time_code_type
        request.hours = hours
        request.minutes = minutes
        request.seconds = seconds
        request.frames = frames
        try:
            self._stub.SendTimeCode(
                controller, request,
                lambda x, y: self._AckMessageComplete(callback, x, y))
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#25
0
    def FetchUIDList(self, universe, callback):
        """Used to get a list of UIDs for a particular universe.

    Args:
      universe: The universe to get the UID list for.
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a iterable of UIDs.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.UniverseRequest()
        request.universe = universe
        done = lambda x, y: self._FetchUIDsComplete(callback, x, y)
        try:
            self._stub.GetUIDs(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#26
0
    def FetchDmx(self, universe, callback):
        """Fetch DMX data from the server

    Args:
      universe: the universe to fetch the data for
      callback: The function to call once complete, takes three arguments, a
        RequestStatus object, a universe number and a list of dmx data.

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.UniverseRequest()
        request.universe = universe
        done = lambda x, y: self._GetDmxComplete(callback, x, y)
        try:
            self._stub.GetDmx(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#27
0
    def FetchDevices(self, callback, plugin_filter=Plugin.OLA_PLUGIN_ALL):
        """Fetch a list of devices from the server.

    Args:
      callback: The function to call once complete, takes two arguments, a
        RequestStatus object and a list of Device objects.
      filter: a plugin id to filter by

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.DeviceInfoRequest()
        request.plugin_id = plugin_filter
        done = lambda x, y: self._DeviceInfoComplete(callback, x, y)
        try:
            self._stub.GetDeviceInfo(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True
示例#28
0
    def PluginDescription(self, callback, plugin_id):
        """Fetch the description of a plugin.

    Args:
      callback: the function to call once complete, takes two arguments, a
        RequestStatus object and the plugin description text.
      plugin_id: the id of the plugin

    Returns:
      True if the request was sent, False otherwise.
    """
        if self._socket is None:
            return False

        controller = SimpleRpcController()
        request = Ola_pb2.PluginDescriptionRequest()
        request.plugin_id = plugin_id
        done = lambda x, y: self._PluginDescriptionComplete(callback, x, y)
        try:
            self._stub.GetPluginDescription(controller, request, done)
        except socket.error:
            raise OLADNotRunningException()
        return True