Esempio n. 1
0
 def _run(self):
     while not self._terminateMe:
         while not self.actionQueue.empty():
             action, payload = self.actionQueue.get()
             if action == 'destroy':
                 self.consumer_lock.acquire()
                 for consumer in self.consumers:
                     if consumer == payload:
                         consumer = self.consumers.pop(consumer)
                         consumer.existence_lock.acquire()
                         consumer.existence_lock.release()
                         del consumer
                         break
                 self.consumer_lock.release()
             elif action == 'message':
                 values = payload.value(CF._tc_Properties)
                 if values is None:
                     print 'WARNING: Unrecognized message type', payload.typecode()
                 for value in values:
                     id = value.id
                     if id in self._messages:
                         msgstruct, callback = self._messages[id]
                         value = struct_from_any(value.value, msgstruct, strictComplete=False)
                         try:
                             callback(id, value)
                         except Exception, e:
                             print "Callback for message "+str(id)+" failed with exception: "+str(e)
                     for allMsg in self._allMsg:
                         if self._storeMessages:
                             self._storedMessages.append(prop_to_dict(value))
                         callback = allMsg[1]
                         try:
                             callback(id, value)
                         except Exception, e:
                             print "Callback for message "+str(id)+" failed with exception: "+str(e)
Esempio n. 2
0
    def msgCallback(self, id, msg):
        """The callback method for the message sink

        This instance of the message callback adds the received timestamp
        into the message structure.

        Parameters
        ----------
        id : str
            The message id

        msg : Message
            The received Message structure
        """
        # convert the corba object into a Python dictionary
        prop = properties.prop_to_dict(msg)

        # ---------  update message to store the current timestamp  ---------
        c_now = bulkio.timestamp.now()

        prop[id]["%s::%s_twsec" % (id, self.name)] = c_now.twsec
        prop[id]["%s::%s_tfsec" % (id, self.name)] = c_now.tfsec

        # -------------------------  store in queue  ------------------------
        self._msg_queue.append(prop)
        self._num_messages += 1
Esempio n. 3
0
    def propertyChange(self, _propChEv):
        if type(self._changeCallbacks) != dict:
            print 'Invalid change callbacks (must be dictionary with property id as a key and a callback function as a value). Printing received event', _propChEv

        _tmp_props = _propChEv.properties
        _triggers = {}

        for _prop_key in self._changeCallbacks:
            for _prop_idx in range(len(_tmp_props)):
                if _tmp_props[_prop_idx].id == _prop_key:
                    if not _triggers.has_key(self._changeCallbacks[_prop_key]):
                        _triggers[self._changeCallbacks[_prop_key]] = {}
                    _triggers[self._changeCallbacks[_prop_key]].update(
                        properties.prop_to_dict(_tmp_props[_prop_idx]))
                    _tmp_props.pop(_prop_idx)
                    break

        if len(_triggers) != 0:
            for _trigger in _triggers:
                _trigger(_propChEv.evt_id, _propChEv.reg_id,
                         _propChEv.resource_id, _triggers[_trigger],
                         _propChEv.timestamp)

        if len(_tmp_props) != 0:
            if self._defaultCallback:
                self._defaultCallback(_propChEv.evt_id, _propChEv.reg_id,
                                      _propChEv.resource_id,
                                      properties.props_to_dict(_tmp_props),
                                      _propChEv.timestamp)
                return
            print 'Property Change Event:'
            print ' event id:', _propChEv.evt_id
            print ' registration id:', _propChEv.reg_id
            print ' resource id:', _propChEv.resource_id
            print ' properties:', properties.props_to_dict(_tmp_props)
            print ' timestamp:', _propChEv.timestamp
 def testStructSeqs(self):
     #######################################################################
     # Launch the component with the default execparams
     execparams = self.getPropertySet(kinds=("execparam",), modes=("readwrite", "writeonly"), includeNil=False)
     execparams = dict([(x.id, any.from_any(x.value)) for x in execparams])
     self.launch(execparams)
     
     #######################################################################
     # Simulate regular component startup
     # Verify that initialize nor configure throw errors
     self.comp_obj.initialize()
     
     consumerPort = MessageConsumerPort()
     self.eventPort = self.comp_obj.getPort('propEvent')
     self.eventPort.connectPort(consumerPort._this(), 'some_id')
     
     #test that an event is created for the first configure
     propID = 'eventStructSeq'
     val = 5
     flag = True
     phrase = 'hello'
     seq = ossie.cf.CF.DataType(id=propID, value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), 
                             [CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), 
                                [ossie.cf.CF.DataType(id='ss_stringSimple', value=CORBA.Any(CORBA.TC_string, phrase)), 
                                 ossie.cf.CF.DataType(id='ss_boolSimple', value=CORBA.Any(CORBA.TC_boolean, flag)),
                                 ossie.cf.CF.DataType(id='ss_shortSimple', value=CORBA.Any(CORBA.TC_short, val)),
                                 ossie.cf.CF.DataType(id='ss_floatSimple', value=CORBA.Any(CORBA.TC_float, val))])]))
     self.comp_obj.configure([seq])
     event = consumerPort.getEvent()
     if not event:
         self.fail("No event was generated for " + str(propID) + " for value " + str(seq))
     
     #test that an event is not created if the value is not changed
     self.comp_obj.configure([seq])
     event = consumerPort.getEvent()
     if event:
         self.fail("An event was generated for " + str(propID) + " when the value was not changed")
     
     #test that an event is created when the value is changed
     val = 6
     flag = False
     phrase = 'goodbye'
     seq = ossie.cf.CF.DataType(id=propID, value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), 
                             [CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), 
                                [ossie.cf.CF.DataType(id='ss_stringSimple', value=CORBA.Any(CORBA.TC_string, phrase)), 
                                 ossie.cf.CF.DataType(id='ss_boolSimple', value=CORBA.Any(CORBA.TC_boolean, flag)),
                                 ossie.cf.CF.DataType(id='ss_shortSimple', value=CORBA.Any(CORBA.TC_short, val)),
                                 ossie.cf.CF.DataType(id='ss_floatSimple', value=CORBA.Any(CORBA.TC_float, val))])]))
     self.comp_obj.configure([seq])
     event = consumerPort.getEvent()
     if not event:
         self.fail("No event was generated for " + str(propID) + " for value " + str(seq))
     
     #test that the configure worked properly
     ret = self.comp_obj.query([ossie.cf.CF.DataType(id='eventStructSeq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), []))])[0]
     propDict = properties.prop_to_dict(ret)[propID][0]
     self.assertEquals(propDict['ss_shortSimple'], val, 
                       msg='configure failed for ' + str(propID) + ', ' + str(propDict['ss_shortSimple']) + ' != ' + str(val))
     self.assertEquals(propDict['ss_floatSimple'], val, 
                       msg='configure failed for ' + str(propID) + ', ' + str(propDict['ss_floatSimple']) + ' != ' + str(val))
     self.assertEquals(propDict['ss_stringSimple'], phrase, 
                       msg='configure failed for ' + str(propID) + ', ' + str(propDict['ss_stringSimple']) + ' != ' + str(phrase))
     self.assertEquals(propDict['ss_boolSimple'], flag, 
                       msg='configure failed for ' + str(propID) + ', ' + str(propDict['ss_boolSimple']) + ' != ' + str(flag))