Esempio n. 1
0
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
Esempio n. 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)
Esempio n. 3
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)
Esempio n. 4
0
 def corba_eq(self, other):
     if not isinstance(other, self.__class__):
         return False
     import omniORB
     corba_type_desc = omniORB.findType(self._NP_RepositoryId)
     for i in range(4, len(corba_type_desc), 2):
         attr_name = corba_type_desc[i]
         if getattr(self, attr_name, None) != getattr(
                 other, attr_name, None):
             return False
     return True
Esempio n. 5
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])
Esempio n. 6
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])
Esempio n. 7
0
def typeCodeFromClassOrRepoId(t):
    try:
        t = t._NP_RepositoryId
    except AttributeError:
        pass

    if not isinstance(t, str):
        raise TypeError("Argument must be CORBA class or repository id.")

    d = omniORB.findType(t)
    if d is None:
        raise TypeError("Unknown CORBA type.")

    return createTypeCode(d)
Esempio n. 8
0
def typeCodeFromClassOrRepoId(t):
    try:
        t = t._NP_RepositoryId
    except AttributeError:
        pass

    if not isinstance(t, str):
        raise TypeError("Argument must be CORBA class or repository id.")

    d = omniORB.findType(t)
    if d is None:
        raise TypeError("Unknown CORBA type.")

    return createTypeCode(d)
Esempio n. 9
0
def instantiateDataType(dtype):
    if isinstance(dtype, int):
        desc = [dtype]
    elif isinstance(dtype, tuple):
        desc = dtype
    else:
        desc = omniORB.findType(dtype._NP_RepositoryId)

    if desc[0] in [omniORB.tcInternal.tv_alias]:
        return instantiateDataType(desc[3])

    if desc[0] in [omniORB.tcInternal.tv_short,
                   omniORB.tcInternal.tv_long,
                   omniORB.tcInternal.tv_ushort,
                   omniORB.tcInternal.tv_ulong,
                   omniORB.tcInternal.tv_boolean,
                   omniORB.tcInternal.tv_char,
                   omniORB.tcInternal.tv_octet,
                   omniORB.tcInternal.tv_longlong,
                   omniORB.tcInternal.tv_enum
                   ]:
                      return 0

    if desc[0] in [omniORB.tcInternal.tv_float,
                   omniORB.tcInternal.tv_double,
                   omniORB.tcInternal.tv_longdouble
                   ]:
                      return 0.0

    if desc[0] in [omniORB.tcInternal.tv_sequence,
                   omniORB.tcInternal.tv_array,
                   ]:
                      return []

    if desc[0] in [omniORB.tcInternal.tv_string]:
        return ""
    if desc[0] in [omniORB.tcInternal.tv_wstring,
                   omniORB.tcInternal.tv_wchar
                   ]:
                      return u""

    if desc[0] == omniORB.tcInternal.tv_struct:
        arg = []
        for i in range(4, len(desc), 2):
            attr = desc[i]
            attr_type = desc[i + 1]
            arg.append(instantiateDataType(attr_type))
        return desc[1](*arg)
    return None
Esempio n. 10
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)
def OmniDataToDDSData(data, gen_info):
  desc=omniORB.findType(data._NP_RepositoryId)
  if desc[0] == omniORB.tcInternal.tv_struct:
    arg = {}
    for i in  range(4, len(desc), 2):
      attr = desc[i]
      attr_type = desc[i+1]
      if isinstance(attr_type, int):
        arg[attr] = data.__dict__[attr]
      else:
        cdata = data.__dict__[attr]
        data_name = cdata._NP_RepositoryId
        data_name = data_name.split(":")[1]
        data_name = data_name.replace("/","::")
        datatype = gen_info.get_class(data_name)
        cv = OmniDataToDDSData(cdata, gen_info)
        arg[attr] = datatype(**cv)
    return arg
Esempio n. 12
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)
Esempio n. 13
0
    def __repr__(self):
        cname = self._NP_ClassName
        if cname is None:
            cname = "%s.%s" % (self.__module__, self.__class__.__name__)

        desc = omniORB.findType(self._NP_RepositoryId)
        if desc is None:
            # Type is not properly registered
            return "<%s instance at 0x%x>" % (cname, builtin_id(self))
        vals = []
        for i in range(4, len(desc), 2):
            attr = desc[i]
            try:
                val = getattr(self, attr)
                vals.append("%s=%s" % (attr,repr(val)))
            except AttributeError:
                vals.append("%s=<not set>" % attr)

        return "%s(%s)" % (cname, ", ".join(vals))
