Exemplo n.º 1
0
// this could have been made easier with a user_timer. 
void CallBackFactory::run() {
  DBG("running CallBack thread.\n");
  while (true) {
    scheduled_calls_mut.lock();
    vector<string> todo;
    time_t now;
    time(&now);
    std::multimap<time_t, string>::iterator it = 
      scheduled_calls.begin();
    while (it != scheduled_calls.end()) {
      if (it->first > now)
	break;
      todo.push_back(it->second);
      scheduled_calls.erase(it);
      it = scheduled_calls.begin(); 
    }      
    scheduled_calls_mut.unlock();

    for (vector<string>::iterator it=todo.begin(); 
	 it != todo.end(); it++)  {
      createCall(*it);
    }

    sleep(1);
  }
}
Exemplo n.º 2
0
void GasMeter::count(Instruction _inst)
{
	if (!m_checkCall)
	{
		// Create gas check call with mocked block cost at begining of current cost-block
		m_checkCall = createCall(m_gasCheckFunc, {m_runtimeManager.getGasPtr(), llvm::UndefValue::get(Type::Gas), m_runtimeManager.getJmpBuf()});
	}

	m_blockCost += getStepCost(_inst);
}
Exemplo n.º 3
0
void GasMeter::count(llvm::Value* _cost, llvm::Value* _jmpBuf, llvm::Value* _gasPtr)
{
	if (_cost->getType() == Type::Word)
	{
		auto gasMax256 = m_builder.CreateZExt(Constant::gasMax, Type::Word);
		auto tooHigh = m_builder.CreateICmpUGT(_cost, gasMax256, "costTooHigh");
		auto cost64 = m_builder.CreateTrunc(_cost, Type::Gas);
		_cost = m_builder.CreateSelect(tooHigh, Constant::gasMax, cost64, "cost");
	}

	assert(_cost->getType() == Type::Gas);
	createCall(m_gasCheckFunc, {_gasPtr ? _gasPtr : m_runtimeManager.getGasPtr(), _cost, _jmpBuf ? _jmpBuf : m_runtimeManager.getJmpBuf()});
}
Exemplo n.º 4
0
int Phone::newCall()
{
	int callId = findFreeCall();
	if (callId == -1)
	{
		try
		{
			callId = createCall();
			emit newCallSignal(callId);
		}
		catch (Error e)
		{
// FIXME		Nothing to do?
		}
	}
//	qWarning(QString("Phone::newCall() = %1").arg(callId));
	return callId;
}
Exemplo n.º 5
0
/*!
  Dials a \a number if there are no currently active calls. If a
  \a contact is specified, it is used as the contact to display and
  insert into the call history. Before calling this function,
  you should check that there are no incoming calls, or active calls.
  If \a sendcallerid is true, then send the caller's identifier as part
  of the dial sequence.

  If \a callType is "Voice" a GSM call will be dialed.  If \a callType is
  "VoIP" a VoIP call will be dialed.
*/
void DialerControl::dial( const QString &number, bool sendcallerid, const QString& callType, const QUniqueId &contact )
{

    QUniqueId matchedContact;
    if (contact.isNull() && !number.isEmpty())
        matchedContact = ServerContactModel::instance()->matchPhoneNumber(number).uid();
    else
        matchedContact = contact;

    if ( isDialing() ) {
        //qWarning("BUG! Attempt to dial while there is already a dialing call");
    }
    if( !hasActiveCalls() && !isDialing() )
    {
        // Collect up the dial options.
        QDialOptions dialopts;
        dialopts.setNumber( number );
        if ( sendcallerid )
            dialopts.setCallerId( QDialOptions::SendCallerId );
        else
            dialopts.setCallerId( QDialOptions::DefaultCallerId );
        dialopts.setContact( matchedContact );

        // Allow other parts of the server (e.g. GsmKeyActions) to
        // modify the dial options to account for supplementary services.
        bool handledAlready = false;
        emit modifyDial( dialopts, handledAlready );
        if ( handledAlready )
            return;

        // Call the specified number.
        QPhoneCall call = createCall(callType);
        phoneValueSpace.setAttribute( "LastDialedCall", QVariant(number) );
        call.dial( dialopts );

        // cache call here to preserve the information even if the battery run out.
        cacheCall( call );
    }
}
void sipXtapiTestSuite::testLineAliases() 
{    
    bool bRC ;
    EventValidator validatorCalling("testLineAliases.calling") ;
    EventValidator validatorCalled("testLineAliases.called") ;

    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)
    {
        printf("\ntestLineAliases (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);
        SIPX_CALL hCall ;
        SIPX_LINE hLine ;
        SIPX_LINE hReceivingLine;
        SIPX_RESULT rc ;

        validatorCalling.reset() ;
        validatorCalled.reset() ;
        validatorCalling.ignoreEventCategory(EVENT_CATEGORY_MEDIA);
        validatorCalled.ignoreEventCategory(EVENT_CATEGORY_MEDIA);

        // Setup Auto-answer call back
        resetAutoAnswerCallback() ;
        sipxEventListenerAdd(g_hInst2, AutoAnswerCallback, NULL) ;
        sipxEventListenerAdd(g_hInst2, UniversalEventValidatorCallback, &validatorCalled) ;        
        sipxEventListenerAdd(g_hInst, UniversalEventValidatorCallback, &validatorCalling) ;

        sipxLineAdd(g_hInst2, "sip:[email protected]:9100", &hReceivingLine, CONTACT_AUTO);
        bRC = validatorCalled.waitForLineEvent(hReceivingLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        rc = sipxLineAddAlias(hReceivingLine, "sip:[email protected]:9100") ;
        CPPUNIT_ASSERT(rc == SIPX_RESULT_SUCCESS) ;

        createCall(&hLine, &hCall) ;
        bRC = validatorCalling.waitForLineEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;

        sipxCallConnect(hCall, "sip:[email protected]:9100") ;
        
        // Validate Calling Side
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;

        // Validate Called Side
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
                
        int connectionId = -1;
        
        CPPUNIT_ASSERT_EQUAL(sipxCallGetConnectionId(hCall, connectionId), SIPX_RESULT_SUCCESS);
        CPPUNIT_ASSERT(connectionId != -1) ;
                
        SIPX_CALL hDestroyedCall = hCall ;
        destroyCall(hCall) ;

        // Validate Calling Side
        bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;

        // Validate Called Side
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;


        validatorCalling.reset() ;
        validatorCalled.reset() ;        
        validatorCalling.ignoreEventCategory(EVENT_CATEGORY_MEDIA);
        validatorCalled.ignoreEventCategory(EVENT_CATEGORY_MEDIA);
        resetAutoAnswerCallback() ;
        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS);

        createCall(&hLine, &hCall) ;
        bRC = validatorCalling.waitForLineEvent(hLine, LINESTATE_PROVISIONED, LINESTATE_PROVISIONED_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;        

        sipxCallConnect(hCall, "sip:[email protected]:9100") ;
        
        // Validate Calling Side
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_DIALTONE, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_REMOTE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;

        // Validate Called Side
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_NEWCALL, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_OFFERING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_ALERTING, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_CONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
                
        connectionId = -1;
        
        CPPUNIT_ASSERT_EQUAL(sipxCallGetConnectionId(hCall, connectionId), SIPX_RESULT_SUCCESS);
        CPPUNIT_ASSERT(connectionId != -1) ;
                
        hDestroyedCall = hCall ;
        destroyCall(hCall) ;

        // Validate Calling Side
        bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalling.waitForCallEvent(hLine, hDestroyedCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;

        // Validate Called Side
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DISCONNECTED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = validatorCalled.waitForCallEvent(hReceivingLine, g_hAutoAnswerCallbackCall, CALLSTATE_DESTROYED, CALLSTATE_CAUSE_NORMAL, true) ;
        CPPUNIT_ASSERT(bRC) ;

        
        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, UniversalEventValidatorCallback, &validatorCalling), SIPX_RESULT_SUCCESS) ;
        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, AutoAnswerCallback, NULL), SIPX_RESULT_SUCCESS) ;
        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, UniversalEventValidatorCallback, &validatorCalled), SIPX_RESULT_SUCCESS) ;
    
        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLine), SIPX_RESULT_SUCCESS);
        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hReceivingLine), SIPX_RESULT_SUCCESS);
    }

    OsTask::delay(TEST_DELAY) ;

    checkForLeaks();
}
void sipXtapiTestSuite::testLines() 
{
    OsSysLog::initialize(0, "sipxTapi_testLines");
    OsSysLog::setLoggingPriority(PRI_DEBUG);
    OsSysLog::setOutputFile(0, "/sdcard/sipxtapi.log");

    for (int iStressFactor = 0; iStressFactor<STRESS_FACTOR; iStressFactor++)
    {
        SIPX_CALL hCall ;
        SIPX_LINE hLineGeorge ;
        SIPX_LINE hLineJane ;
        SIPX_LINE hLineBob ;
        SIPX_LINE hLineJill ;
    
        printf("\ntestLines (%2d of %2d)", iStressFactor+1, STRESS_FACTOR);

        CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, URL_GEORGE_AT_JUNGLE, &hLineGeorge), SIPX_RESULT_SUCCESS) ;
        CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst, URL_JANE_AT_JUNGLE, &hLineJane), SIPX_RESULT_SUCCESS) ;
        CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst2, URL_BOB_AT_LOCALHOST, &hLineBob), SIPX_RESULT_SUCCESS) ;
        CPPUNIT_ASSERT_EQUAL(sipxLineAdd(g_hInst2, URL_JILL_AT_LOCALHOST, &hLineJill), SIPX_RESULT_SUCCESS) ;

        /**
         * Make call as George to Jill
         */
        // Setup Auto-answer call back
        sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_JILL_AT_LOCALHOST) ;

        printf("createCall line: %d %s\n", hLineGeorge, URL_GEORGE_AT_JUNGLE);
        createCall(hLineGeorge, &hCall) ;

        sipxCallConnect(hCall, URL_JILL_AT_LOCALHOST) ;
        OsTask::delay(CALL_DELAY*2) ;
        destroyCall(hCall) ;
        OsTask::delay(CALL_DELAY*4) ;

        // Remove George's line
        g_lineRecorder2.clear() ;
        
        SIPX_RESULT rc = sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_JILL_AT_LOCALHOST);
        CPPUNIT_ASSERT_EQUAL(rc, SIPX_RESULT_SUCCESS) ;

        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineGeorge), SIPX_RESULT_SUCCESS) ;
        OsTask::delay(CALL_DELAY*2);
        
        /**
         * Make call as Jane to Bob
         */ 
        sipxEventListenerAdd(g_hInst, linetest_verify_lineurl, (void*)URL_JANE_AT_JUNGLE) ;

        sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_BOB_AT_LOCALHOST) ;
        printf("createCall line: %d %s\n", hLineJane, URL_JANE_AT_JUNGLE);
        createCall(hLineJane, &hCall) ;

        sipxCallConnect(hCall, URL_BOB_AT_LOCALHOST) ;
        OsTask::delay(CALL_DELAY*2) ;
        destroyCall(hCall) ;
        OsTask::delay(CALL_DELAY*4) ;

        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst, linetest_verify_lineurl, (void*)URL_JANE_AT_JUNGLE), SIPX_RESULT_SUCCESS) ;
        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_BOB_AT_LOCALHOST), SIPX_RESULT_SUCCESS) ;

        /**
         * Make call as Jane to BOGUS (line not defined)
         */
        sipxEventListenerAdd(g_hInst2, basicCall_CallBack_Receive, (void*)URL_EMPTY_STRING) ;
        createCall(hLineJane, &hCall) ;

        sipxCallConnect(hCall, URL_BOGUS_AT_LOCALHOST) ;
        OsTask::delay(22000) ;       
        destroyCall(hCall) ;
        OsTask::delay(CALL_DELAY*4) ;

        CPPUNIT_ASSERT_EQUAL(sipxEventListenerRemove(g_hInst2, basicCall_CallBack_Receive, (void*)URL_EMPTY_STRING), SIPX_RESULT_SUCCESS) ;

        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineJane), SIPX_RESULT_SUCCESS) ; 
        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineBob), SIPX_RESULT_SUCCESS) ; 
        CPPUNIT_ASSERT_EQUAL(sipxLineRemove(hLineJill), SIPX_RESULT_SUCCESS) ; 
    }

    OsTask::delay(TEST_DELAY) ;    
    checkForLeaks();
}