def test_javaPropsRangeStructSeq(self): self.assertNotEqual(self._domMgr, None, "DomainManager not available") self.assertNotEqual(self._devMgr, None, "DeviceManager not available") self.assertNotEqual(self._app, None, "Failed to launch app") # Struct with upper bound upper = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_octet, 255)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_short, 32767)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_ushort, 65535)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_long, 2147483647)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_ulong, 4294967295)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, 9223372036854775807L))]) # Struct with lower bound lower = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_octet, 0)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_short, -32768)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_ushort, 0)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_long, -2147483648)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_ulong, 0)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L))]) my_structseq = CF.DataType(id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [ upper , lower ] )) self._app.configure([my_structseq]) # Make sure values all got set res = self._app.query([]) for r in res: if r.id == 'my_structseq': upper = r.value.value()[0] lower = r.value.value()[1] for v in upper.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 255) elif v.id == 'ss_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'ss_long': self.assertEquals(v.value.value(), 2147483647) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) for v in lower.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_short': self.assertEquals(v.value.value(), -32768) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_long': self.assertEquals(v.value.value(), -2147483648) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), -9223372036854775808L)
def test_hw_load_request(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions my_request = HwLoadRequest() my_request.request_id = str(uuid.uuid1()) my_request.requestor_id = "PG_TESTER" my_request.hardware_id = "PG_TESTER:1" my_request.load_filepath = "/the/path/file/to/load.bin" my_request_any = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), struct_to_props(my_request)) my_requests = CF.DataType( id='hw_load_requests', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [my_request_any])) hw_load_requests = structseq_property(id_="hw_load_requests", name="hw_load_requests", structdef=HwLoadRequest, defvalue=[], configurationkind=("property", ), mode="readwrite") self.comp.start()
def test_javaPropsRangeSeq(self): self.assertNotEqual(self._domMgr, None, "DomainManager not available") self.assertNotEqual(self._devMgr, None, "DeviceManager not available") self.assertNotEqual(self._app, None, "Failed to launch app") # Test upper and lower bounds octet_val = struct.pack('B', 0) + struct.pack('B', 255) seq_octet = CF.DataType( id='seq_octet', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/OctetSeq:1.0"), octet_val)) seq_short = CF.DataType( id='seq_short', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/ShortSeq:1.0"), [-32768, 32767])) seq_ushort = CF.DataType( id='seq_ushort', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/UShortSeq:1.0"), [0, 65535])) seq_long = CF.DataType(id='seq_long', value=any.to_any([-2147483648, 2147483647])) seq_ulong = CF.DataType(id='seq_ulong', value=any.to_any([0, 4294967295])) seq_longlong = CF.DataType( id='seq_longlong', value=any.to_any([-9223372036854775808L, 9223372036854775807L])) self._app.configure([ seq_octet, seq_short, seq_ushort, seq_long, seq_ulong, seq_longlong ]) res = self._app.query([]) for r in res: if r.id == 'seq_octet': # Octets need to be unpacked stored_vals = r.value.value() vals = [] for num in stored_vals: curr = struct.unpack('B', num) vals.append(curr[0]) self.assertEquals(vals[0], 0) self.assertEquals(vals[1], 255) elif r.id == 'seq_short': self.assertEquals(r.value.value()[0], -32768) self.assertEquals(r.value.value()[1], 32767) elif r.id == 'seq_ushort': self.assertEquals(r.value.value()[0], 0) self.assertEquals(r.value.value()[1], 65535) elif r.id == 'seq_long': self.assertEquals(r.value.value()[0], -2147483648) self.assertEquals(r.value.value()[1], 2147483647) elif r.id == 'seq_ulong': self.assertEquals(r.value.value()[0], 0) self.assertEquals(r.value.value()[1], 4294967295) elif r.id == 'seq_longlong': self.assertEquals(r.value.value()[0], -9223372036854775808L) self.assertEquals(r.value.value()[1], 9223372036854775807L)
def test_propertyExceptionsSeq(self): self.preconditions() seq_short = CF.DataType( id='seq_short', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/ShortSeq:1.0"), [11, 22])) self._app.configure([seq_short]) seq_short = CF.DataType(id='seq_short', value=any.to_any([33, 44])) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [seq_short]) seq_long = CF.DataType(id='seq_long', value=any.to_any([55, 66])) self.assertRaises(CF.PropertySet.PartialConfiguration, self._app.configure, [seq_short, seq_long]) # Long sequence should have changed and short did not for r in self._app.query([]): if r.id == 'seq_long': self.assertEquals(r.value.value()[0], 55) self.assertEquals(r.value.value()[1], 66) elif r.id == 'seq_short': self.assertEquals(r.value.value()[0], 11) self.assertEquals(r.value.value()[1], 22)
def con_evfn(batch, objnm, idx, num_events, num_batches, verbose): "consume an any, verify it contains the appropriate MyUnTest value" # initialize consume stats for idx, if necessary if (not con_valid.has_key(idx)): con_valid[idx] = 0 if (not con_total.has_key(idx)): con_total[idx] = 0 # the rest of the consume method if (len(batch) != 1): print "Internal Error (?): any consumer should not get an event batch" # process like a batch regardless for a in batch: con_total[idx] += 1 v = a.value(CORBA.TypeCode(CORBA.id(MyUnType))) if (v == None): if (verbose > 0): print objnm, ": con_evfn: unexpected non-union value consumed" break if (verbose > 0): print objnm, ": con_evfn: consumed union value", v._v if (v._d != MyUnTest.e5): if (verbose > 0): print objnm, ": con_evfn: wrong discriminator value" elif (v._v != Sup_Any_MyUnType.match_long): if (verbose > 0): print objnm, ': con_evfn: value (', v._v, ') != match_long (', Sup_Any_MyUnType.match_long, ')' else: con_valid[idx] += 1
class structSequenceProperty(sequenceProperty): # All struct sequences have the same CORBA typecode. typecode = _CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0") def __init__(self, id, structID, valueType, compRef, defValue=[], mode='readwrite'): """ id - (string): the property ID valueType - (list): each entry in the list is a tuple defined in the following fashion: (id, valueType(as defined for simples), defValue) compRef - (domainless.componentBase) - pointer to the component that owns this property mode - (string): mode for the property, must be in MODES """ if type(valueType) != list: raise('valueType must be provided as a list') self.valueType = valueType self.structID = structID self.defValue = defValue #initialize the parent sequenceProperty.__init__(self, id, valueType='structSeq', compRef=compRef, defValue=self.defValue, mode=mode) # Create a property for the struct definition. self.structDef = structProperty(id=self.structID, valueType=self.valueType, compRef=self.compRef, mode=self.mode) # DEPRECATED: Create the CF.DataType reference self.propRef = _CF.DataType(id=str(self.id), value=_CORBA.Any(self.typecode, [])) def __getitem__(self, index): #the actual struct property doesn't exist, so create it and return it newProp = structProperty(id=self.structID, valueType=self.valueType, compRef=self.compRef, \ parent=self, structSeqRef=self.id, structSeqIdx=index, mode=self.mode) return newProp def __setitem__(self, index, value): #the actual struct property doesn't exist, so create it and configure it, #this will trigure a configure of the entire sequence from within structProperty newProp = structProperty(id=self.structID, valueType=self.valueType, compRef=self.compRef, \ parent=self, structSeqRef=self.id, structSeqIdx=index, mode=self.mode) structProperty.configureValue(newProp, value) def fromAny(self, value): ''' Converts the input value in CORBA Any format to Python. ''' if value is None: return [] return [self.structDef.fromAny(v) for v in value.value()] def toAny(self, value): ''' Converts the input value in Python format to a CORBA Any. ''' if value is None: return _any.to_any(None) return _CORBA.Any(self.typecode, [self.structDef.toAny(v) for v in value])
def _fabricate_registrar(self): """ Returns a fake Registrar object. """ return (CORBA.Any( CORBA.TypeCode("IDL:Registry/Registrar/Detail:1.0"), Registry.Registrar.Detail( id=42L, ico='', dic='', varSymb='', vat=True, handle='test handle', name='Company l.t.d.', organization='test org 1', street1='', street2='', street3='', city='', stateorprovince='', postalcode='', country='CZ', telephone='', fax='', email='', url='www.nic.cz', credit='0.00', unspec_credit=u'120.00', access=[ Registry.Registrar.EPPAccess( id=1, password='******', md5Cert= '60:7E:DF:39:62:C3:9D:3C:EB:5A:87:80:C1:73:4F:99'), Registry.Registrar.EPPAccess( id=2, password='******', md5Cert= '6A:AC:49:24:F8:32:1E:B7:A1:83:B5:D4:CB:74:29:98') ], zones=[ Registry.Registrar.ZoneAccess( id=1L, name='0.2.4.e164.arpa', credit='0', fromDate=ccReg.DateType(1, 1, 2007), toDate=ccReg.DateType(0, 0, 0)), Registry.Registrar.ZoneAccess( id=2L, name='cz', credit='0', fromDate=ccReg.DateType(1, 1, 2007), toDate=ccReg.DateType(0, 0, 0)) ], hidden=False)))
def makeFilterProps(self, tw=400, filterType='lowpass', ripple=0.01, freq1=1000.0, freq2=2000.0,cx=False): """set the filter properties on the component """ return CF.DataType(id='filterProps', value=CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [CF.DataType(id='TransitionWidth', value=CORBA.Any(CORBA.TC_double, tw)), CF.DataType(id='Type', value=CORBA.Any(CORBA.TC_string, filterType)), CF.DataType(id='Ripple', value=CORBA.Any(CORBA.TC_double, ripple)), CF.DataType(id='freq1', value=CORBA.Any(CORBA.TC_double, freq1)), CF.DataType(id='freq2', value=CORBA.Any(CORBA.TC_double, freq2)), CF.DataType(id='filterComplex', value=CORBA.Any(CORBA.TC_boolean, cx)) ]))
def testConfigureQueryStructSeqs(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() props = self.comp_obj.query([]) val = 5 phrase = 'blah' flag = True seq = ossie.cf.CF.DataType(id='structSeqProp', 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='structSeqStringSimple', value=CORBA.Any(CORBA.TC_string, phrase)), ossie.cf.CF.DataType(id='structSeqBoolSimple', value=CORBA.Any(CORBA.TC_boolean, flag)), ossie.cf.CF.DataType(id='structSeqShortSimple', value=CORBA.Any(CORBA.TC_short, val)), ossie.cf.CF.DataType(id='structSeqFloatSimple', value=CORBA.Any(CORBA.TC_float, val))])])) instance = seq.value._v[0] for x in range(4): seq.value._v.append(copy.deepcopy(instance)) self.comp_obj.configure([seq]) ret = self.comp_obj.query([ossie.cf.CF.DataType(id='structSeqProp', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), []))]) for struct in ret[0].value.value(): for simple in struct.value(): if simple.id == 'structSeqStringSimple': self.assertEquals(simple.value.value(), phrase * 2, msg=str(simple.value.value()) + ' != ' + str(phrase*2) + ' for structSeqStringSimple') elif simple.id == 'structSeqBoolSimple': self.assertEquals(simple.value.value(), not flag, msg=str(simple.value.value()) + ' != ' + str(not flag) + ' for structSeqBoolSimple') else: self.assertEquals(simple.value.value(), val * 2, msg=str(simple.value.value()) + ' != ' + str(val*2) + ' for ' + str(simple.id))
def constructDefaultType(typeobj): if isinstance(typeobj, CORBA.TypeCode): tc = typeobj else: tc = CORBA.TypeCode(CORBA.id(typeobj)) kind = tc.kind() if kind == CORBA.tk_alias: return constructDefaultType(tc.content_type()) if kind == CORBA.tk_struct: # This is sort-of-dependent on omniORB implementation details, but # findType() is public by Python convention. It returns a tuple with # details of the type, but here we only need the class object. typeobj = omniORB.findType(tc.id())[1] args = [ constructDefaultType(tc.member_type(idx)) for idx in range(tc.member_count()) ] return typeobj(*args) if kind == CORBA.tk_enum: # As with above, an implementation detail. The last element of the # type details is the list values; return the first. return omniORB.findType(tc.id())[-1][0] if kind == CORBA.tk_union: # See comment in struct branch. typeobj = omniORB.findType(tc.id())[1] index = tc.default_index() if index < 0: index = tc.member_count() + index kwds = {} kwds[tc.member_name(index)] = constructDefaultType( tc.member_type(index)) return typeobj(**kwds) if kind == CORBA.tk_string: return str() if kind in (CORBA.tk_float, CORBA.tk_double): return float() if kind in (CORBA.tk_octet, CORBA.tk_short, CORBA.tk_ushort, CORBA.tk_long, CORBA.tk_boolean): return int() if kind in (CORBA.tk_ulong, CORBA.tk_longlong, CORBA.tk_ulonglong): return long() if kind == CORBA.tk_char: return '\x00' if kind == CORBA.tk_sequence: return [] if kind == CORBA.tk_any: return CORBA.Any(CORBA.TC_null, None) if kind == CORBA.tk_objref: return None raise NotImplementedError, tc
def get_stations_with_var (state,varMajors=None,start=None,end=None) : import Meta from omniORB import CORBA import ucanCallMethods any = CORBA.Any tc = CORBA.TypeCode tc_short = CORBA.TC_short tc_long = CORBA.TC_long tc_string = CORBA.TC_string tc_nativeId = CORBA.TypeCode(Meta.MetaQuery.NativeId) tc_shortSeq = tc(Meta.ShortSeq) tc_floatSeq = tc(Meta.FloatSeq) NativeId = Meta.MetaQuery.NativeId NameAny = Meta.MetaQuery.NameAnyPair # set up ucan ucan = ucanCallMethods.general_ucan() dictionary = {} try: postal = state.upper() if varMajors == None: varMajors = [1,2,4] if start == None: start = (0001,1,1) if end == None : end = (9999,12,31) query = ucan.get_query() qualifier = [ NameAny ('postal', any(tc_string,postal) )] qualifier.append ( NameAny ('var_major_id',any(tc_shortSeq,varMajors) ) ) qualifier.append ( NameAny ('begin_date', any(tc_shortSeq,start) ) ) qualifier.append ( NameAny ('end_date', any(tc_shortSeq,end) ) ) results = query.getStnInfoAsSeq(qualifier,()) query.release() if len(results) == 0: return {} else: dictionary = {} for item in results : r = NameAny_to_dict(item) dictionary[r['ucan_id']] = r except: print_exception() return dictionary
def sup_evfn(objnm, idx, bsize, num_events, num_batches, verbose): "supply an any containing a MyUnType value" # initialize supply stats for idx, if necessary if (not sup_total.has_key(idx)): sup_total[idx] = 0 # the rest of the supply method batch = [] while (len(batch) < bsize): if (verbose > 0): print objnm, ": supplying event #", num_events counter = sup_total[idx] % 10 sup_total[idx] += 1 num_events += 1 if (counter == 0): u = MyUnType(e0_ar5=__str_array1) elif (counter == 1): u = MyUnType(e0_ar5=__str_array2) elif (counter == 2): u = MyUnType(e2_str=match_str) elif (counter == 3): u = MyUnType(e2_str='NOT ' + match_str) elif (counter == 4): u = MyUnType(e5_l=match_long) elif (counter == 5): u = MyUnType(e5_l=match_long + 1) elif (counter == 6): u = MyUnType(e6_s=match_short) elif (counter == 7): u = MyUnType(e6_s=match_short + 1) elif (counter == 8): u = MyUnType(def_b=match_bool) elif (counter == 9): u = MyUnType(def_b=not_match_bool) tc = CORBA.TypeCode(CORBA.id(MyUnType)) a = CORBA.Any(tc, u) if (verbose > 0): print objnm, ": sup_evfn: union value _d = ", u._d print objnm, ": sup_evfn: union value _v = ", u._v print objnm, ": sup_evfn: any value has typecode kind =", a.typecode( ).kind() print objnm, ": sup_evfn: any value =", a.value(a.typecode()) batch.append(a) return batch
def sup_evfn(objnm, idx, bsize, num_events, num_batches, verbose): "supply an any containing a MyStTest.MySt value" # initialize supply stats for idx, if necessary if (not sup_total.has_key(idx)): sup_total[idx] = 0 # the rest of the supply method batch = [] while (len(batch) < bsize): if (verbose > 0): print objnm, ": supplying event #", num_events vs = MySt(num_events) tc = CORBA.TypeCode(CORBA.id(MySt)) a = CORBA.Any(tc, vs) sup_total[idx] += 1 num_events += 1 if (verbose > 0): print objnm, ": sup_evfn: supplying MySt with ul = ", vs.ul batch.append(a) return batch
def makeRealCoefProps(self): return ossie.cf.CF.DataType(id='realFilterCoefficients', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/FloatSeq:1.0"), []))
def makeCxCoefProps(self): return ossie.cf.CF.DataType(id='complexFilterCoefficients', value=CORBA.Any(CORBA.TypeCode("IDL:CF/complexFloatSeq:1.0"), []))
def execute(lang, testType): expSet = resfile.MakeStdExpansionSet('api', lang, testType) resfile.RegisterExpansionSet(expSet) util.SetProfileBaseName("gmon-api-" + lang + "-" + testType + "-" + cmdline.StartDate()) if lang == 'sl': vdmServer = os.path.expanduser(cmdline.LookUp('api-sl-server')) else: vdmServer = os.path.expanduser(cmdline.LookUp('api-pp-server')) start_toolbox = cmdline.LookUp('api-run-start-toolbox') server_args = cmdline.LookUp('server-init-args').split(" ") # corba-init-args is used to pass arguments to the orb client_args = cmdline.LookUp('corba-init-args').split() orb = CORBA.ORB_init(client_args, CORBA.ORB_ID) if start_toolbox == 'yes': pid = os.fork() if pid == 0: report.Progress( 3, "Trying to start " + lang + "-toolbox: " + vdmServer) cmd = vdmServer + " " + "".join( server_args) + " > tb_output.tmp 2>&1" os.system(cmd) report.Error("Startup of Toolbox failed!") return false _exit(-1) waittime = 5 print("Waiting " + str(waittime) + " seconds for " + lang + "-server to start up...") time.sleep(waittime) if "VDM_OBJECT_LOCATION" in environ: location = environ["VDM_OBJECT_LOCATION"] else: if "HOME" in environ: location = environ["HOME"] else: location = "~" if lang == 'sl': location = location + '/vdmref.ior' else: location = location + '/vppref.ior' try: stringified_ior = open(os.path.expanduser(location)).read() except IOError: report.Error("Could not find IOR file " + location + "! Please start " + lang + "-Toolbox!") if start_toolbox == 'yes': os.kill(pid, 9) os.system("tset") return false try: vdmApp = orb.string_to_object(stringified_ior) except CORBA.COMM_FAILURE: _, ex, _ = sys.exc_info() print("CORBA.COMM_FAILUR") print(ex) vdmApp = None except CORBA.MARSHAL: _, ex, _ = sys.exc_info() print("CORBA.MARSHAL") print(ex) # vdmApp = None if vdmApp is None: report.Error("Nil object reference!") if start_toolbox == 'yes': os.kill(pid, 9) return false # check if vdmApp has correct type try: if not vdmApp._is_a('IDL:ToolboxAPI/VDMApplication:1.0'): report.Error("This is not a 'VDMApplication'-server!") if start_toolbox == 'yes': os.kill(pid, 9) return false except CORBA.COMM_FAILURE: report.Error("No connection to 'VDMApplication'-object!") if start_toolbox == 'yes': os.kill(pid, 9) return false # narrow vdmApp and get typecode vdmApp = vdmApp._narrow(ToolboxAPI.VDMApplication) tc = CORBA.TypeCode('IDL:ToolboxAPI/VDMApplication:1.0') # check if server is the one we want (SL or PP) try: toolType = vdmApp._get_Tool() if (lang == 'sl' and toolType == ToolboxAPI.PP_TOOLBOX) or \ (lang == 'pp' and toolType == ToolboxAPI.SL_TOOLBOX): report.Error(vdmServer + " is not a " + lang + "-server") if start_toolbox == 'yes': os.kill(pid, 9) return false else: print(vdmServer + " is a " + lang + "-server") clientID = vdmApp.Register() # run the testcases if not RunTestCases(lang, vdmApp, clientID): vdmApp.Unregister(clientID) if start_toolbox == 'yes': os.kill(pid, 9) return false except CORBA.COMM_FAILURE: report.Error("CORBA Communication error") vdmApp.Unregister(clientID) if start_toolbox == 'yes': os.kill(pid, 9) return false # clean up time.sleep(1) vdmApp.Unregister(clientID) if start_toolbox == 'yes': os.kill(pid, 9) os.system("tset") return true
def setProps(self, TuningRF=None, FilterBW=None, DesiredOutputRate=None, filterProps=None, TuneMode=None, TuningIF=None, TuningNorm=None): myProps = [] if TuningRF != None: self.TuningRF = TuningRF myProps.append( CF.DataType(id='TuningRF', value=CORBA.Any(CORBA.TC_ulonglong, self.TuningRF))) if FilterBW != None: self.FilterBW = FilterBW myProps.append( CF.DataType(id='FilterBW', value=CORBA.Any(CORBA.TC_float, self.FilterBW))) if DesiredOutputRate != None: self.DesiredOutputRate = DesiredOutputRate myProps.append( CF.DataType(id='DesiredOutputRate', value=CORBA.Any(CORBA.TC_float, self.DesiredOutputRate))) if filterProps != None: self.filterProps = filterProps myProps.append( CF.DataType( id='filterProps', value=CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ ossie.cf.CF.DataType( id='FFT_size', value=CORBA.Any(CORBA.TC_ulong, filterProps[0])), ossie.cf.CF.DataType( id='TransitionWidth', value=CORBA.Any(CORBA.TC_double, filterProps[1])), ossie.cf.CF.DataType( id='Ripple', value=CORBA.Any(CORBA.TC_double, filterProps[2])) ]))) if TuneMode != None: self.TuneMode = TuneMode myProps.append( CF.DataType(id='TuneMode', value=CORBA.Any(CORBA.TC_string, TuneMode))) if TuningIF != None: self.TuningIF = TuningIF myProps.append( CF.DataType(id='TuningIF', value=CORBA.Any(CORBA.TC_double, TuningIF))) if TuningNorm != None: self.TuningNorm = TuningNorm myProps.append( CF.DataType(id='TuningNorm', value=CORBA.Any(CORBA.TC_double, TuningNorm))) if myProps: print "configuring with ", myProps #configure it self.comp.configure(myProps) print self.comp.query([])
obj = extContext.resolve(name) except CosNaming.NamingContext.NotFound, ex: print "Name not found" sys.exit(-1) source_ref = obj._narrow(OTGraph.Network.OTEntity) if source_ref is None: print "Object found in NamingService is not of type OTEntity" sys.exit(-1) previous_time = time.time() period = 1.0 / rate while True: #ev = OTGraph.Event([0.1, 0.2, 0.3],[math.cos(math.pi/4), 0.0, math.sin(math.pi/4), 0.0], time.time()*1000.0, 0, 0.2) ev = [ OTGraph.EventAttribute( "position", CORBA.Any(CORBA.TypeCode("IDL:OTGraph/FloatVector:1.0"), [0.1, 0.2, 0.3])), OTGraph.EventAttribute("foo", any.to_any("bar")), OTGraph.EventAttribute("confidence", CORBA.Any(CORBA.TC_float, 0.053)), OTGraph.EventAttribute("timestamp", CORBA.Any(CORBA.TC_float, 1001.323)), OTGraph.EventAttribute("button", CORBA.Any(CORBA.TC_ushort, 6)) ] #,[math.cos(math.pi/4), 0.0, math.sin(math.pi/4), 0.0], time.time()*1000.0, 0, 0.2) try: print ".", source_ref.setEvent(ev, None) except CORBA.COMM_FAILURE: print "caught COMM_FAILURE" except CORBA.TRANSIENT: print "caught CORBA.TRANSIENT"
def testConfigureQueryStructs(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() val = 5 phrase = 'blah' flag = True charval = 'a' self.comp_obj.configure([ossie.cf.CF.DataType(id='structProp', value=CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ossie.cf.CF.DataType(id='structStringSimple', value=CORBA.Any(CORBA.TC_string, phrase)), ossie.cf.CF.DataType(id='structBoolSimple', value=CORBA.Any(CORBA.TC_boolean, flag)), ossie.cf.CF.DataType(id='structUlongSimple', value=CORBA.Any(CORBA.TC_ulong, val)), ossie.cf.CF.DataType(id='structShortSimple', value=CORBA.Any(CORBA.TC_short, val)), ossie.cf.CF.DataType(id='structFloatSimple', value=CORBA.Any(CORBA.TC_float, val)), ossie.cf.CF.DataType(id='structOctetSimple', value=CORBA.Any(CORBA.TC_octet, val)), ossie.cf.CF.DataType(id='structUshortSimple', value=CORBA.Any(CORBA.TC_ushort, val)), ossie.cf.CF.DataType(id='structDoubleSimple', value=CORBA.Any(CORBA.TC_double, val)), ossie.cf.CF.DataType(id='structLongSimple', value=CORBA.Any(CORBA.TC_long, val)), ossie.cf.CF.DataType(id='structLonglongSimple', value=CORBA.Any(CORBA.TC_longlong, val)), ossie.cf.CF.DataType(id='structUlonglongSimple', value=CORBA.Any(CORBA.TC_ulonglong, val)), ossie.cf.CF.DataType(id='structCharSimple', value=CORBA.Any(CORBA.TC_char, charval))]))]) ret = self.comp_obj.query([ossie.cf.CF.DataType(id='structProp', value=CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ossie.cf.CF.DataType(id='structShortSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structFloatSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structOctetSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structUlongSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structUshortSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structStringSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structDoubleSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structLonglongSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structBoolSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structLongSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structUlonglongSimple', value=any.to_any( None)), ossie.cf.CF.DataType(id='structCharSimple', value=any.to_any( None))]))]) for x in ret[0].value.value(): if x.id == 'structBoolSimple': boolCheck = x break self.assertEquals(x.value.value(), not flag, msg=str(x.value.value()) + ' != ' + str(not flag) + ' for structBoolSimple') ret[0].value.value().remove(x) for y in ret[0].value.value(): if y.id == 'structStringSimple': boolCheck = y break self.assertEquals(y.value.value(), phrase*2, msg=str(y.value.value()) + ' != ' + str(phrase*2) + ' for structStringSimple') ret[0].value.value().remove(y) for xx in ret[0].value.value(): if xx.id == 'structCharSimple': boolCheck = xx break self.assertEquals(xx.value.value(), charval.upper(), msg=str(xx.value.value()) + ' != ' + charval.upper() + ' for structCharSimple') ret[0].value.value().remove(xx) for z in ret[0].value.value(): self.assertEquals(z.value.value(), val*2, msg=str(z.value.value()) + ' != ' + str(val*2) + ' for ' + str(z.id))
def test_cppPropsRangeStructSeq(self): self.preconditions() # Struct with upper bound upper = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_octet, 255)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_short, 32767)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_ushort, 65535)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_long, 2147483647)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_ulong, 4294967295)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, 9223372036854775807L)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 18446744073709551615L)) ]) # Struct with lower bound lower = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_octet, 0)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_short, -32768)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_ushort, 0)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_long, -2147483648)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_ulong, 0)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 0)) ]) my_structseq = CF.DataType( id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [upper, lower])) self._app.configure([my_structseq]) # Make sure values all got set res = self._app.query([]) for r in res: if r.id == 'my_structseq': upper = r.value.value()[0] lower = r.value.value()[1] for v in upper.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 255) elif v.id == 'ss_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'ss_long': self.assertEquals(v.value.value(), 2147483647) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) elif v.id == 'ss_ulonglong': self.assertEquals(v.value.value(), 18446744073709551615L) for v in lower.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_short': self.assertEquals(v.value.value(), -32768) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_long': self.assertEquals(v.value.value(), -2147483648) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), -9223372036854775808L) elif v.id == 'ss_ulonglong': self.assertEquals(v.value.value(), 0)
def test_pythonPropsRangeStructSeq(self): self._app = self._launchApp('TestPythonPropsRange') # Struct with upper bound upper = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, 255)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, 32767)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, 65535)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, 2147483647)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, 4294967295)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_ulonglong, 9223372036854775807L)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 18446744073709551615L))]) # Struct with lower bound lower = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, 0)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, -32768)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, 0)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, -2147483648)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, 0)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_longlong, 0))]) my_structseq = CF.DataType(id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [ upper , lower ] )) self._app.configure([my_structseq]) # Make sure values all got set res = self._app.query([]) for r in res: if r.id == 'my_structseq': upper = r.value.value()[0] lower = r.value.value()[1] for v in upper.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 255) elif v.id == 'ss_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'ss_long': self.assertEquals(v.value.value(), 2147483647) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) elif v.id == 'ss_ulonglong': self.assertEquals(v.value.value(), 18446744073709551615L) for v in lower.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_short': self.assertEquals(v.value.value(), -32768) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_long': self.assertEquals(v.value.value(), -2147483648) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), -9223372036854775808L) elif v.id == 'ss_ulonglong': self.assertEquals(v.value.value(), 0) # Loop through each member of the struct to test one beyond the upper bound for r in res: if r.id == 'my_structseq': val = r.value.value()[1] for v in val.value(): # All default values are valid octet_val = 0 short_val = 0 ushort_val = 0 long_val = 0 ulong_val = 0 longlong_val = 0 ulonglong_val = 0 # Creates struct with only 1 invalid member, which will still cause invalid configuration if v.id == 'ss_octet': octet_val = 256 elif v.id == 'ss_short': short_val = 32768 elif v.id == 'ss_ushort': ushort_val = 65536 elif v.id == 'ss_long': long_val = 2147483648 elif v.id == 'ss_ulong': ulong_val = 4294967296 elif v.id == 'ss_longlong': longlong_val = 9223372036854775808L elif v.id == 'ss_ulonglong': # No value large enough to test outside range of ulonglong continue bad_struct = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, octet_val)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, short_val)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, ushort_val)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, long_val)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, ulong_val)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_ulonglong, longlong_val)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, ulonglong_val))]) my_structseq = CF.DataType(id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [ upper , bad_struct ] )) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_structseq]) # Loop through each member of the struct to test one beyond the lower bound for r in res: if r.id == 'my_structseq': val = r.value.value()[0] for v in val.value(): # All default values are valid octet_val = 0 short_val = 0 ushort_val = 0 long_val = 0 ulong_val = 0 longlong_val = 0 ulonglong_val = 0 # Creates struct with only 1 invalid member, which will still cause invalid configuration if v.id == 'ss_octet': octet_val = -1 elif v.id == 'ss_short': short_val = -32769 elif v.id == 'ss_ushort': ushort_val = -1 elif v.id == 'ss_long': long_val = -2147483649 elif v.id == 'ss_ulong': ulong_val = -1 elif v.id == 'ss_longlong': # No value to test below range of longlong continue elif v.id == 'ss_ulonglong': ulonglong_val = -1 bad_struct = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, octet_val)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, short_val)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, ushort_val)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, long_val)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, ulong_val)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, longlong_val)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_longlong, ulonglong_val))]) my_structseq = CF.DataType(id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [ bad_struct, lower ] )) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_structseq])
try: rate = float(sys.argv[2]) except IndexError: rate = 2.0 previous_time = time.time() period = 1.0 / rate omega = 1 r = 40 while True: t = time.time() ev = [ OT_CORBA.EventAttribute( "position", CORBA.Any( CORBA.TypeCode("IDL:OT_CORBA/FloatVector:1.0"), [r * math.cos(omega * t), r * math.sin(omega * t), 0.5])), OT_CORBA.EventAttribute( "orientation", CORBA.Any(CORBA.TypeCode("IDL:OT_CORBA/FloatVector:1.0"), [math.cos(omega * t), 0.0, 0.0, math.sin(omega * t)])), OT_CORBA.EventAttribute("foo", any.to_any("bar")), OT_CORBA.EventAttribute("confidence", CORBA.Any(CORBA.TC_float, 0.053)), OT_CORBA.EventAttribute("timestamp", CORBA.Any(CORBA.TC_float, 1001.323)), OT_CORBA.EventAttribute("button", CORBA.Any(CORBA.TC_ushort, 6)) ] #,[math.cos(math.pi/4), 0.0, math.sin(math.pi/4), 0.0], time.time()*1000.0, 0, 0.2) try: source_ref.setEvent(ev)
def test_AllPropTypeCallbacks(self): languages = ['Cpp', 'Python'] for lang in languages: self.launchApplication(lang) self.preconditions() res = self._app.query( [CF.DataType(id='simple_string', value=any.to_any(None))]) self._app.configure(res) res = self._app.query([]) self.checkValue(res, 'simple_string', '42', same=False) res = self._app.query([]) for r in res: if r.value._t == CORBA.TC_null: if r.id == 'simple_boolean': r.value = any.to_any(False) elif r.id == 'simple_char': r.value = any.to_any('o') r.value._t = CORBA.TC_char elif r.id == 'simple_string': r.value = any.to_any('foo') r.value._t = CORBA.TC_string elif r.id == 'simple_double': r.value = any.to_any(1.0) r.value._t = CORBA.TC_double elif r.id == 'simple_float': r.value = any.to_any(1.0) r.value._t = CORBA.TC_float elif r.id == 'simple_short': r.value = any.to_any(1) r.value._t = CORBA.TC_short elif r.id == 'simple_ushort': r.value = any.to_any(1) r.value._t = CORBA.TC_ushort elif r.id == 'simple_long': r.value = any.to_any(1) r.value._t = CORBA.TC_long elif r.id == 'simple_longlong': r.value = any.to_any(1) r.value._t = CORBA.TC_longlong elif r.id == 'simple_ulong': r.value = any.to_any(1) r.value._t = CORBA.TC_ulong elif r.id == 'simple_ulonglong': r.value = any.to_any(1) r.value._t = CORBA.TC_ulonglong elif r.id == 'simple_objref': r.value = any.to_any('o') r.value._t = CORBA.TC_string elif r.id == 'simple_octet': r.value = any.to_any(1) r.value._t = CORBA.TC_octet elif r.id == 'simple_sequence_boolean': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/BooleanSeq:1.0") elif r.id == 'simple_sequence_char': r.value = any.to_any('') r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/CharSeq:1.0") elif r.id == 'simple_sequence_double': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/DoubleSeq:1.0") elif r.id == 'simple_sequence_float': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/FloatSeq:1.0") elif r.id == 'simple_sequence_long': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/LongSeq:1.0") elif r.id == 'simple_sequence_longlong': r.value = any.to_any([]) r.value._t = _tcInternal.typeCodeFromClassOrRepoId( _PortTypes.LongLongSequence) elif r.id == 'simple_sequence_string': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/StringSeq:1.0") elif r.id == 'simple_sequence_objref': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/StringSeq:1.0") elif r.id == 'simple_sequence_octet': r.value = any.to_any('') r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/OctetSeq:1.0") elif r.id == 'simple_sequence_short': r.value = any.to_any([]) r.value._t = _tcInternal.typeCodeFromClassOrRepoId( CORBA.UShortSeq) elif r.id == 'simple_sequence_ulong': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/ULongSeq:1.0") elif r.id == 'simple_sequence_ulonglong': r.value = any.to_any([]) r.value._t = _tcInternal.typeCodeFromClassOrRepoId( _PortTypes.UlongLongSequence) elif r.id == 'simple_sequence_ushort': r.value = any.to_any([]) r.value._t = CORBA.TypeCode( "IDL:omg.org/CORBA/UShortSeq:1.0") if r.id == 'struct_vars': for item in r.value._v: if item.value._t != CORBA.TC_null: continue if item.id == 'struct_string': item.value = any.to_any('foo') item.value._t = CORBA.TC_string elif item.id == 'struct_boolean': item.value = any.to_any(False) elif item.id == 'struct_ulong': item.value = any.to_any(1) item.value._t = CORBA.TC_ulong elif item.id == 'struct_objref': item.value = any.to_any('o') item.value._t = CORBA.TC_string elif item.id == 'struct_short': item.value = any.to_any(1) item.value._t = CORBA.TC_short elif item.id == 'struct_float': item.value = any.to_any(1.0) item.value._t = CORBA.TC_float elif item.id == 'struct_octet': item.value = any.to_any(1) item.value._t = CORBA.TC_octet elif item.id == 'struct_char': item.value = any.to_any('o') item.value._t = CORBA.TC_char elif item.id == 'struct_ushort': item.value = any.to_any(1) item.value._t = CORBA.TC_ushort elif item.id == 'struct_double': item.value = any.to_any(1.0) item.value._t = CORBA.TC_double elif item.id == 'struct_long': item.value = any.to_any(1) item.value._t = CORBA.TC_long elif item.id == 'struct_longlong': item.value = any.to_any(1) item.value._t = CORBA.TC_longlong elif item.id == 'struct_ulonglong': item.value = any.to_any(1) item.value._t = CORBA.TC_ulonglong if type(r.value._v) == int or type(r.value._v) == long or type( r.value._v) == float: r.value._v = r.value._v + 1 elif r.value._t == CORBA.TC_char: r.value._v = 'o' elif type(r.value._v) == str: r.value._v = 'foo' elif type(r.value._v) == bool: r.value._v = False elif type(r.value._v) == list: if r.id == 'simple_sequence_string': r.value._v = ['foo'] elif r.id == 'simple_sequence_boolean': r.value._v = [False] elif r.id == 'simple_sequence_ulong': r.value._v = [1] elif r.id == 'simple_sequence_short': r.value._v = [1] elif r.id == 'simple_sequence_float': r.value._v = [1.0] elif r.id == 'simple_sequence_ushort': r.value._v = [1] elif r.id == 'simple_sequence_double': r.value._v = [1.0] elif r.id == 'simple_sequence_long': r.value._v = [1] elif r.id == 'simple_sequence_longlong': r.value._v = [1] elif r.id == 'simple_sequence_ulonglong': r.value._v = [1] if r.id == 'struct_seq': if r.value._v == []: seq_vars = CORBA.Any( CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='struct_seq_string', value=CORBA.Any( CORBA.TC_string, 'foo')), CF.DataType(id='struct_seq_boolean', value=CORBA.Any( CORBA.TC_boolean, False)), CF.DataType(id='struct_seq_ulong', value=CORBA.Any(CORBA.TC_ulong, 1)), CF.DataType(id='struct_seq_objref', value=CORBA.Any( CORBA.TC_string, 'o')), CF.DataType(id='struct_seq_short', value=CORBA.Any(CORBA.TC_short, 1)), CF.DataType(id='struct_seq_float', value=CORBA.Any( CORBA.TC_float, 1.0)), CF.DataType(id='struct_seq_octet', value=CORBA.Any(CORBA.TC_octet, 1)), CF.DataType(id='struct_seq_char', value=CORBA.Any( CORBA.TC_char, 'o')), CF.DataType(id='struct_seq_ushort', value=CORBA.Any( CORBA.TC_ushort, 1)), CF.DataType(id='struct_seq_double', value=CORBA.Any( CORBA.TC_double, 1.0)), CF.DataType(id='struct_seq_long', value=CORBA.Any(CORBA.TC_long, 1)), CF.DataType(id='struct_seq_longlong', value=CORBA.Any( CORBA.TC_longlong, 1)), CF.DataType(id='struct_seq_ulonglong', value=CORBA.Any( CORBA.TC_ulonglong, 1)), ]) r = CF.DataType( id='struct_seq', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [any.to_any(seq_vars)])) self._app.configure([r]) res = self._app.query([]) self.checkValue(res, 'simple_string', '42') self.checkValue(res, 'simple_boolean', True) self.checkValue(res, 'simple_ulong', 43) self.checkValue(res, 'simple_objref', '44') self.checkValue(res, 'simple_short', 45) self.checkValue(res, 'simple_float', 46.0) self.checkValue(res, 'simple_octet', 47) self.checkValue(res, 'simple_char', struct.pack('b', 48)) self.checkValue(res, 'simple_ushort', 49) self.checkValue(res, 'simple_double', 50.0) self.checkValue(res, 'simple_long', 51) self.checkValue(res, 'simple_longlong', 52) self.checkValue(res, 'simple_ulonglong', 53) self.checkValue(res, 'simple_sequence_string', '54') self.checkValue(res, 'simple_sequence_boolean', True) self.checkValue(res, 'simple_sequence_ulong', 55) # self.checkValue(res, 'simple_sequence_objref', '56') Broken in python self.checkValue(res, 'simple_sequence_short', 57) self.checkValue(res, 'simple_sequence_float', 58) # self.checkValue(res, 'simple_sequence_octet', struct.pack('B', 59)) Broken in python # self.checkValue(res, 'simple_sequence_char', struct.pack('b', 60)) Borken in python self.checkValue(res, 'simple_sequence_ushort', 61) self.checkValue(res, 'simple_sequence_double', 62) self.checkValue(res, 'simple_sequence_long', 63) self.checkValue(res, 'simple_sequence_longlong', 64) self.checkValue(res, 'simple_sequence_ulonglong', 65) self.checkValue(res, 'struct_vars', '66') self.checkValue(res, 'struct_seq', '67')
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))
def test_OptionalPropertiesInStruct(self): comp = sb.launch('TestJavaOptionalProps') octet_val = struct.pack('B', 0) + struct.pack('B', 255) my_struct = CF.DataType( id='my_struct', value=any.to_any([ CF.DataType(id='struct_octet', value=CORBA.Any(CORBA.TC_octet, 255)), CF.DataType(id='struct_short', value=CORBA.Any(CORBA.TC_short, 32767)), CF.DataType(id='struct_ushort', value=CORBA.Any(CORBA.TC_ushort, 65535)), CF.DataType(id='struct_long', value=CORBA.Any(CORBA.TC_long, 2147483647)), CF.DataType(id='struct_ulong', value=CORBA.Any(CORBA.TC_ulong, 4294967295)), CF.DataType(id='struct_longlong', value=CORBA.Any(CORBA.TC_longlong, 9223372036854775807L)), CF.DataType(id='struct_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 18446744073709551615L)), CF.DataType(id='struct_string', value=CORBA.Any(CORBA.TC_string, "new string")), CF.DataType( id='struct_seq_octet', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/OctetSeq:1.0"), octet_val)), CF.DataType( id='struct_seq_short', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/ShortSeq:1.0"), [0, 32767])), CF.DataType( id='struct_seq_ushort', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/UShortSeq:1.0"), [0, 65535])), CF.DataType(id='struct_seq_long', value=any.to_any([0, 2147483647])), CF.DataType(id='struct_seq_ulong', value=any.to_any([0, 4294967295])), CF.DataType(id='struct_seq_longlong', value=any.to_any([0, 9223372036854775807L])), #CF.DataType(id='struct_seq_ulonglong', value=any.to_any([0, 9223372036854775807L])) ])) comp.configure([my_struct]) res = comp.query([]) for r in res: if r.id == 'my_struct': val = r.value.value() for v in val: if v.id == 'struct_octet': self.assertEquals(v.value.value(), 255) elif v.id == 'struct_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'struct_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'struct_long': self.assertEquals(v.value.value(), 2147483647) elif v.id == 'struct_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'struct_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) elif v.id == 'struct_ulonglong': self.assertEquals(v.value.value(), 18446744073709551615L) elif v.id == 'struct_string': self.assertEquals(v.value.value(), "new string") elif v.id == 'struct_seq_octet': # Octets need to be unpacked stored_vals = v.value.value() vals = [] for num in stored_vals: curr = struct.unpack('B', num) vals.append(curr[0]) self.assertEquals(vals[0], 0) self.assertEquals(vals[1], 255) elif v.id == 'struct_seq_short': self.assertEquals(v.value.value(), [0, 32767]) elif v.id == 'struct_seq_ushort': self.assertEquals(v.value.value(), [0, 65535]) elif v.id == 'struct_seq_long': self.assertEquals(v.value.value(), [0, 2147483647]) elif v.id == 'struct_seq_ulong': self.assertEquals(v.value.value(), [0, 4294967295]) elif v.id == 'struct_seq_longlong': self.assertEquals(v.value.value(), [0, 9223372036854775807L]) #elif v.id == 'struct_seq_ulonglong': # self.assertEquals(v.value.value(), [0, 9223372036854775807L]) # Configure only certain properties my_struct = CF.DataType( id='my_struct', value=any.to_any([ CF.DataType(id='struct_octet', value=CORBA.Any(CORBA.TC_octet, 255)), CF.DataType(id='struct_short', value=CORBA.Any(CORBA.TC_short, 32767)), CF.DataType(id='struct_ushort', value=CORBA.Any(CORBA.TC_ushort, 65535)), #CF.DataType(id='struct_long', value=CORBA.Any(CORBA.TC_long, 2147483647)), CF.DataType(id='struct_ulong', value=CORBA.Any(CORBA.TC_ulong, 4294967295)), CF.DataType(id='struct_longlong', value=CORBA.Any(CORBA.TC_longlong, 9223372036854775807L)), #CF.DataType(id='struct_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 18446744073709551615L)), CF.DataType(id='struct_string', value=CORBA.Any(CORBA.TC_string, "new string")), CF.DataType( id='struct_seq_octet', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/OctetSeq:1.0"), octet_val)), CF.DataType( id='struct_seq_short', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/ShortSeq:1.0"), [0, 32767])), #CF.DataType(id='struct_seq_ushort', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/UShortSeq:1.0"), [0, 65535])), CF.DataType(id='struct_seq_long', value=any.to_any([0, 2147483647])), CF.DataType(id='struct_seq_ulong', value=any.to_any([0, 4294967295])), CF.DataType(id='struct_seq_longlong', value=any.to_any([0, 9223372036854775807L])), #CF.DataType(id='struct_seq_ulonglong', value=any.to_any([0, 9223372036854775807L])) ])) comp.configure([my_struct]) res = comp.query([]) for r in res: if r.id == 'my_struct': val = r.value.value() valIds = [v.id for v in val] self.assertTrue('struct_long' not in valIds) self.assertTrue('struct_ulonglong' not in valIds) self.assertTrue('struct_seq_ushort' not in valIds) self.assertTrue('struct_seq_ulonglong' not in valIds) for v in val: if v.id == 'struct_octet': self.assertEquals(v.value.value(), 255) if v.id == 'struct_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'struct_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'struct_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'struct_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) elif v.id == 'struct_string': self.assertEquals(v.value.value(), "new string") elif v.id == 'struct_seq_octet': # Octets need to be unpacked stored_vals = v.value.value() vals = [] for num in stored_vals: curr = struct.unpack('B', num) vals.append(curr[0]) self.assertEquals(vals[0], 0) self.assertEquals(vals[1], 255) elif v.id == 'struct_seq_short': self.assertEquals(v.value.value(), [0, 32767]) elif v.id == 'struct_seq_long': self.assertEquals(v.value.value(), [0, 2147483647]) elif v.id == 'struct_seq_ulong': self.assertEquals(v.value.value(), [0, 4294967295]) elif v.id == 'struct_seq_longlong': self.assertEquals(v.value.value(), [0, 9223372036854775807L])
class structProperty(Property): # All structs have the same CORBA typecode. typecode = _CORBA.TypeCode("IDL:CF/Properties:1.0") def __init__(self, id, valueType, compRef, defValue=None, parent=None, structSeqRef=None, structSeqIdx=None, mode='readwrite'): """ id - (string): the property ID valueType - (list): each entry in the list is a tuple defined in the following fashion: (id, valueType(as defined for simples), defValue) compRef - (domainless.componentBase) - pointer to the component that owns this property structSeqRef - (string) - name of the struct sequence that this struct is a part of, or None structSeqIdx - (int) - index of the struct int the struct sequence, or None mode - (string): mode for the property, must be in MODES """ if type(valueType) != list: raise('valueType must be provided as a list') self.valueType = valueType self.defValue = defValue #used when the struct is part of a struct sequence self.structSeqRef = structSeqRef self.structSeqIdx = structSeqIdx #initialize the parent Property.__init__(self, id, type='struct', compRef=compRef, mode=mode, action='external', parent=parent) #each of these members is itself a simple property self.members = {} for _id, _type, _defValue, _clean_name in valueType: if self.structSeqRef: simpleProp = simpleProperty(_id, _type, compRef=compRef, defValue=_defValue, parent=self, structRef=id, structSeqRef=self.structSeqRef, structSeqIdx=self.structSeqIdx) simpleProp.clean_name = _clean_name else: simpleProp = simpleProperty(_id, _type, compRef=compRef, defValue=_defValue, parent=self, structRef=id) simpleProp.clean_name = _clean_name self.members[_id] = (simpleProp) # DEPRECATED: create the CF.DataType reference self.propRef = _CF.DataType(id=str(self.id), value=_CORBA.Any(self.typecode, None)) def _queryValue(self): if self._isNested(): # Get the full struct sequence value. results = self._parent._queryValue() if results is None: return None return results.value()[self.structSeqIdx] else: # Standalone struct, do standard query. return super(structProperty,self)._queryValue() def fromAny(self, value): ''' Converts the input value in CORBA Any format to Python. ''' if value is None: return {} structVal = {} for simple in value.value(): member = self.members[simple.id] structVal[simple.id] = member.fromAny(simple.value) return structVal def toAny(self, value): ''' Converts the input value in Python format to a CORBA Any. ''' if value is None: props = [_CF.DataType(str(m.id), m.toAny(None)) for m in self.members.values()] return _CORBA.Any(self.typecode, props) if not isinstance(value, dict): raise TypeError, 'configureValue() must be called with dict instance as second argument (got ' + str(type(value))[7:-2] + ' instance instead)' # Check that the value passed in matches the struct definition self._checkValue(value) # Convert struct items into CF::Properties. props = [] for _id, member in self.members.iteritems(): memberVal = value.get(_id, member.defValue) props.append(_CF.DataType(str(_id), member.toAny(memberVal))) return _CORBA.Any(self.typecode, props) def _checkValue(self, value): for memberId in value: if memberId not in self.members: raise TypeError, "'%s' is not a member of '%s'" % (memberId, self.id) def _configureValue(self, value): # Check if this struct is a member of a struct sequence if self._isNested(): # Get the full struct sequence value. results = self._parent._queryValue() if results is None: return # Replace the struct in the list. results._v[self.structSeqIdx] = value # Configure the complete, updated struct sequence. self._parent._configureValue(results) else: # Standalone struct, do standard configure. super(structProperty,self)._configureValue(value) def configureValue(self, value): ''' Helper function for configuring a struct property, using a dictionary as the passed in value ''' if value is not None: # Fill in any missing member values from the current value. self._checkValue(value) for propId, propVal in self.queryValue().items(): if propId not in value: value[propId] = propVal super(structProperty,self).configureValue(value) def __str__(self): currValue = self.queryValue() structView = "ID: " + self.id for key in currValue: structView = structView + '\n ' + str(self.members[key].clean_name) + ": " + str(currValue[key]) return structView def __repr__(self): currValue = self.queryValue() structView = "ID: " + self.id for key in currValue: structView = structView + '\n ' + str(self.members[key].clean_name) + ": " + str(currValue[key]) print structView, return '' def __getattr__(self, name): ''' If the attribute being looked up is actually a member of the struct, then return that simple property, otherwise default to the normal getattribute function ''' try: return object.__getattribute__(self, "members")[_displayNames[self.compRef._refid][name]] except: return object.__getattribute__(self,name) def __setattr__(self, name, value): ''' If the attribute being looked up is actually a member of the struct, then try to configure the simple property. This will result in a configure of the entire struct in the simpleProperty class ''' try: self.members[_displayNames[self.compRef._refid][name]].configureValue(value) except AttributeError: return object.__setattr__(self, name, value) except KeyError: return object.__setattr__(self, name, value)
def test_javaPropsRangeStructSeq(self): self.assertNotEqual(self._domMgr, None, "DomainManager not available") self.assertNotEqual(self._devMgr, None, "DeviceManager not available") self.assertNotEqual(self._app, None, "Failed to launch app") # Struct with upper bound octet_val = struct.pack('B', 0) + struct.pack('B', 255) upper = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_octet, 255)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_short, 32767)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_ushort, 65535)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_long, 2147483647)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_ulong, 4294967295)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, 9223372036854775807L)), CF.DataType(id='ss_seq_octet', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/OctetSeq:1.0"), octet_val)), CF.DataType(id='ss_seq_short', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/ShortSeq:1.0"), [0, 32767])), CF.DataType(id='ss_seq_ushort', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/UShortSeq:1.0"), [0, 65535])), CF.DataType(id='ss_seq_long', value=any.to_any([0, 2147483647])), CF.DataType(id='ss_seq_ulong', value=any.to_any([0, 4294967295])), CF.DataType(id='ss_seq_longlong', value=any.to_any([0, 9223372036854775807L])), CF.DataType(id='ss_seq_ulonglong', value=any.to_any([0, 9223372036854775807L])) ]) # Struct with lower bound lower = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_octet, 0)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_short, -32768)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_ushort, 0)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_long, -2147483648)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_ulong, 0)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L)), CF.DataType(id='ss_seq_octet', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/OctetSeq:1.0"), octet_val)), CF.DataType(id='ss_seq_short', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/ShortSeq:1.0"), [-32768, 32767])), CF.DataType(id='ss_seq_ushort', value=CORBA.Any( CORBA.TypeCode("IDL:omg.org/CORBA/UShortSeq:1.0"), [0, 65535])), CF.DataType(id='ss_seq_long', value=any.to_any([-2147483648, 2147483647])), CF.DataType(id='ss_seq_ulong', value=any.to_any([0, 4294967295])), CF.DataType(id='ss_seq_longlong', value=any.to_any( [-9223372036854775808L, 9223372036854775807L])), CF.DataType(id='ss_seq_ulonglong', value=any.to_any([0, 9223372036854775807L])) ]) my_structseq = CF.DataType( id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [upper, lower])) self._app.configure([my_structseq]) # Make sure values all got set res = self._app.query([]) for r in res: if r.id == 'my_structseq': upper = r.value.value()[0] lower = r.value.value()[1] for v in upper.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 255) elif v.id == 'ss_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'ss_long': self.assertEquals(v.value.value(), 2147483647) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) elif v.id == 'ss_seq_octet': # Octets need to be unpacked stored_vals = v.value.value() vals = [] for num in stored_vals: curr = struct.unpack('B', num) vals.append(curr[0]) self.assertEquals(vals[0], 0) self.assertEquals(vals[1], 255) elif v.id == 'ss_seq_short': self.assertEquals(v.value.value(), [0, 32767]) elif v.id == 'ss_seq_ushort': self.assertEquals(v.value.value(), [0, 65535]) elif v.id == 'ss_seq_long': self.assertEquals(v.value.value(), [0, 2147483647]) elif v.id == 'ss_seq_ulong': self.assertEquals(v.value.value(), [0, 4294967295]) elif v.id == 'ss_seq_longlong': self.assertEquals(v.value.value(), [0, 9223372036854775807L]) elif v.id == 'ss_seq_ulonglong': self.assertEquals(v.value.value(), [0, 9223372036854775807L]) for v in lower.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_short': self.assertEquals(v.value.value(), -32768) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_long': self.assertEquals(v.value.value(), -2147483648) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), -9223372036854775808L) elif v.id == 'ss_seq_octet': # Octets need to be unpacked stored_vals = v.value.value() vals = [] for num in stored_vals: curr = struct.unpack('B', num) vals.append(curr[0]) self.assertEquals(vals[0], 0) self.assertEquals(vals[1], 255) elif v.id == 'ss_seq_short': self.assertEquals(v.value.value(), [-32768, 32767]) elif v.id == 'ss_seq_ushort': self.assertEquals(v.value.value(), [0, 65535]) elif v.id == 'ss_seq_long': self.assertEquals(v.value.value(), [-2147483648, 2147483647]) elif v.id == 'ss_seq_ulong': self.assertEquals(v.value.value(), [0, 4294967295]) elif v.id == 'ss_seq_longlong': self.assertEquals( v.value.value(), [-9223372036854775808L, 9223372036854775807L]) elif v.id == 'ss_seq_ulonglong': self.assertEquals(v.value.value(), [0, 9223372036854775807L])
# check if vdmApp has correct type try: if not vdmApp._is_a('IDL:ToolboxAPI/VDMApplication:1.0'): report.Error("This is not a 'VDMApplication'-server!") if start_toolbox == 'yes': os.kill(pid, 9) return false except CORBA.COMM_FAILURE: report.Error("No connection to 'VDMApplication'-object!") if start_toolbox == 'yes': os.kill(pid, 9) return false # narrow vdmApp and get typecode vdmApp = vdmApp._narrow(ToolboxAPI.VDMApplication) tc = CORBA.TypeCode('IDL:ToolboxAPI/VDMApplication:1.0') # check if server is the one we want (SL or PP) try: toolType = vdmApp._get_Tool() if (lang == 'sl' and toolType == ToolboxAPI.PP_TOOLBOX) or \ (lang == 'pp' and toolType == ToolboxAPI.SL_TOOLBOX): report.Error(vdmServer + " is not a " + lang + "-server") if start_toolbox == 'yes': os.kill(pid, 9) return false else: print vdmServer + " is a " + lang + "-server" clientID = vdmApp.Register()
def getNearestCoop(baselat, baselon, varmajor, sd, ed, detailed_check): import math from mx import DateTime from omniORB import CORBA import Meta, Data, ucanCallMethods NameAny = Meta.MetaQuery.NameAnyPair LatLonDistance = Meta.MetaQuery.LatLonDistance any = CORBA.Any tc = CORBA.TypeCode tc_shortseq = tc(Meta.ShortSeq) tc_floatseq = tc(Meta.FloatSeq) tc_LatLonDistance = CORBA.TypeCode(Meta.MetaQuery.LatLonDistance) ucan = ucanCallMethods.general_ucan() if detailed_check == 1: sd_dt = DateTime.DateTime(sd[0], sd[1], sd[2], 0) ed_dt = DateTime.DateTime(ed[0], ed[1], ed[2], 0) search_rad = 40. # initial radius 40 miles non_matches = [] query = ucan.get_query() while search_rad < 101: qual = [ NameAny('var_major_id', any(tc_shortseq, [varmajor])), NameAny('begin_date', any(tc_shortseq, sd)), NameAny('end_date', any(tc_shortseq, ed)), NameAny( 'near_latlon', any(tc_LatLonDistance, LatLonDistance(baselat, baselon, search_rad, 'miles'))), ] results = query.getStnInfoAsSeq(qual, ('coop_id', )) if len(results) > 0: for r in results: d = ucanCallMethods.NameAny_to_dict(r) cid = d.get('coop_id', '') uid = d.get('ucan_id', '') if cid != '' and uid != '': if cid in non_matches: continue #already checked if detailed_check == 1: # Make sure the valid date range is within dates of interest try: data_daily = ucan.get_data() vals = None vals = data_daily.newTSVar(varmajor, 0, uid) dates = vals.getValidDateRange() svd_dt = DateTime.DateTime(*dates[0]) evd_dt = DateTime.DateTime(*dates[1]) vals.release() except: if vals: vals.release() non_matches.append(cid) output = ucanCallMethods.print_exception() for i in output: print i continue if detailed_check == 0 or \ (detailed_check == 1 and sd_dt >= svd_dt and ed_dt <= evd_dt): query.release() return (cid) else: non_matches.append(cid) search_rad = search_rad + 60. #increase radius by 60 miles query.release() return (-1)
try: type_name = str(simple_data.__class__.__name__) except Exception, e: self.logger.logWarning(str(e)) print_exc() type_name = str(CORBA.id(simple_data)) elif (simple_data == None): raise CouldntPerformActionExImpl(nvSeq=[ NameValue("channelname", self.channelName), NameValue("reason", "Empty data") ]) #create the CORBA Any in the "normal" manner first. If this #fails, try omniORB's any helper module designed for simple types. try: corba_any = CORBA.Any(CORBA.TypeCode(CORBA.id(simple_data)), simple_data) except Exception, e: self.logger.logTrace(str(e)) try: corba_any = any.to_any(simple_data) except Exception, e: print_exc() raise TypeNotSupportedExImpl(nvSeq=[ NameValue("channelname", self.channelName), NameValue("exception", str(e)), NameValue("reason", "Data not a CORBA type") ]) #Create the real structured event. Look at CosNotification.idl to see these definitions fixed_header = CosNotification.FixedEventHeader(