Example #1
0
def _convertToCorbaAny(value):
    from sys import version_info

    if version_info.major > 2:
        integers = (int, )
    else:
        integers = (
            long,  # noqa: F821
            int,
        )
    import CORBA

    t = type(value)
    if t is float:
        return CORBA.Any(CORBA.TC_double, value)
    elif isinstance(value, bool):
        return CORBA.Any(CORBA.TC_boolean, value)
    elif isinstance(value, integers):
        return CORBA.Any(CORBA.TC_longlong, value)
    elif isinstance(value, str):
        return CORBA.Any(CORBA.TC_string, value)
    elif isinstance(value, (list, tuple)):
        if isinstance(value[0], (list, tuple)):
            return CORBA.Any(CORBA.TypeCode("IDL:hpp/floatSeqSeq:1.0"), value)
        else:
            return CORBA.Any(CORBA.TypeCode("IDL:hpp/floatSeq:1.0"), value)
    else:  # Assume value is already a CORBA.Any
        return value
Example #2
0
	def test_any(self):
		import random
		pick = random.randint(0, 2)
		if pick == 0:
			return CORBA.Any(CORBA.TypeCode("IDL:CORBA/String:1.0"), "abc123")
		elif pick == 1:
			return CORBA.Any(CORBA.TypeCode("IDL:CORBA/Short:1.0"), 42)
		elif pick == 2:
			new_props = Fruit.Properties(name = "pineapple", color = Fruit.yellow)
			return CORBA.Any(CORBA.TypeCode(new_props), new_props)
    def test28_typecode(self):
        '''TypeCodes'''
        objref = factory.getAnyServer()

        inarg = CORBA.TypeCode('IDL:matecorba/test/ArrayUnion:1.0')
        inoutarg = CORBA.TypeCode('IDL:matecorba/test/AnyServer:1.0')
        retn, inout, out = objref.opTypeCode(inarg, inoutarg)

        assert retn == CORBA.TypeCode(
            'IDL:matecorba/test/VariableLengthStruct:1.0')
        assert inout == CORBA.TypeCode('IDL:matecorba/test/TestException:1.0')
        assert out == CORBA.TypeCode('IDL:matecorba/test/AnEnum:1.0')
Example #4
0
def _convertToCorbaAny(value):
    import CORBA
    t = type(value)
    if t is float:
        return CORBA.Any(CORBA.TC_double, value)
    elif isinstance(value, bool):
        return CORBA.Any(CORBA.TC_boolean, value)
    elif isinstance(value, (long, int)):
        return CORBA.Any(CORBA.TC_longlong, value)
    elif isinstance(value, str):
        return CORBA.Any(CORBA.TC_string, value)
    elif isinstance(value, (list, tuple)):
        if isinstance(value[0], (list, tuple)):
            return CORBA.Any(CORBA.TypeCode("IDL:hpp/floatSeqSeq:1.0"), value)
        else:
            return CORBA.Any(CORBA.TypeCode("IDL:hpp/floatSeq:1.0"), value)
    else:  # Assume value is already a CORBA.Any
        return value
Example #5
0
 def getEvent(self):
     t = time.time()
     x = self.radius * cos(self.omega * t)
     y = self.radius * sin(self.omega * t)
     z = 0.0
     alpha = self.omega * t
     qx, qy, qz, qw = 0.0, 0.0, sin(alpha * 0.5), cos(alpha * 0.5)
     return [
         OT_CORBA.EventAttribute(
             "position",
             CORBA.Any(CORBA.TypeCode("IDL:OT_CORBA/FloatVector:1.0"),
                       [x, y, z])),
         OT_CORBA.EventAttribute(
             "orientation",
             CORBA.Any(CORBA.TypeCode("IDL:OT_CORBA/FloatVector:1.0"),
                       [qx, qy, qz, qw])),
         OT_CORBA.EventAttribute("timestamp", any.to_any(t))
     ]
 def opAnyStruct(self, inArg, inoutArg):
     tc = CORBA.TypeCode('IDL:matecorba/test/VariableLengthStruct:1.0')
     assert inArg.typecode() == tc
     assert inArg.value().a == constants.STRING_IN
     assert inoutArg.typecode() == tc
     assert inoutArg.value().a == constants.STRING_INOUT_IN
     return (CORBA.Any(tc, matecorba.test.VariableLengthStruct(constants.STRING_RETN)),
             CORBA.Any(tc, matecorba.test.VariableLengthStruct(constants.STRING_INOUT_OUT)),
             CORBA.Any(tc, matecorba.test.VariableLengthStruct(constants.STRING_OUT)))
 def opAnyString(self, inArg, inoutArg):
     tc = CORBA.TypeCode('IDL:omg.org/CORBA/string:1.0')
     assert inArg.typecode() == tc
     assert inArg.value() == constants.STRING_IN
     assert inoutArg.typecode() == tc
     assert inoutArg.value() == constants.STRING_INOUT_IN
     return (CORBA.Any(tc, constants.STRING_RETN),
             CORBA.Any(tc, constants.STRING_INOUT_OUT),
             CORBA.Any(tc, constants.STRING_OUT))
