Example #1
0
bool PosixSemaphore::Init(const char *fileName, const char *fileSuffix,
		bool create, int initval) {
	m_Create = create;
	snprintf(m_FileName, sizeof(m_FileName), "%s%s", fileName, fileSuffix);

	SID_VDBG("PosixSemaphore::Init sem %s, create: %d, initval: %d", m_FileName, create, initval);

	/* android libc only supports sem_init, not sem_open. So we need to create small shm where we can place semaphore*/
	if (!m_Shm.Init(m_FileName, sizeof(sem_t), create)) {
		SID_ERROR("m_Shm.Init: %s: failed!, error %d %s", m_FileName, errno, strerror(errno));
		Uninit();
		return false;
	}
	m_Sem = (sem_t*)m_Shm.GetMemPtr();

	if (create) {
		if (sem_init(m_Sem, 0, initval) == -1) {
			m_Sem = SEM_FAILED;
			SID_ERROR("sem_init: %s: failed!, error %d %s", m_FileName, errno, strerror(errno));
			Uninit();
			return false;
		}
	}

	return true;
}
Example #2
0
// Init
status_t
VirtualVolume::Init(const char* name)
{
	status_t error = Volume::Init(name);
	if (error != B_OK)
		return error;

	// get an ID for the root node
	vnode_id rootNodeID = fVolumeManager->NewNodeID(this);
	if (rootNodeID < 0) {
		Uninit();
		return rootNodeID;
	}

	// create the root node
	fRootNode = new(std::nothrow) VirtualDir(this, rootNodeID);
	if (!fRootNode) {
		Uninit();
		fVolumeManager->RemoveNodeID(rootNodeID);
		return B_NO_MEMORY;
	}
	error = fRootNode->InitCheck();
	if (error != B_OK) {
		Uninit();
		return error;
	}

	return B_OK;
}
Example #3
0
// Init
status_t
ServerVolume::Init(const char* name)
{
	status_t error = VirtualVolume::Init(name);
	if (error != B_OK)
		return error;

	// create the server connection provider
	fConnectionProvider = new ServerConnectionProvider(fVolumeManager,
		fServerInfo, GetRootID());
	if (!fConnectionProvider) {
		Uninit();
		return B_NO_MEMORY;
	}
	error = fConnectionProvider->Init();
	if (error != B_OK) {
		Uninit();
		return error;
	}

	// add share volumes
	int32 count = fServerInfo->CountShares();
	for (int32 i = 0; i < count; i++) {
		ExtendedShareInfo* shareInfo = fServerInfo->ShareInfoAt(i);

		error = _AddShare(shareInfo);
		if (error != B_OK) {
			ERROR("ServerVolume::Init(): ERROR: Failed to add share `%s': "
				"%s\n", shareInfo->GetShareName(), strerror(error));
		}
	}

	return B_OK;
}
Example #4
0
bool CTlsSocket::Init()
{
	// This function initializes GnuTLS
	m_initialized = true;
	int res = gnutls_global_init();
	if (res) {
		LogError(res, _T("gnutls_global_init"));
		Uninit();
		return false;
	}

#if TLSDEBUG
	if (!pLoggingControlSocket) {
		pLoggingControlSocket = m_pOwner;
		gnutls_global_set_log_function(log_func);
		gnutls_global_set_log_level(99);
	}
#endif
	res = gnutls_certificate_allocate_credentials(&m_certCredentials);
	if (res < 0) {
		LogError(res, _T("gnutls_certificate_allocate_credentials"));
		Uninit();
		return false;
	}

	if (!InitSession())
		return false;

	m_shutdown_requested = false;

	// At this point, we can start shaking hands.

	return true;
}
Example #5
0
bool CTlsSocket::InitSession()
{
	int res = gnutls_init(&m_session, GNUTLS_CLIENT);
	if (res) {
		LogError(res, _T("gnutls_init"));
		Uninit();
		return false;
	}

	// Even though the name gnutls_db_set_cache_expiration
	// implies expiration of some cache, it also governs
	// the actual session lifetime, independend whether the
	// session is cached or not.
	gnutls_db_set_cache_expiration(m_session, 100000000);

	res = gnutls_priority_set_direct(m_session, ciphers, 0);
	if (res) {
		LogError(res, _T("gnutls_priority_set_direct"));
		Uninit();
		return false;
	}

	gnutls_dh_set_prime_bits(m_session, 512);

	gnutls_credentials_set(m_session, GNUTLS_CRD_CERTIFICATE, m_certCredentials);

	// Setup transport functions
	gnutls_transport_set_push_function(m_session, PushFunction);
	gnutls_transport_set_pull_function(m_session, PullFunction);
	gnutls_transport_set_ptr(m_session, (gnutls_transport_ptr_t)this);

	return true;
}
Example #6
0
bool MmapShm::Init(const char *fileName, int size, int create) {
	SID_DBG("Shm::Init: %s, size: %d, create: %d", fileName, size, create);
	m_Create = create;
	m_Size = size;
	strncpy(m_FileName, fileName, sizeof(m_FileName));
	int m_Fd = open(m_FileName, (create ? O_CREAT | O_RDWR  : O_RDWR), 0600);
	if (m_Fd < 0) {
		SID_ERROR( "ShmChannel: open failed: file %s, errno: %d, strerror(errno): %s", m_FileName, errno, strerror(errno));
		Uninit();
		return false;
	}

	if (create) {
		if (ftruncate(m_Fd, size) == -1) {
			SID_ERROR( "ShmChannel: ftruncate failed: file %s, errno: %d, strerror(errno): %s", m_FileName, errno, strerror(errno));
			Uninit();
			return false;
		}
	}

	if ((int)(m_Shmemory = (unsigned char *)mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, m_Fd, 0)) == -1) {
		SID_ERROR( "ShmChannel: mmap failed: file %s, errno: %d, strerror(errno): %s", m_FileName, errno, strerror(errno));
		Uninit();
		return false;
	}
	return true;
}
Example #7
0
bool CTlsSocket::Init()
{
	// This function initializes GnuTLS
	int res = gnutls_global_init();
	if (res)
	{
		LogError(res);
		return false;
	}
	m_initialized = true;

	res = gnutls_certificate_allocate_credentials(&m_certCredentials);
	if (res < 0)
	{
		LogError(res);
		Uninit();
		return false;
	}

	res = gnutls_init(&m_session, GNUTLS_CLIENT);
	if (res)
	{
		LogError(res);
		Uninit();
		return false;
	}

	res = gnutls_set_default_priority(m_session);
	if (res)
	{
		LogError(res);
		Uninit();
		return false;
	}
	
	// Set which type of certificates we accept
	const int cert_type_priority[] = { GNUTLS_CRT_X509, 0 };
	gnutls_certificate_type_set_priority(m_session, cert_type_priority);
	if (res)
	{
		LogError(res);
		Uninit();
		return false;
	}

	gnutls_credentials_set(m_session, GNUTLS_CRD_CERTIFICATE, m_certCredentials);

	// Setup transport functions
	gnutls_transport_set_push_function(m_session, PushFunction);
	gnutls_transport_set_pull_function(m_session, PullFunction);
	gnutls_transport_set_ptr(m_session, (gnutls_transport_ptr_t)this);
	gnutls_transport_set_lowat(m_session, 0);

	m_shutdown_requested = false;

	// At this point, we can start shaking hands.

	return true;
}
Example #8
0
bool CTaskProcessor::Init()
{
	Uninit(); // if already initialized

//	Initialize the Task Queue. If successful...
	if (m_queueTasks.Init())
	{
	//	Create an Event which can be asserted to stop the processor. If successful...
		if (m_hStop = CreateEvent(NULL, TRUE, FALSE, NULL))
		{
			THREAD_INIT_PARAM		stParam;

			stParam.m_pThis = this;
			stParam.m_bInitResult = false;
		//	Create an Event which, when asserted, will signal that the thread is initialized.
		//	If successful...
			if (stParam.m_hInitEvent = CreateEvent(NULL, TRUE, FALSE, NULL))
			{
				UINT nThread = 0;

				if (m_hThread = (HANDLE) _beginthreadex(NULL, 0, ProcessingFunc, &stParam, 0, &nThread))
				{
					DWORD dwRes = WaitForSingleObject(stParam.m_hInitEvent, m_dwStartupTimeout);

					if (WAIT_OBJECT_0 == dwRes)
					{
						if (stParam.m_bInitResult)
							return true;
						else
							AddLog(LOG_ERROR, _T("Task processor failed to initialize"));
					}
					else
					{
						if (WAIT_TIMEOUT == dwRes)
							AddLog(LOG_ERROR, _T("Task processor initialization timed out"));
						else
							AddLog(LOG_ERROR, _T("WaitForSingleObject failed"));
					}
				} 
				else
					AddLog(LOG_ERROR, _T("_beginthreadex failed"));
			} 
			else
				AddLog(LOG_ERROR, _T("CreateEvent failed"));
		} 
		else
			AddLog(LOG_ERROR, _T("CreateEvent failed"));
	}
	else
		AddLog(LOG_ERROR, _T("Failed to create the queue"));

	Uninit();
	return false;
}
/// reads in danger plots info
void CvDangerPlots::Read(FDataStream& kStream)
{
	// Version number to maintain backwards compatibility
	uint uiVersion;
	kStream >> uiVersion;
	MOD_SERIALIZE_INIT_READ(kStream);

	kStream >> m_ePlayer;
	kStream >> m_bArrayAllocated;

	int iGridSize;
	kStream >> iGridSize;

	Uninit();
	m_DangerPlots = FNEW(CvDangerPlotContents[iGridSize], c_eCiv5GameplayDLL, 0);
	m_bArrayAllocated = true;

	for (int i = 0; i < iGridSize; i++)
	{
		kStream >> m_DangerPlots[i];
	}

	m_knownUnits.clear();
	int iCount;
	kStream >> iCount;
	for (int i=0; i<iCount; i++)
	{
		int iTemp1,iTemp2;
		kStream >> iTemp1;
		kStream >> iTemp2;
		m_knownUnits.insert( std::make_pair((PlayerTypes)iTemp1,iTemp2) );
	}

	m_bDirty = false;
}
Example #10
0
int CMySqlAccess::Reinit()
{
	Uninit();
	mysql_init(m_mysql);
	m_res_ptr = NULL;

        if (mysql_library_init(0, NULL, NULL))
        {
                printf("mysql_library_init return failed\n");
                return -1;
        }

        if ((m_mysql = mysql_init(NULL)) == NULL)
        {
                printf("mysql_init return failed, errinfo = %s\n", mysql_error(m_mysql));
                return -1;
        }

	 MYSQL *connect = mysql_real_connect(m_mysql, m_strHost.c_str(), 
					m_strUid.c_str(), m_strPasswd.c_str(), 
					m_strDb.c_str(), 0, NULL, 0);

	if (connect ==  NULL)
	{
		printf("%s\n", mysql_error(m_mysql));
		mysql_close(m_mysql);
		return -1;
	}

//	printf(">>> init end\n");
	return 0;
}
Example #11
0
bool CDBSrcMySql::ExecSql(void)
{
	int re = -1;
	re = mysql_query(m_DBHandle, m_strSql.c_str());
	if(re != 0)
	{
		int iError = mysql_errno(m_DBHandle);
		if (iError == CR_SERVER_GONE_ERROR) //2006 server has gone away
		{
			//mysql_ping(m_DBHandle);
			//mysql_query(m_DBHandle, "set names 'gb2312';");
			Uninit();
			//Disconnect();
			Init();
			while(! Connect(m_strConnStr)) 
				Disconnect();
			re = mysql_query(m_DBHandle, m_strSql.c_str());
		}
	}
	
	if (re == 0)
	{
		//mysql_commit(m_DBHandle);
		return true;
	}

	return false;
}
Example #12
0
void IsuCompetition::AddEvent(OsisEvent* newEvent)
{
   if (!newEvent)
   {
      return;
   }
   if (newEvent->Id == -1)
   {
      delete newEvent;
      return;
   }

   if (!Current_Event)
   {
      Current_Event = newEvent;
      return;
   }

   if (Current_Event->Id != newEvent->Id)
   {
      Uninit();
      Current_Event = newEvent;
   }
   else
   {
      Current_Event->Update(newEvent);
   }
}
Example #13
0
//---------------------------------------------------------------------------
void tTVPTimerThread::Remove(tTJSNI_Timer *item)
{
	if(TVPTimerThread)
	{
		if(!TVPTimerThread->RemoveItem(item)) Uninit();
	}
}
Example #14
0
int main(int argc, char **argv)
{
	if (!Init())
	{
		LOG::Message("Initialization failed.");
		AppRunning = false;
	}
	
	for (unsigned i = 0; i < argc; i++) 
		LOG::Message(argv[i]);
	
	time_t lastTime = time(0);
	while(AppRunning)
	{
		SDL_Event event;
		while (SDL_PollEvent(&event)) 
			Listen(event);
		
		time_t newTime = time(0);
		if (newTime > lastTime)
		{
			OnTick();
			OnFrame();
			lastTime = newTime;
		}
	}

	if (!Uninit()) 
		LOG::Message("Uninitialization failed.");
	return 0;
}
Example #15
0
CTlsSocket::~CTlsSocket()
{
	remove_handler();

	Uninit();
	delete m_pSocketBackend;
}
Example #16
0
void CTlsSocket::Failure(int code, int socket_error, const wxString& function)
{
	m_pOwner->LogMessage(::Debug_Debug, _T("CTlsSocket::Failure(%d, %d)"), code, socket_error);
	if (code)
	{
		LogError(code, function);
		if (m_socket_eof)
		{
			if (code == GNUTLS_E_UNEXPECTED_PACKET_LENGTH
#ifdef GNUTLS_E_PREMATURE_TERMINATION
				|| code == GNUTLS_E_PREMATURE_TERMINATION
#endif
				)
			{
				m_pOwner->LogMessage(Status, _("Server did not properly shut down TLS connection"));
			}
		}
	}
	Uninit();

	if (socket_error)
	{
		CSocketEvent *evt = new CSocketEvent(m_pEvtHandler, this, CSocketEvent::close, socket_error);
		CSocketEventDispatcher::Get().SendEvent(evt);
	}
}
Example #17
0
CWelsThreadPool::~CWelsThreadPool() {
  //fprintf(stdout, "CWelsThreadPool::~CWelsThreadPool: delete %x, %x, %x\n", m_cWaitedTasks, m_cIdleThreads, m_cBusyThreads);
  if (0 != m_iRefCount) {
    m_iRefCount = 0;
    Uninit();
  }
}
Example #18
0
	~PulseAudioSource()
	{
		mQuit = true;
		Uninit();
		AudioDeinit();
		mResampler = src_delete(mResampler);
	}
