示例#1
0
 def visitAttribute(self, at):
     active = self.active_interface
     downcastStr = '_downcast_' + string.join(active.scopedName(), '_') +\
                   '()'
     psemi = ''
     pfq = 'CCI::' + active.corbacxxscoped + '::'
     if self.doing_header:
         psemi = ';'
         pfq = ''
     typename = simplecxx.typeToSimpleCXX(at.attrType())
     typenameC = simplecxx.typeToSimpleCXX(at.attrType(), is_const=1)
     if simplecxx.doesTypeNeedLength(at.attrType()):
         extra_getter_params = 'uint32_t* _length_attr'
         extra_setter_params = ', uint32_t _length_attr'
     else:
         extra_getter_params = ''
         extra_setter_params = ''
     for n in at.declarators():
         self.cci.out(typename + ' ' + pfq + n.simplename + '(' +
                      extra_getter_params + ') throw(std::exception&)' +
                      psemi)
         if not self.doing_header:
             self.cci.out('{')
             self.cci.inc_indent()
             self.cci.out('try')
             self.cci.out('{')
             self.cci.inc_indent()
             # 1) Declare storage...
             self.declareCORBAStorage(at.attrType(), '_corba_value')
             # 2) Call the getter and assign...
             self.cci.out('_corba_value = ' + downcastStr + '->' +\
                          n.simplename + '();')
             self.cci.ci_count = 0
             self.declareSimpleStorage(at.attrType(), '_simple_value')
             if simplecxx.doesTypeNeedLength(at.attrType()):
                 self.CORBASequenceToSimple(at.attrType(),
                                            '_corba_value',
                                            '_simple_value',
                                            '(*_length_attr)',
                                            needAlloc=1)
                 conversionutils.destroyCORBASequence(self.cci,\
                                                      at.attrType(),\
                                                      '_corba_value')
             else:
                 self.CORBAValueToSimple(at.attrType(), '_corba_value',\
                                         '_simple_value')
                 conversionutils.destroyCORBAValue(self.cci,\
                                                   at.attrType(),\
                                                   '_corba_value')
             self.cci.out('return _simple_value;')
             self.cci.dec_indent()
             self.cci.out('}')
             self.cci.out('catch (CORBA::Exception& cce)')
             self.cci.out('{')
             self.cci.inc_indent()
             self.cci.out(
                 'throw std::exception(/*"A CORBA error occurred"*/);')
             self.cci.dec_indent()
             self.cci.out('}')
             self.cci.dec_indent()
             self.cci.out('}')
         if not at.readonly():
             self.cci.out('void ' + pfq + n.simplename + '(' + typenameC +
                          ' attr' + extra_setter_params +
                          ') throw(std::exception&)' + psemi)
             if not self.doing_header:
                 self.cci.out('{')
                 self.cci.inc_indent()
                 self.cci.out('try')
                 self.cci.out('{')
                 self.cci.inc_indent()
                 self.cci.ci_count = 0
                 self.declareCORBAStorage(at.attrType(), '_corba_value')
                 if simplecxx.doesTypeNeedLength(at.attrType()):
                     self.simpleSequenceToCORBA(at.attrType(), 'attr',
                                                '_length_attr',
                                                '_corba_value')
                 else:
                     self.simpleValueToCORBA(at.attrType(), 'attr', \
                                             '_corba_value')
                 # Finally, call the setter...
                 self.cci.out(downcastStr + '->' + n.simplename +\
                              '(_corba_value);')
                 self.cci.dec_indent()
                 self.cci.out('}')
                 self.cci.out('catch (CORBA::Exception& cce)')
                 self.cci.out('{')
                 self.cci.inc_indent()
                 self.cci.out('throw std::exception(' +\
                              '/*"A CORBA error occurred"*/);')
                 self.cci.dec_indent()
                 self.cci.out('}')
                 self.cci.dec_indent()
                 self.cci.out('}')