Esempio n. 14
0
    def __repr__(self):
        cname = self._NP_ClassName
        if cname is None:
            cname = "%s.%s" % (self.__module__, self.__class__.__name__)

        desc = omniORB.findType(self._NP_RepositoryId)
        if desc is None:
            # Type is not properly registered
            return "<%s instance at 0x%x>" % (cname, builtin_id(self))
        vals = []
        for i in range(4, len(desc), 2):
            attr = desc[i]
            try:
                val = getattr(self, attr)
                vals.append("%s=%s" % (attr, repr(val)))
            except AttributeError:
                vals.append("%s=<not set>" % attr)

        return "%s(%s)" % (cname, ", ".join(vals))
Esempio n. 15
0
def instantiateDataType(dtype):
   if isinstance(dtype, int) : desc = [dtype]
   elif isinstance(dtype, tuple) : desc = dtype
   else : 
     desc=omniORB.findType(dtype._NP_RepositoryId) 

   if desc[0] in [omniORB.tcInternal.tv_alias ]: return instantiateDataType(desc[2])

   if desc[0] in [omniORB.tcInternal.tv_short, 
                  omniORB.tcInternal.tv_long, 
                  omniORB.tcInternal.tv_ushort, 
                  omniORB.tcInternal.tv_ulong,
                  omniORB.tcInternal.tv_boolean,
                  omniORB.tcInternal.tv_char,
                  omniORB.tcInternal.tv_octet,
                  omniORB.tcInternal.tv_longlong,
                  omniORB.tcInternal.tv_enum
		 ]: return 0

   if desc[0] in [omniORB.tcInternal.tv_float, 
                  omniORB.tcInternal.tv_double,
                  omniORB.tcInternal.tv_longdouble
                 ]: return 0.0

   if desc[0] in [omniORB.tcInternal.tv_sequence, 
                  omniORB.tcInternal.tv_array,
                 ]: return []


   if desc[0] in [omniORB.tcInternal.tv_string ]: return ""
   if desc[0] in [omniORB.tcInternal.tv_wstring,
                  omniORB.tcInternal.tv_wchar
		   ]: return u""

   if desc[0] == omniORB.tcInternal.tv_struct:
     arg=[]
     for i in  range(4, len(desc), 2):
       attr=desc[i]
       attr_type=desc[i+1]
       arg.append(instantiateDataType(attr_type))
     return desc[1](*arg)
   return None
Esempio n. 16
0
    def __repr__(self):
        if self.__in_repr:
            return "..."

        self.__in_repr = 1
        try:
            cname = self._NP_ClassName
            if cname is None:
                cname = "%s.%s" % (self.__module__, self.__class__.__name__)

            desc = omniORB.findType(self._NP_RepositoryId)
            if desc is None:
                # Type is not properly registered
                return "<%s instance at 0x%x>" % (cname, builtin_id(self))

            descs = []
            while desc != tcInternal.tv_null:
                descs.append(desc)
                desc = desc[6]
            descs.reverse()

            vals = []

            for desc in descs:
                for i in range(7, len(desc), 3):
                    attr = desc[i]
                    try:
                        val = getattr(self, attr)
                        vals.append("%s=%s" % (attr,repr(val)))
                    except AttributeError:
                        vals.append("%s=<not set>" % attr)

            return "%s(%s)" % (cname, ", ".join(vals))
        finally:
            try:
                del self.__in_repr
            except AttributeError:
                pass
Esempio n. 17
0
    def __repr__(self):
        if self.__in_repr:
            return "..."

        self.__in_repr = 1
        try:
            cname = self._NP_ClassName
            if cname is None:
                cname = "%s.%s" % (self.__module__, self.__class__.__name__)

            desc = omniORB.findType(self._NP_RepositoryId)
            if desc is None:
                # Type is not properly registered
                return "<%s instance at 0x%x>" % (cname, builtin_id(self))

            descs = []
            while desc != tcInternal.tv_null:
                descs.append(desc)
                desc = desc[6]
            descs.reverse()

            vals = []

            for desc in descs:
                for i in range(7, len(desc), 3):
                    attr = desc[i]
                    try:
                        val = getattr(self, attr)
                        vals.append("%s=%s" % (attr, repr(val)))
                    except AttributeError:
                        vals.append("%s=<not set>" % attr)

            return "%s(%s)" % (cname, ", ".join(vals))
        finally:
            try:
                del self.__in_repr
            except AttributeError:
                pass
