TEST_F(SwitchInputMapperTest, testProcessInput) {
    MockInputReportDefinition reportDef;
    MockInputDeviceNode deviceNode;
    deviceNode.addSwitch(SW_LID);

    EXPECT_CALL(reportDef, addCollection(_, _));
    EXPECT_CALL(reportDef, declareUsages(_, _, _));

    mMapper->configureInputReport(&deviceNode, &reportDef);

    MockInputReport report;
    EXPECT_CALL(reportDef, allocateReport())
    .WillOnce(Return(&report));

    {
        // Test two switch events in order
        InSequence s;
        EXPECT_CALL(report, setBoolUsage(INPUT_COLLECTION_ID_SWITCH, INPUT_USAGE_SWITCH_LID, 1, 0));
        EXPECT_CALL(report, reportEvent(_));
        EXPECT_CALL(report, setBoolUsage(INPUT_COLLECTION_ID_SWITCH, INPUT_USAGE_SWITCH_LID, 0, 0));
        EXPECT_CALL(report, reportEvent(_));
    }

    InputEvent events[] = {
        {0, EV_SW, SW_LID, 1},
        {1, EV_SYN, SYN_REPORT, 0},
        {2, EV_SW, SW_LID, 0},
        {3, EV_SYN, SYN_REPORT, 0},
    };
    for (auto e : events) {
        mMapper->process(e);
    }
}
/*------------------------------------------------------------------------------
 *  The thread function
 *----------------------------------------------------------------------------*/
void *
MultiThreadedConnector :: ThreadData :: threadFunction( void  * param )
{
    struct sched_param  sched;
    int sched_type;
    ThreadData     * threadData = (ThreadData*) param;
    
    pthread_getschedparam( threadData->thread, &sched_type, &sched );

    reportEvent( 5, "MultiThreadedConnector :: ThreadData :: threadFunction, was (thread, priority, type): ",
        param,
	sched.sched_priority,
        sched_type == SCHED_FIFO ? "SCHED_FIFO" :
            sched_type == SCHED_RR ? "SCHED_RR" :
            sched_type == SCHED_OTHER ? "SCHED_OTHER" :
            "INVALID"
    );

    sched.sched_priority = 1;
    pthread_setschedparam( threadData->thread, SCHED_FIFO, &sched);

    pthread_getschedparam( threadData->thread, &sched_type, &sched );
    reportEvent( 5, "MultiThreadedConnector :: ThreadData :: threadFunction, now is (thread, priority, type): ",
        param,
	sched.sched_priority,
        sched_type == SCHED_FIFO ? "SCHED_FIFO" :
            sched_type == SCHED_RR ? "SCHED_RR" :
            sched_type == SCHED_OTHER ? "SCHED_OTHER" :
            "INVALID"
    );

    threadData->connector->sinkThread( threadData->ixSink);

    return 0;
}
Exemple #3
0
/*------------------------------------------------------------------------------
 *  Tell each sink to cut what they are doing, and start again.
 *----------------------------------------------------------------------------*/
void
DarkIce :: cut ( void )                             throw ()
{
    reportEvent( 5, "cutting");

    encConnector->cut();

    reportEvent( 5, "cutting ends");
}
Exemple #4
0
/*------------------------------------------------------------------------------
 *  Run
 *----------------------------------------------------------------------------*/
int
DarkIce :: run ( void )                             throw ( Exception )
{
    reportEvent( 3, "encoding");
    setRealTimeScheduling();
    encode();
    setOriginalScheduling();
    reportEvent( 3, "encoding ends");

    return 0;
}
Exemple #5
0
/*------------------------------------------------------------------------------
 *  Set POSIX real-time scheduling
 *----------------------------------------------------------------------------*/
