Example #1
0
    def __init__(self, profile,nv_dict=None, handle=None) :
        Port.__init__(self, profile, nv_dict, handle)
        con_prop_dict={'dataport.dataflow_type':'pull',
		       'dataport.buffer.type':'ringbuffer',
                       'dataport.buffer.read.empty_policy':'last',
		       'dataport.buffer.length':'1'}
        self.con = IOConnector([self], prop_dict=con_prop_dict)
        self.get_info()
#        if 'dataport.corba_any.outport_ref' in self.con.prop_dict :
#          self.ref = self.con.prop_dict['dataport.corba_any.outport_ref']
        if 'dataport.corba_cdr.outport_ref' in self.con.prop_dict :
           self.ref = self.con.prop_dict['dataport.corba_cdr.outport_ref']
        else :
           self.ref=None
#        self.data_class = eval('RTC.' + self.prop['dataport.data_type'])
#        self.data_tc = eval('RTC._tc_' + self.prop['dataport.data_type'])

        tmp=strip_data_class(self.prop['dataport.data_type'])
        dtype = findType(self.prop['dataport.data_type'])
	if isinstance(dtype, tuple):
            self.data_type=tmp
            self.data_class = dtype[1]
            self.data_tc = findTypeCode(self.prop['dataport.data_type'])
        else:
            self.data_type=tmp
            self.data_class = eval('RTC.' + tmp)
            self.data_tc = eval('RTC._tc_' + tmp)
Example #2
0
    def __init__(self, profile, nv_dict=None, handle=None):
        Port.__init__(self, profile, nv_dict, handle)
        con_prop_dict = {
            'dataport.dataflow_type': 'pull',
            'dataport.buffer.type': 'ringbuffer',
            'dataport.buffer.read.empty_policy': 'last',
            'dataport.buffer.length': '1'
        }
        self.con = IOConnector([self], prop_dict=con_prop_dict)
        self.get_info()
        #        if 'dataport.corba_any.outport_ref' in self.con.prop_dict :
        #          self.ref = self.con.prop_dict['dataport.corba_any.outport_ref']
        if 'dataport.corba_cdr.outport_ref' in self.con.prop_dict:
            self.ref = self.con.prop_dict['dataport.corba_cdr.outport_ref']
        else:
            self.ref = None
#        self.data_class = eval('RTC.' + self.prop['dataport.data_type'])
#        self.data_tc = eval('RTC._tc_' + self.prop['dataport.data_type'])

        tmp = strip_data_class(self.prop['dataport.data_type'])
        dtype = findType(self.prop['dataport.data_type'])
        if isinstance(dtype, tuple):
            self.data_type = tmp
            self.data_class = dtype[1]
            self.data_tc = findTypeCode(self.prop['dataport.data_type'])
        else:
            self.data_type = tmp
            self.data_class = eval('RTC.' + tmp)
            self.data_tc = eval('RTC._tc_' + tmp)
Example #3
0
    def __init__(self, profile,nv_dict=None, handle=None) :
        Port.__init__(self, profile, nv_dict, handle)
        tmp=strip_data_class(self.prop['dataport.data_type'])
        dtype = findType(self.prop['dataport.data_type'])
	if isinstance(dtype, tuple):
            self.data_type=tmp
            self.data_class = dtype[1]
            self.data_tc = findTypeCode(self.prop['dataport.data_type'])
        else:
            self.data_type=tmp
            self.data_class = eval('RTC.' + tmp)
            self.data_tc = eval('RTC._tc_' + tmp)
        self.con = IOConnector([self])
Example #4
0
 def __init__(self, profile, nv_dict=None, handle=None):
     Port.__init__(self, profile, nv_dict, handle)
     tmp = strip_data_class(self.prop['dataport.data_type'])
     dtype = findType(self.prop['dataport.data_type'])
     if isinstance(dtype, tuple):
         self.data_type = tmp
         self.data_class = dtype[1]
         self.data_tc = findTypeCode(self.prop['dataport.data_type'])
     else:
         self.data_type = tmp
         self.data_class = eval('RTC.' + tmp)
         self.data_tc = eval('RTC._tc_' + tmp)
     self.con = IOConnector([self])
