def getRandomStruct(typeCode, compRef): ''' Helper function ''' structDef = getDefinition(typeCode.id()) try: return getKnownBaciType(structDef._get_id()) except: pass #determine which namespace the struct is in... #changes 'IDL:alma/someMod/.../struct:1.0" to # [ 'someMod', ...,'struct' ] nameHierarchy = structDef._get_id().split(':')[1].split('/')[1:] #Just the 'struct' part... structName = nameHierarchy.pop() moduleName = nameHierarchy.pop(0) LOGGER.logTrace("module=" + moduleName + "; hierarchy=" + str(nameHierarchy) + "; struct=" + structName) #import the top module tGlobals = {} tLocals = {} #module object where the struct is contained container = __import__(moduleName, tGlobals, tLocals, []) if container == None: msg = "import of module \'" + moduleName + "\' failed" LOGGER.logCritical(msg) raise CORBA.NO_IMPLEMENT(msg) # Now navigate down the nested hierarchy of objects for h in nameHierarchy: previousContainer = container container = container.__dict__.get(h) if container == None: msg = "Name \'" + h + "\' not found in " + str(previousContainer) LOGGER.logCritical(msg) raise CORBA.NO_IMPLEMENT(msg) #class object for the struct tClass = container.__dict__.get(structName) if tClass == None: msg = "Could not get structure \'" + structName + "\' from " \ + str(container) LOGGER.logCritical(msg) raise CORBA.NO_IMPLEMENT(msg) #create an instance of the struct using a kooky Python mechanism. retVal = instance(tClass) #populate the fields of the struct using the IFR for member in structDef._get_members(): LOGGER.logTrace("Adding a member variable for: " + str(member.name)) retVal.__dict__[member.name] = getRandomValue( member.type_def._get_type(), compRef) return retVal
def getUnsupported(typeCode, compRef): ''' Helper function ''' valType = typeCode.kind() LOGGER.logCritical(str(valType) + " not yet supported") raise CORBA.NO_IMPLEMENT()
def setAccelTimeJoint(self, aclTime): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getRandomSimpleValue(valType): ''' Helper function returns a random value of (typecode) valType or throws an exception if valType is not a simple type. Sample usage could be: getRandomSimpleValue(CORBA.tk_boolean) Parameters: valType is a typeCode Returns: a random value of type typeCode Raises: an exception if valType is not really a simple CORBA type ''' if valType == CORBA.tk_boolean: #randomly returns 0 or 1 retVal = randrange(0, 100) % 2 elif valType == CORBA.tk_char: #randomly returns some predetermined character retVal = choice(getCHARS()) elif valType == CORBA.tk_octet: #returns 0-255 retVal = int(randrange(0, 256)) elif valType == CORBA.tk_short: #returns a random short retVal = int(randrange(-(2**15), (2**15) - 1)) elif valType == CORBA.tk_ushort: #returns a random unsigned short retVal = int(randrange(0, (2**16) - 1)) elif valType == CORBA.tk_long: #returns a random long retVal = int(randrange(-(2**31), (2**31) - 1)) elif valType == CORBA.tk_ulong: #returns a random unsigned long retVal = long(randrange(0, (2**32) - 1)) elif valType == CORBA.tk_longlong: #returns a random long long retVal = long(randrange(-(2**63), (2**63) - 1)) elif valType == CORBA.tk_ulonglong: #returns a random unsigned long long retVal = long(randrange(0, (2**64) - 1)) elif valType == CORBA.tk_float: #DWF-make this really go through a float's entire range of values retVal = eval( str(getRandomSimpleValue(CORBA.tk_short)) + '.' + str(getRandomSimpleValue(CORBA.tk_octet))) elif valType == CORBA.tk_double: #returns a random float plus more digits retVal = getRandomSimpleValue(CORBA.tk_float) * 1000.0 elif valType == CORBA.tk_longdouble: #DWF-CORBA IDL->Py mapping specifies a CORBA.long_double() object #to be used in cases like these. Unfortunately omniORB does not #currently support it. LOGGER.logDebug("long doubles not supported by omniORBPy") return 3.1415926535897931 elif valType == CORBA.tk_string: retVal = "..." + str(getRandomSimpleValue(CORBA.tk_double)) + "..." elif valType == CORBA.tk_void: retVal = None elif valType == CORBA.tk_null: retVal = None else: raise CORBA.NO_IMPLEMENT() return retVal
def getState(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getFeedbackPosJoint(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def clearAlarms(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def set_value(self, value): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getMaxSpeedCartesian(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getFeedbackPosCartesian(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getBaseOffset(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def setSpeedJoint(self, spdRatio): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def setSpeedCartesian(self, spdRatio): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def setSoftLimitCartesian(self, xLimit, yLimit, zLimit): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def setControlPointOffset(self, offset): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def echo12(self, ss, ss3): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def echo(self, msg): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getMaxSpeedJoint(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def get_value_history(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getMinAccelTimeCartesian(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getActiveAlarm(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getMinAccelTimeJoint(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getManipInfo(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getSoftLimitCartesian(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def setSoftLimitJoint(self, softLimit): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def moveGripper(self, angleRatio): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def moveLinearCartesianAbs(self, carPoint): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def echo04(self): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)
def getRandomTuple(typeCode, compRef, valType): ''' Helper function returns a random Python tuple for CORBA sequences and array types. Parameters: - type code is quite literally a CORBA typecode - compRef is a reference to a component used to activated IDL OffShoot interfaces - valType is the value type of the random value we are trying to get Returns: a random enumeration of the type specified by typeCode Raises: an (unknown) exception if the typecode does not really specify a list type to be returned or a CORBA.NO_IMPLEMENT if we have not gotten around to supporting the specific typecode yet (e.g., value boxes). ''' #if this next block does not throw an exception... realValType = typeCode.content_type().kind() realTypeCode = getDefinition( typeCode.id())._get_original_type_def()._get_element_type() #we're really dealing with a sequence, array, value_box, or an alias LOGGER.logTrace("Dealing with a sequence, array, value_box, or alias:" + str(realValType) + " " + str(realTypeCode)) #Sequence if realValType == CORBA.tk_sequence: LOGGER.logTrace("Dealing with a sequence.") retVal = [] for i in range(0, randrange(0, getMaxSeqSize())): retVal.append(getRandomValue(realTypeCode, compRef)) #Sequences of octects and characters must be handled specially in #Python if realTypeCode.kind() == CORBA.tk_octet or realTypeCode.kind( ) == CORBA.tk_char: LOGGER.logTrace("Dealing with a sequence of characters/octets.") return reduce((lambda x, y: str(x) + str(y)), retVal) else: return tuple(retVal) #Array #DWF-take into consideration multi-dimensional arrays elif realValType == CORBA.tk_array: size = getDefinition( typeCode.id())._get_original_type_def()._get_type().length() LOGGER.logTrace("Dealing with an array of size:" + str(size)) retVal = [] for i in range(0, size): retVal.append(getRandomValue(realTypeCode, compRef)) #Sequences of octects and characters must be handled specially in #Python if realTypeCode.kind() == CORBA.tk_octet or realTypeCode.kind( ) == CORBA.tk_char: LOGGER.logTrace("Dealing with an array of characters/octets.") return reduce((lambda x, y: str(x) + str(y)), retVal) else: return tuple(retVal) #Value Box elif realValType == CORBA.tk_value_box: LOGGER.logCritical("value_box not yet supported") raise CORBA.NO_IMPLEMENT() #If this block of code can ever really be executed in practice...I'll #be amazed! elif valType == CORBA.tk_alias: return getRandomValue(realTypeCode, compRef)
def setAccelTimeCartesian(self, aclTime): raise CORBA.NO_IMPLEMENT(0, CORBA.COMPLETED_NO)