void
DarkIce :: setRealTimeScheduling ( void )               throw ( Exception )
{
// Only if the OS has the POSIX real-time scheduling functions implemented.
#if defined( HAVE_SCHED_GETSCHEDULER ) && defined( HAVE_SCHED_GETPARAM )
    int                 high_priority;
    struct sched_param  param;

    /* store the old scheduling parameters */
    if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) {
        throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno);
    }

    if ( sched_getparam( 0, &param) == -1 ) {
        throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
    }
    origSchedPriority = param.sched_priority;
    
    /* set SCHED_FIFO with max - 1 priority or user configured value */
    if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
        throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
    }
    reportEvent( 8, "scheduler high priority", high_priority);

    if (realTimeSchedPriority > high_priority) {
        param.sched_priority = high_priority - 1;
    } else {
        param.sched_priority = realTimeSchedPriority;
    }

    if ( sched_setscheduler( 0, SCHED_FIFO, &param) == -1 ) {
        reportEvent( 1,
                     "Could not set POSIX real-time scheduling, "
                     "this may cause recording skips.\n"
                     "Try to run darkice as the super-user.");
    } else {
        /* ask the new priortiy and report it */
        if ( sched_getparam( 0, &param) == -1 ) {
            throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
        }

        reportEvent( 1,
                     "Using POSIX real-time scheduling, priority",
                     param.sched_priority );
    }
#else
    reportEvent( 1, "POSIX scheduling not supported on this system, "
                    "this may cause recording skips");
#endif // HAVE_SCHED_GETSCHEDULER && HAVE_SCHED_GETPARAM
}
Exemple #6
0
/*------------------------------------------------------------------------------
 *  Set POSIX real-time scheduling, if super-user
 *----------------------------------------------------------------------------*/
void
DarkIce :: setRealTimeScheduling ( void )               throw ( Exception )
{
    uid_t   euid;

    euid = geteuid();

    if ( euid == 0 ) {
        int                 high_priority;
        struct sched_param  param;

        /* store the old scheduling parameters */
        if ( (origSchedPolicy = sched_getscheduler(0)) == -1 ) {
            throw Exception( __FILE__, __LINE__, "sched_getscheduler", errno);
        }

        if ( sched_getparam( 0, &param) == -1 ) {
            throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
        }
        origSchedPriority = param.sched_priority;
        
        /* set SCHED_FIFO with max - 1 priority */
        if ( (high_priority = sched_get_priority_max(SCHED_FIFO)) == -1 ) {
            throw Exception(__FILE__,__LINE__,"sched_get_priority_max",errno);
        }
        reportEvent( 8, "scheduler high priority", high_priority);

        param.sched_priority = high_priority - 1;

        if ( sched_setscheduler( 0, SCHED_FIFO, &param) == -1 ) {
            throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno);
        }

        /* ask the new priortiy and report it */
        if ( sched_getparam( 0, &param) == -1 ) {
            throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
        }

        reportEvent( 1,
                     "Using POSIX real-time scheduling, priority",
                     param.sched_priority );
    } else {
        reportEvent( 1,
        "Not running as super-user, unable to use POSIX real-time scheduling" );
        reportEvent( 1,
        "It is recommended that you run this program as super-user");
    }
}
Exemple #7
0
/*------------------------------------------------------------------------------
 *  Open the audio source
 *----------------------------------------------------------------------------*/
