void* MoonlightInstance::ConnectionThreadFunc(void* context) {
    MoonlightInstance* me = (MoonlightInstance*)context;
    int err;
    SERVER_INFORMATION serverInfo;

    // Post a status update before we begin
    pp::Var response("Starting connection to " + me->m_Host);
    me->PostMessage(response);

    LiInitializeServerInformation(&serverInfo);
    serverInfo.address = me->m_Host.c_str();
    serverInfo.serverInfoAppVersion = me->m_AppVersion.c_str();

    err = LiStartConnection(&serverInfo,
                            &me->m_StreamConfig,
                            &MoonlightInstance::s_ClCallbacks,
                            &MoonlightInstance::s_DrCallbacks,
                            &MoonlightInstance::s_ArCallbacks,
                            NULL, 0);
    if (err != 0) {
        // Notify the JS code that the stream has ended
        pp::Var response(MSG_STREAM_TERMINATED);
        me->PostMessage(response);
        return NULL;
    }

    // Set running state before starting connection-specific threads
    me->m_Running = true;

    pthread_create(&me->m_GamepadThread, NULL, MoonlightInstance::GamepadThreadFunc, me);

    return NULL;
}
Exemple #2
0
void* MoonlightInstance::ConnectionThreadFunc(void* context) {
    MoonlightInstance* me = (MoonlightInstance*)context;
    int err;
    
    // Post a status update before we begin
    pp::Var response("Starting connection to " + me->m_Host);
    me->PostMessage(response);
    
    err = LiStartConnection(me->m_Host.c_str(),
                            &me->m_StreamConfig,
                            &MoonlightInstance::s_ClCallbacks,
                            &MoonlightInstance::s_DrCallbacks,
                            &MoonlightInstance::s_ArCallbacks,
                            NULL, 0,
                            me->m_ServerMajorVersion);
    if (err != 0) {
        // Notify the JS code that the stream has ended
        pp::Var response(MSG_STREAM_TERMINATED);
        me->PostMessage(response);
        return NULL;
    }
    
    // Set running state before starting connection-specific threads
    me->m_Running = true;
    
    pthread_create(&me->m_GamepadThread, NULL, MoonlightInstance::GamepadThreadFunc, me);
    
    return NULL;
}
void* MoonlightInstance::GamepadThreadFunc(void* context) {
    MoonlightInstance* me = (MoonlightInstance*)context;

    while (me->m_Running) {
        me->PollGamepads();

        // Poll every 10 ms
        usleep(10 * 1000);
    }

    return NULL;
}