def create(stream_id, frontend_status, identifier = 'my_id', collector_frequency = -1.0 ): _sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.0, xunits=BULKIO.UNITS_TIME, subsize=0, ystart=0.0, ydelta=0.0, yunits=BULKIO.UNITS_NONE, mode=0, streamID=stream_id, blocking=False, keywords=[]) if frontend_status.sample_rate <= 0.0: _sri.xdelta = 1.0 else: _sri.xdelta = 1/frontend_status.sample_rate if collector_frequency < 0: colFreq = frontend_status.center_frequency else: colFreq = float(collector_frequency) _col_rf = CF.DataType(id='COL_RF', value=_any.to_any(colFreq)) _col_rf.value._t = CORBA.TC_double _sri.keywords.append(_col_rf) _chan_rf = CF.DataType(id='CHAN_RF', value=_any.to_any(frontend_status.center_frequency)) _chan_rf.value._t = CORBA.TC_double _sri.keywords.append(_chan_rf) _rf_flow_id = CF.DataType(id='FRONTEND::RF_FLOW_ID', value=_any.to_any(frontend_status.rf_flow_id)) _sri.keywords.append(_rf_flow_id) _bw_rf = CF.DataType(id='FRONTEND::BANDWIDTH', value=_any.to_any(frontend_status.bandwidth)) _bw_rf.value._t = CORBA.TC_double _sri.keywords.append(_bw_rf) _dev_id = CF.DataType(id='FRONTEND::DEVICE_ID', value=_any.to_any(identifier)) _sri.keywords.append(_dev_id) return _sri
def getProp(self): content = [] for member in self.getMembers(): content.append( CF.DataType(id=member[0], value=_any.to_any(member[1]))) retval = CF.DataType(id=self.getId(), value=_any.to_any(content)) return retval
def convert(timeString): if timeString == 'now': return now() _sets = timeString.split(':') if len(_sets) != 7: return CF.UTCTime(0, 0, 0) _year, _month, _day, _blank, _hours, _minutes, _seconds = timeString.split( ':') _full_seconds = float(_seconds) _time = time.mktime( (int(_year), int(_month), int(_day), int(_hours), int(_minutes), int(_full_seconds), 0, 0, 0)) - time.timezone return CF.UTCTime(1, _time, _full_seconds - int(_full_seconds))
def test_runtime(self): comp = sb.launch('cpp_dev') teststring = CF.DataType(id='teststring', value=_any.to_any('foo')) comp.configure([teststring]) teststring = CF.DataType(id='teststring', value=_any.to_any(None)) retval = comp.query([teststring]) self.assertEquals(retval[0].value._v, 'foo') comp.teststring = 'hello' retval = comp.query([teststring]) self.assertEquals(retval[0].value._v, 'hello') snk = sb.DataSink() comp.connect(snk) sb.start() self.assertTrue(comp._get_started()) time.sleep(2) self.assertTrue(len(snk.getData()) > 10000)
def registerComponent(self, registeringComponent): with self._lock: _id = registeringComponent.identifier if _id in self._context: raise CF.RegisterError() self._context[_id] = registeringComponent.componentObject._narrow(CF.ResourceComponent) resource = registeringComponent.componentObject._narrow(CF.ResourceComponent)
def now(): """ Generates a CF.UTCTime object using the current CPU time that you can use in the pushPacket call """ ts = time.time() return CF.UTCTime(1, int(ts), ts - int(ts))
def executeLinked(self, entryPoint, options, parameters, deps): log.debug( 'Executing shared library %s %s', entryPoint, ' '.join('%s=%s' % (k, v) for k, v in parameters.iteritems())) params = [ CF.DataType(k, to_any(str(v))) for k, v in parameters.iteritems() ] self.ref.executeLinked(entryPoint, options, params, deps)
def runConfigurationTest(self, spd_file, prf_file): """ Tests all the properties defined in the PRF file and attempts to configure each property. If the property is of kind 'configure' and the mode is not readonly, then it compares the results with what is expected. Otherwise it expects an exception to be thrown Inputs: <spd_file> The component's SPD file <prf_file> The component's properties file """ self.launch() prf = PRFParser.parse(prf_file) props = prf.get_simple() int_off = 1 frac_off = 1.0 # iterating through all the properties for prop in props: id_ = prop.get_id() mode_ = prop.get_mode() val_ = prop.get_value() type_ = prop.get_type() kinds = prop.get_kind() is_configurable = False # check each kind to see if at least one of them is configure for kind in kinds: kind_type = kind.get_kindtype() if kind_type == 'configure': is_configurable = True break # generate some bogus value if type_ == 'double' or type_ == 'float': new_val = frac_off + float(val_) elif type_ == 'integer' or type_ == 'long': new_val = int_off + int(val_) else: new_val = '%s_%d' % (val_, int_off) conf_prop = CF.DataType(id=str(id_), value=any.to_any(new_val)) # if it can be configured, test that is the case if is_configurable and mode_ != 'readonly': self.comp_obj.configure([conf_prop]) q_value = self.comp_obj.query([conf_prop]) self.assertEqual(len(q_value), 1) self.assertEqual(conf_prop.id, q_value[0].id) self.assertEqual(conf_prop.value._v, q_value[0].value._v) # this property should be be configurable else: try: self.comp_obj.configure([conf_prop]) self.assertFalse() except: # Got an expected error, so we should continue continue
def createProps(prop_dict, prf=None): props = [] for _key in prop_dict: if isinstance(prop_dict[_key], dict): vals = [] for _subkey in prop_dict[_key]: vals.append( CF.DataType(id=_subkey, value=any.to_any(prop_dict[_key][_subkey]))) props.append(CF.DataType(id=_key, value=any.to_any(vals))) elif isinstance(prop_dict[_key], list): if len(prop_dict[_key]) == 0: props.append( CF.DataType(id=_key, value=any.to_any(prop_dict[_key]))) elif isinstance(prop_dict[_key][0], dict): vals = [] for _item in prop_dict[_key]: subval = [] for _subkey in _item: subval.append( CF.DataType(id=_subkey, value=any.to_any(_item[_subkey]))) vals.append(any.to_any(subval)) props.append(CF.DataType(id=_key, value=any.to_any(vals))) else: props.append( CF.DataType(id=_key, value=any.to_any(prop_dict[_key]))) else: props.append( CF.DataType(id=_key, value=any.to_any(prop_dict[_key]))) if prf: props = matchTypes(props, prf=prf) return props
def launch(self, comp): # Pack the execparams into an array of string-valued properties properties = [CF.DataType(k, to_any(str(v))) for k, v in self._execparams.iteritems()] # Pack the remaining props by having the component do the conversion properties.extend(comp._itemToDataType(k,v) for k,v in self._initProps.iteritems()) properties.extend(comp._itemToDataType(k,v) for k,v in self._configProps.iteritems()) # Tell the IDE to launch a specific implementation, if given if comp._impl is not None: properties.append(CF.DataType('__implementationID', to_any(comp._impl))) ref = comp._sandbox._createResource(comp._profile, comp._instanceName, properties) # The IDE sandbox API only allows us to specify the instance name, not # the identifier, so update by querying the component itself comp._refid = ref._get_identifier() return ref
def retrieve(self): if not self.enabled: return None self.runningStats = PortStatistics(portName=self.name, averageQueueDepth=-1, elementsPerSecond=-1, bitsPerSecond=-1, callsPerSecond=-1, streamIDs=[], timeSinceLastCall=-1, keywords=[]) listPtr = ( self.receivedStatistics_idx + 1 ) % self.historyWindow # don't count the first set of data, since we're looking at change in time rather than absolute time frontTime = self.receivedStatistics[(self.receivedStatistics_idx - 1) % self.historyWindow].secs backTime = self.receivedStatistics[self.receivedStatistics_idx].secs totalData = 0.0 queueSize = 0.0 while (listPtr != self.receivedStatistics_idx): totalData += self.receivedStatistics[listPtr].elements queueSize += self.receivedStatistics[listPtr].queueSize listPtr += 1 listPtr = listPtr % self.historyWindow # copy stream ids used streamIDs = [] for sid in self.activeStreamIDs: streamIDs.append(sid) receivedSize = len(self.receivedStatistics) currentTime = time.time() totalTime = currentTime - backTime if totalTime == 0: totalTime = 1e6 self.runningStats.bitsPerSecond = (totalData * self.bitSize) / totalTime self.runningStats.elementsPerSecond = totalData / totalTime self.runningStats.averageQueueDepth = queueSize / receivedSize self.runningStats.callsPerSecond = float( (receivedSize - 1)) / totalTime self.runningStats.streamIDs = streamIDs self.runningStats.timeSinceLastCall = currentTime - frontTime if not self.flushTime == None: flushTotalTime = currentTime - self.flushTime self.runningStats.keywords = [ CF.DataType(id="timeSinceLastFlush", value=CORBA.Any(CORBA.TC_double, flushTotalTime)) ] return self.runningStats
def create(whole_secs=-1.0, fractional_secs=-1.0): """ Generates a CF.UTCTime object using the current CPU time that you can use in the pushPacket call """ wsec = whole_secs fsec = fractional_secs if wsec < 0.0 and fsec < 0.0: ts = time.time() wsec = int(ts) fsec = ts - int(ts) return CF.UTCTime(1, wsec, fsec)
def handle(self, logRecord): if self._enable: if self._ecm and self._pub : #print "RH_LogEventAppender::handle .... connection to ECM::Publisher rec: " + str(logRecord) eventLogLevel = sca.logger.ConvertLog4ToCFLevel(self.level) logEvent = any.to_any(CF.LogEvent(self.prodId,self.prodName,self.prodFQN,long(logRecord.created),eventLogLevel,logRecord.getMessage())) try: self._pub.push(logEvent) except Exception, e: print "RH_LogEventAppender::handle EVENT CHANNEL, PUSH OPERATION FAILED WITH EXCEPTION " + str(e) else: print "RH_LogEventAppender::handle No EVENT CHANNEL to publish on."
def buildDevSeq(dasXML): das = xml.dom.minidom.parse(dasXML) ds = [] for x in das.getElementsByTagName( 'deploymentenforcement')[0].getElementsByTagName( 'deviceassignmentsequence')[0].getElementsByTagName( 'deviceassignmenttype'): #print "component id:", x.componentid #print "assignmentdevid:", x.assigndeviceid compid = x.getElementsByTagName('componentid')[0].childNodes[0].data assgnid = x.getElementsByTagName( 'assigndeviceid')[0].childNodes[0].data ds.append(CF.DeviceAssignmentType(str(compid), str(assgnid))) return ds
def setKeyword(sri, name, value, format=None): """ Sets the current value of a keyword in the SRI. If the keyword "name" already exists, its value is updated to "value". If the keyword "name" does not exist, the new keyword is appended. If the optional 'format' argument is given, it must be the name of the desired CORBA type. Otherwise, the CORBA type is determined based on the Python type of 'value'. """ if format is None: value = omniORB.any.to_any(value) else: value = sca.properties.to_tc_value(value, format) for dt in sri.keywords: if dt.id == name: dt.value = value return sri.keywords.append(CF.DataType(name, value))
def sendPropertiesEvent(self, ids=None): # Avoid marshalling overhead if there are no connections if not self._outPorts: self._component._log.debug("Skipping sendPropertiesEvent (no connections)") return if ids is None: ids = [prop._id for prop in self._component._props.values() if prop.isSendEventChange()] self._component._log.debug("sendPropertiesEvent %s", ids) properties = [] for id_ in ids: propDef = self._component._props.getPropDef(id_) if not propDef.isSendEventChange(): self._component._log.warning("Send property event for non-eventable property %s", id_) v = propDef._toAny(propDef.get(self._component)) properties.append(CF.DataType(id_, v)) if len(properties) == 0: self._component._log.debug("Refusing to send empty property event") else: event = any.to_any(ExtendedEvent.PropertySetChangeEventType(self._component._id, self._component._name, properties)) self.sendEvent(event)
def queryTimestamp(): return CF.DataType(id='QUERY_TIMESTAMP', value=_any.to_any(None))
def notSet(): """ Generates a CF.UTCTime object with zero time and an invalid flag. This is used by the automatic EOS """ return CF.UTCTime(1, 0.0, 0.0)
if self._shared: container = comp._sandbox._getComponentHost(_debugger=debugger) else: container = comp._sandbox._launchComponentHost( comp._instanceName, _debugger=debugger) container.executeLinked(entry_point, [], execparams, deps) process = container._process else: if not self._host: process = device.execute(entry_point, deps, execparams, debugger, window, self._stdout) else: _cmdline_params = [] for item in execparams: _cmdline_params.append( CF.DataType(id=item, value=to_any(execparams[item]))) try: process = device.execute( entry_point[len(sdrroot.getLocation()) + 4:], [], _cmdline_params) except Exception, e: print 'received exception', e # Set up a callback to notify when the component exits abnormally. name = comp._instanceName def terminate_callback(pid, status): if status > 0: print 'Component %s (pid=%d) exited with status %d' % ( name, pid, status) elif status < 0:
def configure(self, v): self.__component.configure( [CF.DataType(id=self.__property._id, value=any.to_any(v))])
def query(self, v): val = self.__component.query([ CF.DataType(id=self.__property._id, value=any.to_any(None)) ]) return any.from_any(val[0].value)
def getPropertySet(self, kinds=("configure","property",), \ modes=("readwrite", "writeonly", "readonly"), \ action="external", \ includeNil=True, commandline=False): """ A useful utility function that extracts specified property types from the PRF file and turns them into a CF.PropertySet """ propertySet = [] # Simples if self.prf != None: for prop in self.prf.get_simple(): if self.isMatch(prop, modes, kinds, (action, )): if prop.get_value() is not None: if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) value = stringToComplex(prop.get_value(), type) else: type = prop.get_type() value = prop.get_value() dt = properties.to_tc_value(value, type) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Simple Sequences for prop in self.prf.get_simplesequence(): if self.isMatch(prop, modes, kinds, (action, )): if prop.get_values() is not None: seq = [] if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) for v in prop.get_values().get_value(): seq.append(stringToComplex(v, type)) expectedType = properties.getTypeCode(type) expectedTypeCode = tcInternal.createTypeCode( (tcInternal.tv_sequence, expectedType._d, 0)) dt = CORBA.Any(expectedTypeCode, [ properties._convertComplexToCFComplex( item, type) for item in seq ]) else: type = prop.get_type() for v in prop.get_values().get_value(): value = v seq.append(properties.to_pyvalue(value, type)) dt = any.to_any(seq) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Structures for prop in self.prf.get_struct(): if self.isMatch(prop, modes, kinds, (action, )): if (prop.get_simple() is not None) or (prop.get_simplesequence() is not None): fields = [] hasValue = False if prop.get_simple() is not None: for p in prop.get_simple(): if p.get_value() is not None: hasValue = True dt = properties.to_tc_value( p.get_value(), p.get_type()) fields.append( CF.DataType(id=str(p.get_id()), value=dt)) if prop.get_simplesequence() is not None: for p in prop.get_simplesequence(): if p.get_values() is not None: hasValue = True dt = properties.to_tc_value( p.get_values(), p.get_type()) fields.append( CF.DataType(id=str(p.get_id()), value=dt)) if not hasValue and not includeNil: continue dt = any.to_any(fields) else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Struct Sequence for prop in self.prf.get_structsequence(): if self.isMatch(prop, modes, kinds, (action, )): baseProp = [] if prop.get_struct() != None: fields = [] for internal_prop in prop.get_struct().get_simple(): fields.append( CF.DataType(id=str(internal_prop.get_id()), value=any.to_any(None))) for internal_prop in prop.get_struct( ).get_simplesequence(): fields.append( CF.DataType(id=str(internal_prop.get_id()), value=any.to_any(None))) for val in prop.get_structvalue(): baseProp.append(copy.deepcopy(fields)) for entry in val.get_simpleref(): val_type = None for internal_prop in prop.get_struct().get_simple( ): if str(internal_prop.get_id()) == entry.refid: val_type = internal_prop.get_type() for subfield in baseProp[-1]: if subfield.id == entry.refid: subfield.value = properties.to_tc_value( entry.get_value(), val_type) for entry in val.get_simplesequenceref(): val_type = None for internal_prop in prop.get_struct( ).get_simplesequence(): if str(internal_prop.get_id()) == entry.refid: val_type = internal_prop.get_type() for subfield in baseProp[-1]: if subfield.id == entry.refid: subfield.value = properties.to_tc_value( entry.get_values(), val_type) anybp = [] for bp in baseProp: anybp.append(properties.props_to_any(bp)) p = CF.DataType(id=str(prop.get_id()), value=any.to_any(anybp)) propertySet.append(p) return propertySet