def test_javaPropsRangeStruct(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 bounds 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)) ])) self._app.configure([my_struct]) res = self._app.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) # Test lower bounds my_struct = CF.DataType(id='my_struct', value=any.to_any([ CF.DataType(id='struct_octet', value=CORBA.Any(CORBA.TC_octet, 0)), CF.DataType(id='struct_short', value=CORBA.Any(CORBA.TC_short, -32768)), CF.DataType(id='struct_ushort', value=CORBA.Any(CORBA.TC_ushort, 0)), CF.DataType(id='struct_long', value=CORBA.Any(CORBA.TC_long, -2147483648)), CF.DataType(id='struct_ulong', value=CORBA.Any(CORBA.TC_ulong, 0)), CF.DataType(id='struct_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L)) ])) self._app.configure([my_struct]) res = self._app.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(), 0) elif v.id == 'struct_short': self.assertEquals(v.value.value(), -32768) elif v.id == 'struct_ushort': self.assertEquals(v.value.value(), 0) elif v.id == 'struct_long': self.assertEquals(v.value.value(), -2147483648) elif v.id == 'struct_ulong': self.assertEquals(v.value.value(), 0) elif v.id == 'struct_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_get_rows_dict_multiple_rows(self): """ get_rows_dict returns multiple rows correctly. """ self.init_itertable(self.pagetable_mock, columnDesc=["c1", "c2"], start=0, numPageRows=1, numRows=20, pageSize=10) self.pagetable_mock._set_pageSize(11) self.itertable_update(self.pagetable_mock) for i in range(5, 16): self.pagetable_mock.getRow(i).AndReturn([ CORBA.Any(CORBA.TC_string, 'test value %i.1' % i), CORBA.Any(CORBA.TC_string, 'test value %i.2' % i) ]) self.pagetable_mock.getRowId(i).AndReturn(i) self.corba_mock.ReplayAll() table = IterTable("test_req_object", test_corba_session_string, pagesize=10) rows = table.get_rows_dict(start=5, limit=11) assert len(rows) == 11 assert len(rows[6]) == 3 assert rows[6].get(u'Id') == u'11' assert rows[6].get(u'c1') == u'test value 11.1' assert rows[6].get(u'c2') == u'test value 11.2'
def test_next(self): """ IterTable works as an iterator (`for row in itertable` expression works). """ self.init_itertable(self.pagetable_mock, columnDesc=["c1", "c2"], start=0, numPageRows=10, numRows=20, pageSize=5) for i in range(0, 10): self.pagetable_mock.getRow(i).AndReturn([ CORBA.Any(CORBA.TC_string, 'test value %i.1' % i), CORBA.Any(CORBA.TC_string, 'test value %i.2' % i) ]) self.pagetable_mock.getRowId(i).AndReturn(i) self.corba_mock.ReplayAll() table = IterTable("test_req_object", test_corba_session_string, pagesize=5) for i, row in enumerate(table): assert row is not None assert len(row) == 3 if i == 0: assert row[0].get(u'value') == "" else: assert row[0].get(u'value') == str(i) self.corba_mock.VerifyAll()
def sup_evfn(objnm, idx, bsize, num_events, num_batches, verbose): "Supply CosNotification::StructuredEvent vals containing ULTest::UL events" # initialize supply stats for idx, if necessary if (not sup_total.has_key(idx)): sup_total[idx] = 0 # the rest of the supply method if ((verbose > 0) and (num_batches != 0)): print objnm, ": ------------------------------------------------------------" print objnm, ": sup_evfn supplying batch #", num_batches batch = [] while (len(batch) < bsize): if (verbose > 0): print objnm, ": sup_evfn: supplying event #", num_events sup_total[idx] += 1 # build an event etype = CosNotification.EventType("ULTest", "UL") ename = "foo" fhdr = CosNotification.FixedEventHeader(etype, ename) vhdr = [] hdr = CosNotification.EventHeader(fhdr, vhdr) f1pair = CosNotification.Property( "ul", CORBA.Any(CORBA._tc_ulong, num_events)) fdata = [f1pair] rob = CORBA.Any(CORBA._tc_ulong, num_events) ev = CosNotification.StructuredEvent(hdr, fdata, rob) if (verbose > 0): print objnm, ": sup_evfn: event with type ULTest::UL with $ul == ", num_events num_events += 1 batch.append(ev) if (verbose > 0): print objnm, ": sup_evfn: returning event batch of length", len(batch) if (num_batches != 0): print objnm, ": ------------------------------------------------------------" return batch
def test_externalAndACProp(self): self._createApp("") # Make sure external props that are in the AC can be accessed by either ID cppPropExt = CF.DataType(id="ext_prop_long", value=CORBA.Any(CORBA.TC_long, -11)) cppPropQueryExt = CF.DataType(id="ext_prop_long", value=any.to_any(None)) cppProp = CF.DataType(id="DCE:9d1e3621-27ca-4cd0-909d-90b7448b8f71", value=CORBA.Any(CORBA.TC_long, -22)) cppPropQuery = CF.DataType( id="DCE:9d1e3621-27ca-4cd0-909d-90b7448b8f71", value=any.to_any(None)) self._app.configure([cppProp]) self.assertEquals( self._app.query([cppPropQuery])[0].value.value(), -22) self.assertEquals( self._app.query([cppPropQueryExt])[0].value.value(), -22) self._app.configure([cppPropExt]) self.assertEquals( self._app.query([cppPropQuery])[0].value.value(), -11) self.assertEquals( self._app.query([cppPropQueryExt])[0].value.value(), -11)
def test_get_rows_dict(self): """ get_rows_dict returns correct rows when no arguments are given. """ self.init_itertable(columnDesc=["c1", "c2"], page=1, pageSize=2, start=5, numRows=10, numPageRows=2) self.pagetable_mock.getRow.side_effect = lambda row_num: \ {5: [CORBA.Any(CORBA.TC_string, 'test value 1.1'), CORBA.Any(CORBA.TC_string, 'test value 1.2')], 6: [CORBA.Any(CORBA.TC_string, 'test value 2.1'), CORBA.Any(CORBA.TC_string, 'test value 2.2')], }[row_num] self.pagetable_mock.getRowId.side_effect = lambda row_num: row_num table = IterTable('test_req_object', test_corba_session_string, pagesize=2) rows = table.get_rows_dict() assert_equal(len(rows), 2) assert_equal(len(rows[0]), 3) assert_equal(rows[0].get(u'Id'), u'5') assert_equal(rows[0].get(u'c1'), u'test value 1.1') assert_equal(rows[0].get(u'c2'), u'test value 1.2') assert_equal(len(rows[1]), 3) assert_equal(rows[1].get(u'Id'), u'6') assert_equal(rows[1].get(u'c1'), u'test value 2.1') assert_equal(rows[1].get(u'c2'), u'test value 2.2')
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 testBadAlpha(self): """Send in some bad alpha values and ensure it stays between 0 and 1 """ self.setProps(alpha=1.5) input = [random.random() for _ in xrange(1024)] output = self.main(input) res = self.comp.query( [CF.DataType(id='alpha', value=CORBA.Any(CORBA.TC_float, 0.0))]) self.assertTrue(0 < res[0].value.value() < 1) self.setProps(alpha=-5.0) output = self.main(input) res = self.comp.query( [CF.DataType(id='alpha', value=CORBA.Any(CORBA.TC_float, 0.0))]) self.assertTrue(0 < res[0].value.value() < 1)
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 initialize(self): bogomipsId = "DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8" self.devMgr = self.domMgr._get_deviceManagers()[0] self.device = self.devMgr._get_registeredDevices()[0] self.props = [ CF.DataType(bogomipsId, CORBA.Any(CORBA.TC_long, 100000000 / 100)) ]
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 sup_evfn(objnm, idx, bsize, num_events, num_batches, verbose): "Supply CosNotification::StructuredEvent vals w/ Stock::Ticker,Bond::Ticker events" # initialize supply stats for idx, if necessary if (not sup_total.has_key(idx)): sup_total[idx] = 0 # the rest of the supply method if ((verbose > 0) and (num_batches != 0)): print objnm, ": ------------------------------------------------------------" print objnm, ": sup_evfn supplying batch #", num_batches batch = [] while (len(batch) < bsize): if (verbose > 0): print objnm, ": sup_evfn: supplying event #", num_events counter = sup_total[idx] % 10 sup_total[idx] += 1 d = "Bond" if (counter < 5): d = "Stock" name = __sample_stockbond_nm[counter] val = __sample_stockbond_val[counter] # Update value -- we are nice and do not let the value drop below 5 if (val <= 5): __sample_stockbond_val[counter] += random.choice([0, 1]) else: __sample_stockbond_val[counter] += random.choice([-1, 0, 1]) # build an event etype = CosNotification.EventType(d, "Ticker") ename = "foo" fhdr = CosNotification.FixedEventHeader(etype, ename) vhdr = [] hdr = CosNotification.EventHeader(fhdr, vhdr) f1pair = CosNotification.Property("Name", CORBA.Any(CORBA._tc_string, name)) f2pair = CosNotification.Property("Value", CORBA.Any(CORBA._tc_ulong, val)) fdata = [f1pair, f2pair] rob = CORBA.Any(CORBA._tc_ulong, num_events) ev = CosNotification.StructuredEvent(hdr, fdata, rob) num_events += 1 if (verbose > 0): print objnm, ": sup_evfn: event with type", d + "::Ticker, Company", name, "Value", val batch.append(ev) if (verbose > 0): print objnm, ": sup_evfn: returning event batch of length", len(batch) if (num_batches != 0): print objnm, ": ------------------------------------------------------------" return batch
def test_deallocate_overage_java(self): from ossie.utils import sb self.dev = sb.launch('DevC', impl="java", configure={'myulong': 3}) res = self.dev.allocateCapacity({'myulong': 3}) self.assertEquals(res, True) a = [ CF.DataType(id='myulong', value=CORBA.Any(CORBA.TC_ulong, 3)), CF.DataType(id='myulong', value=CORBA.Any(CORBA.TC_ulong, 3)) ] self.assertRaises(CF.Device.InvalidCapacity, self.dev.deallocateCapacity, a) self.dev.releaseObject() self.dev = None sb.release()
def try_pull(self): "channel tries to pull an event" data = self.L_try_pull(1) if (data == None): a = CORBA.Any(CORBA._tc_null, None) return a, CORBA.FALSE # has_event = false a = data[0] return a, CORBA.TRUE # has_event = true
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 test_deallocate_overage_node_java(self): domBooter, self._domMgr = self.launchDomainManager() devBooter, self._devMgr = self.launchDeviceManager( "/nodes/invalid_capacity/DeviceManager.dcd.xml.overage.java") from ossie.utils import redhawk dom = redhawk.attach(scatest.getTestDomainName()) d = dom.devices[0] self.assertNotEquals(d, None) res = d.allocateCapacity({'myulong': 3}) self.assertEquals(res, True) a = [ CF.DataType(id='myulong', value=CORBA.Any(CORBA.TC_ulong, 3)), CF.DataType(id='myulong', value=CORBA.Any(CORBA.TC_ulong, 3)) ] self.assertRaises(CF.Device.InvalidCapacity, d.deallocateCapacity, a)
def L_connect_helper(self): "connect self to my_proxy" # first change MaximumBatchSize prop1 = CosNotification.Property("MaximumBatchSize", CORBA.Any(CORBA._tc_long, self.__batch_size)) self.__my_proxy.set_qos( [prop1] ) # connect self.__my_proxy.connect_sequence_push_consumer(self._this())
def setParameters (hpp, name, params): if isinstance(params, dict): for k, v in params.items(): setParameters (hpp, name + "/" + k, v) elif python_to_corba.has_key(type(params)): hpp.problem.setParameters(name, CORBA.Any(python_to_corba[type(params)], params)) else: rospy.logwarn("Could not set parameter " + name + " with value " + str(params) + " of unknown type " + str(type(params)))
def _runTest(self, dataTypeTest): # Create a property structure prop = CF.DataType(id=dataTypeTest.id, value=CORBA.Any(dataTypeTest.typecode, dataTypeTest.default)) # Check the default property value via query defaultProps = self._app.query([prop]) self._compareComplexValues(defaultProps[0].value.value(), dataTypeTest.override)
def testAccessRules(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() #try to configure a read only property should fail self.assertRaises(resource.CF.PropertySet.InvalidConfiguration, self.comp_obj.configure, [ossie.cf.CF.DataType(id='simpleROnly', value=CORBA.Any(CORBA.TC_short, 0))]) #try to query a write only property should fail self.assertRaises(ossie.cf.CF.UnknownProperties, self.comp_obj.query, [ossie.cf.CF.DataType(id='simpleWOnly', value=any.to_any(None))]) #try to configure an execparam should fail if it isn't configure as well self.assertRaises(resource.CF.PropertySet.InvalidConfiguration, self.comp_obj.configure, [ossie.cf.CF.DataType(id='simpleExec', value=CORBA.Any(CORBA.TC_short, 0))]) #THIS TEST IS NOT BEING USED. It was determined by the REDHAWK Team that this is a valid action due #to the fact that it may be unclear to someone that they need to check the configure box in order #to be able to configure/query an execparam, but that it is a justifiable assumption that you would #be able to query an execparam no matter what # #try to query an execparam should fail if it isn't configure as well # self.assertRaises(ossie.cf.CF.UnknownProperties, self.comp_obj.query, # [ossie.cf.CF.DataType(id='simpleExec', value=any.to_any(None))]) #try to configure and query and execparam that is also configure should not fail confval = 100 self.comp_obj.configure([ossie.cf.CF.DataType(id='simpleConfNExec', value=CORBA.Any(CORBA.TC_short, confval))]) curval = self.comp_obj.query([ossie.cf.CF.DataType(id='simpleConfNExec', value=any.to_any(None))])[0].value.value() self.assertEquals(confval, curval) #try to configure and query and the kitchen sink, should work fine confval = 'blah' self.comp_obj.configure([ossie.cf.CF.DataType(id='simpleKitchenSink', value=CORBA.Any(CORBA.TC_string, confval))]) curval = self.comp_obj.query([ossie.cf.CF.DataType(id='simpleKitchenSink', value=any.to_any(None))])[0].value.value() self.assertEquals(confval, curval)
def test_InvalidCapacity_node(self): domBooter, self._domMgr = self.launchDomainManager() devBooter, self._devMgr = self.launchDeviceManager("/nodes/invalid_capacity/DeviceManager.dcd.xml.java") from ossie.utils import redhawk dom=redhawk.attach(scatest.getTestDomainName()) dev=dom.devices[0] self.assertNotEquals(dev,None) b=[ CF.DataType(id='myulong', value=CORBA.Any(CORBA.TC_ulong,3))] self.assertRaises(CF.Device.InvalidCapacity, dev.allocateCapacity, b)
def testEventPortSendFunction(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') propIDs = ['eventShortSimple', 'eventStringSimple', 'eventBoolSimple', 'eventUlongSimple', 'eventFloatSimple', 'eventOctetSimple', 'eventCharSimple', 'eventUshortSimple', 'eventDoubleSimple', 'eventLongSimple', 'eventLonglongSimple', 'eventUlonglongSimple', 'eventStringSeq', 'eventBoolSeq', 'eventUlongSeq', 'eventFloatSeq', 'eventOctetSeq', 'eventCharSeq', 'eventUshortSeq', 'eventDoubleSeq', 'eventLongSeq', 'eventLonglongSeq', 'eventUlonglongSeq', 'eventShortSeq', 'eventStruct', 'eventStructSeq'] for propID in propIDs: #test that the internal code sends out an event for each of these properties self.comp_obj.configure([ossie.cf.CF.DataType(id='propToSend', value=CORBA.Any(CORBA.TC_string, propID))]) eventSent = False while not eventSent: ret = self.comp_obj.query([ossie.cf.CF.DataType(id='eventSent',value=any.to_any(None))])[0] if ret.value.value(): eventSent = True time.sleep(.003) #allow the event send to complete in the other thread event = consumerPort.getEvent() if not event: self.fail("No event was generated for " + str(propID))
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 dummy_event(): # build a dummy event etype = CosNotification.EventType("", "") ename = "" fhdr = CosNotification.FixedEventHeader(etype, ename) vhdr = [] hdr = CosNotification.EventHeader(fhdr, vhdr) fdata = [] rob = CORBA.Any(CORBA._tc_null, None) ev = CosNotification.StructuredEvent(hdr, fdata, rob) return ev
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 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 toAny(value, type): if type in ("short", "long", "octet", "ulong", "ushort"): value = int(value) elif type in ("float", "double"): value = float(value) elif type == "boolean": value = str(value.lower()) in ("true", "1") elif type == "longlong": value = long(value) elif type == "char": value = value[0] return CORBA.Any(TYPE_MAP[type], value)
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 test_get_rows_dict(self): """ get_rows_dict returns correct rows when no arguments are given. """ self.init_itertable(self.pagetable_mock, columnDesc=["c1", "c2"], page=1, pageSize=2, start=5, numRows=10, numPageRows=2) self.pagetable_mock.getRow(5).AndReturn([ CORBA.Any(CORBA.TC_string, 'test value 1.1'), CORBA.Any(CORBA.TC_string, 'test value 1.2') ]) self.pagetable_mock.getRowId(5).AndReturn(5) self.pagetable_mock.getRow(6).AndReturn([ CORBA.Any(CORBA.TC_string, 'test value 2.1'), CORBA.Any(CORBA.TC_string, 'test value 2.2') ]) self.pagetable_mock.getRowId(6).AndReturn(6) self.corba_mock.ReplayAll() table = IterTable("test_req_object", test_corba_session_string, pagesize=2) rows = table.get_rows_dict() assert len(rows) == 2 assert len(rows[0]) == 3 assert rows[0].get(u'Id') == u'5' assert rows[0].get(u'c1') == u'test value 1.1' assert rows[0].get(u'c2') == u'test value 1.2' assert len(rows[1]) == 3 assert rows[1].get(u'Id') == u'6' assert rows[1].get(u'c1') == u'test value 2.1' assert rows[1].get(u'c2') == u'test value 2.2' self.corba_mock.VerifyAll()