Example #8
0
 def getEvent(self):
     t = time.time()
     x = self.a * cos(self.omega * t)
     y = 1.7
     z = self.b * sin(self.omega * t)
     xdot = -self.a * self.omega * sin(self.omega * t)
     zdot = self.b * self.omega * cos(self.omega * t)
     theta = atan2(xdot, zdot)
     alpha = theta
     qx, qy, qz, qw = 0.0, sin(alpha * 0.5), 0.0, cos(alpha * 0.5)
     return [
         OT_CORBA.EventAttribute(
             "position",
             CORBA.Any(CORBA.TypeCode("IDL:OT_CORBA/FloatVector:1.0"),
                       [x, y, z])),
         OT_CORBA.EventAttribute(
             "orientation",
             CORBA.Any(CORBA.TypeCode("IDL:OT_CORBA/FloatVector:1.0"),
                       [qx, qy, qz, qw])),
         OT_CORBA.EventAttribute("timestamp", any.to_any(t))
     ]  #OT_CORBA.Event([x, y, z], [qx, qy, qz, qw], t, 0, 0.5)
    def test27_any_equivalence(self):
        '''anys equivalence'''

        tc = CORBA.TypeCode('IDL:matecorba/test/unionSeq:1.0')
        seq = [
            test.VariableLengthUnion(4, CORBA.TRUE),
            test.VariableLengthUnion(2, 'blah'),
            test.VariableLengthUnion(55, constants.LONG_IN)
        ]
        a = CORBA.Any(tc, seq)
        b = CORBA.Any(tc, seq)

        assert a == b
    def test23_any_string(self):
        '''any with strings'''
        objref = factory.getAnyServer()

        tc = CORBA.TypeCode('IDL:omg.org/CORBA/string:1.0')
        retn, inout, out = objref.opAnyString(
            CORBA.Any(tc, constants.STRING_IN),
            CORBA.Any(tc, constants.STRING_INOUT_IN))

        assert retn.typecode() == tc
        assert retn.value() == constants.STRING_RETN
        assert inout.typecode() == tc
        assert inout.value() == constants.STRING_INOUT_OUT
        assert out.typecode() == tc
        assert out.value() == constants.STRING_OUT
    def test25_any_struct(self):
        '''any with structs'''
        objref = factory.getAnyServer()

        tc = CORBA.TypeCode('IDL:matecorba/test/VariableLengthStruct:1.0')
        inarg = CORBA.Any(tc, test.VariableLengthStruct(constants.STRING_IN))
        inoutarg = CORBA.Any(
            tc, test.VariableLengthStruct(constants.STRING_INOUT_IN))

        retn, inout, out = objref.opAnyStruct(inarg, inoutarg)

        assert retn.typecode() == tc
        assert retn.value().a == constants.STRING_RETN
        assert inout.typecode() == tc
        assert inout.value().a == constants.STRING_INOUT_OUT
        assert out.typecode() == tc
        assert out.value().a == constants.STRING_OUT
    def test26_any_exception(self):
        '''any with exception'''

        tc = CORBA.TypeCode('IDL:matecorba/test/TestException:1.0')
        any = CORBA.Any(tc, test.TestException('reason', 42, [], factory))
        del any
 def opStructAny(self):
     tc = CORBA.TypeCode('IDL:omg.org/CORBA/long:1.0')
     return matecorba.test.StructAny(constants.STRING_IN,
                                 CORBA.Any(tc, constants.LONG_IN))
 def opTypeCode(self, inArg, inoutArg):
     assert inArg == CORBA.TypeCode('IDL:matecorba/test/ArrayUnion:1.0')
     assert inoutArg == CORBA.TypeCode('IDL:matecorba/test/AnyServer:1.0')
     return (CORBA.TypeCode('IDL:matecorba/test/VariableLengthStruct:1.0'),
             CORBA.TypeCode('IDL:matecorba/test/TestException:1.0'),
             CORBA.TypeCode('IDL:matecorba/test/AnEnum:1.0'))
 def opAnyStrSeq(self):
     tc = CORBA.TypeCode('IDL:matecorba/test/StrSeq:1.0')
     return CORBA.Any(tc, [ 'foo' ] * 16)