Exemple #1
0
	/*! Add a T* to the manager; takes ownership of the object
	  \param name unique name for this session
	  \param what T* to add
	  \return true if successful */
	bool add(const f8String& name, T *what)
	{
		if (!what)
			throw f8Exception("bad or missing session");
		f8_scoped_lock guard(_mutex);
		return _sessionmap.insert({name, what}).second;
	}
Exemple #2
0
std::pair<SessionMap::iterator, bool> CKManager::CreateSession()
{
	// Try to insert the new session into the session map
	CK_SESSION_HANDLE newHandle;
	CKSessionClass newSession;

	int numTries = 0;
	std::pair<SessionMap::iterator, bool> insertResult;
	do
	{
		// Create unique session handle
		newHandle = 0;
		for (size_t i = 0; i < sizeof(newHandle); ++i)
		{
			newHandle <<= 8;
			newHandle += gRNG.GenerateByte();
		}

		// Try to insert the new entry
		insertResult = m_sessionMap.insert(
			SessionMap::value_type(newHandle, newSession));

	} while (!insertResult.second && (++numTries < 100));

	return insertResult;
}
Exemple #3
0
void
LaunchDaemon::_HandleRegisterSessionDaemon(BMessage* message)
{
	uid_t user = _GetUserID(message);
	if (user < 0)
		return;

	status_t status = B_OK;

	BMessenger target;
	if (message->FindMessenger("daemon", &target) != B_OK)
		status = B_BAD_VALUE;

	if (status == B_OK) {
		Session* session = new (std::nothrow) Session(user, target);
		if (session != NULL)
			fSessions.insert(std::make_pair(user, session));
		else
			status = B_NO_MEMORY;
	}

	BMessage reply((uint32)status);
	message->SendReply(&reply);
}