/****************************************************************************
Desc:
****************************************************************************/
RCODE F_IOBufferMgr::setupBufferMgr(
	FLMUINT			uiMaxBuffers,
	FLMUINT			uiMaxBytes,
	FLMBOOL			bReuseBuffers)
{
	RCODE				rc = NE_FLM_OK;
	
	f_assert( uiMaxBuffers);
	f_assert( uiMaxBytes);
	
	if( RC_BAD( rc = f_mutexCreate( &m_hMutex)))
	{
		goto Exit;
	}
	
#if !defined( FLM_UNIX) && !defined( FLM_NLM)
	if( RC_BAD( rc = f_semCreate( &m_hAvailSem)))
	{
		goto Exit;
	}
#endif
	
	m_uiMaxBuffers = uiMaxBuffers;
	m_uiMaxBufferBytes = uiMaxBytes;
	m_bReuseBuffers = bReuseBuffers;
	
Exit:

	return( rc);
}
FINLINE int _sema_wait(
	sema_t *			pSem)
{
	int	iErr = 0;

	pthread_mutex_lock( &pSem->lock);
	while( !pSem->count)
	{
		if( (iErr = pthread_cond_wait( &pSem->cond, &pSem->lock)) != 0)
		{
			if( iErr == EINTR)
			{
				iErr = 0;
			}
			else
			{
				f_assert( 0);
				goto Exit;
			}
		}
	}

	pSem->count--;
	f_assert( pSem->count >= 0);

Exit:

	pthread_mutex_unlock( &pSem->lock);
	return( iErr);
}
/****************************************************************************
Desc:
****************************************************************************/
void F_IOBuffer::notifyComplete(
	RCODE					completionRc)
{
	f_assert( m_bPending);
	
	m_bPending = FALSE;
	m_bCompleted = TRUE;
	m_completionRc = completionRc;
	m_uiEndTime = FLM_GET_TIMER();
	m_uiElapsedTime = FLM_TIMER_UNITS_TO_MILLI( 
		FLM_ELAPSED_TIME( m_uiEndTime, m_uiStartTime));

	if( m_fnCompletion)
	{
		m_fnCompletion( this, m_pvData);
		m_fnCompletion = NULL;
		m_pvData = NULL;
	}

	if( m_pBufferMgr)
	{
		f_assert( m_eList == MGR_LIST_PENDING);
		f_mutexLock( m_pBufferMgr->m_hMutex);
		
		m_pBufferMgr->unlinkFromList( this);
		m_pBufferMgr->linkToList( &m_pBufferMgr->m_pFirstUsed, this);
		
		if( RC_OK( m_pBufferMgr->m_completionRc) && RC_BAD( completionRc))
		{
			m_pBufferMgr->m_completionRc = completionRc;
		}
		
		f_mutexUnlock( m_pBufferMgr->m_hMutex);		
	}
}
/****************************************************************************
Desc:
****************************************************************************/
void F_IOBufferMgr::linkToList(
	F_IOBuffer **		ppListHead,
	F_IOBuffer *		pIOBuffer)
{
	f_assertMutexLocked( m_hMutex);
	f_assert( pIOBuffer->m_eList == MGR_LIST_NONE);
	
	pIOBuffer->m_pPrev = NULL;
	
	if( (pIOBuffer->m_pNext = *ppListHead) != NULL)
	{
		(*ppListHead)->m_pPrev = pIOBuffer;
	}
	
	*ppListHead = pIOBuffer;
	
	if( ppListHead == &m_pFirstPending)
	{
		f_assert( !pIOBuffer->m_bPending);
		pIOBuffer->m_eList = MGR_LIST_PENDING;
	}
	else if( ppListHead == &m_pFirstUsed)
	{
		pIOBuffer->m_eList = MGR_LIST_USED;
	}
	else
	{
		pIOBuffer->m_eList = MGR_LIST_AVAIL;
	}
}
void FLMAPI f_mutexLock(
	F_MUTEX			hMutex)
{
	F_INTERLOCK *		pInterlock = (F_INTERLOCK *)hMutex;

#ifdef FLM_DEBUG
	if( pInterlock->locked)
	{
		f_assert( pInterlock->uiThreadId != _threadid);
	}
#endif

	while( f_atomicExchange( &pInterlock->locked, 1) != 0)
	{
#ifdef FLM_DEBUG
		f_atomicInc( &pInterlock->waitCount);
#endif
		Sleep( 0);
	}

#ifdef FLM_DEBUG
	f_assert( pInterlock->uiThreadId == 0);
	pInterlock->uiThreadId = _threadid;
	f_atomicInc( &pInterlock->lockedCount);
#endif
}
bool TestExtOptions::test_assert() {
  f_assert(true);
  try {
    f_assert(false);
  } catch (Assertion e) {
    return Count(true);
  }
  return Count(true);
}
void FLMAPI f_assertMutexLocked(
	F_MUTEX		hMutex)
{
#ifdef FLM_DEBUG
	f_assert( ((F_INTERLOCK *)hMutex)->locked == 1);
	f_assert( ((F_INTERLOCK *)hMutex)->uiThreadId == _threadid);
#else
	F_UNREFERENCED_PARM( hMutex);
#endif
}
void FLMAPI f_mutexUnlock(
	F_MUTEX		hMutex)
{
	F_INTERLOCK *		pInterlock = (F_INTERLOCK *)hMutex;

	f_assert( pInterlock->locked == 1);
#ifdef FLM_DEBUG
	f_assert( pInterlock->uiThreadId == _threadid);
	pInterlock->uiThreadId = 0;
#endif
	f_atomicExchange( &pInterlock->locked, 0);
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE FLMAPI f_rwlockAcquire(
	F_RWLOCK				hReadWriteLock,
	F_SEM					hSem,
	FLMBOOL				bWriter)
{
	RCODE					rc = NE_FLM_OK;
	F_RWLOCK_IMP *		pReadWriteLock = (F_RWLOCK_IMP *)hReadWriteLock;
	FLMBOOL				bMutexLocked = FALSE;
	
	f_mutexLock( pReadWriteLock->hMutex);
	bMutexLocked = TRUE;
	
	if( bWriter)
	{
		if( pReadWriteLock->iRefCnt != 0)
		{
			rc = f_notifyWait( pReadWriteLock->hMutex, hSem, (void *)((FLMINT)bWriter),
				&pReadWriteLock->pNotifyList); 
		}
		
		if( RC_OK( rc))
		{
			f_assert( !pReadWriteLock->iRefCnt);
			pReadWriteLock->iRefCnt = -1;
			pReadWriteLock->uiWriteThread = f_threadId();
		}
	}
	else
	{	 
		if( pReadWriteLock->iRefCnt < 0 || pReadWriteLock->pNotifyList)
		{
			rc = f_notifyWait( pReadWriteLock->hMutex, hSem, (void *)((FLMINT)bWriter), 
				&pReadWriteLock->pNotifyList); 
		}
		
		if( RC_OK( rc))
		{
			pReadWriteLock->iRefCnt++;
		}
	}
	
	f_assert( RC_BAD( rc) || pReadWriteLock->iRefCnt);
	
	if( bMutexLocked)
	{
		f_mutexUnlock( pReadWriteLock->hMutex);
	}
	
	return( rc);
}
Exemple #10
0
int tr069_load_cookie(tr069_rpc_mgr *rpc_handle)
{
	tr069_debug("\n");

	tr069_interface_mgr *interface_handle = NULL;
	VOID_T *curl_handle = NULL;
	interface_handle = rpc_handle->tr069_handle->interface_handle;
	f_assert(NULL != interface_handle);
	curl_handle = interface_handle->curl_handle;
	f_assert(NULL != curl_handle);

	curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, N_STB_PARAM_PATH "/cookie.txt");
	return FV_OK;
}
Exemple #11
0
int tr069_clr_req_cookie(tr069_rpc_mgr *rpc_handle)
{
	tr069_debug("\n");

	tr069_interface_mgr *interface_handle = NULL;
	VOID_T *curl_handle = NULL;
	interface_handle = rpc_handle->tr069_handle->interface_handle;
	f_assert(NULL != interface_handle);
	curl_handle = interface_handle->curl_handle;
	f_assert(NULL != curl_handle);

	curl_easy_setopt(curl_handle, CURLOPT_COOKIE, "");

	return FV_OK;
}
/****************************************************************************
Desc:	Retrieves the value associated with the specified name from the list
	   of INI_STRUCTs
****************************************************************************/
FLMBOOL FTKAPI F_IniFile::getParam(
	const char *	pszParamName,
	FLMUINT *		puiParamVal)
{
	FLMBOOL		bFound = FALSE;
	INI_LINE *	pLine = NULL;

	f_assert( m_bReady);
	
	pLine = findParam( pszParamName);
	if( !pLine)
	{
		goto Exit;
	}

	if( !pLine->pszParamValue)
	{
		goto Exit;
	}
	
	fromAscii( puiParamVal, pLine->pszParamValue);
	bFound = TRUE;
	
Exit:

	return( bFound);
}
Exemple #13
0
int tr069_clear_cookie(tr069_rpc_mgr *rpc_handle)
{
	tr069_debug("\n");

	tr069_interface_mgr *interface_handle = NULL;
	VOID_T *curl_handle = NULL;
	interface_handle = rpc_handle->tr069_handle->interface_handle;
	f_assert(NULL != interface_handle);
	curl_handle = interface_handle->curl_handle;
	f_assert(NULL != curl_handle);

	curl_easy_setopt(curl_handle, CURLOPT_COOKIESESSION, 1);
	curl_easy_setopt(curl_handle, CURLOPT_COOKIELIST, "ALL");
	curl_easy_setopt(curl_handle, CURLOPT_COOKIELIST, "FLUSH");
	return FV_OK;
}
/****************************************************************************
Desc:	Stores a new value for the specified name (or creates a new name/value
	   pair) in the list of INI_STRUCTs
****************************************************************************/
RCODE FTKAPI F_IniFile::setParam(
	const char *	pszParamName,
	const char *	pszParamVal)
{
	RCODE				rc = NE_FLM_OK;
	INI_LINE *		pLine;

	f_assert( m_bReady);

	// If the parameter exists in the list, just store the new value.
	// Othewise, create a new INI_LINE and add it to the list
	
	pLine = findParam( pszParamName);
	if( !pLine)
	{
		if( RC_BAD( rc = setParamCommon( &pLine, pszParamName)))
		{
			goto Exit;
		}
	}

	if( RC_BAD( rc = toAscii( &pLine->pszParamValue, pszParamVal)))
	{
		goto Exit;
	}
	
Exit:

	return( rc);
}
/****************************************************************************
Desc:	Retrieves the value associated with the specified name from the list
	   of INI_STRUCTs
****************************************************************************/
FLMBOOL FTKAPI F_IniFile::getParam(
	const char *	pszParamName,
	char **			ppszParamVal)
{
	FLMBOOL		bFound = FALSE;
	INI_LINE *	pLine = NULL;

	f_assert( m_bReady);
	*ppszParamVal = NULL;

	pLine = findParam( pszParamName);

	if( !pLine)
	{
		goto Exit;
	}

	if( pLine->pszParamValue == NULL)
	{
		goto Exit;
	}

	*ppszParamVal = pLine->pszParamValue;
	bFound = TRUE;

Exit:

	return( bFound);
}
/****************************************************************************
Desc:	Retrieves the value associated with the specified name from the list
	   of INI_STRUCTs
****************************************************************************/
FLMBOOL FTKAPI F_IniFile::getParam(
	const char *	pszParamName,
	FLMBOOL *		pbParamVal)		// Out: The value associated with name
{
	FLMBOOL			bFound = FALSE;
	INI_LINE *		pLine = NULL;
	
	f_assert( m_bReady);

	pLine = findParam( pszParamName);

	if( !pLine)
	{
		goto Exit;
	}

	if( !pLine->pszParamValue)
	{
		goto Exit;
	}
	
	fromAscii( pbParamVal, pLine->pszParamValue);
	bFound = TRUE;
	
Exit:

	return( bFound);
}
RCODE f_semWait(
	F_SEM			hSem,
	FLMUINT		uiTimeout)
{
	RCODE			rc	= NE_FLM_OK;

	f_assert( hSem != F_SEM_NULL);

	// Catch the F_WAITFOREVER flag so we can directly call _sema_wait
	// instead of passing F_WAITFOREVER through to _sema_timedwait.
	// Note that on AIX the datatype of the uiTimeout (in the timespec
	// struct) is surprisingly a signed int, which makes this catch
	// essential.

	if( uiTimeout == F_WAITFOREVER)
	{
		if( _sema_wait( (sema_t *)hSem))
		{
			rc = RC_SET( NE_FLM_ERROR_WAITING_ON_SEMAPHORE);
		}
	}
	else
	{
		if( _sema_timedwait( (sema_t *)hSem, (unsigned int)uiTimeout))
		{
			rc = RC_SET( NE_FLM_WAIT_TIMEOUT);
		}
	}

	return( rc);
}
FINLINE int _sema_wait(
	sema_t *			pSem)
{
	int	iErr = 0;

	for( ;;)
	{
		if( (iErr = sema_wait( pSem)) != 0)
		{
			if( iErr == EINTR)
			{
				iErr = 0;
				continue;
			}
			else
			{
				f_assert( 0);
				goto Exit;
			}
		}

		break;
	}

Exit:

	return( iErr);
}
RCODE f_semCreate(
	F_SEM *		phSem)
{
	RCODE			rc = NE_FLM_OK;

	f_assert( phSem != NULL);

	if( RC_BAD( rc = f_alloc( sizeof( sema_t), phSem)))
	{
		goto Exit;
	}

#if defined( FLM_SOLARIS)
	if( sema_init( (sema_t *)*phSem, 0, USYNC_THREAD, NULL) < 0) 
#else
	if( sema_init( (sema_t *)*phSem) < 0)
#endif
	{
		f_free( phSem);
		*phSem = F_SEM_NULL;
		rc = RC_SET( NE_FLM_COULD_NOT_CREATE_SEMAPHORE);
		goto Exit;
	}

Exit:

	return( rc);
}
/****************************************************************************
Desc:
****************************************************************************/
void FTKAPI F_IOBuffer::clearPending( void)
{
	f_assert( m_bPending);
	
	if( m_pBufferMgr)
	{
		f_assert( m_eList == MGR_LIST_PENDING);
		
		f_mutexLock( m_pBufferMgr->m_hMutex);
		m_pBufferMgr->unlinkFromList( this);
		m_pBufferMgr->linkToList( &m_pBufferMgr->m_pFirstUsed, this);
		f_mutexUnlock( m_pBufferMgr->m_hMutex);
	}

	m_bPending = FALSE;
	m_uiStartTime = 0;
}
Exemple #21
0
/****************************************************************************
Desc:
****************************************************************************/
F_MultiFileHdl::~F_MultiFileHdl()
{
	if( m_bOpen)
	{
		closeFile();
	}

	f_assert( !m_pLockFileHdl);
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE FLMAPI f_rwlockPromote(
	F_RWLOCK				hReadWriteLock,
	F_SEM					hSem)
{
	RCODE					rc = NE_FLM_OK;
	F_RWLOCK_IMP *		pReadWriteLock = (F_RWLOCK_IMP *)hReadWriteLock;
	FLMBOOL				bMutexLocked = FALSE;
	
	f_mutexLock( pReadWriteLock->hMutex);
	bMutexLocked = TRUE;
	
	if( pReadWriteLock->iRefCnt <= 0)
	{
		rc = RC_SET_AND_ASSERT( NE_FLM_ILLEGAL_OP);
		goto Exit;
	}
	
	pReadWriteLock->iRefCnt--;
		
	if( pReadWriteLock->iRefCnt != 0)
	{
		rc = f_notifyWait( pReadWriteLock->hMutex, hSem, (void *)TRUE, 
			&pReadWriteLock->pNotifyList); 
	}
	
	if( RC_OK( rc))
	{
		f_assert( !pReadWriteLock->iRefCnt);
		pReadWriteLock->iRefCnt = -1;
		pReadWriteLock->uiWriteThread = f_threadId();
	}

Exit:

	f_assert( RC_BAD( rc) || pReadWriteLock->iRefCnt);
	
	if( bMutexLocked)
	{
		f_mutexUnlock( pReadWriteLock->hMutex);
	}
	
	return( rc);
}
int sema_signal(
	sema_t *			pSem)
{
	pthread_mutex_lock( &pSem->lock);
	pSem->count++;
	f_assert( pSem->count > 0);
	pthread_cond_signal( &pSem->cond);
	pthread_mutex_unlock( &pSem->lock);

	return( 0);
}
void FLMAPI f_mutexDestroy(
	F_MUTEX *	phMutex)
{
	f_assert( phMutex != NULL);

	if (*phMutex != F_MUTEX_NULL)
	{
		free( *phMutex);
		*phMutex = F_MUTEX_NULL;
	}
}
/****************************************************************************
Desc:
****************************************************************************/
RCODE FLMAPI f_rwlockRelease(
	F_RWLOCK				hReadWriteLock)
{
	RCODE					rc = NE_FLM_OK;
	F_RWLOCK_IMP *		pReadWriteLock = (F_RWLOCK_IMP *)hReadWriteLock;
	FLMBOOL				bMutexLocked = FALSE;
	
	f_mutexLock( pReadWriteLock->hMutex);
	bMutexLocked = TRUE;
	
	if( pReadWriteLock->iRefCnt > 0)
	{
		pReadWriteLock->iRefCnt--;
	}
	else if( pReadWriteLock->iRefCnt == -1)
	{
		f_assert( pReadWriteLock->uiWriteThread == f_threadId());
		pReadWriteLock->iRefCnt = 0;
	}
	else
	{
		rc = RC_SET_AND_ASSERT( NE_FLM_ILLEGAL_OP);
		goto Exit;
	}
	
	if( !pReadWriteLock->iRefCnt && pReadWriteLock->pNotifyList)
	{
		f_rwlockNotify( pReadWriteLock);
	}
	
Exit:
	
	f_assert( RC_BAD( rc) || pReadWriteLock->iRefCnt >= 0);
	
	if( bMutexLocked)
	{
		f_mutexUnlock( pReadWriteLock->hMutex);
	}

	return( rc);
}
void f_semDestroy(
	F_SEM  *		phSem)
{
	f_assert( phSem != NULL);

	if (*phSem != F_SEM_NULL)
	{
		sema_destroy( (sema_t *)*phSem);
		f_free( phSem);
		*phSem = F_SEM_NULL;
	}
}
RCODE FLMAPI f_mutexCreate(
	F_MUTEX *			phMutex)
{
	RCODE								rc = NE_FLM_OK;
	pthread_mutexattr_t *		pMutexAttr = NULL;

	f_assert( phMutex != NULL);

	// NOTE: Cannot call f_alloc because the memory initialization needs
	// to be able to set up mutexes.

	if ((*phMutex = (F_MUTEX)malloc( 
		sizeof( pthread_mutex_t))) == F_MUTEX_NULL)
	{
		rc = RC_SET( NE_FLM_MEM);
		goto Exit;
	}

#if defined( FLM_DEBUG) && defined( FLM_LINUX)
	{
		pthread_mutexattr_t			mutexAttr;
	
		if( !pthread_mutexattr_init( &mutexAttr))
		{
			pMutexAttr = &mutexAttr;
			pthread_mutexattr_settype( pMutexAttr, PTHREAD_MUTEX_ERRORCHECK_NP);
		}
	}
#endif

	if( pthread_mutex_init( (pthread_mutex_t *)*phMutex, pMutexAttr) != 0)
	{
		// NOTE: Cannot call f_free because we had to use malloc up above due
		// to the fact that the memory subsystem uses a mutex before itis
		// completely ready to go.

		free( *phMutex);
		*phMutex = F_MUTEX_NULL;
		rc = RC_SET( NE_FLM_COULD_NOT_CREATE_MUTEX);
		goto Exit;
	}

Exit:

	if( pMutexAttr)
	{
		pthread_mutexattr_destroy( pMutexAttr);
	}

	return( rc);
}
/****************************************************************************
Desc:
****************************************************************************/
F_IOBufferMgr::~F_IOBufferMgr()
{
	f_assert( !m_pFirstPending);
	f_assert( !m_pFirstUsed);
	f_assert( !m_pAvailNotify);
	
	while( m_pFirstAvail)
	{
		m_pFirstAvail->Release();
	}
	
	if( m_hMutex != F_MUTEX_NULL)
	{
		f_mutexDestroy( &m_hMutex);
	}
	
#if !defined( FLM_UNIX) && !defined( FLM_NLM)
	if( m_hAvailSem != F_SEM_NULL)
	{
		f_semDestroy( &m_hAvailSem);
	}
#endif
}
/****************************************************************************
Desc:
****************************************************************************/
void FTKAPI F_IOBuffer::setPending( void)
{
	f_assert( !m_bPending);
	
	if( m_pBufferMgr)
	{
		f_assert( m_eList == MGR_LIST_USED);
		
		f_mutexLock( m_pBufferMgr->m_hMutex);
		m_pBufferMgr->unlinkFromList( this);
		m_pBufferMgr->linkToList( &m_pBufferMgr->m_pFirstPending, this);
		f_mutexUnlock( m_pBufferMgr->m_hMutex);
	}

#ifndef FLM_UNIX
	f_assert( !m_pAsyncClient || 
				 f_semGetSignalCount( ((F_FileAsyncClient *)m_pAsyncClient)->m_hSem) == 0);
#endif

	m_bPending = TRUE;
	m_uiStartTime = FLM_GET_TIMER();
	m_uiEndTime = 0;
}
Exemple #30
0
/****************************************************************************
Desc: Sets a character's type flag in the character lookup table
****************************************************************************/
void F_XML::setCharFlag(
	FLMUNICODE		uLowChar,
	FLMUNICODE		uHighChar,
	FLMUINT16		ui16Flag)
{
	FLMUINT		uiLoop;

	f_assert( uLowChar <= uHighChar);

	for( uiLoop = (FLMUINT)uLowChar; uiLoop <= (FLMUINT)uHighChar; uiLoop++)
	{
		m_pCharTable[ uiLoop].ucFlags |= (FLMBYTE)ui16Flag;
	}
}