Example #5
0
    def __init__(self, profile, nv_dict=None, handle=None) :
        Port.__init__(self, profile, nv_dict, handle)
        self.con = IOConnector([self], prop_dict={'dataport.dataflow_type':'push'})
        self.get_info() 
#       self.ref = self.con.prop_dict['dataport.corba_any.inport_ref']
        self.ref = self.con.prop_dict['dataport.corba_cdr.inport_ref']
#        self.data_class = eval('RTC.' + self.prop['dataport.data_type'])
#        self.data_tc = eval('RTC._tc_' + self.prop['dataport.data_type'])
        tmp=strip_data_class(self.prop['dataport.data_type'])
        dtype = findType(self.prop['dataport.data_type'])
	if isinstance(dtype, tuple):
            self.data_type=tmp
            self.data_class = dtype[1]
            self.data_tc = findTypeCode(self.prop['dataport.data_type'])
        else:
            self.data_type=tmp
            self.data_class = eval('RTC.' + tmp)
            self.data_tc = eval('RTC._tc_' + tmp)
Example #6
0
    def __init__(self, profile, nv_dict=None, handle=None) :
        Port.__init__(self, profile, nv_dict, handle)
        self.con = IOConnector([self], prop_dict={'dataport.dataflow_type':'push'})
        self.get_info() 
#       self.ref = self.con.prop_dict['dataport.corba_any.inport_ref']
        self.ref = self.con.prop_dict['dataport.corba_cdr.inport_ref']
#        self.data_class = eval('RTC.' + self.prop['dataport.data_type'])
#        self.data_tc = eval('RTC._tc_' + self.prop['dataport.data_type'])
        tmp=strip_data_class(self.prop['dataport.data_type'])
        dtype = findType(self.prop['dataport.data_type'])
	if isinstance(dtype, tuple):
            self.data_type=tmp
            self.data_class = dtype[1]
            self.data_tc = findTypeCode(self.prop['dataport.data_type'])
        else:
            self.data_type=tmp
            self.data_class = eval('RTC.' + tmp)
            self.data_tc = eval('RTC._tc_' + tmp)
Example #7
0
        value = apply(cls, svals)
        return tc, value

    elif isinstance(data, FixedType):
        if data == CORBA.fixed(0):
            tc = tcInternal.createTypeCode((tcInternal.tv_fixed, 1, 0))
        else:
            tc = tcInternal.createTypeCode((tcInternal.tv_fixed,
                                            data.precision(), data.decimals()))
        return tc, data

    elif isinstance(data, CORBA.Any):
        return data._t, data._v

    elif isinstance(data, omniORB.EnumItem):
        return omniORB.findTypeCode(data._parent_id), data

    elif hasattr(data, "_NP_RepositoryId"):
        return omniORB.findTypeCode(data._NP_RepositoryId), data

    raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType,
                          CORBA.COMPLETED_NO)


def from_any(any, keep_structs=0):
    """from_any(any, keep_structs=0) -- extract the data from an Any.

    If keep_structs is true, CORBA structs are left as Python
    instances; if false, structs are turned into dictionaries with
    string keys.
    """
Example #8
0
        value = cls(*svals)
        return tc, value

    elif isinstance(data, FixedType):
        if data == CORBA.fixed(0):
            tc = tcInternal.createTypeCode((tcInternal.tv_fixed, 1, 0))
        else:
            tc = tcInternal.createTypeCode((tcInternal.tv_fixed,
                                            data.precision(), data.decimals()))
        return tc, data

    elif isinstance(data, CORBA.Any):
        return data._t, data._v

    elif isinstance(data, omniORB.EnumItem):
        return omniORB.findTypeCode(data._parent_id), data

    elif hasattr(data, "_NP_RepositoryId"):
        return omniORB.findTypeCode(data._NP_RepositoryId), data

    raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType,
                          CORBA.COMPLETED_NO)


#
# from_any

