def _enable_dynamic(self, enable=True):
     if enable:
         obs = rtctree.sdo.RTCObserver(self)
         uuid_val = uuid.uuid4().get_bytes()
         intf_type = obs._this()._NP_RepositoryId
         props = utils.dict_to_nvlist(
             {"heartbeat.enable": "YES", "heartbeat.interval": "1.0", "observed_status": "ALL"}
         )
         sprof = SDOPackage.ServiceProfile(
             id=uuid_val, interface_type=intf_type, service=obs._this(), properties=props
         )
         conf = self.object.get_configuration()
         res = conf.add_service_profile(sprof)
         if res:
             self._dynamic = True
             self._obs = obs
             self._obs_id = uuid_val
             # If we could set an observer, the component is alive
             self._last_heartbeat = time.time()
     else:  # Disable
         conf = self.object.get_configuration()
         res = conf.remove_service_profile(self._obs_id)
         if res:
             self._dynamic = False
             self._obs = None
             self._obs_id = None
    def add_logger(self, cb, level="NORMAL", filters="ALL"):
        """Add a callback to receive log events from this component.

        @param cb The callback function to receive log events. It must have the
            signature cb(name, time, source, level, message), where name is the
            name of the component the log record came from, time is a
            floating-point time stamp, source is the name of the logger that
            provided the log record, level is the log level of the record and
            message is a text string.
        @param level The maximum level of log records to receive.
        @param filters Filter the objects from which to receive log messages.
        @return An ID for this logger. Use this ID in future operations such as
                removing this logger.
        @raises AddLoggerError

        """
        with self._mutex:
            obs = rtctree.sdo.RTCLogger(self, cb)
            uuid_val = uuid.uuid4()
            intf_type = obs._this()._NP_RepositoryId
            props = {"logger.log_level": level, "logger.filter": filters}
            props = utils.dict_to_nvlist(props)
            sprof = SDOPackage.ServiceProfile(
                id=uuid_val.get_bytes(), interface_type=intf_type, service=obs._this(), properties=props
            )
            conf = self.object.get_configuration()
            res = conf.add_service_profile(sprof)
            if res:
                self._loggers[uuid_val] = obs
                return uuid_val
            raise exceptions.AddLoggerError(self.name)
Beispiel #3
0
    def add_logger(self, cb, level='NORMAL', filters='ALL'):
        '''Add a callback to receive log events from this component.

        @param cb The callback function to receive log events. It must have the
            signature cb(name, time, source, level, message), where name is the
            name of the component the log record came from, time is a
            floating-point time stamp, source is the name of the logger that
            provided the log record, level is the log level of the record and
            message is a text string.
        @param level The maximum level of log records to receive.
        @param filters Filter the objects from which to receive log messages.
        @return An ID for this logger. Use this ID in future operations such as
                removing this logger.
        @raises AddLoggerError

        '''
        with self._mutex:
            obs = rtctree.sdo.RTCLogger(self, cb)
            uuid_val = uuid.uuid4()
            intf_type = obs._this()._NP_RepositoryId
            props = {'logger.log_level': level,
                    'logger.filter': filters}
            props = utils.dict_to_nvlist(props)
            sprof = SDOPackage.ServiceProfile(id=uuid_val.get_bytes(),
                    interface_type=intf_type, service=obs._this(),
                    properties=props)
            conf = self.object.get_configuration()
            res = conf.add_service_profile(sprof)
            if res:
                self._loggers[uuid_val] = obs
                return uuid_val
            raise exceptions.AddLoggerError(self.name)
Beispiel #4
0
 def _enable_dynamic(self, enable=True):
     if enable:
         obs = rtctree.sdo.RTCObserver(self)
         uuid_val = uuid.uuid4().get_bytes()
         intf_type = obs._this()._NP_RepositoryId
         props = utils.dict_to_nvlist({'heartbeat.enable': 'YES',
             'heartbeat.interval': '1.0',
             'observed_status': 'ALL'})
         sprof = SDOPackage.ServiceProfile(id=uuid_val,
                 interface_type=intf_type, service=obs._this(),
                 properties=props)
         conf = self.object.get_configuration()
         res = conf.add_service_profile(sprof)
         if res:
             self._dynamic = True
             self._obs = obs
             self._obs_id = uuid_val
             # If we could set an observer, the component is alive
             self._last_heartbeat = time.time()
     else: # Disable
         conf = self.object.get_configuration()
         res = conf.remove_service_profile(self._obs_id)
         if res:
             self._dynamic = False
             self._obs = None
             self._obs_id = None
