Example #1
0
CNetRange *GetNetRange(list<CNetRange> &plNetRanges)
{	g_mScanner.Lock();
	int iHighestScore=0; CNetRange *pNetRange=NULL;
	for(list<CNetRange>::iterator in=plNetRanges.begin(); in!=plNetRanges.end(); in++)
	{	int iScore=brandom(0, (*in).iPriority);
		if(iScore > iHighestScore) { iHighestScore=iScore; pNetRange=&(*in); } }
	g_mScanner.Unlock(); return pNetRange; }
/**
 * Close device.
 *
 * Removes all sessions to a connection. Though, clientLib rejects the closeDevice()
 * command if still sessions connected to the device, this is needed to clean up all
 * sessions if client dies.
 */
void MobiCoreDevice::close(Connection *connection)
{
    trustletSessionList_t::reverse_iterator interator;
    static CMutex mutex;
    // 1. Iterate through device session to find connection
    // 2. Decide what to do with open Trustlet sessions
    // 3. Remove & delete deviceSession from vector

    // Enter critical section
    mutex.lock();
    for (interator = trustletSessions.rbegin();
            interator != trustletSessions.rend();
            interator++) {
        TrustletSession *ts = *interator;

        if (ts->deviceConnection == connection) {
            closeSession(connection, ts->sessionId);
        }
    }
    // Leave critical section
    mutex.unlock();

    // After the trustlet is done make sure to tell the driver to cleanup
    // all the orphaned drivers
    cleanupWsmL2();

    connection->connectionData = NULL;
}
Example #3
0
	bool SendHeartbeat (bool bWithStash) {
		LOGDEBUG (TEXT ("Sending heartbeat message"));
		FudgeStatus status;
		FudgeMsg msg;
		if ((status = FudgeMsg_create (&msg)) != FUDGE_OK) {
			LOGFATAL (TEXT ("Couldn't create message, status ") << status);
			assert (0);
			return false;
		}
		if ((status = ConnectorMessage_setOperation (msg, HEARTBEAT)) != FUDGE_OK) {
			FudgeMsg_release (msg);
			LOGFATAL (TEXT ("Couldn't create message, status ") << status);
			assert (0);
			return false;
		}
		if (bWithStash) {
			m_oStashMutex.Enter ();
			if (m_msgStash) {
				if ((status = ConnectorMessage_setStash (msg, m_msgStash)) != FUDGE_OK) {
					LOGFATAL (TEXT ("Couldn't create message, status ") << status);
					assert (0);
					status = FUDGE_OK;
					// Not good, but can carry on
				}
			}
			m_oStashMutex.Leave ();
		}
		bool bResult = m_poService->Send (MESSAGE_DIRECTIVES_CLIENT, msg);
		FudgeMsg_release (msg);
		return bResult;
	}
//////////////////////////////////////////////////////////////////////////
// 
//  Function Name:  ViewFinderCallBackFun 
//  Description:    The function which receives the picture from a camera 
//  Parameters:     cdVoid *pBuf
//                  cdUInt32 Size
//                  cdUInt32 Format
//                  cdContext Context
//  Returns:        cdError code
//  Summary:       
//  Author:         CannonSDK                           
///////////////////////////////////////////////////////////////////////////
cdUInt32 cdSTDCALL	CCameraConnect::ViewFinderCallBackFun(	cdVoid		*pBuf,
											 			cdUInt32	Size,
														cdUInt32	Format,
														cdContext	Context )
{
	cdError				err=cdOK;
	LPBYTE				bpPixel;
	PBITMAPFILEHEADER	pBmpFileheader;
	PBITMAPINFOHEADER	pBmpInfoheader;
	CCameraConnect			*CpThis;
	
	CpThis = (CCameraConnect*)Context;
	
	
	if( Format == FILEFORMAT_BMP )
	{
		pBmpFileheader = (PBITMAPFILEHEADER)pBuf;
		pBmpInfoheader = (PBITMAPINFOHEADER)((LPBYTE)pBuf + sizeof(BITMAPFILEHEADER));
		bpPixel = (LPBYTE)pBuf + pBmpFileheader->bfOffBits;
		
		// A picture is saved at a buffer. 
		g_CVFMutex.Lock();
		memcpy(CpThis->m_BackSurface.vpBits, bpPixel, pBmpInfoheader->biSizeImage );
		g_CVFMutex.Unlock();
		// A picture is displayed. 
		g_CpVFThread->ResumeThread();

	}
	
	return	err;

 }