bool
SerialUlaw :: open ( void )                       throw ( Exception )
{
    struct termios    ts;

    if ( isOpen() ) {
        return false;
    }

    switch ( getBitsPerSample() ) {
        case 16:
            break;

        default:
            return false;
    }

    if (getChannel() != 1) {
        reportEvent(3, "Only mono input supported for Serial ULaw");
        return false;
    }
    if (getSampleRate() != 8000) {
        reportEvent(3, "Only 8000 Hz sample rate supported for Serial ULaw");
        return false;
    }

    if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) {
        fileDescriptor = 0;
        return false;
    }

    if(tcgetattr(fileDescriptor, &ts) < 0) {
        close();
        throw Exception( __FILE__, __LINE__, "can't get tty settings");
    }

    cfsetispeed(&ts, B115200);
    cfmakeraw(&ts);
    ts.c_cflag |= CLOCAL;
    if(tcsetattr(fileDescriptor, TCSANOW, &ts) < 0) {
        close();
        throw Exception( __FILE__, __LINE__, "can't set tty settings");
    }

    tcflush(fileDescriptor, TCIFLUSH);

    return true;
}
Exemple #8
0
static TI_STATUS state_WaitFwInit(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_FW_INIT_DONE:
		this->fCurrentState = state_WaitDrvStart;

		wlanDrvIf_UpdateDriverState(this->hOs, DRV_STATE_RUNNING);

		/* transition is now complete */
		notifyTransitionComplete(this, TI_FALSE);
		rc = TI_OK;

		break;
	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
Exemple #9
0
/*------------------------------------------------------------------------------
 *  Open the connection
 *----------------------------------------------------------------------------*/
bool
CastSink :: open ( void )                       throw ( Exception )
{
    if ( isOpen() ) {
        return false;
    }

    if ( !getSink()->open() ) {
        return false;
    }

    if ( !sendLogin() ) {
        close();
        return false;
    }

    if ( streamDump != 0 ) {
        if ( !streamDump->isOpen() ) {
            if ( !streamDump->open() ) {
                reportEvent( 2, "can't open stream dump");
            }
        }
    }
    
    return true;
}
/*------------------------------------------------------------------------------
 *  Send pending Vorbis blocks to the underlying stream
 *----------------------------------------------------------------------------*/
void
VorbisLibEncoder :: vorbisBlocksOut ( void )                throw ()
{
    while ( 1 == vorbis_analysis_blockout( &vorbisDspState, &vorbisBlock) ) {
        ogg_packet      oggPacket;
        ogg_page        oggPage;

        vorbis_analysis( &vorbisBlock, &oggPacket);
#ifdef VORBIS_LIB_RC3
        vorbis_bitrate_addblock( &vorbisBlock);

        while ( vorbis_bitrate_flushpacket( &vorbisDspState, &oggPacket) ) {
#endif

            ogg_stream_packetin( &oggStreamState, &oggPacket);

            while ( ogg_stream_pageout( &oggStreamState, &oggPage) ) {
                int    written;
                
                written  = sink->write( oggPage.header, oggPage.header_len);
                written += sink->write( oggPage.body, oggPage.body_len);

                if ( written < oggPage.header_len + oggPage.body_len ) {
                    // just let go data that could not be written
                    reportEvent( 2,
                           "couldn't write full vorbis data to underlying sink",
                           oggPage.header_len + oggPage.body_len - written);
                }
            }
#ifdef VORBIS_LIB_RC3
        }
#endif
    }
}
Exemple #11
0
static TI_STATUS state_WaitSmeStop(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_SME_STOPPED:
		this->fCurrentState = state_Sleep;

		if (this->tCurrentTransition.bContinueToOff)
		{
			this->tCurrentTransition.bContinueToOff = TI_FALSE;
			rc = this->fCurrentState(this, PWRSTATE_EVNT_OFF);
		}
		else
		{
			/* transition is now complete */
			TWD_CompleteSuspend(this->hTWD);
			notifyTransitionComplete(this, TI_FALSE);
			rc = TI_OK;
		}

		break;

	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
Exemple #12
0
static TI_STATUS state_LowOn(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_ON:
		this->fCurrentState = state_FullOn;

		powerMgr_Resume(this->hPowerMgr);
		scanCncn_Resume(this->hScanCncn);
		measurementMgr_Resume(this->hMeasurementMgr);

		/* transition is now complete */
		notifyTransitionComplete(this, TI_FALSE);
		rc = TI_OK;

		break;

	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
Exemple #13
0
static TI_STATUS state_WaitScanStopDueToSleepOff(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_SCANCNCN_STOPPED:
	{
		this->fCurrentState = state_WaitSmeStop;

		sme_Stop(this->hSme);

		rc = TI_PENDING;

		break;
	}
	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
Exemple #14
0
static TI_STATUS state_WaitScanStopDueToDoze(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_SCANCNCN_STOPPED:
	{
		this->fCurrentState = state_WaitDoze;

		tmr_StartTimer(this->hDozeTimer, pwrState_DozeTimeout, this, this->tConfig.uDozeTimeout, TI_FALSE);
		rc = powerMgr_Suspend(this->hPowerMgr, &this->tConfig, pwrState_DozeDone, this);

		break;
	}
	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
Exemple #15
0
static TI_STATUS state_WaitDrvStop(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_DRVMAIN_STOPPED:
		this->fCurrentState = state_Off;

		wlanDrvIf_UpdateDriverState(this->hOs, DRV_STATE_STOPPED);

		/* transition is now complete */
		TWD_CompleteSuspend(this->hTWD);
		notifyTransitionComplete(this, TI_FALSE);
		rc = TI_OK;

		break;
	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
Exemple #16
0
/*------------------------------------------------------------------------------
 *  Flush the data from the encoder
 *----------------------------------------------------------------------------*/
void
LameLibEncoder :: flush ( void )
                                                            throw ( Exception )
{
    if ( !isOpen() ) {
        return;
    }

    // data chunk size estimate according to lame documentation
    unsigned int    mp3Size = 7200;
    unsigned char * mp3Buf  = new unsigned char[mp3Size];
    int             ret;

    ret = lame_encode_flush( lameGlobalFlags, mp3Buf, mp3Size );

    unsigned int    written = sink->write( mp3Buf, ret);
    delete[] mp3Buf;

    // just let go data that could not be written
    if ( written < (unsigned int) ret ) {
        reportEvent( 2,
                     "couldn't write all from encoder to underlying sink",
                     ret - written);
    }

    sink->flush();
}
void AmDtmfDetector::registerKeyReleased(int event, Dtmf::EventSource source,
                                         const struct timeval& start,
                                         const struct timeval& stop,
					 bool has_eventid, unsigned int event_id)
{
  // Old event has not been sent yet
  // push out it now
  if ((m_eventPending && m_currentEvent != event) ||
      (m_eventPending && has_eventid && m_current_eventid_i && (event_id != m_current_eventid))) {
#ifdef EXCESSIVE_DTMF_DEBUGINFO
    DBG("event differs - reportEvent()\n");
#endif
    reportEvent();
  }

  m_eventPending = true;
  m_currentEvent = event;
  if (has_eventid) {
    m_current_eventid_i = true;
    m_current_eventid = event_id;
  }

  if(timercmp(&start,&stop,<)){
    memcpy(&m_startTime, &start, sizeof(struct timeval));
    memcpy(&m_lastReportTime, &stop, sizeof(struct timeval));
  }
  else {
static void onFullScanResult(wifi_request_id id, wifi_scan_result *result) {

    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onFullScanResult called, vm = %p, obj = %p, env = %p", mVM, mCls, env);

    jobject scanResult = createScanResult(env, result);

    ALOGD("Creating a byte array of length %d", result->ie_length);

    jbyteArray elements = env->NewByteArray(result->ie_length);
    if (elements == NULL) {
        ALOGE("Error in allocating array");
        return;
    }

    ALOGE("Setting byte array");

    jbyte *bytes = (jbyte *)&(result->ie_data[0]);
    env->SetByteArrayRegion(elements, 0, result->ie_length, bytes);

    ALOGE("Returning result");

    reportEvent(env, mCls, "onFullScanResult", "(ILandroid/net/wifi/ScanResult;[B)V", id,
            scanResult, elements);

    env->DeleteLocalRef(scanResult);
    env->DeleteLocalRef(elements);
}
Exemple #19
0
static TI_STATUS state_Off(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_ON:
		this->fCurrentState = state_WaitFwInit;

		rc = drvMain_Start(this->hDrvMain, pwrState_FwInitDone, this, pwrState_DrvMainStarted, this);

		/* if failed to start the driver, revert back to this state */
		if (TI_NOK == rc)
		{
			this->fCurrentState = state_Off;
		}

		break;
	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
/*------------------------------------------------------------------------------
 *  Open the source and all the sinks if needed
 *  Create the sink threads
 *----------------------------------------------------------------------------*/
bool
MultiThreadedConnector :: open ( void )                     throw ( Exception )
{
    unsigned int        i;
    size_t              st;

    if ( !Connector::open() ) {
        return false;
    }

    running = true;

    pthread_attr_init( &threadAttr);
    pthread_attr_getstacksize(&threadAttr, &st);
    if (st < 128 * 1024) {
        reportEvent( 5, "MultiThreadedConnector :: open, stack size ",
                        (long)st);
        st = 128 * 1024;
        pthread_attr_setstacksize(&threadAttr, st);
    }
    pthread_attr_setdetachstate( &threadAttr, PTHREAD_CREATE_JOINABLE);

    threads = new ThreadData[numSinks];
    for ( i = 0; i < numSinks; ++i ) {
        ThreadData    * threadData = threads + i;

        threadData->connector = this;
        threadData->ixSink    = i;
        threadData->accepting = true;
        threadData->isDone    = true;
        if ( pthread_create( &(threadData->thread),
                             &threadAttr,
                             ThreadData::threadFunction,
                             threadData ) ) {
            break;
        }
    }

    // if could not create all, delete the ones created
    if ( i < numSinks ) {
        unsigned int    j;

        // signal to stop for all running threads
        pthread_mutex_lock( &mutexProduce);
        running = false;
        pthread_cond_broadcast( &condProduce);
        pthread_mutex_unlock( &mutexProduce);

        for ( j = 0; j < i; ++j ) {
            pthread_join( threads[j].thread, 0);
        }

        delete[] threads;
        threads = 0;

        return false;
    }

    return true;
}
Exemple #21
0
/*------------------------------------------------------------------------------
 *  Read from the audio source
 *----------------------------------------------------------------------------*/
unsigned int
AlsaDspSource :: read (    void          * buf,
                           unsigned int    len )     throw ( Exception )
{
    snd_pcm_sframes_t ret;

    if ( !isOpen() ) {
        return 0;
    }

    do {
        ret = snd_pcm_readi(captureHandle, buf, len/bytesPerFrame);

        // Check for buffer overrun
        if (ret == -EPIPE) {
            reportEvent(1, "Buffer overrun!");
            snd_pcm_prepare(captureHandle);
            ret = -EAGAIN;
        }
    } while (ret == -EAGAIN);

    if ( ret < 0 ) {
        throw Exception(__FILE__, __LINE__, snd_strerror(ret));
    }

    running = true;
    return ret * bytesPerFrame;
}
Exemple #22
0
/*------------------------------------------------------------------------------
 *  Set the original scheduling of the process, the one prior to the
 *  setRealTimeScheduling call.
 *  WARNING: make sure you don't call this before setRealTimeScheduling!!
 *----------------------------------------------------------------------------*/
void
DarkIce :: setOriginalScheduling ( void )               throw ( Exception )
{
// Only if the OS has the POSIX real-time scheduling functions implemented.
#if defined( HAVE_SCHED_GETSCHEDULER ) && defined( HAVE_SCHED_GETPARAM )
    uid_t   euid;

    euid = geteuid();

    if ( euid == 0 ) {
        struct sched_param  param;

        if ( sched_getparam( 0, &param) == -1 ) {
            throw Exception( __FILE__, __LINE__, "sched_getparam", errno);
        }

        param.sched_priority = origSchedPriority;

        if ( sched_setscheduler( 0, origSchedPolicy, &param) == -1 ) {
            throw Exception( __FILE__, __LINE__, "sched_setscheduler", errno);
        }

        reportEvent( 5, "reverted to original scheduling");
    }
#endif // HAVE_SCHED_GETSCHEDULER && HAVE_SCHED_GETPARAM
}
static void onScanEvent(wifi_scan_event event, unsigned status) {
    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onScanStatus called, vm = %p, obj = %p, env = %p", mVM, mCls, env);

    reportEvent(env, mCls, "onScanStatus", "(I)V", status);
}
static void onScanResultsAvailable(wifi_request_id id, unsigned num_results) {

    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onScanResultsAvailable called, vm = %p, obj = %p, env = %p", mVM, mCls, env);

    reportEvent(env, mCls, "onScanResultsAvailable", "(I)V", id);
}
/*------------------------------------------------------------------------------
 *  The function for each thread.
 *  Read the presented data
 *----------------------------------------------------------------------------*/
void
MultiThreadedConnector :: sinkThread( int       ixSink )
{
    ThreadData    * threadData = &threads[ixSink];
    Sink          * sink       = sinks[ixSink].get();

    while ( running ) {
        // wait for some data to become available
        pthread_mutex_lock( &mutexProduce);
        while ( running && threadData->isDone ) {
            pthread_cond_wait( &condProduce, &mutexProduce);
        }
        if ( !running ) {
            pthread_mutex_unlock( &mutexProduce);
            break;
        }

        if ( threadData->accepting ) {
            if ( sink->canWrite( 0, 0) ) {
                try {
                    sink->write( dataBuffer, dataSize);
                } catch ( Exception     & e ) {
                    // something wrong. don't accept more data, try to
                    // reopen the sink next time around
                    threadData->accepting = false;
                }
            } else {
                reportEvent( 4,
                            "MultiThreadedConnector :: sinkThread can't write ",
                             ixSink);
                // don't care if we can't write
            }
        }
        threadData->isDone = true;
        pthread_cond_broadcast( &condProduce);
        pthread_mutex_unlock( &mutexProduce);

        if ( !threadData->accepting ) {
            if ( reconnect ) {
                // if we're not accepting, try to reopen the sink
                try {
                    sink->close();
                    sink->open();
                    threadData->accepting = sink->isOpen();
                } catch ( Exception   & e ) {
                    // don't care, just try and try again
                }
            } else {
                // if !reconnect, just stop the connector
                running = false;
            }
        }
    }
}
void AmDtmfDetector::flushKey(unsigned int event_id) {
  // flush the current key if it corresponds to the one with event_id
#ifdef EXCESSIVE_DTMF_DEBUGINFO
  DBG("flushKey\n");
#endif
  if (m_eventPending && m_current_eventid_i && event_id == m_current_eventid) {
#ifdef EXCESSIVE_DTMF_DEBUGINFO
    DBG("flushKey - reportEvent()\n");
#endif
    reportEvent();
  }
}
Exemple #27
0
/*------------------------------------------------------------------------------
 *  Cut what we've done so far, and start anew.
 *----------------------------------------------------------------------------*/
void
FileSink :: cut ( void )                            throw ()
{
    flush();
    close();

    try {
        std::string     archiveFileName = getArchiveFileName();

        if (::rename(fileName, archiveFileName.c_str()) != 0) {
            reportEvent(2, "couldn't move file", fileName,
                           "to", archiveFileName);
        }

    } catch ( Exception &e ) {
        reportEvent(2, "error during archive cut", e);
    }

    create();
    open();
}
static void onRttResults(wifi_request_id id, unsigned num_results, wifi_rtt_result results[]) {
    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onRttResults called, vm = %p, obj = %p, env = %p", mVM, mCls, env);

    jclass clsRttResult = (env)->FindClass("android/net/wifi/RttManager$RttResult");
    if (clsRttResult == NULL) {
        ALOGE("Error in accessing class");
        return;
    }

    jobjectArray rttResults = env->NewObjectArray(num_results, clsRttResult, NULL);
    if (rttResults == NULL) {
        ALOGE("Error in allocating array");
        return;
    }

    for (unsigned i = 0; i < num_results; i++) {

        wifi_rtt_result& result = results[i];

        jobject rttResult = createObject(env, "android/net/wifi/RttManager$RttResult");
        if (rttResult == NULL) {
            ALOGE("Error in creating rtt result");
            return;
        }

        char bssid[32];
        sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", result.addr[0], result.addr[1],
            result.addr[2], result.addr[3], result.addr[4], result.addr[5]);

        setStringField(env, rttResult, "bssid", bssid);
        setIntField(env,  rttResult, "status",               result.status);
        setIntField(env,  rttResult, "requestType",          result.type);
        setLongField(env, rttResult, "ts",                   result.ts);
        setIntField(env,  rttResult, "rssi",                 result.rssi);
        setIntField(env,  rttResult, "rssi_spread",          result.rssi_spread);
        setIntField(env,  rttResult, "tx_rate",              result.tx_rate.bitrate);
        setLongField(env, rttResult, "rtt_ns",               result.rtt);
        setLongField(env, rttResult, "rtt_sd_ns",            result.rtt_sd);
        setLongField(env, rttResult, "rtt_spread_ns",        result.rtt_spread);
        setIntField(env,  rttResult, "distance_cm",          result.distance);
        setIntField(env,  rttResult, "distance_sd_cm",       result.distance_sd);
        setIntField(env,  rttResult, "distance_spread_cm",   result.distance_spread);

        env->SetObjectArrayElement(rttResults, i, rttResult);
    }

    reportEvent(env, mCls, "onRttResults", "(I[Landroid/net/wifi/RttManager$RttResult;)V",
        id, rttResults);
}
Exemple #29
0
static TI_STATUS state_FullOn(TI_HANDLE hPwrState, EPwrStateSmEvent eEvent)
{
	TPwrState *this = (TPwrState*) hPwrState;
	TI_STATUS rc;

	reportEvent(this, eEvent);

	switch (eEvent)
	{
	case PWRSTATE_EVNT_OFF:
		/* stop scan and move to Sleep, and then Off state */

		TWD_PrepareSuspend(this->hTWD, &this->tConfig.tTwdSuspendConfig);

		this->fCurrentState = state_WaitScanStopDueToSleepOff;
		this->tCurrentTransition.bContinueToOff = TI_TRUE;
		rc = scanCncn_Suspend(this->hScanCncn);

		break;

	case PWRSTATE_EVNT_SLEEP:
		/* stop scan and move to Sleep state */

		TWD_PrepareSuspend(this->hTWD, &this->tConfig.tTwdSuspendConfig);

		this->fCurrentState = state_WaitScanStopDueToSleepOff;
		rc = scanCncn_Suspend(this->hScanCncn);

		break;

	case PWRSTATE_EVNT_DOZE:
		TWD_PrepareSuspend(this->hTWD, &this->tConfig.tTwdSuspendConfig);

		this->fCurrentState = state_WaitMeasureStop;

		rc = measurementMgr_Suspend(this->hMeasurementMgr, pwrState_MeasurementStopped, this);

		break;

	case PWRSTATE_EVNT_SME_DISCONNECTED:
		this->fCurrentState = state_Standby;

		rc = TI_OK;
		break;

	default:
		handleUnexpectedEvent(this, eEvent);
		rc = TI_NOK;
	}

	return rc;
}
static void onHotlistApFound(wifi_request_id id,
        unsigned num_results, wifi_scan_result *results) {

    JNIEnv *env = NULL;
    mVM->AttachCurrentThread(&env, NULL);

    ALOGD("onHotlistApFound called, vm = %p, obj = %p, env = %p, num_results = %d",
            mVM, mCls, env, num_results);

    jclass clsScanResult = (env)->FindClass("android/net/wifi/ScanResult");
    if (clsScanResult == NULL) {
        ALOGE("Error in accessing class");
        return;
    }

    jobjectArray scanResults = env->NewObjectArray(num_results, clsScanResult, NULL);
    if (scanResults == NULL) {
        ALOGE("Error in allocating array");
        return;
    }

    for (unsigned i = 0; i < num_results; i++) {

        jobject scanResult = createObject(env, "android/net/wifi/ScanResult");
        if (scanResult == NULL) {
            ALOGE("Error in creating scan result");
            return;
        }

        setStringField(env, scanResult, "SSID", results[i].ssid);

        char bssid[32];
        sprintf(bssid, "%02x:%02x:%02x:%02x:%02x:%02x", results[i].bssid[0], results[i].bssid[1],
            results[i].bssid[2], results[i].bssid[3], results[i].bssid[4], results[i].bssid[5]);

        setStringField(env, scanResult, "BSSID", bssid);

        setIntField(env, scanResult, "level", results[i].rssi);
        setIntField(env, scanResult, "frequency", results[i].channel);
        setLongField(env, scanResult, "timestamp", results[i].ts);

        env->SetObjectArrayElement(scanResults, i, scanResult);

        ALOGD("Found AP %32s %s", results[i].ssid, bssid);
    }

    reportEvent(env, mCls, "onHotlistApFound", "(I[Landroid/net/wifi/ScanResult;)V",
        id, scanResults);
}