Example #19
0
HRESULT CRegistryKey::Init(HKEY hKey, const TCHAR *pszPath, const TCHAR *pszKeyName, REGSAM CurrentAccess)
{
  HRESULT hr = Uninit();
  if (FAILED(hr))
    return hr;

  if (!pszKeyName || !hKey)
    return E_INVALIDARG;

  // copy key name name
  size_t size = _tcslen(pszKeyName);
  if (pszPath)
    size += _tcslen(pszPath);

  m_pszKeyName = new (std::nothrow) TCHAR [size+2];
  if (!m_pszKeyName)
    return E_OUTOFMEMORY;
  _stprintf(m_pszKeyName,_T("%s%s\\"),pszPath?pszPath:_T(""),pszKeyName);

	m_CurrentAccess = CurrentAccess;
	m_hKey = hKey;
  ASSERT(m_hKey);

  return S_OK;
}
Example #20
0
void rOctree<T>::Init(const box_type& volume , size_t maxDepth) {
    Uninit();

    m_root = new node_type(volume, 0);
    m_numNodes = 1;

    m_maxDepth = maxDepth;
}
CTcpClientSocketHelper::~CTcpClientSocketHelper(void)
{
	if (!m_bNoAutoCloseSocket)
	{
		Uninit();
	}

}
Example #22
0
	//--------------------------------------------------------------------------------
	CImageList::~CImageList()
	{
		_WINQ_FCONTEXT( "CImageList::~CImageList" );			
		__QOR_PROTECT
		{
			Uninit();
			m_ComCtl32Library.ImageList_Destroy( reinterpret_cast< ::HIMAGELIST >( m_Handle.Use() ) );				
		}__QOR_ENDPROTECT
	}