def from_any(any, keep_structs=0):
    """from_any(any, keep_structs=0) -- extract the data from an Any.

    If keep_structs is true, CORBA structs are left as Python
Example #9
0
def _to_tc_value(data):
    """_to_tc_value(data) -- return TypeCode and value for Any insertion"""

    if data is None:
        return CORBA.TC_null, None

    elif isinstance(data, str):
        return CORBA.TC_string, data

    elif isinstance(data, str):
        return CORBA.TC_wstring, data

    elif isinstance(data, bytes):
        return CORBA._tc_OctetSeq, data

    elif isinstance(data, bool):
        return CORBA.TC_boolean, data

    elif isinstance(data, int):
        if -2147483648 <= data <= 2147483647:
            return CORBA.TC_long, int(data)
        elif 0 <= data <= 4294967295:
            return CORBA.TC_ulong, data
        elif -9223372036854775808 <= data <= 9223372036854775807:
            return CORBA.TC_longlong, data
        elif 0 <= data <= 18446744073709551615:
            return CORBA.TC_ulonglong, data
        else:
            raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_PythonValueOutOfRange,
                                  CORBA.COMPLETED_NO)

    elif isinstance(data, float):
        return CORBA.TC_double, data

    elif isinstance(data, list):
        if data == []:
            tc = tcInternal.createTypeCode(
                (tcInternal.tv_sequence, tcInternal.tv_any, 0))
            return tc, data

        d0 = data[0]

        if isinstance(d0, str):
            for d in data:
                if not isinstance(d, str):
                    break
            else:
                # List of strings
                tc = tcInternal.createTypeCode(
                    (tcInternal.tv_sequence, CORBA.TC_string._d, 0))
                return tc, data

        elif isinstance(d0, str):
            for d in data:
                if not isinstance(d, str):
                    break
            else:
                # List of wstrings
                tc = tcInternal.createTypeCode(
                    (tcInternal.tv_sequence, CORBA.TC_wstring._d, 0))
                return tc, data

        elif isinstance(d0, bytes):
            for d in data:
                if not isinstance(d, bytes):
                    break
            else:
                # List of bytes
                tc = tcInternal.createTypeCode(
                    (tcInternal.tv_sequence, CORBA._tc_OctetSeq, 0))
                return tc, data

        elif isinstance(d0, bool):
            for d in data:
                if not isinstance(d, bool):
                    break
            else:
                tc = tcInternal.createTypeCode(
                    (tcInternal.tv_sequence, tcInternal.tv_boolean, 0))
                return tc, data

        elif isinstance(d0, int):
            # Numeric. Try to find a numeric type suitable for the whole list
            min_v = max_v = 0
            for d in data:
                if (not (isinstance(d, int) or isinstance(d, bool))):
                    break
                if d < min_v: min_v = d
                if d > max_v: max_v = d
            else:
                if min_v >= -2147483648 and max_v <= 2147483647:
                    tc = tcInternal.createTypeCode(
                        (tcInternal.tv_sequence, tcInternal.tv_long, 0))
                    return tc, list(map(int, data))
                elif min_v >= 0 and max_v <= 4294967295:
                    tc = tcInternal.createTypeCode(
                        (tcInternal.tv_sequence, tcInternal.tv_ulong, 0))
                    return tc, list(map(int, data))
                elif (min_v >= -9223372036854775808
                      and max_v <= 9223372036854775807):
                    tc = tcInternal.createTypeCode(
                        (tcInternal.tv_sequence, tcInternal.tv_longlong, 0))
                    return tc, list(map(int, data))
                elif min_v >= 0 and max_v <= 18446744073709551615:
                    tc = tcInternal.createTypeCode(
                        (tcInternal.tv_sequence, tcInternal.tv_ulonglong, 0))
                    return tc, list(map(int, data))
                else:
                    raise CORBA.BAD_PARAM(
                        omniORB.BAD_PARAM_PythonValueOutOfRange,
                        CORBA.COMPLETED_NO)

        elif isinstance(d0, float):
            for d in data:
                if not isinstance(d, float):
                    break
            else:
                # List of doubles
                tc = tcInternal.createTypeCode(
                    (tcInternal.tv_sequence, tcInternal.tv_double, 0))
                return tc, data

        elif isinstance(d0, CORBA.Any):
            for d in data:
                if not isinstance(d, CORBA.Any):
                    break
            else:
                # List of anys
                tc = tcInternal.createTypeCode(
                    (tcInternal.tv_sequence, tcInternal.tv_any, 0))
                return tc, data

        # Generic list
        tc = tcInternal.createTypeCode(
            (tcInternal.tv_sequence, tcInternal.tv_any, 0))
        any_list = list(map(to_any, data))

        atc = any_list[0]._t

        if atc._k._v not in INVALID_MEMBER_KINDS:
            for a in any_list:
                if not a._t.equivalent(atc):
                    break
            else:
                tc = tcInternal.createTypeCode(
                    (tcInternal.tv_sequence, atc._d, 0))
                for i in range(len(any_list)):
                    any_list[i] = any_list[i]._v

        return tc, any_list

    elif isinstance(data, tuple):
        return _to_tc_value(list(data))

    elif isinstance(data, dict):
        # Represent dictionaries as structs
        global _idcount

        _idlock.acquire()
        try:
            _idcount = _idcount + 1
            id = "omni:%s:%08x" % (_idbase, _idcount)
        finally:
            _idlock.release()

        dl = [tcInternal.tv_struct, None, id, ""]
        ms = []
        svals = []
        items = list(data.items())
        for (k, v) in items:
            if not isinstance(k, str):
                raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType,
                                      CORBA.COMPLETED_NO)
            t, v = _to_tc_value(v)

            if t._k._v in INVALID_MEMBER_KINDS:
                v = CORBA.Any(t, v)
                t = CORBA.TC_any

            ms.append(k)
            dl.append(k)
            dl.append(t._d)
            svals.append(v)
        cls = omniORB.createUnknownStruct(id, ms)
        dl[1] = cls
        tc = tcInternal.createTypeCode(tuple(dl))
        value = cls(*svals)
        return tc, value

    elif isinstance(data, FixedType):
        if data == CORBA.fixed(0):
            tc = tcInternal.createTypeCode((tcInternal.tv_fixed, 1, 0))
        else:
            tc = tcInternal.createTypeCode(
                (tcInternal.tv_fixed, data.precision(), data.decimals()))
        return tc, data

    elif isinstance(data, CORBA.Any):
        return data._t, data._v

    elif isinstance(data, omniORB.EnumItem):
        return omniORB.findTypeCode(data._parent_id), data

    elif hasattr(data, "_NP_RepositoryId"):
        return omniORB.findTypeCode(data._NP_RepositoryId), data

    raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType,
                          CORBA.COMPLETED_NO)
Example #10
0
def _to_tc_value(data):
    """_to_tc_value(data) -- return TypeCode and value for Any insertion"""

    if data is None:
        return CORBA.TC_null, None

    elif isinstance(data, str):
        return CORBA.TC_string, data

    elif isinstance(data, str):
        return CORBA.TC_wstring, data

    elif isinstance(data, bytes):
        return CORBA._tc_OctetSeq, data

    elif isinstance(data, bool):
        return CORBA.TC_boolean, data

    elif isinstance(data, int):
        if -2147483648 <= data <= 2147483647:
            return CORBA.TC_long, int(data)
        elif 0 <= data <= 4294967295:
            return CORBA.TC_ulong, data
        elif -9223372036854775808 <= data <= 9223372036854775807:
            return CORBA.TC_longlong, data
        elif 0 <= data <= 18446744073709551615:
            return CORBA.TC_ulonglong, data
        else:
            raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_PythonValueOutOfRange,
                                  CORBA.COMPLETED_NO)

    elif isinstance(data, float):
        return CORBA.TC_double, data

    elif isinstance(data, list):
        if data == []:
            tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                            tcInternal.tv_any, 0))
            return tc, data

        d0 = data[0]

        if isinstance(d0, str):
            for d in data:
                if not isinstance(d, str):
                    break
            else:
                # List of strings
                tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                CORBA.TC_string._d, 0))
                return tc, data

        elif isinstance(d0, str):
            for d in data:
                if not isinstance(d, str):
                    break
            else:
                # List of wstrings
                tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                CORBA.TC_wstring._d, 0))
                return tc, data

        elif isinstance(d0, bytes):
            for d in data:
                if not isinstance(d, bytes):
                    break
            else:
                # List of bytes
                tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                CORBA._tc_OctetSeq, 0))
                return tc, data

        elif isinstance(d0, bool):
            for d in data:
                if not isinstance(d, bool):
                    break
            else:
                tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                tcInternal.tv_boolean, 0))
                return tc, data

        elif isinstance(d0, int):
            # Numeric. Try to find a numeric type suitable for the whole list
            min_v = max_v = 0
            for d in data:
                if (not (isinstance(d, int) or isinstance(d, bool))):
                    break
                if d < min_v: min_v = d
                if d > max_v: max_v = d
            else:
                if min_v >= -2147483648 and max_v <= 2147483647:
                    tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                    tcInternal.tv_long, 0))
                    return tc, list(map(int, data))
                elif min_v >= 0 and max_v <= 4294967295:
                    tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                    tcInternal.tv_ulong, 0))
                    return tc, list(map(int, data))
                elif (min_v >= -9223372036854775808 and
                      max_v <= 9223372036854775807):
                    tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                    tcInternal.tv_longlong, 0))
                    return tc, list(map(int, data))
                elif min_v >= 0 and max_v <= 18446744073709551615:
                    tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                    tcInternal.tv_ulonglong,0))
                    return tc, list(map(int, data))
                else:
                    raise CORBA.BAD_PARAM(
                        omniORB.BAD_PARAM_PythonValueOutOfRange,
                        CORBA.COMPLETED_NO)

        elif isinstance(d0, float):
            for d in data:
                if not isinstance(d, float):
                    break
            else:
                # List of doubles
                tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                tcInternal.tv_double, 0))
                return tc, data

        elif isinstance(d0, CORBA.Any):
            for d in data:
                if not isinstance(d, CORBA.Any):
                    break
            else:
                # List of anys
                tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                tcInternal.tv_any, 0))
                return tc, data

        # Generic list
        tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                        tcInternal.tv_any, 0))
        any_list = list(map(to_any, data))

        atc = any_list[0]._t

        if atc._k._v not in INVALID_MEMBER_KINDS:
            for a in any_list:
                if not a._t.equivalent(atc):
                    break
            else:
                tc = tcInternal.createTypeCode((tcInternal.tv_sequence,
                                                atc._d, 0))
                for i in range(len(any_list)):
                    any_list[i] = any_list[i]._v
            
        return tc, any_list

    elif isinstance(data, tuple):
        return _to_tc_value(list(data))

    elif isinstance(data, dict):
        # Represent dictionaries as structs
        global _idcount

        _idlock.acquire()
        try:
            _idcount = _idcount + 1
            id = "omni:%s:%08x" % (_idbase, _idcount)
        finally:
            _idlock.release()

        dl = [tcInternal.tv_struct, None, id, ""]
        ms = []
        svals = []
        items = list(data.items())
        for (k,v) in items:
            if not isinstance(k, str):
                raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType,
                                      CORBA.COMPLETED_NO)
            t, v = _to_tc_value(v)

            if t._k._v in INVALID_MEMBER_KINDS:
                v = CORBA.Any(t,v)
                t = CORBA.TC_any
            
            ms.append(k)
            dl.append(k)
            dl.append(t._d)
            svals.append(v)
        cls   = omniORB.createUnknownStruct(id, ms)
        dl[1] = cls
        tc    = tcInternal.createTypeCode(tuple(dl))
        value = cls(*svals)
        return tc, value

    elif isinstance(data, FixedType):
        if data == CORBA.fixed(0):
            tc = tcInternal.createTypeCode((tcInternal.tv_fixed, 1, 0))
        else:
            tc = tcInternal.createTypeCode((tcInternal.tv_fixed,
                                            data.precision(), data.decimals()))
        return tc, data

    elif isinstance(data, CORBA.Any):
        return data._t, data._v

    elif isinstance(data, omniORB.EnumItem):
        return omniORB.findTypeCode(data._parent_id), data

    elif hasattr(data, "_NP_RepositoryId"):
        return omniORB.findTypeCode(data._NP_RepositoryId), data

    raise CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType,
                          CORBA.COMPLETED_NO)