def __init__(self, id, valueType, enum, compRef, kinds,defValue=None, parent=None, mode='readwrite', action='external', structRef=None, structSeqRef=None, structSeqIdx=None): """ Create a new simple property. Arguments: id - The property ID valueType - Type of the property, must be in VALUE_TYPES compRef - Reference to the PropertySet that owns this property defValue - Default Python value for this property (default: None) parent - Parent property that contains this property (default: None) mode - Mode for the property, must be in MODES (default: 'readwrite') action - Allocation action type (default: 'external') Deprecated arguments: structRef, structSeqRef, structSeqIdx """ if valueType not in SCA_TYPES: raise('"' + str(valueType) + '"' + ' is not a valid valueType, choose from\n ' + str(SCA_TYPES)) # Initialize the parent Property.__init__(self, id, type=valueType, kinds=kinds,compRef=compRef, mode=mode, action=action, parent=parent, defValue=defValue) self.valueType = valueType self.typecode = getTypeCode(self.valueType) if enum != None: self._enums = self._parseEnumerations(enum) else: self._enums = None
def __init__(self, id, valueType, compRef, defValue=None, parent=None, structRef=None, structSeqRef=None, structSeqIdx=None, mode='readwrite', action='external'): """ id - (string): the property ID valueType - (string): type of the property, must be in VALUE_TYPES compRef - (domainless.componentBase) - pointer to the component that owns this property structRef - (string): name of the struct that this simple is a member of, or None structSeqRef - (string): name of the struct sequence the above struct is a member of, or None structSeqIdx - (int): index of the above struct in the struct sequence, or None mode - (string): mode for the property, must be in MODES """ if valueType not in SCA_TYPES: raise('"' + str(valueType) + '"' + ' is not a valid valueType, choose from\n ' + str(SCA_TYPES)) # Initialize the parent Property.__init__(self, id, type=valueType, compRef=compRef, mode=mode, action=action, parent=parent) self.valueType = valueType self.defValue = defValue self.typecode = getTypeCode(self.valueType) #used when the simple is part of a struct self.structRef = structRef # DEPRECATED: used when the struct is part of a struct sequence self.structSeqRef = structSeqRef self.structSeqIdx = structSeqIdx # DEPRECATED: create the CF.DataType reference, change value to the correct type self.propRef = _CF.DataType(id=str(self.id), value=_any.to_any(None)) self.propRef.value._t = self.typecode
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
def configureProp(compRef, propName, propValue): propRef = _CF.DataType(id=str(str(propName)), value=_any.to_any(None)) #try the query to see if we can get the valid type results = compRef.query([propRef]) if results != None: if results[0].value._t != _CORBA.TC_null: propRef.value._t = esults[0].value._t propRef.value._v = propValue compRef.configure([propRef]) return #if we couldn't find the type of the property, then we need #to try ones that might fit until one works applicableTypes = None if type(propValue) == list: strTypes = [_tcInternal.typeCodeFromClassOrRepoId(_CORBA.StringSeq), _tcInternal.typeCodeFromClassOrRepoId(_CORBA.CharSeq)] boolTypes = [_tcInternal.typeCodeFromClassOrRepoId(_CORBA.BooleanSeq)] longTypes = [_tcInternal.typeCodeFromClassOrRepoId(_CORBA.ULongSeq), _tcInternal.typeCodeFromClassOrRepoId(_CORBA.ShortSeq), _tcInternal.typeCodeFromClassOrRepoId(_CORBA.OctetSeq), _tcInternal.typeCodeFromClassOrRepoId(_CORBA.UShortSeq), _tcInternal.typeCodeFromClassOrRepoId(_CORBA.LongSeq), _tcInternal.typeCodeFromClassOrRepoId(_PortTypes.LongLongSequence), _tcInternal.typeCodeFromClassOrRepoId(_PortTypes.UlongLongSequence)] floatTypes = [_tcInternal.typeCodeFromClassOrRepoId(_CORBA.FloatSeq), _tcInternal.typeCodeFromClassOrRepoId(_CORBA.DoubleSeq)] if len(propValue) > 0: valueType = type(propValue[0]) else: applicableTypes = strListTypes + boolListTypes + longListTypes + floatListTypes else: strTypes = [getTypeCode('string'), getTypeCode('char')] boolTypes = [getTypeCode('boolean')] longTypes = [getTypeCode('ulong'), getTypeCode('short'), getTypeCode('octet'), getTypeCode('ushort'), getTypeCode('long'), getTypeCode('longlong'), getTypeCode('ulonglong')] floatTypes = [getTypeCode('float'), getTypeCode('double')] valueType = type(propValue) if not applicableTypes: if valueType == str: applicableTypes = strTypes elif valueType == bool: applicableTypes = boolTypes elif valueType == long: applicableTypes = longTypes elif valueType == float: applicableTypes = floatTypes else: raise Exception, 'Could not match "'+str(valueType)+'" to a valid CORBA type' passConfigure = False for propType in applicableTypes: propRef.value._t = propType propRef.value._v = propValue try: compRef.configure([propRef]) passConfigure = True break except: pass if not passConfigure: msg = 'Was not able to configure property: "'+str(propName)+'", trying the following types:\n' for propType in applicableTypes: msg += (' ' + str(propType) + '\n') raise Exception, msg
def getPropertySet(self, kinds=("configure",), \ modes=("readwrite", "writeonly", "readonly"), \ action="external", \ includeNil=True): """ A useful utility function that extracts specified property types from the PRF file and turns them into a CF.PropertySet """ propertySet = [] # Simples 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: fields = [] hasValue = False for s in prop.get_simple(): if s.get_value() is not None: hasValue = True dt = properties.to_tc_value(s.get_value(), s.get_type()) fields.append(CF.DataType(id=str(s.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) # Structures 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 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) 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) # Struct Sequence return propertySet