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


C++ OsEvent::signal方法代码示例

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


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

示例1: handleMessage

// Handle an incoming message
// Return TRUE if the message was handled, otherwise FALSE.
UtlBoolean MpMediaTask::handleMessage(OsMsg& rMsg)
{
   UtlBoolean           handled;
   MpFlowGraphBase*    pFlowGraph;
   MpMediaTaskMsg*     pMsg;

   if (rMsg.getMsgType() != OsMsg::MP_TASK_MSG)
      return FALSE;    // the method only handles MP_TASK_MSG messages

   pMsg = (MpMediaTaskMsg*) &rMsg;
   pFlowGraph = (MpFlowGraphBase*) pMsg->getPtr1();

   handled = TRUE;     // until proven otherwise, assume we'll handle the msg

   switch (pMsg->getMsg())
   {
   case MpMediaTaskMsg::MANAGE:
      {
         OsEvent* event = (OsEvent*)pMsg->getPtr2();
         if (!handleManage(pFlowGraph))
            mHandleMsgErrs++;
         if (event) event->signal(0);
         break;
      }
   case MpMediaTaskMsg::SET_FOCUS:
      if (!handleSetFocus(pFlowGraph))
         mHandleMsgErrs++;
      break;
   case MpMediaTaskMsg::START:
      if (!handleStart(pFlowGraph))
         mHandleMsgErrs++;
      break;
   case MpMediaTaskMsg::STOP:
      if (!handleStop(pFlowGraph))
         mHandleMsgErrs++;
      break;
   case MpMediaTaskMsg::UNMANAGE:
      {
         OsEvent* event = (OsEvent*)pMsg->getPtr2();
         if (!handleUnmanage(pFlowGraph))
            mHandleMsgErrs++;
         if (event) event->signal(0);
         break;
      }
   case MpMediaTaskMsg::WAIT_FOR_SIGNAL:
      if (!handleWaitForSignal(pMsg))
         mHandleMsgErrs++;
      break;
   default:
      handled = FALSE; // we didn't handle the message after all
      break;
   }

   return handled;
}
开发者ID:Jaroslav23,项目名称:sipxtapi,代码行数:57,代码来源:MpMediaTask.cpp

示例2: handleMessage

    UtlBoolean handleMessage(OsMsg& rMsg)
    {
        int waitMsec = rand();
        delay((waitMsec % 3 ) * 50);

        OsEvent* event = ((OsRpcMsg&)rMsg).getEvent();
        CPPUNIT_ASSERT(event);
   
        mNumEvents++;
        int eventIndex =-1;
        event->getUserData(eventIndex);
        //CPPUNIT_ASSERT(mNumEvents == eventIndex);
        CPPUNIT_ASSERT(mNumEvents < mMaxEvents);

        OsStatus eventStat = event->signal(mNumEvents);
        if(eventStat == OS_ALREADY_SIGNALED)
        {
           // The Right side lost, the Left side is done
           // we delete on this side
           delete event;
           event = NULL;
           mpDeletedEvent[mNumEvents] = TRUE;
        }
        else
        {
           // This/Right side won. we do nothing
           mpDeletedEvent[mNumEvents] = FALSE;
           //osPrintf("Right: %d\n", eventStat);
        }
        return(TRUE);
    }
开发者ID:Jaroslav23,项目名称:sipxtapi,代码行数:31,代码来源:OsEventTest.cpp

示例3: run

int ClientTask::run(void* runArg)
{
    OsEvent* pEvent = (OsEvent*)runArg;
    OsStatus status;
    
    fileExecute(InputFile, false);
    
    do {
        //printf("%s is signaling\n", mName.data());
        status = pEvent->signal(1);
    } 
    while (status == OS_ALREADY_SIGNALED);
   
    return 0;
}
开发者ID:mranga,项目名称:sipxecs,代码行数:15,代码来源:configrpc.cpp

示例4: testTimedEvent

    void testTimedEvent()
    {
        OsTime   eventTimeout(2,0);
        OsEvent* pEvent;

        pEvent = new OsEvent(12345);
        time_t epochTime = time(NULL);
        CPPUNIT_ASSERT(pEvent->wait(eventTimeout) != OS_SUCCESS);
        pEvent->signal(67890);
        CPPUNIT_ASSERT_EQUAL(OS_SUCCESS, pEvent->wait(eventTimeout));
        pEvent->reset();
        CPPUNIT_ASSERT(pEvent->wait(eventTimeout) != OS_SUCCESS);
        epochTime = time(NULL) - epochTime;
   
        // Make sure we waited (approximately) 2 seconds each time.
        CPPUNIT_ASSERT(epochTime > 2 && epochTime < 6);
   
        delete pEvent;
    }
开发者ID:Jaroslav23,项目名称:sipxtapi,代码行数:19,代码来源:OsEventTest.cpp

示例5: main


//.........这里部分代码省略.........

