当前位置: 首页>>代码示例>>C++>>正文


C++ PyObjectHandle类代码示例

本文整理汇总了C++中PyObjectHandle的典型用法代码示例。如果您正苦于以下问题:C++ PyObjectHandle类的具体用法?C++ PyObjectHandle怎么用?C++ PyObjectHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PyObjectHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: invoke

    void invoke(const Ice::ConnectionPtr& con)
    {
        AdoptThread adoptThread; // Ensure the current thread is able to call into Python.
#ifndef NDEBUG
        ConnectionObject* c = reinterpret_cast<ConnectionObject*>(_con);
        assert(con == *(c->connection));
#endif

        PyObjectHandle args = Py_BuildValue(STRCAST("(O)"), _con);
        assert(_cb);
        PyObjectHandle tmp = PyObject_Call(_cb, args.get(), 0);
        if(PyErr_Occurred())
        {
            PyException ex; // Retrieve it before another Python API call clears it.

            //
            // A callback that calls sys.exit() will raise the SystemExit exception.
            // This is normally caught by the interpreter, causing it to exit.
            // However, we have no way to pass this exception to the interpreter,
            // so we act on it directly.
            //
            ex.checkSystemExit();

            ex.raise();
        }
    }
开发者ID:chenbk85,项目名称:ice,代码行数:26,代码来源:Connection.cpp

示例2: assert

void
IcePy::ServantLocatorWrapper::finished(const Ice::Current& current, const Ice::ObjectPtr&,
                                       const Ice::LocalObjectPtr& cookie)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    CookiePtr c = CookiePtr::dynamicCast(cookie);
    assert(c);

    ServantWrapperPtr wrapper = ServantWrapperPtr::dynamicCast(c->servant);
    PyObjectHandle servantObj = wrapper->getObject();

    PyObjectHandle res = PyObject_CallMethod(_locator, STRCAST("finished"), STRCAST("OOO"), c->current,
                                             servantObj.get(), c->cookie);
    if(PyErr_Occurred())
    {
        PyException ex; // Retrieve the exception before another Python API call clears it.

        //
        // A locator that calls sys.exit() will raise the SystemExit exception.
        // This is normally caught by the interpreter, causing it to exit.
        // However, we have no way to pass this exception to the interpreter,
        // so we act on it directly.
        //
        ex.checkSystemExit();

        PyObject* userExceptionType = lookupType("Ice.UserException");
        if(PyObject_IsInstance(ex.ex.get(), userExceptionType))
        {
            throw ExceptionWriter(ex.ex);
        }

        ex.raise();
    }
}
开发者ID:BlackHoleJet,项目名称:ice,代码行数:35,代码来源:ObjectAdapter.cpp

示例3: communicatorFlushBatchRequests