Example #5
0
String CHttpServer::directRequest( const String& method, const String& uri, const String& query, const HeaderList& headers ,const String& body )
{
  common::CMutexLock lock(m_mxSyncRequest);
  
  String ret;
  if ( m_pQueue != 0 )
  {
    CDirectHttpRequestQueue::CDirectHttpRequest req;
  
    pthread_cond_t signal;
    pthread_cond_init(&signal,0);
    
    CMutex m;
  
    req.signal = &signal;
    req.mutex = m.getNativeMutex();
    req.method = method;
    req.uri = uri;
    req.query = query;
    req.headers = headers;
    req.body = body;
  
    pthread_mutex_lock(m.getNativeMutex());

    m_pQueue->doRequest( req );
    
    pthread_cond_wait(&signal, m.getNativeMutex());
    pthread_mutex_unlock(m.getNativeMutex());
    
    ret = m_pQueue->getResponse();
  }
  
  return ret;
 
}
Example #6
0
void CTxWndDrawClockMgr::CheckClock( UINT nClockIn )
{
	g_mutexDrawClock.Lock(1000);
	
	MAPCLOCLKDATA::iterator itb = m_mapClockData.begin();
	MAPCLOCLKDATA::iterator ite = m_mapClockData.end();

	HWND hInvalidWnd = FALSE;
	for (; itb != ite; itb++)
	{
		if (itb->second.nCurrentTick < nClockIn)
		{
			//send draw msg
			if (::IsWindow(itb->first))
			{
				::PostMessage(itb->first, MSG_TXDRAWCLOCK, itb->second.wparam, itb->second.lparam);
				itb->second.nCurrentTick = nClockIn + itb->second.nTickInternal;
			}
			else
			{
				//error;
				hInvalidWnd = itb->first;
			}
		}
	}

	g_mutexDrawClock.Unlock();

	if (hInvalidWnd != NULL)
	{
		ST_DRAWCLOCKDATA data;
		data.hwnd = hInvalidWnd;
		UnRegisterDrawClock(data);
	}
}
void CAppManConnectController::deleteInstance()
{
    gInstanceMutex.lock();
    delete mspInstance;
    mspInstance = 0;
    gInstanceMutex.unlock();
}
Example #8
0
bool CThread::getStopFlag() const
{
   mStopFlagMutex.lock();
   bool stop = mStopFlag;
   mStopFlagMutex.unlock();
   return stop;
}
Example #9
0
void LListCtrl::SetHeaderControlText( DWORD dwPos, const CUString& strValue )
{
    myLockListCtrl.Lock();
    if ( m_hWnd )
    {
        CHeaderCtrl* pHeaderCtrl = GetHeaderCtrl();

        ASSERT( (int)dwPos < pHeaderCtrl->GetItemCount() );

        HDITEM hdi;

        memset( &hdi, 0, sizeof( HDITEM ) );

        // Get header item data
        pHeaderCtrl->GetItem( dwPos, &hdi );

        // modify item data
        CUStringConvert strCnv;
        hdi.pszText = strCnv.ToT( strValue );
        hdi.mask = HDI_TEXT;

        // Set item data
        pHeaderCtrl->SetItem( dwPos, &hdi );

    }
    myLockListCtrl.Unlock();
}
Example #10
0
AFS_API int32 PrintErrorV(const char* sFormat, CVaList& pArgList)
{
	g_oStdOutMutex.Enter();
	int32 nRet = CSingleInstance<CStdErrFormatter>::GetInstance()->oFormatter.PrintV(sFormat, pArgList);
	g_oStdOutMutex.Leave();
	return nRet;
}
Example #11
0
AFS_API int32 ScanV(const char* sFormat, CVaList& pArgList)
{
	g_oStdInMutex.Enter();
	int32 nRet = CSingleInstance<CStdInFormatter>::GetInstance()->oFormatter.ScanV(sFormat, pArgList);
	g_oStdInMutex.Leave();
	return nRet;
}
Example #12
0
//设置一个回调函数,当数据准备好后,将数据回馈过去
void ZTDataBase::setPreparedCallback(DataProparedFunc *callbackFunc){
    CMutex mutex;
    mutex.Lock();
    
    m_callbackfunc = callbackFunc;
    
    mutex.Unlock();
}
Example #13
0
CAcmUdp::~CAcmUdp()
{
	if(m_bRegistered)
	{
		g_oMutex.Enter();
		g_oUdpTable.Remove(m_nDomain);
		g_oMutex.Leave();
	}
}
Example #14
0
static void dyn_lock_callback(int mode, CRYPTO_dynlock_value *dlock, const char *file, int line) {
	CMutex *mtx = (CMutex*)dlock;

	if(mode & CRYPTO_LOCK) {
		mtx->lock();
	} else {
		mtx->unlock();
	}
}
Example #15
0
CString GetHost(CNetRange *pNetRange)
{	if(!pNetRange) return CString(""); CString sRetVal; g_mScanner.Lock(); switch(pNetRange->iNetMask) {
	case 0:		sRetVal.Format("%d.%d.%d.%d", brandom(0, 255),		brandom(0, 255),	brandom(0, 255),	brandom(0, 255)		); break;
	case 8:		sRetVal.Format("%d.%d.%d.%d", pNetRange->iPart1,	brandom(0, 255),	brandom(0, 255),	brandom(0, 255)		); break;
	case 16:	sRetVal.Format("%d.%d.%d.%d", pNetRange->iPart1,	pNetRange->iPart2,	brandom(0, 255),	brandom(0, 255)		); break;
	case 24:	sRetVal.Format("%d.%d.%d.%d", pNetRange->iPart1,	pNetRange->iPart2,	pNetRange->iPart3,	brandom(0, 255)		); break;
	default:
	case 32:	sRetVal.Format("%d.%d.%d.%d", pNetRange->iPart1,	pNetRange->iPart2,	pNetRange->iPart3,	pNetRange->iPart4	); break; }
	g_mScanner.Unlock(); return sRetVal; }