#if !defined(_VXWORKS)
   try
   {
      OsMsgQ* pMsgQ2 = new OsMsgQ(OsMsgQ::DEF_MAX_MSGS,
                                  OsMsgQ::DEF_MAX_MSG_LEN,
                                  OsMsgQ::Q_PRIORITY,
                                  "MQ1");
      delete pMsgQ2;
   }
   catch (const OsExcept* exc)
   {

      UtlString txt;
      cout << "Exception:" << endl;
      cout << "  Major Code: " << exc->getMajorCode() << endl;
      cout << "  Minor Code: " << exc->getMinorCode() << endl;
      txt = exc->getText();
      cout << "  Text:       " << txt.data()    << endl;
      txt = exc->getContext();
      cout << "  Context:    " << txt.data() << endl;

      delete exc;
   }
#endif

   delete pMsgQ1;

/* ============================ OsCallback ================================ */

   OsCallback* pCallback;

   pCallback = new OsCallback(12345, handleTimerEvent);
   pCallback->signal(67890);
   delete pCallback;

/* ============================ OsEvent =================================== */

   OsTime   eventTimeout(2,0);
   OsEvent* pEvent;

   cout << "Testing OsEvent, please wait..." << endl;
   pEvent = new OsEvent(12345);
   int epochTime = time(NULL);
   assert(pEvent->wait(eventTimeout) != OS_SUCCESS);
   pEvent->signal(67890);
   assert(pEvent->wait(eventTimeout) == OS_SUCCESS);
   pEvent->reset();
   assert(pEvent->wait(eventTimeout) != OS_SUCCESS);
   epochTime = time(NULL) - epochTime;

   // Make sure we waited (approximately) 2 seconds each time.
   assert(epochTime > 2 && epochTime < 6);

   delete pEvent;
   cout << "Done testing OsEvent." << endl;

/* ============================ OsConfigDb ================================ */

   OsConfigDb* pConfigDb;

   pConfigDb = new OsConfigDb();
   delete pConfigDb;

/* ============================ OsTimerTask =============================== */
开发者ID:ClydeFroq,项目名称:sipxecs,代码行数:66,代码来源:main.cpp

示例6: waitUntilAvailable

UtlBoolean SipTransactionList::waitUntilAvailable(SipTransaction* transaction,
                                                 const UtlString& hash)
{
    UtlBoolean exists;
    UtlBoolean busy = FALSE;
    int numTries = 0;

    do
    {
        numTries++;

        lock();
        exists = transactionExists(transaction, hash);

        if(exists)
        {
            busy =  transaction->isBusy();
            if(!busy)
            {
                transaction->markBusy();
                unlock();
//#ifdef TEST_PRINT
                OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipTransactionList::waitUntilAvailable %p locked after %d tries\n",
                    transaction, numTries);
//#endif
            }
            else
            {
                // We set an event to be signaled when a
                // transaction is released.
                OsEvent* waitEvent = new OsEvent;
                transaction->notifyWhenAvailable(waitEvent);

                // Must unlock while we wait or there is a dead lock
                unlock();

//#ifdef TEST_PRINT
                OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipTransactionList::waitUntilAvailable %p waiting on: %p after %d tries\n",
                    transaction, waitEvent, numTries);
//#endif

                OsStatus waitStatus;
                OsTime transBusyTimeout(1, 0);
                int waitTime = 0;
                do
                {
                    if(waitTime > 0)
                        OsSysLog::add(FAC_SIP, PRI_WARNING, "SipTransactionList::waitUntilAvailable %p still waiting: %d",
                            transaction, waitTime);

                    waitStatus = waitEvent->wait(transBusyTimeout);
                    waitTime+=1;
                }
                while(waitStatus != OS_SUCCESS && waitTime < 30);

                // If we were never signaled, then we signal the
                // event so the other side knows that it has to
                // free up the event
                if(waitEvent->signal(-1) == OS_ALREADY_SIGNALED)
                {
                    delete waitEvent;
                    waitEvent = NULL;
                }

                // If we bailed out before the event was signaled
                // pretend the transaction does not exist.
                if(waitStatus != OS_SUCCESS)
                {
                    exists = FALSE;
                }

                if(waitTime > 1)
                {
                    if (OsSysLog::willLog(FAC_SIP, PRI_WARNING))
                    {
                        UtlString transTree;
                        UtlString waitingTaskName;
                        OsTask* waitingTask = OsTask::getCurrentTask();
                        if(waitingTask) waitingTaskName = waitingTask->getName();
                        transaction->dumpTransactionTree(transTree, FALSE);
                        OsSysLog::add(FAC_SIP, PRI_WARNING, "SipTransactionList::waitUntilAvailable status: %d wait time: %d transaction: %p task: %s transaction tree: %s",
                            waitStatus, waitTime, transaction, waitingTaskName.data(), transTree.data());
                    }
                }

//#ifdef TEST_PRINT
                OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipTransactionList::waitUntilAvailable %p done waiting after %d tries\n",
                    transaction, numTries);
//#endif
            }
        }
        else
        {
            unlock();
//#ifdef TEST_PRINT
            OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipTransactionList::waitUntilAvailable %p gone after %d tries\n",
                    transaction, numTries);
//#endif
        }
    }
//.........这里部分代码省略.........
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:101,代码来源:SipTransactionList.cpp

