예제 #1
0
    def generateMethod(self, classname, cxxmethodname, retType, params):
        self.cxx.out('class meth%s' % classname)
        self.cxx.out('  : public iface::CGRS::GenericMethod')
        self.cxx.out('{')
        self.cxx.out('public:')
        self.cxx.inc_indent()

        self.cxx.out('CDA_IMPL_REFCOUNT;')
        self.cxx.out('CDA_IMPL_ID;')
        self.cxx.out('CDA_IMPL_QI1(CGRS::GenericMethod);')
        self.cxx.out('std::vector<iface::CGRS::GenericParameter*> parameters() throw()')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out('std::vector<iface::CGRS::GenericParameter*> params;')

        for (pname, ptype, pIsIn, pIsOut) in params:
            self.cxx.out('params.push_back(new Param%s());' % pname)

        self.cxx.out('return params;')
        self.cxx.dec_indent()
        self.cxx.out('}')

        self.cxx.out('already_AddRefd<iface::CGRS::GenericType> returnType() throw()')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out('ObjRef<CDA_GenericsService> cgs = CreateGenericsServiceInternal();')
        self.cxx.out(GetTypeInformation(retType).fetchType())
        self.cxx.dec_indent()
        self.cxx.out('}')

        self.cxx.out('already_AddRefd<iface::CGRS::GenericValue>')
        self.cxx.out('invoke(iface::CGRS::ObjectValue* aInvokeOn, const std::vector<iface::CGRS::GenericValue*>& aInValues,')
        self.cxx.out('       std::vector<iface::CGRS::GenericValue*>& aOutValues, bool* aWasException)')
        self.cxx.out('  throw(std::exception&)')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out('ObjRef<CDA_GenericsService> cgs = CreateGenericsServiceInternal();')
        self.cxx.out('if (aInvokeOn == NULL) throw iface::CGRS::CGRSError();')
        self.cxx.out('ObjRef<iface::XPCOM::IObject> obj = aInvokeOn->asObject();')
        self.cxx.out('DECLARE_QUERY_INTERFACE_OBJREF(obji, obj, %s);' % self.iface)
        self.cxx.out('if (obji == NULL) throw iface::CGRS::CGRSError();')

        incnt = 0
        for (pname, ptype, pIsIn, pIsOut) in params:
            if pIsIn:
                incnt = incnt + 1
        self.cxx.out('if (aInValues.size() != %d) throw iface::CGRS::CGRSError();' % incnt)

        inidx = 0
        pidx = 0
        paramstring = ''
        for (pname, ptype, pIsIn, pIsOut) in params:
            ti = GetTypeInformation(ptype)
            self.cxx.out(ti.makeStorage('param%d' % pidx))
            self.cxx.out(ti.makeScopedDestructor('param%d' % pidx))
            if pIsIn:
                self.cxx.out('DECLARE_QUERY_INTERFACE_OBJREF(inValues%d, (aInValues[%d]), %s);' % (inidx, inidx, ti.genericIface))
                self.cxx.out(ti.convertGenericToNative('inValues%d' % inidx, 'param%d' % pidx))
                inidx = inidx + 1
            if pidx != 0:
                paramstring = paramstring + ', '
            paramstring = paramstring + '%sparam%d' % (ti.ref(pIsOut), pidx)
            pidx = pidx + 1

        rti = GetTypeInformation(retType)
        self.cxx.out(rti.makeStorage('retval'))
        self.cxx.out(rti.makeScopedDestructor('retval'))
        self.cxx.out('*aWasException = false;')
        self.cxx.out('try')
        self.cxx.out('{')
        self.cxx.inc_indent()
        if rti.typename == 'void':
            retAssign = ''
        else:
            retAssign = 'retval = '
        self.cxx.out('%sobji->%s(%s);' % (retAssign, cxxmethodname, paramstring))
        self.cxx.dec_indent()
        self.cxx.out('}')
        self.cxx.out('catch (...)')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out(rti.defaultStorageValue('retval'))
        pidx = 0
        for (pname, ptype, pIsIn, pIsOut) in params:
            if pIsOut:
                self.cxx.out(rti.defaultStorageValue('param%d' % pidx))
            pidx = pidx + 1
        self.cxx.out('*aWasException = true;')
        self.cxx.dec_indent()
        self.cxx.out('}')

        pidx = 0
        for (pname, ptype, pIsIn, pIsOut) in params:
            ti = GetTypeInformation(ptype)
            if pIsOut:
                self.cxx.out('{')
                self.cxx.inc_indent()
                self.cxx.out('iface::CGRS::GenericValue* gval;')
                self.cxx.out(ti.convertNativeToGeneric('param%d' % pidx, 'gval'))
                self.cxx.out('aOutValues.push_back(gval);')
                self.cxx.dec_indent()
                self.cxx.out('}')
            pidx = pidx + 1

        if rti.typename != 'void':
            self.cxx.out('ObjRef<iface::%s> gretval;' % rti.genericIface)
            self.cxx.out(rti.convertNativeToGeneric('retval', 'gretval'))
            self.cxx.out('gretval->add_ref();')
            self.cxx.out('return gretval.getPointer();')
        else:
            self.cxx.out('return cgs->makeVoid();')

        self.cxx.dec_indent()
        self.cxx.out('}')

        self.cxx.dec_indent()
        self.cxx.out('private:')
        self.cxx.inc_indent()

        for (pname, ptype, pIsIn, pIsOut) in params:
            self.cxx.out('class Param%s' % pname)
            self.cxx.out('  : public iface::CGRS::GenericParameter')
            self.cxx.out('{')
            self.cxx.out('public:')
            self.cxx.inc_indent()
            self.cxx.out('CDA_IMPL_ID;')
            self.cxx.out('CDA_IMPL_REFCOUNT;')
            self.cxx.out('CDA_IMPL_QI1(CGRS::GenericParameter);')
            self.cxx.out('bool isIn() throw() { return ' + ternary(pIsIn, lambda: "true", lambda: "false") + "; }")
            self.cxx.out('bool isOut() throw() { return ' + ternary(pIsOut, lambda: "true", lambda: "false") + "; }")
            self.cxx.out('std::string name() throw() { return "%s"; }' % pname)
            self.cxx.out('already_AddRefd<iface::CGRS::GenericType> type() throw()')
            self.cxx.out('{')
            self.cxx.inc_indent()
            self.cxx.out('ObjRef<CDA_GenericsService> cgs = CreateGenericsServiceInternal();')
            self.cxx.out(GetTypeInformation(ptype).fetchType())
            self.cxx.dec_indent()
            self.cxx.out('}')
            self.cxx.dec_indent()
            self.cxx.out('};')
        self.cxx.dec_indent()
        self.cxx.out('};')