Esempio n. 18
0
def createTypeCode(d):
    try:
        r = basicTypeCodes.get(d)
        if r is not None:
            return r
    except TypeError:
        # Happens if d contains a mutable object
        pass

    if not isinstance (d, tuple):
        raise INTERNAL()

    k = d[0]

    if   k == tv_string:  return TypeCode_string(d)
    elif k == tv_wstring: return TypeCode_wstring(d)
    elif k == tv_fixed:   return TypeCode_fixed(d)

    elif k in [ tv_objref, tv_abstract_interface, tv_local_interface ]:
        tc = typeCodeMapping.get(d[1])
        if tc is None:
            tc = TypeCode_objref(d)
        return tc

    elif k == tv_struct:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_struct(d)
        return tc
    
    elif k == tv_union:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_union(d)
        return tc
    
    elif k == tv_enum:
        tc = typeCodeMapping.get(d[1])
        if tc is None:
            tc = TypeCode_enum(d)
        return tc

    elif k == tv_sequence:  return TypeCode_sequence(d)
    elif k == tv_array:     return TypeCode_array(d)

    elif k == tv_alias:
        tc = typeCodeMapping.get(d[1])
        if tc is None:
            tc = TypeCode_alias(d)
        return tc
    
    elif k == tv_except:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_except(d)
        return tc

    elif k == tv_value:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_value(d)
        return tc

    elif k == tv_value_box:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_value_box(d)
        return tc

    elif k == tv__indirect:
        if isinstance(d[1][0], str):
            nd = omniORB.findType(d[1][0])
            if nd is None:
                raise BAD_TYPECODE(omniORB.BAD_TYPECODE_InvalidIndirection,
                                   COMPLETED_NO)
            d[1][0] = nd
        return createTypeCode(d[1][0])

    raise INTERNAL()
Esempio n. 19
0
def getTypeDesc(x):
  if(type(x) == tuple) : repId = x[2]
  else: repId=x._NP_RepositoryId
  return omniORB.findType(repId)
Esempio n. 20
0
def createTypeCode(d):
    try:
        r = basicTypeCodes.get(d)
        if r is not None:
            return r
    except TypeError:
        # Happens if d contains a mutable object
        pass

    if not isinstance(d, tuple):
        raise INTERNAL()

    k = d[0]

    if k == tv_string: return TypeCode_string(d)
    elif k == tv_wstring: return TypeCode_wstring(d)
    elif k == tv_fixed: return TypeCode_fixed(d)

    elif k in [tv_objref, tv_abstract_interface, tv_local_interface]:
        tc = typeCodeMapping.get(d[1])
        if tc is None:
            tc = TypeCode_objref(d)
        return tc

    elif k == tv_struct:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_struct(d)
        return tc

    elif k == tv_union:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_union(d)
        return tc

    elif k == tv_enum:
        tc = typeCodeMapping.get(d[1])
        if tc is None:
            tc = TypeCode_enum(d)
        return tc

    elif k == tv_sequence:
        return TypeCode_sequence(d)
    elif k == tv_array:
        return TypeCode_array(d)

    elif k == tv_alias:
        tc = typeCodeMapping.get(d[1])
        if tc is None:
            tc = TypeCode_alias(d)
        return tc

    elif k == tv_except:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_except(d)
        return tc

    elif k == tv_value:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_value(d)
        return tc

    elif k == tv_value_box:
        tc = typeCodeMapping.get(d[2])
        if tc is None:
            tc = TypeCode_value_box(d)
        return tc

    elif k == tv__indirect:
        if isinstance(d[1][0], str):
            nd = omniORB.findType(d[1][0])
            if nd is None:
                raise BAD_TYPECODE(omniORB.BAD_TYPECODE_InvalidIndirection,
                                   COMPLETED_NO)
            d[1][0] = nd
        return createTypeCode(d[1][0])

    raise INTERNAL()
Esempio n. 21
0
def getTypeDesc(x):
  if(type(x) == tuple) : repId = x[2]
  else: repId=x._NP_RepositoryId
  return omniORB.findType(repId)