Beispiel #5
0
    def connect(self, dests=[], name=None, id='', props={}):
        '''Connect this port to other ports.

        After the connection has been made, a delayed reparse of the
        connections for this and the destination port will be triggered.

        @param dests A list of the destination Port objects. Must be provided.
        @param name The name of the connection. If None, a suitable default
                    will be created based on the names of the two ports.
        @param id The ID of this connection. If None, one will be generated by
               the RTC implementation.
        @param props Properties of the connection. Required values depend on
                     the type of the two ports being connected.
        @raises IncompatibleDataPortConnectionPropsError, FailedToConnectError

        '''
        with self._mutex:
            if self.porttype == 'DataInPort' or self.porttype == 'DataOutPort':
                for prop in props:
                    if prop in self.properties:
                        if props[prop] not in [x.strip() for x in self.properties[prop].split(',')] and \
                                'any' not in self.properties[prop].lower():
                            # Invalid property selected
                            raise IncompatibleDataPortConnectionPropsError
                    for d in dests:
                        if prop in d.properties:
                            if props[prop] not in [x.strip() for x in d.properties[prop].split(',')] and \
                                    'any' not in d.properties[prop].lower():
                                # Invalid property selected
                                raise IncompatibleDataPortConnectionPropsError
            if not name:
                name = self.name + '_'.join([d.name for d in dests])
            props = dict_to_nvlist(props)
            profile = RTC.ConnectorProfile(name, id,
                    [self._obj] + [d._obj for d in dests], props)
            return_code, profile = self._obj.connect(profile)
            if return_code != RTC.RTC_OK:
                raise FailedToConnectError(return_code)
            self.reparse_connections()
            for d in dests:
                d.reparse_connections()
Beispiel #6
0
    def connect(self, dests=[], name=None, id='', props={}):
        '''Connect this port to other ports.

        After the connection has been made, a delayed reparse of the
        connections for this and the destination port will be triggered.

        @param dests A list of the destination Port objects. Must be provided.
        @param name The name of the connection. If None, a suitable default
                    will be created based on the names of the two ports.
        @param id The ID of this connection. If None, one will be generated by
               the RTC implementation.
        @param props Properties of the connection. Required values depend on
                     the type of the two ports being connected.
        @raises IncompatibleDataPortConnectionPropsError, FailedToConnectError

        '''
        with self._mutex:
            if self.porttype == 'DataInPort' or self.porttype == 'DataOutPort':
                for prop in props:
                    if prop in self.properties:
                        if props[prop] not in [x.strip() for x in self.properties[prop].split(',')] and \
                                'any' not in self.properties[prop].lower():
                            # Invalid property selected
                            raise exceptions.IncompatibleDataPortConnectionPropsError
                    for d in dests:
                        if prop in d.properties:
                            if props[prop] not in [x.strip() for x in d.properties[prop].split(',')] and \
                                    'any' not in d.properties[prop].lower():
                                # Invalid property selected
                                raise exceptions.IncompatibleDataPortConnectionPropsError
            if not name:
                name = self.name + '_'.join([d.name for d in dests])
            props = utils.dict_to_nvlist(props)
            profile = RTC.ConnectorProfile(name, id, [self._obj] +
                                           [d._obj for d in dests], props)
            return_code, profile = self._obj.connect(profile)
            if return_code != RTC.RTC_OK:
                raise exceptions.FailedToConnectError(return_code)
            self.reparse_connections()
            for d in dests:
                d.reparse_connections()
Beispiel #7
0
 def set_param(self, param, value):
     '''Set a parameter in this configuration set.'''
     self.data[param] = value
     self._object.configuration_data = utils.dict_to_nvlist(self.data)
Beispiel #8
0
 def set_param(self, param, value):
     '''Set a parameter in this configuration set.'''
     self.data[param] = value
     self._object.configuration_data = utils.dict_to_nvlist(self.data)