static PyObject*
communicatorFlushBatchRequests(CommunicatorObject* self, PyObject* args)
{
    PyObject* compressBatchType = lookupType("Ice.CompressBatch");
    PyObject* compressBatch;
    if(!PyArg_ParseTuple(args, STRCAST("O!"), compressBatchType, &compressBatch))
    {
        return 0;
    }

    PyObjectHandle v = getAttr(compressBatch, "_value", false);
    assert(v.get());
    Ice::CompressBatch cb = static_cast<Ice::CompressBatch>(PyLong_AsLong(v.get()));

    assert(self->communicator);
    try
    {
        AllowThreads allowThreads; // Release Python's global interpreter lock to avoid a potential deadlock.
        (*self->communicator)->flushBatchRequests(cb);
    }
    catch(const Ice::Exception& ex)
    {
        setPythonException(ex);
        return 0;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:29,代码来源:Communicator.cpp

示例4: getValueInfo

Ice::ValuePtr
IcePy::FactoryWrapper::create(const string& id)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    //
    // Get the type information.
    //
    ValueInfoPtr info = getValueInfo(id);

    if(!info)
    {
        return 0;
    }

    PyObjectHandle obj = PyObject_CallFunction(_valueFactory, STRCAST("s"), id.c_str());

    if(!obj.get())
    {
        assert(PyErr_Occurred());
        throw AbortMarshaling();
    }

    if(obj.get() == Py_None)
    {
        return 0;
    }

    return new ObjectReader(obj.get(), info);
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:30,代码来源:ValueFactoryManager.cpp

示例5: PyDict_New

void
IcePy::UpdateCallbackWrapper::updated(const Ice::PropertyDict& dict)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    PyObjectHandle result = PyDict_New();
    if(result.get())
    {
        for(Ice::PropertyDict::const_iterator p = dict.begin(); p != dict.end(); ++p)
        {
            PyObjectHandle key = createString(p->first);
            PyObjectHandle val = createString(p->second);
            if(!val.get() || PyDict_SetItem(result.get(), key.get(), val.get()) < 0)
            {
                return;
            }
        }
    }

    PyObjectHandle obj = PyObject_CallMethod(_callback, STRCAST("updated"), STRCAST("O"), result.get());
    if(!obj.get())
    {
        assert(PyErr_Occurred());
        throw AbortMarshaling();
    }
}
开发者ID:zeroc-ice,项目名称:ice-debian-packaging,代码行数:26,代码来源:PropertiesAdmin.cpp

示例6: getAttr

void
IcePy::handleSystemExit(PyObject* ex)
{
    //
    // This code is similar to handle_system_exit in pythonrun.c.
    //
    PyObjectHandle code;
    if(PyExceptionInstance_Check(ex))
    {
        code = getAttr(ex, "code", true);
    }
    else
    {
        code = ex;
        Py_INCREF(ex);
    }

    int status;
    if(PyLong_Check(code.get()))
    {
        status = static_cast<int>(PyLong_AsLong(code.get()));
    }
    else
    {
        PyObject_Print(code.get(), stderr, Py_PRINT_RAW);
        PySys_WriteStderr(STRCAST("\n"));
        status = 1;
    }

    code = 0;
    Py_Exit(status);
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:32,代码来源:Util.cpp

示例7: convertException

void
IcePy::setPythonException(const Ice::Exception& ex)
{
    PyObjectHandle p = convertException(ex);
    if(p.get())
    {
        setPythonException(p.get());
    }
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:9,代码来源:Util.cpp

示例8: PyObject_GetAttrString

PyObject*
IcePy::callMethod(PyObject* obj, const string& name, PyObject* arg1, PyObject* arg2)
{
    PyObjectHandle method = PyObject_GetAttrString(obj, const_cast<char*>(name.c_str()));
    if(!method.get())
    {
        return 0;
    }
    return callMethod(method.get(), arg1, arg2);
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:10,代码来源:Util.cpp

示例9: PyObject_CallMethod

void
IcePy::LoggerWrapper::error(const string& message)
{
    AdoptThread adoptThread; // Ensure the current thread is able to call into Python.

    PyObjectHandle tmp = PyObject_CallMethod(_logger.get(), STRCAST("error"), STRCAST("s"), message.c_str());
    if(!tmp.get())
    {
        throwPythonException();
    }
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:11,代码来源:Logger.cpp

示例10: lookupType

Ice::ObjectAdapterPtr
IcePy::unwrapObjectAdapter(PyObject* obj)
{
#ifndef NDEBUG
    PyObject* wrapperType = lookupType("Ice.ObjectAdapterI");
#endif
    assert(wrapperType);
    assert(PyObject_IsInstance(obj, wrapperType));
    PyObjectHandle impl = PyObject_GetAttrString(obj, STRCAST("_impl"));
    assert(impl.get());
    return getObjectAdapter(impl.get());
}
开发者ID:BlackHoleJet,项目名称:ice,代码行数:12,代码来源:ObjectAdapter.cpp

示例11: assert

bool
IcePy::getIdentity(PyObject* p, Ice::Identity& ident)
{
    assert(checkIdentity(p));
    PyObjectHandle name = getAttr(p, "name", true);
    PyObjectHandle category = getAttr(p, "category", true);
    if(name.get())
    {
        if(!checkString(name.get()))
        {
            PyErr_Format(PyExc_ValueError, STRCAST("identity name must be a string"));
            return false;
        }
        ident.name = getString(name.get());
    }
    if(category.get())
    {
        if(!checkString(category.get()))
        {
            PyErr_Format(PyExc_ValueError, STRCAST("identity category must be a string"));
            return false;
        }
        ident.category = getString(category.get());
    }
    return true;
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:26,代码来源:Util.cpp

示例12: communicatorFlushBatchRequestsAsync

static PyObject*
communicatorFlushBatchRequestsAsync(CommunicatorObject* self, PyObject* args, PyObject* /*kwds*/)
{
    PyObject* compressBatchType = lookupType("Ice.CompressBatch");
    PyObject* compressBatch;
    if(!PyArg_ParseTuple(args, STRCAST("O!"), compressBatchType, &compressBatch))
    {
        return 0;
    }

    PyObjectHandle v = getAttr(compressBatch, "_value", false);
    assert(v.get());
    Ice::CompressBatch cb = static_cast<Ice::CompressBatch>(PyLong_AsLong(v.get()));

    assert(self->communicator);
    const string op = "flushBatchRequests";

    FlushAsyncCallbackPtr d = new FlushAsyncCallback(op);
    Ice::Callback_Communicator_flushBatchRequestsPtr callback =
        Ice::newCallback_Communicator_flushBatchRequests(d, &FlushAsyncCallback::exception, &FlushAsyncCallback::sent);

    Ice::AsyncResultPtr result;

    try
    {
        result = (*self->communicator)->begin_flushBatchRequests(cb, callback);
    }
    catch(const Ice::Exception& ex)
    {
        setPythonException(ex);
        return 0;
    }

    PyObjectHandle asyncResultObj = createAsyncResult(result, 0, 0, self->wrapper);
    if(!asyncResultObj.get())
    {
        return 0;
    }

    PyObjectHandle future = createFuture(op, asyncResultObj.get());
    if(!future.get())
    {
        return 0;
    }
    d->setFuture(future.get());
    return future.release();
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:47,代码来源:Communicator.cpp

示例13: createVersion

template<typename T> PyObject*
createVersion(const T& version, const char* type)
{
    PyObject* versionType = lookupType(type);

    PyObjectHandle obj = PyObject_CallObject(versionType, 0);
    if(!obj.get())
    {
        return 0;
    }

    if(!setVersion<T>(obj.get(), version, type))
    {
        return 0;
    }

    return obj.release();
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:18,代码来源:Util.cpp

示例14: lookupType

PyObject*
IcePy::createIdentity(const Ice::Identity& ident)
{
    PyObject* identityType = lookupType("Ice.Identity");

    PyObjectHandle obj = PyObject_CallObject(identityType, 0);
    if(!obj.get())
    {
        return 0;
    }

    if(!setIdentity(obj.get(), ident))
    {
        return 0;
    }

    return obj.release();
}
开发者ID:yuanbaopapa,项目名称:ice,代码行数:18,代码来源:Util.cpp

示例15: implicitContextGetContext

static PyObject*
implicitContextGetContext(ImplicitContextObject* self)
{
    Ice::Context ctx = (*self->implicitContext)->getContext();

    PyObjectHandle dict = PyDict_New();
    if(!dict.get())
    {
        return 0;
    }

    if(!contextToDictionary(ctx, dict.get()))
    {
        return 0;
    }

    return dict.release();
}
开发者ID:bjarnescottlee,项目名称:ice,代码行数:18,代码来源:ImplicitContext.cpp


注:本文中的PyObjectHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。