Example #16
0
CAcmUdp* CAcmUdp::QueryUdp(uint32 nDomain)
{
	CAcmUdp* pUdp = NULL;
	g_oMutex.Enter();
	CRbTreeNode* pIt = g_oUdpTable.Find(nDomain);
	if(pIt != g_oUdpTable.End())
		pUdp = g_oUdpTable.GetItem(pIt);
	g_oMutex.Leave();
	return pUdp;
}
Example #17
0
/// Returns the binary encoding of the message.
///
/// @return the encoding
const void *CFudgeMsgInfo::GetData () {
	if (!m_pData) {
		g_oMutex.Enter ();
		if (!m_pData) {
			m_pData = _EncodeFudgeMsg (m_msg, &m_cbData);
		}
		g_oMutex.Leave ();
	}
	return m_pData;
}
Example #18
0
void DuplicateBootCheck(LPCTSTR mutexName)
{
	CMutex mutex;
	try{
		mutex.createMutex(mutexName);
	}catch(std::exception e){
		::ErrorMessageBox(L"多重起動です");
		exit(0);
	}
}
Example #19
0
/// Attempts to stop the service.
///
/// @param[in] bForce TRUE to stop the service immediately by closing the IPC, FALSE to initiate a
/// lazy close when the IPC goes idle.
void ServiceStop (bool bForce) {
	g_oMutex.Enter ();
	if (bForce) {
		_ReportStateStopping ();
		g_poPipe->Close ();
	} else {
		g_poPipe->LazyClose ();
	}
	g_oMutex.Leave ();
}
Example #20
0
	void SetStash (FudgeMsg msgStash) {
		m_oStashMutex.Enter ();
		if (m_msgStash) {
			LOGDEBUG (TEXT ("Discarding old stash message"));
			FudgeMsg_release (m_msgStash);
		}
		FudgeMsg_retain (msgStash);
		m_msgStash = msgStash;
		m_oStashMutex.Leave ();
	}
Example #21
0
/// Returns the length of the binary encoding of the message in bytes.
///
/// @return the length if bytes
size_t CFudgeMsgInfo::GetLength () {
	if (!m_pData) {
		g_oMutex.Enter ();
		if (!m_pData) {
			m_pData = _EncodeFudgeMsg (m_msg, &m_cbData);
		}
		g_oMutex.Leave ();
	}
	return m_cbData;
}
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcCloseDevice(
    uint32_t deviceId
)
{
    mcResult_t mcResult = MC_DRV_OK;
#ifndef WIN32

	devMutex.lock();
    LOG_I("===%s(%i)===", __FUNCTION__, deviceId);
    do {
        Device *device = resolveDeviceId(deviceId);
        CHECK_DEVICE_CLOSED(device, deviceId);

        Connection *devCon = device->connection;

        if (device->openCount != 1) {
            device->openCount--;
            break;
        }

        // Check if daemon is still alive
        if (!devCon->isConnectionAlive()) {
            removeDevice(deviceId);
            LOG_E("Daemon is  dead removing device");
            mcResult = MC_DRV_ERR_DAEMON_UNREACHABLE;
            break;
        }

        // Return if not all sessions have been closed
        // TODO-2012-08-31-haenellu: improve check, if device connection is dead, this makes no more sense.
        if (device->hasSessions()) {
            LOG_E("Trying to close device while sessions are still pending.");
            mcResult = MC_DRV_ERR_SESSION_PENDING;
            break;
        }

        SEND_TO_DAEMON(devCon, MC_DRV_CMD_CLOSE_DEVICE);

        RECV_FROM_DAEMON(devCon, &mcResult);

        if (mcResult != MC_DRV_OK) {
            LOG_W(" %s(): Request at Daemon failed, respId=%d ", __FUNCTION__, mcResult);
            break;
        }

        removeDevice(deviceId);

    } while (false);

    devMutex.unlock();

#endif /* WIN32 */
	return mcResult;
}
Example #23
0
CMdb* CMdb::GetMdb(const char* sDbName)
{
	CMdb* pDb = NULL;
	CRbTreeNode* pEnd = m_oMdbTable.End();
	g_oMdbMutex.Enter();
	CRbTreeNode* pIt = m_oMdbTable.Find(sDbName);
	if(pIt != pEnd)
		pDb = m_oMdbTable.GetItem(pIt);
	g_oMdbMutex.Leave();
	return pDb;
}
Example #24
0
void CTimeoutManager::deleteInstance()
{
   gsInstanceMutex.lock();
   if (msInstance)
   {
      msInstance->finish();
      delete msInstance;
      msInstance = 0;
   }
   gsInstanceMutex.unlock();
}
Example #25
0
	void UnLoad(CShareLibrary* pLib)
	{
		if(pLib)
		{
			CRbTreeNode* pEnd = m_oLibs.End();
			m_oMutex.Enter();
			CRbTreeNode* pIt = m_oLibs.Find(pLib->GetFileName());
			if( (pIt != pEnd) && (pLib == m_oLibs.GetItem(pIt)) && pLib->Release())
				m_oLibs.Remove(pIt);
			m_oMutex.Leave();
		}
	}