Example #23
0
BOOL P2PManager::Disconnect()
{
	DoEnd();
	End();

	Uninit();

	return TRUE;
}
Example #24
0
BOOL P2PManager::EndP2P()		
{
	DoEnd();
	End();

	Uninit();

	return TRUE;
}
Example #25
0
void CTlsSocket::Failure(int code)
{
	if (code)
		LogError(code);
	Uninit();

	wxSocketEvent evt(GetId());
	evt.m_event = wxSOCKET_LOST;
	wxPostEvent(m_pEvtHandler, evt);
}
NS_IMETHODIMP
DisplayDeviceProvider::SetListener(nsIPresentationDeviceListener* aListener)
{
  mDeviceListener = do_GetWeakReference(aListener);
  nsresult rv = mDeviceListener ? Init() : Uninit();
  if(NS_WARN_IF(NS_FAILED(rv))) {
      return rv;
  }
  return NS_OK;
}
Example #27
0
void CWelsThreadPool::RemoveInstance() {
  CWelsAutoLock  cLock (m_cInitLock);
  //fprintf(stdout, "m_iRefCount=%d\n", m_iRefCount);
  -- m_iRefCount;
  if (0 == m_iRefCount) {
    StopAllRunning();
    Uninit();
    //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());
  }
}
Example #28
0
KppUserLog::~KppUserLog()
{
	if (m_bInitFlag)
	{
		Uninit();
	}

	m_bInitFlag = FALSE;
	m_pFile = NULL;
}
Example #29
0
void IsuCompetition::AddIsuOsis(IsuOsis* newIsuOsis)
{
   if (Current_DB_ID == -1 || Current_DB_ID != newIsuOsis->DatabaseId)
   {
      Uninit();

      // Use Database ID to validate current Event
      Current_DB_ID = newIsuOsis->DatabaseId;
      delete newIsuOsis;
   }
}
Example #30
0
status_t
BDebugContext::Init(team_id team, port_id nubPort)
{
	Uninit();

	status_t error = init_debug_context(&fContext, team, nubPort);
	if (error != B_OK) {
		fContext.team = -1;
		return error;
	}

	return B_OK;
}