Example #1
0
    def visitAttribute(self, at):
        active = self.active_interface
        downcastStr = '_downcast_' + string.join(active.scopedName(), '_') +\
                      '()'
        psemi = ''
        pfq = 'SCI::' + active.corbacxxscoped + '::'
        if self.doing_header:
            psemi = ';'
            pfq = ''
        typenameIn = corbacxx.typeToCORBACXX(at.attrType(),
                                             corbacxx.DIRECTION_IN)
        typenameRet = corbacxx.typeToCORBACXX(at.attrType(),
                                              corbacxx.DIRECTION_RET)
        self.sci.ci_count = 0
        for n in at.declarators():
            self.sci.out(typenameRet + ' ' + pfq + n.simplename + '()' + psemi)
            if not self.doing_header:
                self.sci.out('{')
                self.sci.inc_indent()
                self.sci.out('try')
                self.sci.out('{')
                self.sci.inc_indent()
                args = ''
                if simplecxx.doesTypeNeedLength(at.attrType()):
                    self.sci.out('size_t length;')
                    args = '&length'
                self.declareSimpleStorage(at.attrType(), 'value')
                self.sci.out('value = ' + downcastStr + '->' +\
                             n.simplename + '(' + args + ');')
                # Next, convert to a CORBA value...
                self.declareCORBAStorage(at.attrType(), 'corba_value')
                if simplecxx.doesTypeNeedLength(at.attrType()):
                    self.simpleSequenceToCORBA(\
                            at.attrType(), 'value', 'length', 'corba_value',\
                            0, toParam=1)
                    conversionutils.destroySimpleSequence(self.sci, at.attrType(),
                                                          'value', 'length')
                else:
                    self.simpleValueToCORBA(\
                            at.attrType(), 'value', 'corba_value',\
                            0, toParam=1)
                    conversionutils.destroySimpleValue(self.sci, at.attrType(),
                                                       'value')
                self.sci.out('return ' +\
                             conversionutils.returnExpr(at.attrType(),
                                                        'corba_value') + ';')
                self.sci.dec_indent()
                self.sci.out('}')
                self.sci.out('catch (...)')
                self.sci.out('{')
                self.sci.inc_indent()
                self.sci.out('throw CORBA::UNKNOWN();')
                self.sci.dec_indent()
                self.sci.out('}')
                self.sci.dec_indent()
                self.sci.out('}')
            # If its not readonly, we also need a setter...
            if at.readonly():
                return
            self.sci.out('void ' + pfq + n.simplename + '(' + typenameIn +\
                         ' attr)' + psemi)
            if self.doing_header:
                return

            self.sci.out('{')
            self.sci.inc_indent()
            self.sci.out('try')
            self.sci.out('{')
            self.sci.inc_indent()
            # Declare storage for the simple value...
            if simplecxx.doesTypeNeedLength(at.attrType()):
                self.sci.out('size_t length;')
            self.declareSimpleStorage(at.attrType(), 'value')
            # Convert the CORBA value to a simple value...
            if simplecxx.doesTypeNeedLength(at.attrType()):
                self.CORBASequenceToSimple(at.attrType(), 'attr', 'value',
                                           'length', 1, 1)
                callstr = 'length, value'
            else:
                self.CORBAValueToSimple(at.attrType(), 'attr', 'value', 1)
                callstr = 'value'
            self.sci.out(downcastStr + '->' + n.simplename + '(' + callstr +\
                         ');')
            if simplecxx.doesTypeNeedLength(at.attrType()):
                conversionutils.destroySimpleSequence(self.sci, at.attrType(),
                                                      'value', 'length')
            else:
                conversionutils.destroySimpleValue(self.sci, at.attrType(),
                                                   'value')
            self.sci.dec_indent()
            self.sci.out('}')
            self.sci.out('catch (...)')
            self.sci.out('{')
            self.sci.inc_indent()
            self.sci.out('throw CORBA::UNKNOWN();')
            self.sci.dec_indent()
            self.sci.out('}')
            self.sci.dec_indent()
            self.sci.out('}')
    def visitOperation(self, op):
        active = self.active_interface
        downcastStr = '_downcast_' + string.join(active.scopedName(), '_') +\
                      '()'
        psemi = ''
        pfq = 'CCI::' + active.corbacxxscoped + '::'
        if self.doing_header:
            psemi = ';'
            pfq = ''
        # Firstly, get the return type...
        rtype = simplecxx.typeToSimpleCXX(op.returnType())
        if op.simplename == 'query_interface':
            rtype = 'void*'
        # Next, build up all the parameters...
        parstr = ''
        callstr = ''
        needcomma = 0
        for p in op.parameters():
            if needcomma:
                parstr = parstr + ', '
            else:
                needcomma = 1
            if p.is_out():
                extrapointer = 1
            else:
                extrapointer = 0
            if simplecxx.doesTypeNeedLength(p.paramType()):
                parstr = parstr + 'uint32_t'
                if p.is_out():
                    parstr = parstr + '*'
                parstr = parstr + ' _length_' + p.simplename + ', '
            parstr = parstr + simplecxx.typeToSimpleCXX(p.paramType(), \
                                                        extrapointer, not p.is_out()) +\
                     ' ' + p.simplename
        
        if simplecxx.doesTypeNeedLength(op.returnType()):
            if needcomma:
                parstr = parstr + ', '
            parstr = parstr + 'uint32_t* _length__return'
        
        self.cci.out(rtype + ' ' + pfq + op.simplename + '(' + parstr +\
                     ') throw(std::exception&)' + psemi)
        if self.doing_header:
            return
        self.cci.ci_count = 0
        if op.simplename == 'add_ref':
            self.writeAddRef()
        elif op.simplename == 'release_ref':
            self.writeReleaseRef()
        elif op.simplename == 'query_interface':
            self.writeQueryInterface()
        else:
            self.cci.out('{')
            self.cci.inc_indent()

            # All in parameters get converted to CORBA parameters
            for p in op.parameters():
                if callstr != '':
                    callstr = callstr + ','
                callstr = callstr + '_corba_' + p.simplename
                self.declareCORBAStorage(p.paramType(), '_corba_' + p.simplename)
                # If it isn't an in parameter, leave it for now...
                if not p.is_in():
                    continue
                if simplecxx.doesTypeNeedLength(p.paramType()):
                    sname = p.simplename
                    slength = '_length_' + p.simplename
                    if p.is_out():
                        sname = '(*' + p.simplename + ')'
                        slength = '(*_length_' + p.simplename + ')'
                    self.simpleSequenceToCORBA(p.paramType(), sname, slength, \
                                               '_corba_' + p.simplename)
                else:
                    sname = p.simplename
                    if p.is_out():
                        sname = '(*' + sname + ')'
                    self.simpleValueToCORBA(p.paramType(), sname, \
                                            '_corba_' + p.simplename)
            # Declare storage for the return value...
            rt = op.returnType()
            returns = (rt.kind() != idltype.tk_void)
            retprefix = ''
            if returns:
                self.declareCORBAStorage(rt, '_corba_return')
                retprefix = '_corba_return = '
            self.cci.out('try')
            self.cci.out('{')
            self.cci.inc_indent()
            # Next, make the call...
            self.cci.out(retprefix + downcastStr + '->' +\
                         op.simplename + '(' + callstr + ');')

            for p in op.parameters():
                if p.is_out():
                    if p.is_in():
                        if simplecxx.doesTypeNeedLength(p.paramType()):
                            conversionutils.destroySimpleSequence(\
                                self.cci, p.paramType(), '(*' + p.simplename + ')',
                                '(*_length_' + p.simplename + ')')
                        else:
                            conversionutils.destroySimpleValue(\
                                self.cci, \
                                p.paramType(), \
                                '(*' + p.simplename + ')')
                    # Assign the simple value from the CORBA value.
                    if simplecxx.doesTypeNeedLength(p.paramType()):
                        sname = '(*' + p.simplename + ')'
                        slength = '(*_length_' + p.simplename + ')'
                        self.CORBASequenceToSimple(p.paramType(),\
                                                   '_corba_' + p.simplename,\
                                                   sname, slength, needAlloc=1)
                    else:
                        sname = '(*' + p.simplename + ')'
                        self.CORBAValueToSimple(p.paramType(),\
                                                   '_corba_' + p.simplename,\
                                                   sname)
                if p.is_in():
                    # Free the CORBA value...
                    if simplecxx.doesTypeNeedLength(p.paramType()):
                        conversionutils.destroyCORBASequence(\
                            self.cci, \
                            p.paramType(), \
                            '_corba_' + p.simplename)
                    else:
                        conversionutils.destroyCORBAValue(\
                            self.cci, \
                            p.paramType(), \
                            '_corba_' + p.simplename)

            if returns:
                self.declareSimpleStorage(rt, '_simple_return')
                if simplecxx.doesTypeNeedLength(rt):
                    self.CORBASequenceToSimple(rt, '_corba_return',
                                               '_simple_return', '(*_length__return)',
                                               needAlloc=1)
                    conversionutils.destroyCORBASequence(\
                        self.cci, rt, '_corba_return')
                else:
                    self.CORBAValueToSimple(rt, '_corba_return', '_simple_return')
                    conversionutils.destroyCORBAValue(\
                        self.cci, rt, '_corba_return')
                self.cci.out('return _simple_return;')
            
            self.cci.dec_indent()
            self.cci.out('}')
            self.cci.out('catch (CORBA::Exception& e)')
            self.cci.out('{')
            self.cci.inc_indent()
            self.cci.out('throw std::exception(/*"A CORBA exception ' +\
                         'occurred."*/);');
            self.cci.dec_indent()
            self.cci.out('}')
            self.cci.dec_indent()
            self.cci.out('}')