Example #26
0
void CMdb::RemoveAll()
{
	RemoveAccessTable();
	g_oMdbMutex.Enter();
	while(m_oMdbTable.GetSize())
	{
		CRbTreeNode* pIt = m_oMdbTable.First();
		CMdb* pDb = m_oMdbTable.GetItem(pIt);
		delete pDb;
	}
	g_oMdbMutex.Leave();
}
Example #27
0
iviLink::BaseUid iviLink::generateUid()
{
   std::stringstream ss;
   gMutex.lock();
   {
      ss << gCounter;
      ++gCounter;
   }
   gMutex.unlock();

   return BaseUid(ss.str());
}
//------------------------------------------------------------------------------
__MC_CLIENT_LIB_API mcResult_t mcCloseSession(mcSessionHandle_t *session)
{
    mcResult_t mcResult = MC_DRV_OK;
#ifndef WIN32

    LOG_I("===%s()===", __FUNCTION__);
    devMutex.lock();
    do {
        CHECK_NOT_NULL(session);
        LOG_I(" Closing session %03x.", session->sessionId);

        Device *device = resolveDeviceId(session->deviceId);
        CHECK_DEVICE(device);

        Connection *devCon = device->connection;

        Session *nqSession = device->resolveSessionId(session->sessionId);

        CHECK_SESSION(nqSession, session->sessionId);

        SEND_TO_DAEMON(devCon, MC_DRV_CMD_CLOSE_SESSION, session->sessionId);

        RECV_FROM_DAEMON(devCon, &mcResult);

        if (mcResult != MC_DRV_OK) {
            LOG_E("CMD_CLOSE_SESSION failed, respId=%d", mcResult);
            // TODO-2012-08-03-haenellu: Remove once tests can handle it.
            mcResult = MC_DRV_ERR_UNKNOWN_DEVICE;
            break;
        }

        bool r = device->removeSession(session->sessionId);
        if (!r)
        {
            LOG_E("removeSession failed");
            assert(0);
        }



    } while (false);

    if (mcResult == MC_DRV_ERR_SOCKET_WRITE || mcResult == MC_DRV_ERR_SOCKET_READ) {
        LOG_E("Connection is dead, removing device.");
        removeDevice(session->deviceId);
    }

    devMutex.unlock();

#endif /* WIN32 */
    return mcResult;
}
Example #29
0
CTimeoutManager * CTimeoutManager::getInstance()
{
   if (0 == CTimeoutManager::msInstance)
   {
      gsInstanceMutex.lock();
      if (0 == CTimeoutManager::msInstance)
      {
         CTimeoutManager::msInstance = new CTimeoutManager();
      }
      gsInstanceMutex.unlock();
   }
   return CTimeoutManager::msInstance;
}
Example #30
0
/// Decrements the R reference count, destroying the object when the count reaches zero.
void CFudgeMsgInfo::Release (CFudgeMsgInfo *poMessage) {
	g_oMutex.Enter ();
	LOGDEBUG (TEXT ("Releasing CFudgeMsgInfo, rc=") << poMessage->m_nRefCount);
	if (--poMessage->m_nRefCount == 0) {
		TFudgeMsgMap::iterator itr = g_oMap.find (poMessage->m_msg);
		if (itr != g_oMap.end ()) {
			LOGDEBUG (TEXT ("Removing message from map (size = ") << (g_oMap.size () - 1) << TEXT (")"));
			g_oMap.erase (itr);
			g_cbData -= MESSAGE_INFO_OVERHEAD;
		}
		delete poMessage;
	}
	g_oMutex.Leave ();
}