// Handle the FLOWGRAPH_ENABLE message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpFlowGraphBase::handleEnable(void) { int i; MpFlowGraphMsg msg(MpFlowGraphMsg::RESOURCE_ENABLE); MpResource* pResource; // iterate over all resources // invoke the enable() method for each resource in the flow graph for (i=0; i < mResourceCnt; i++) { // iterate through the resources pResource = mUnsorted[i]; // make each resource handle a RESOURCE_ENABLE message msg.setMsgDest(pResource); if (!pResource->handleMessage(msg)) { assert(FALSE); return FALSE; } } return TRUE; }
// Handle the FLOWGRAPH_SET_SAMPLES_PER_SEC message. // Returns TRUE if the message was handled, otherwise FALSE. UtlBoolean MpFlowGraphBase::handleSetSamplesPerSec(int samplesPerSec) { int i; MpFlowGraphMsg msg(MpFlowGraphMsg::RESOURCE_SET_SAMPLES_PER_SEC, NULL, NULL, NULL, samplesPerSec); MpResource* pResource; // iterate over all resources for (i=0; i < mResourceCnt; i++) { pResource = mUnsorted[i]; // make each resource handle a SET_SAMPLES_PER_SEC message msg.setMsgDest(pResource); if (!pResource->handleMessage(msg)) { assert(FALSE); return FALSE; } } mSamplesPerSec = samplesPerSec; return TRUE; }
// Processes all of the messages currently queued for this flow graph. // For now, this method always returns OS_SUCCESS. OsStatus MpFlowGraphBase::processMessages(void) { OsWriteLock lock(mRWMutex); UtlBoolean done; UtlBoolean handled; static MpFlowGraphMsg* pStopMsg = NULL; MpResource* pMsgDest; OsStatus res; // First, we send ourselves a FLOWGRAPH_PROCESS_FRAME message. // This message serves as a "stopper" in the message queue. When we // handle that message, we know that we have processed all of the messages // for the flowgraph (and its resources) that had arrived prior to the // start of this frame processing interval. if (NULL == pStopMsg) { pStopMsg = new MpFlowGraphMsg(MpFlowGraphMsg::FLOWGRAPH_PROCESS_FRAME); pStopMsg->setReusable(TRUE); } res = postMessage(*pStopMsg); assert(res == OS_SUCCESS); done = FALSE; while (!done) { // get the next message OsMsg* pMsg ; res = mMessages.receive(pMsg, OsTime::NO_WAIT); assert(res == OS_SUCCESS); if (pMsg->getMsgType() == OsMsg::MP_FLOWGRAPH_MSG) { MpFlowGraphMsg* pRcvdMsg = (MpFlowGraphMsg*) pMsg ; // determine if this message is intended for a resource in the // flow graph (as opposed to a message for the flow graph itself) pMsgDest = pRcvdMsg->getMsgDest(); if (pMsgDest != NULL) { // deliver the message if the resource is still part of this graph if (pMsgDest->getFlowGraph() == this) { handled = pMsgDest->handleMessage(*pRcvdMsg); assert(handled); } } else { // since pMsgDest is NULL, this msg is intended for the flow graph switch (pRcvdMsg->getMsg()) { case MpFlowGraphMsg::FLOWGRAPH_PROCESS_FRAME: done = TRUE; // "stopper" message encountered -- we are done break; // processing messages for this frame interval default: handled = handleMessage(*pRcvdMsg); assert(handled); break; } } pRcvdMsg->releaseMsg(); // free the msg } else { handled = handleMessage(*pMsg); assert(handled); pMsg->releaseMsg() ; } } return OS_SUCCESS; }