Example #3
0
    def visitOperation(self, op):
        active = self.active_interface
        downcastStr = '_downcast_' + string.join(active.scopedName(), '_') +\
                      '()'
        psemi = ''
        pfq = 'SCI::' + active.corbacxxscoped + '::'
        if self.doing_header:
            psemi = ';'
            pfq = ''
        # Firstly, get the return type...
        rtype = corbacxx.typeToCORBACXX(op.returnType(),
                                        corbacxx.DIRECTION_RET)
        # Next, build up all the parameters...
        parstr = ''
        callstr = ''
        needcomma = 0
        for p in op.parameters():
            if needcomma:
                parstr = parstr + ', '
            else:
                needcomma = 1
            if p.is_in():
                if p.is_out():
                    direction = corbacxx.DIRECTION_INOUT
                else:
                    direction = corbacxx.DIRECTION_IN
            else:
                direction = corbacxx.DIRECTION_OUT
            parstr = parstr + corbacxx.typeToCORBACXX(p.paramType(), \
                                                      direction) + ' ' +\
                                                      p.simplename

        self.sci.out(rtype + ' ' + pfq + op.simplename + '(' + parstr +\
                     ')' + psemi)
        if self.doing_header:
            return
        self.sci.ci_count = 0
        if op.simplename == 'add_ref':
            self.writeAddRef()
        elif op.simplename == 'release_ref':
            self.writeReleaseRef()
        elif op.simplename == 'query_interface':
            self.writeQueryInterface()
        else:
            self.sci.out('{')
            self.sci.inc_indent()

            # All in parameters get converted to simple parameters
            for p in op.parameters():
                if callstr != '':
                    callstr = callstr + ','
                if p.is_out():
                    amp = '&'
                else:
                    amp = ''
                if simplecxx.doesTypeNeedLength(p.paramType()):
                    callstr = callstr + amp + '_length_' + p.simplename + ', '
                    self.sci.out('size_t _length_' + p.simplename + ';')
                callstr = callstr + amp + '_simple_' + p.simplename
                self.declareSimpleStorage(p.paramType(), '_simple_' +\
                                          p.simplename)
                # If it isn't an in parameter, leave it for now...
                if not p.is_in():
                    continue
                if simplecxx.doesTypeNeedLength(p.paramType()):
                    sname = '_simple_' + p.simplename
                    slength = '_length_' + p.simplename
                    self.CORBASequenceToSimple(p.paramType(), p.simplename, \
                                               sname, slength, 1, 1)
                else:
                    sname = '_simple_' + p.simplename
                    self.CORBAValueToSimple(p.paramType(), p.simplename, \
                                            sname, 1)
            # Declare storage for the return value...
            rt = op.returnType()
            returns = (rt.kind() != idltype.tk_void)
            retprefix = ''
            if returns:
                if simplecxx.doesTypeNeedLength(rt):
                    retlength = 1
                    self.sci.out('size_t _length_return;');
                    if callstr == '':
                        callstr = callstr + ', '
                    callstr = callstr + '&_length_return'
                else:
                    retlength = 0
                self.declareSimpleStorage(rt, '_simple_return')
                retprefix = '_simple_return = '
            self.sci.out('try')
            self.sci.out('{')
            self.sci.inc_indent()
            # Next, make the call...
            self.sci.out(retprefix + downcastStr + '->' +\
                         op.simplename + '(' + callstr + ');')

            self.sci.dec_indent()
            self.sci.out('}')
            for r in op.raises():
                self.sci.out('catch (::' + r.simplecxxscoped + '& _e)')
                self.sci.out('{')
                self.sci.inc_indent()
                for p in op.parameters():
                    if p.is_in():
                        # Free the CORBA value...
                        if simplecxx.doesTypeNeedLength(p.paramType()):
                            conversionutils.destroySimpleSequence(\
                            self.sci, \
                            p.paramType(), \
                            '_simple_' + p.simplename, \
                            '_length_' + p.simplename)
                        else:
                            conversionutils.destroySimpleValue(\
                            self.sci, \
                            p.paramType(), \
                            '_simple_' + p.simplename)
                self.sci.out('throw ::' + r.corbacxxscoped + '();')
                self.sci.dec_indent()
                self.sci.out('}')
            self.sci.out('catch (...)')
            self.sci.out('{')
            self.sci.inc_indent()
            for p in op.parameters():
                if p.is_in():
                    # Free the CORBA value...
                    if simplecxx.doesTypeNeedLength(p.paramType()):
                        conversionutils.destroySimpleSequence(\
                            self.sci, \
                            p.paramType(), \
                            '_simple_' + p.simplename, \
                            '_length_' + p.simplename)
                    else:
                        conversionutils.destroySimpleValue(\
                            self.sci, \
                            p.paramType(), \
                            '_simple_' + p.simplename)
            self.sci.out('throw CORBA::UNKNOWN(/*"A CORBA exception ' +\
                         'occurred."*/);')
            self.sci.dec_indent()
            self.sci.out('}')
            for p in op.parameters():
                if p.is_out():
                    if p.is_in():
                        if simplecxx.doesTypeNeedLength(p.paramType()):
                            conversionutils.destroyCORBASequence(\
                                self.sci, p.paramType(), p.simplename, 1)
                        else:
                            conversionutils.destroyCORBAValue(\
                                self.sci, p.paramType(), p.simplename, 1)
                    # Assign the simple value from the CORBA value.
                    if simplecxx.doesTypeNeedLength(p.paramType()):
                        sname = '_simple_' + p.simplename
                        slength = '_length_' + p.simplename
                        self.simpleSequenceToCORBA(\
                            p.paramType(), sname, slength, p.simplename,\
                            fromCall=p.is_in(), toParam=1)
                    else:
                        sname = '_simple_' + p.simplename
                        self.simpleValueToCORBA(\
                            p.paramType(), sname, p.simplename, toParam=1)
                if p.is_in():
                    # Free the CORBA value...
                    if simplecxx.doesTypeNeedLength(p.paramType()):
                        conversionutils.destroySimpleSequence(\
                            self.sci, \
                            p.paramType(), \
                            '_simple_' + p.simplename, \
                            '_length_' + p.simplename)
                    else:
                        conversionutils.destroySimpleValue(\
                            self.sci, \
                            p.paramType(), \
                            '_simple_' + p.simplename)

            if returns:
                self.declareCORBAStorage(rt, '_corba_return')
                if retlength:
                    self.simpleSequenceToCORBA(rt, '_simple_return',\
                                               '_length_return', \
                                               '_corba_return', toParam=1)
                    conversionutils.destroySimpleSequence(\
                        self.sci, rt, '_simple_return', '_length_return')
                else:
                    self.simpleValueToCORBA(rt, '_simple_return', \
                                            '_corba_return', toParam=1)
                    conversionutils.destroySimpleValue(\
                        self.sci, rt, '_simple_return')

                self.sci.out('return ' +\
                             conversionutils.returnExpr(rt, '_corba_return') +\
                             ';')
            self.sci.dec_indent()
            self.sci.out('}')