示例#2
0
    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('}')
 def visitAttribute(self, at):
     active = self.active_interface
     downcastStr = '_downcast_' + string.join(active.scopedName(), '_') +\
                   '()'
     psemi = ''
     pfq = 'CCI::' + active.corbacxxscoped + '::'
     if self.doing_header:
         psemi = ';'
         pfq = ''
     typename = simplecxx.typeToSimpleCXX(at.attrType())
     typenameC = simplecxx.typeToSimpleCXX(at.attrType(), is_const=1)
     if simplecxx.doesTypeNeedLength(at.attrType()):
         extra_getter_params = 'uint32_t* _length_attr'
         extra_setter_params = ', uint32_t _length_attr'
     else:
         extra_getter_params = ''
         extra_setter_params = ''
     for n in at.declarators():
         self.cci.out(typename + ' ' + pfq + n.simplename + '(' +
                      extra_getter_params +
                      ') throw(std::exception&)' + psemi)
         if not self.doing_header:
             self.cci.out('{')
             self.cci.inc_indent()
             self.cci.out('try')
             self.cci.out('{')
             self.cci.inc_indent()
             # 1) Declare storage...
             self.declareCORBAStorage(at.attrType(), '_corba_value')
             # 2) Call the getter and assign...
             self.cci.out('_corba_value = ' + downcastStr + '->' +\
                          n.simplename + '();')
             self.cci.ci_count = 0
             self.declareSimpleStorage(at.attrType(), '_simple_value')
             if simplecxx.doesTypeNeedLength(at.attrType()):
                 self.CORBASequenceToSimple(at.attrType(), '_corba_value',
                                            '_simple_value', '(*_length_attr)',
                                            needAlloc=1)
                 conversionutils.destroyCORBASequence(self.cci,\
                                                      at.attrType(),\
                                                      '_corba_value')
             else:
                 self.CORBAValueToSimple(at.attrType(), '_corba_value',\
                                         '_simple_value')
                 conversionutils.destroyCORBAValue(self.cci,\
                                                   at.attrType(),\
                                                   '_corba_value')
             self.cci.out('return _simple_value;')
             self.cci.dec_indent()
             self.cci.out('}')
             self.cci.out('catch (CORBA::Exception& cce)')
             self.cci.out('{')
             self.cci.inc_indent()
             self.cci.out('throw std::exception(/*"A CORBA error occurred"*/);')
             self.cci.dec_indent()
             self.cci.out('}')
             self.cci.dec_indent()
             self.cci.out('}')
         if not at.readonly():
             self.cci.out('void ' + pfq + n.simplename + '(' + typenameC +
                          ' attr' + extra_setter_params +
                          ') throw(std::exception&)' + psemi)
             if not self.doing_header:
                 self.cci.out('{')
                 self.cci.inc_indent()
                 self.cci.out('try')
                 self.cci.out('{')
                 self.cci.inc_indent()
                 self.cci.ci_count = 0
                 self.declareCORBAStorage(at.attrType(), '_corba_value')
                 if simplecxx.doesTypeNeedLength(at.attrType()):
                     self.simpleSequenceToCORBA(at.attrType(), 'attr',
                                                '_length_attr', '_corba_value')
                 else:
                     self.simpleValueToCORBA(at.attrType(), 'attr', \
                                             '_corba_value')
                 # Finally, call the setter...
                 self.cci.out(downcastStr + '->' + n.simplename +\
                              '(_corba_value);')
                 self.cci.dec_indent()
                 self.cci.out('}')
                 self.cci.out('catch (CORBA::Exception& cce)')
                 self.cci.out('{')
                 self.cci.inc_indent()
                 self.cci.out('throw std::exception(' +\
                              '/*"A CORBA error occurred"*/);')
                 self.cci.dec_indent()
                 self.cci.out('}')
                 self.cci.dec_indent()
                 self.cci.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('}')
示例#5
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('}')
示例#6
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('}')