示例7: testThreadedEvent

    void testThreadedEvent()
    {
        // Seed the random number generator
        srand(OsDateTime::getSecsSinceEpoch());

        int numTries = 100;
        int* rightResults = new int[numTries];
        int* leftResults = new int[numTries];

        // Create the Right thread.  This context will be the
        // Left thread.
        RightEventThread rightThread(rightResults, numTries);
        rightThread.start();

        int index;
        for(index = 0; index < numTries; index++)
        {
            OsEvent* event = new OsEvent(index);
            OsRpcMsg eventMsg(OsMsg::USER_START,0,*event);
            rightThread.postMessage(eventMsg);

            int waitTimeMsec = (rand() % 3) * 110;
            OsTime time(0, waitTimeMsec * 1000);
            event->wait(time);

            OsStatus eventStat = event->signal(index);
            if(eventStat == OS_ALREADY_SIGNALED)
            {
                // We (Left) lost the other side is done
                int eventData;
                event->getEventData(eventData);
                CPPUNIT_ASSERT(eventData == index);

                // This/Left side deletes the event
                delete event;
                event = NULL;
               leftResults[index] = TRUE;
            }
            else
            {
                // The other/Right side lost
                // Do nothing
                leftResults[index] = FALSE;
                //osPrintf("Left: %d\n", eventStat);
            }
        }

        OsTask::delay(1000);

        int leftDeletes = 0;
        int rightDeletes = 0;
        for(index = 0; index < numTries; index++)
        {
            if(leftResults[index] == TRUE)
            {
                leftDeletes++;
            }
            if(rightResults[index] == TRUE)
            {
                rightDeletes++;
            }
            if(rightResults[index] == leftResults[index])
            {
               //osPrintf("Left deleted: %d Right deleted: %d\n",
               //           leftDeletes, rightDeletes);
               //osPrintf("[%d]: Both sides %s\n", index, 
               //        rightResults[index] ? "Deleted" : "Did not delete");
            }
            CPPUNIT_ASSERT(rightResults[index] != leftResults[index]);
        }

        //osPrintf("Left deleted: %d Right deleted: %d\n",
        //        leftDeletes, rightDeletes);

        CPPUNIT_ASSERT(leftDeletes + rightDeletes == numTries);
    }
开发者ID:Jaroslav23,项目名称:sipxtapi,代码行数:76,代码来源:OsEventTest.cpp

示例8: waitForClientToWrite

UtlBoolean SipProtocolServerBase::waitForClientToWrite(SipClient* client)
{
    UtlBoolean exists;
    UtlBoolean busy = FALSE;
    int numTries = 0;

    do
    {
        numTries++;

        mClientLock.acquireWrite();
        exists = clientExists(client);

        if(exists)
        {
            busy =  client->isInUseForWrite();
            if(!busy)
            {
                client->markInUseForWrite();
                mClientLock.releaseWrite();
                if(numTries > 1)
                {
                   OsSysLog::add(FAC_SIP, PRI_DEBUG,
                                 "Sip%sServerBase::waitForClientToWrite %p locked after %d tries",
                                 mProtocolString.data(), client, numTries);
                }
            }
            else
            {
                // We set an event to be signaled when a
                // transaction is released.
                OsEvent* waitEvent = new OsEvent();
                client->notifyWhenAvailableForWrite(*waitEvent);

                // Must unlock while we wait or there is a dead lock
                mClientLock.releaseWrite();
#ifdef TEST_PRINT
                OsSysLog::add(FAC_SIP, PRI_DEBUG,
                              "Sip%sServerBase::waitForClientToWrite %p "
                              "waiting on: %p after %d tries",
                              mProtocolString.data(), client, waitEvent, numTries);
#endif

                // Do not block forever
                OsTime maxWaitTime(0, 500000);

                // If the other side signaled
                if(waitEvent->wait(maxWaitTime)  == OS_SUCCESS)
                {
                    // The other side is no longer referencing
                    // the event.  This side must clean it up
                    delete waitEvent;
                    waitEvent = NULL;
                }
                // A timeout occurred and the other side did not signal yet
                else
                {
                    // Signal the other side to indicate we are done
                    // with the event.  If already signaled, we lost
                    // a race and the other side was done first.
                    if(waitEvent->signal(0) == OS_ALREADY_SIGNALED)
                    {
                        delete waitEvent;
                        waitEvent = NULL;
                    }
                }

#ifdef TEST_PRINT
                OsSysLog::add(FAC_SIP, PRI_DEBUG,
                              "Sip%sServerBase::waitForClientToWrite %p done waiting after %d tries",
                              mProtocolString.data(), client, numTries);
#endif
            }
        }
        else
        {
            mClientLock.releaseWrite();

            OsSysLog::add(FAC_SIP, PRI_ERR,
                          "Sip%sServerBase::waitForClientToWrite %p gone after %d tries",
                          mProtocolString.data(), client, numTries);
        }
    }
    while(exists && busy);

    return(exists && !busy);
}
开发者ID:John-Chan,项目名称:sipXtapi,代码行数:87,代码来源:SipProtocolServerBase.cpp


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