Ejemplo n.º 1
0
//-------------------------------------------------------------------------------------
PyObject* BaseRemoteMethod::tp_call(PyObject* self, PyObject* args,
                                    PyObject* kwds)
{
    BaseRemoteMethod* rmethod = static_cast<BaseRemoteMethod*>(self);
    MethodDescription* methodDescription = rmethod->getDescription();
    EntityMailboxAbstract* mailbox = rmethod->getMailbox();

    if(!mailbox->isClient())
    {
        return RemoteEntityMethod::tp_call(self, args, kwds);
    }

    Base* pEntity = Baseapp::getSingleton().findEntity(mailbox->getID());
    if(pEntity == NULL)
    {
        //WARNING_MSG(boost::format("BaseRemoteMethod::callClientMethod: not found entity(%1%).\n") %
        //	mailbox->getID());

        return RemoteEntityMethod::tp_call(self, args, kwds);
    }

    // 如果是调用客户端方法, 我们记录事件并且记录带宽
    if(methodDescription->checkArgs(args))
    {
        Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
        mailbox->newMail((*pBundle));

        MemoryStream* mstream = MemoryStream::ObjPool().createObject();
        methodDescription->addToStream(mstream, args);

        if(mstream->wpos() > 0)
            (*pBundle).append(mstream->data(), mstream->wpos());

        // 记录这个事件产生的数据量大小
        g_privateClientEventHistoryStats.trackEvent(pEntity->getScriptName(),
                methodDescription->getName(),
                pBundle->currMsgLength(),
                "::");

        mailbox->postMail((*pBundle));

        Mercury::Bundle::ObjPool().reclaimObject(pBundle);
        MemoryStream::ObjPool().reclaimObject(mstream);
    }

    S_Return;
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------------------------
PyObject* EntityMailboxAbstract::__py_reduce_ex__(PyObject* self, PyObject* protocol)
{
	EntityMailboxAbstract* emailbox = static_cast<EntityMailboxAbstract*>(self);
	PyObject* args = PyTuple_New(2);
	PyObject* unpickleMethod = script::Pickler::getUnpickleFunc("Mailbox");
	PyTuple_SET_ITEM(args, 0, unpickleMethod);
	PyObject* args1 = PyTuple_New(4);
	PyTuple_SET_ITEM(args1, 0, PyLong_FromUnsignedLong(emailbox->getID()));
	PyTuple_SET_ITEM(args1, 1, PyLong_FromUnsignedLongLong(emailbox->getComponentID()));
	PyTuple_SET_ITEM(args1, 2, PyLong_FromUnsignedLong(emailbox->getUType()));
	PyTuple_SET_ITEM(args1, 3, PyLong_FromUnsignedLong(emailbox->getType()));
	PyTuple_SET_ITEM(args, 1, args1);

	if(unpickleMethod == NULL){
		Py_DECREF(args);
		return NULL;
	}
	return args;
}