Bug 839647 - Synchronize CCApp thread start-up r=ehugg

This commit is contained in:
Adam Roach [:abr] 2013-02-22 10:08:47 -06:00
parent 722e4eafbb
commit 36f1d91887
3 changed files with 65 additions and 12 deletions

View File

@ -4,6 +4,8 @@
#include <errno.h>
#include <string>
#include <prcvar.h>
#include <prlock.h>
#include "CSFLog.h"
@ -19,8 +21,13 @@
extern "C"
{
#include "config_api.h"
extern PRCondVar *ccAppReadyToStartCond;
extern PRLock *ccAppReadyToStartLock;
extern char ccAppReadyToStart;
}
static const char* logTag = "CallControlManager";
static std::string logDestination = "CallControl.log";
@ -205,6 +212,7 @@ bool CallControlManagerImpl::startP2PMode(const std::string& user)
bool CallControlManagerImpl::startSDPMode()
{
bool retval = false;
CSFLogInfo(logTag, "startSDPMode");
if(phone != NULL)
{
@ -212,6 +220,16 @@ bool CallControlManagerImpl::startSDPMode()
return false;
}
ccAppReadyToStartLock = PR_NewLock();
if (!ccAppReadyToStartLock) {
return false;
}
ccAppReadyToStartCond = PR_NewCondVar(ccAppReadyToStartLock);
if (!ccAppReadyToStartCond) {
return false;
}
softPhone = CC_SIPCCServicePtr(new CC_SIPCCService());
phone = softPhone;
phone->init("JSEP", "", "127.0.0.1", "sipdevice");
@ -219,7 +237,16 @@ bool CallControlManagerImpl::startSDPMode()
phone->addCCObserver(this);
phone->setSDPMode(true);
return phone->startService();
retval = phone->startService();
// Now that everything is set up, we let the CCApp thread
// know that it's okay to start processing messages.
PR_Lock(ccAppReadyToStartLock);
ccAppReadyToStart = 1;
PR_NotifyAllCondVar(ccAppReadyToStartCond);
PR_Unlock(ccAppReadyToStartLock);
return retval;
}
bool CallControlManagerImpl::disconnect()

View File

@ -18,6 +18,7 @@
#include "PeerConnectionCtx.h"
#include "runnable_utils.h"
#include "cpr_socket.h"
#include "debug-psipcc-types.h"
#include "nsIObserverService.h"
#include "nsIObserver.h"
@ -210,18 +211,25 @@ void PeerConnectionCtx::onDeviceEvent(ccapi_device_event_e aDeviceEvent,
// with ChangeSipccState in the debug message and compound if below
PeerConnectionImpl::SipccState currentSipccState = mSipccState;
CSFLogDebug(logTag, "%s - %d : %d", __FUNCTION__, state, currentSipccState);
switch (aDeviceEvent) {
case CCAPI_DEVICE_EV_STATE:
CSFLogDebug(logTag, "%s - %d : %d", __FUNCTION__, state, currentSipccState);
if (CC_STATE_INS == state) {
// SIPCC is up
if (PeerConnectionImpl::kStarting == currentSipccState ||
PeerConnectionImpl::kIdle == currentSipccState) {
ChangeSipccState(PeerConnectionImpl::kStarted);
} else {
CSFLogError(logTag, "%s PeerConnection already started", __FUNCTION__);
}
} else {
NS_NOTREACHED("Unsupported Signaling State Transition");
if (CC_STATE_INS == state) {
// SIPCC is up
if (PeerConnectionImpl::kStarting == currentSipccState ||
PeerConnectionImpl::kIdle == currentSipccState) {
ChangeSipccState(PeerConnectionImpl::kStarted);
} else {
CSFLogError(logTag, "%s PeerConnection already started", __FUNCTION__);
}
} else {
NS_NOTREACHED("Unsupported Signaling State Transition");
}
break;
default:
CSFLogDebug(logTag, "%s: Ignoring event: %s\n",__FUNCTION__,
device_event_getname(aDeviceEvent));
}
}

View File

@ -7,10 +7,17 @@
#include "CCProvider.h"
#include "platform_api.h"
#include <prcvar.h>
#include <prlock.h>
extern cprMsgQueue_t ccapp_msgq;
extern void CCAppInit();
static sll_lite_list_t sll_list;
PRCondVar *ccAppReadyToStartCond = NULL;
PRLock *ccAppReadyToStartLock = NULL;
char ccAppReadyToStart = 0;
/**
* Add/Get ccapp task listener
*/
@ -154,6 +161,17 @@ void CCApp_task(void * arg)
CCAppInit();
// If the "ready to start" condition variable has been created
// (is non-null), we're going to wait for it to be signaled
// before we start processing messages.
if (ccAppReadyToStartCond) {
PR_Lock(ccAppReadyToStartLock);
while (!ccAppReadyToStart) {
PR_WaitCondVar(ccAppReadyToStartCond, PR_INTERVAL_NO_TIMEOUT);
}
PR_Unlock(ccAppReadyToStartLock);
}
while (1) {
msg = cprGetMessage(ccapp_msgq, TRUE, (void **) &syshdr);
if ( msg) {