예제 #2
0
    def generateMethod(self, classname, cxxmethodname, retType, params):
        self.cxx.out('class meth%s' % classname)
        self.cxx.out('  : public iface::CGRS::GenericMethod')
        self.cxx.out('{')
        self.cxx.out('public:')
        self.cxx.inc_indent()

        self.cxx.out('CDA_IMPL_REFCOUNT;')
        self.cxx.out('CDA_IMPL_ID;')
        self.cxx.out('CDA_IMPL_QI1(CGRS::GenericMethod);')
        self.cxx.out(
            'std::vector<iface::CGRS::GenericParameter*> parameters() throw()')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out('std::vector<iface::CGRS::GenericParameter*> params;')

        for (pname, ptype, pIsIn, pIsOut) in params:
            self.cxx.out('params.push_back(new Param%s());' % pname)

        self.cxx.out('return params;')
        self.cxx.dec_indent()
        self.cxx.out('}')

        self.cxx.out(
            'already_AddRefd<iface::CGRS::GenericType> returnType() throw()')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out(
            'ObjRef<CDA_GenericsService> cgs = CreateGenericsServiceInternal();'
        )
        self.cxx.out(GetTypeInformation(retType).fetchType())
        self.cxx.dec_indent()
        self.cxx.out('}')

        self.cxx.out('already_AddRefd<iface::CGRS::GenericValue>')
        self.cxx.out(
            'invoke(iface::CGRS::ObjectValue* aInvokeOn, const std::vector<iface::CGRS::GenericValue*>& aInValues,'
        )
        self.cxx.out(
            '       std::vector<iface::CGRS::GenericValue*>& aOutValues, bool* aWasException)'
        )
        self.cxx.out('  throw(std::exception&)')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out(
            'ObjRef<CDA_GenericsService> cgs = CreateGenericsServiceInternal();'
        )
        self.cxx.out('if (aInvokeOn == NULL) throw iface::CGRS::CGRSError();')
        self.cxx.out(
            'ObjRef<iface::XPCOM::IObject> obj = aInvokeOn->asObject();')
        self.cxx.out('DECLARE_QUERY_INTERFACE_OBJREF(obji, obj, %s);' %
                     self.iface)
        self.cxx.out('if (obji == NULL) throw iface::CGRS::CGRSError();')

        incnt = 0
        for (pname, ptype, pIsIn, pIsOut) in params:
            if pIsIn:
                incnt = incnt + 1
        self.cxx.out(
            'if (aInValues.size() != %d) throw iface::CGRS::CGRSError();' %
            incnt)

        inidx = 0
        pidx = 0
        paramstring = ''
        for (pname, ptype, pIsIn, pIsOut) in params:
            ti = GetTypeInformation(ptype)
            self.cxx.out(ti.makeStorage('param%d' % pidx))
            self.cxx.out(ti.makeScopedDestructor('param%d' % pidx))
            if pIsIn:
                self.cxx.out(
                    'DECLARE_QUERY_INTERFACE_OBJREF(inValues%d, (aInValues[%d]), %s);'
                    % (inidx, inidx, ti.genericIface))
                self.cxx.out(
                    ti.convertGenericToNative('inValues%d' % inidx,
                                              'param%d' % pidx))
                inidx = inidx + 1
            if pidx != 0:
                paramstring = paramstring + ', '
            paramstring = paramstring + '%sparam%d' % (ti.ref(pIsOut), pidx)
            pidx = pidx + 1

        rti = GetTypeInformation(retType)
        self.cxx.out(rti.makeStorage('retval'))
        self.cxx.out(rti.makeScopedDestructor('retval'))
        self.cxx.out('*aWasException = false;')
        self.cxx.out('try')
        self.cxx.out('{')
        self.cxx.inc_indent()
        if rti.typename == 'void':
            retAssign = ''
        else:
            retAssign = 'retval = '
        self.cxx.out('%sobji->%s(%s);' %
                     (retAssign, cxxmethodname, paramstring))
        self.cxx.dec_indent()
        self.cxx.out('}')
        self.cxx.out('catch (...)')
        self.cxx.out('{')
        self.cxx.inc_indent()
        self.cxx.out(rti.defaultStorageValue('retval'))
        pidx = 0
        for (pname, ptype, pIsIn, pIsOut) in params:
            if pIsOut:
                self.cxx.out(rti.defaultStorageValue('param%d' % pidx))
            pidx = pidx + 1
        self.cxx.out('*aWasException = true;')
        self.cxx.dec_indent()
        self.cxx.out('}')

        pidx = 0
        for (pname, ptype, pIsIn, pIsOut) in params:
            ti = GetTypeInformation(ptype)
            if pIsOut:
                self.cxx.out('{')
                self.cxx.inc_indent()
                self.cxx.out('iface::CGRS::GenericValue* gval;')
                self.cxx.out(
                    ti.convertNativeToGeneric('param%d' % pidx, 'gval'))
                self.cxx.out('aOutValues.push_back(gval);')
                self.cxx.dec_indent()
                self.cxx.out('}')
            pidx = pidx + 1

        if rti.typename != 'void':
            self.cxx.out('ObjRef<iface::%s> gretval;' % rti.genericIface)
            self.cxx.out(rti.convertNativeToGeneric('retval', 'gretval'))
            self.cxx.out('gretval->add_ref();')
            self.cxx.out('return gretval.getPointer();')
        else:
            self.cxx.out('return cgs->makeVoid();')

        self.cxx.dec_indent()
        self.cxx.out('}')

        self.cxx.dec_indent()
        self.cxx.out('private:')
        self.cxx.inc_indent()

        for (pname, ptype, pIsIn, pIsOut) in params:
            self.cxx.out('class Param%s' % pname)
            self.cxx.out('  : public iface::CGRS::GenericParameter')
            self.cxx.out('{')
            self.cxx.out('public:')
            self.cxx.inc_indent()
            self.cxx.out('CDA_IMPL_ID;')
            self.cxx.out('CDA_IMPL_REFCOUNT;')
            self.cxx.out('CDA_IMPL_QI1(CGRS::GenericParameter);')
            self.cxx.out('bool isIn() throw() { return ' +
                         ternary(pIsIn, lambda: "true", lambda: "false") +
                         "; }")
            self.cxx.out('bool isOut() throw() { return ' +
                         ternary(pIsOut, lambda: "true", lambda: "false") +
                         "; }")
            self.cxx.out('std::string name() throw() { return "%s"; }' % pname)
            self.cxx.out(
                'already_AddRefd<iface::CGRS::GenericType> type() throw()')
            self.cxx.out('{')
            self.cxx.inc_indent()
            self.cxx.out(
                'ObjRef<CDA_GenericsService> cgs = CreateGenericsServiceInternal();'
            )
            self.cxx.out(GetTypeInformation(ptype).fetchType())
            self.cxx.dec_indent()
            self.cxx.out('}')
            self.cxx.dec_indent()
            self.cxx.out('};')
        self.cxx.dec_indent()
        self.cxx.out('};')