예제 #1
0
POVMSResult POVMS_MessageReceiver::ReceiveHandler(POVMSObjectPtr msg, POVMSObjectPtr result, int mode, void *privatedataptr)
{
    POVMS_MessageReceiver *self = (POVMS_MessageReceiver *)privatedataptr;
    HandlerNode *nodeptr = nullptr;
    POVMSType hclass = kPOVMSType_Null;
    POVMSType hid = kPOVMSType_Null;
    POVMSResult err = pov_base::kNoErr;

    if (self == nullptr)
        err = pov_base::kParamErr;
    if(err == pov_base::kNoErr)
        err = POVMSMsg_GetMessageClass(msg, &hclass);
    if(err == pov_base::kNoErr)
        err = POVMSUtil_GetType(msg, kPOVMSMessageIdentID, &hid);
    for (nodeptr = self->receivers; nodeptr != nullptr && err == pov_base::kNoErr; nodeptr = nodeptr->next)
    {
        if((nodeptr->hclass == hclass) && ((nodeptr->hid == hid) || (nodeptr->hid == kPOVMSType_WildCard)))
        {
            if (nodeptr->handleroo != nullptr)
            {
                POVMS_Message result_obj(result);
                POVMS_Message msg_obj(msg);

                // Note: This try-catch block is only required because msg_obj.DetachData always has to be executed! [trf]
                try
                {
                    nodeptr->handleroo->Call(msg_obj, result_obj, mode);
                }
                catch(...)
                {
                    // result and msg no longer own their resources; if we don't clear them here,
                    // we can get a double-free in a parent method when this method throws an exception.
                    // an example of this is when create scene fails with an out-of-memory exception.
                    memset(result, 0, sizeof(*result));
                    memset(msg, 0, sizeof(*msg));

                    msg_obj.DetachData();
                    throw;
                }

                msg_obj.DetachData();

                if ((result != nullptr) && (result_obj.IsNull() == false))
                    *result = result_obj();
            }
            else if (nodeptr->handler != nullptr)
                nodeptr->handler->Call(msg, result, mode);
            else
                err = pov_base::kNullPointerErr;
        }
    }

    return err;
}
예제 #2
0
POVMSType POVMS_Message::GetClass()
{
	POVMSType type;
	int err;

	err = POVMSMsg_GetMessageClass(&data, &type);
	if(err != kNoErr)
		throw err;

	return type;
}
예제 #3
0
POVMSType POVMS_Message::GetClass()
{
    POVMSType type;
    int err;

    err = POVMSMsg_GetMessageClass(&data, &type);
    if(err != pov_base::kNoErr)
        throw POV_EXCEPTION_CODE(err);

    return type;
}
예제 #4
0
int POVMS_MessageReceiver::ReceiveHandler(POVMSObjectPtr msg, POVMSObjectPtr result, int mode, void *privatedataptr)
{
	POVMS_MessageReceiver *self = (POVMS_MessageReceiver *)privatedataptr;
	HandlerNode *nodeptr = NULL;
	POVMSType hclass = kPOVMSType_Null;
	POVMSType hid = kPOVMSType_Null;
	int err = kNoErr;

	if(self == NULL)
		err = kParamErr;
	if(err == kNoErr)
		err = POVMSMsg_GetMessageClass(msg, &hclass);
	if(err == kNoErr)
		err = POVMSUtil_GetType(msg, kPOVMSMessageIdentID, &hid);
	if(err == kNoErr)
	{
		for(nodeptr = self->receivers; nodeptr != NULL; nodeptr = nodeptr->next)
		{
			if((nodeptr->hclass == hclass) && ((nodeptr->hid == hid) || (nodeptr->hid == kPOVMSType_WildCard)))
			{
				try
				{
					if(nodeptr->handleroo != NULL)
					{
						POVMS_Message msg_obj(msg);
						POVMS_Message result_obj(result);

						nodeptr->handleroo->Call(msg_obj, result_obj, mode);

						msg_obj.DetachData();
						if(result != NULL)
							*result = result_obj();
						result_obj.DetachData();
					}
					else if(nodeptr->handler != NULL)
						nodeptr->handler->Call(msg, result, mode);
					else
						err = kNullPointerErr;
				}
				catch(int e)
				{
					err = e;
				}
				catch(...)
				{
					err = kParamErr;
				}
			}
		}
	}

	return err;
}