Example #1
0
BOOL 
CNdasEventPublisher::AddEvent(
	const NDAS_EVENT_MESSAGE& eventMessage)
{
	m_queueLock.Lock();
	m_EventMessageQueue.push(eventMessage);
	m_queueLock.Unlock();
	BOOL fSuccess = ::ReleaseSemaphore(m_hSemQueue, 1, NULL);
	if (!fSuccess) {
		// Queue Full
		DBGPRT_ERR_EX(_FT("Event Message Queue Full, Discarded %s :"), 
			NdasEventTypeString(eventMessage.EventType));
		return FALSE;
	}
	DBGPRT_INFO(_FT("Event Message Queued: %s\n"), 
		NdasEventTypeString(eventMessage.EventType));
	return TRUE;
}
Example #2
0
BOOL 
CNdasEventPublisher::AddEvent(
	PNDAS_EVENT_MESSAGE pEventMessage)
{
	_ASSERTE(!::IsBadReadPtr(pEventMessage, sizeof(PNDAS_EVENT_MESSAGE)));
	m_queueLock.Lock();
	m_EventMessageQueue.push(*pEventMessage);
	m_queueLock.Unlock();
	BOOL fSuccess = ::ReleaseSemaphore(m_hSemQueue, 1, NULL);
	if (!fSuccess) {
		// Queue Full
		return FALSE;
	}
	DPInfo(_FT("Event Message Queued: %s\n"), 
		NdasEventTypeString(pEventMessage->EventType));
	return TRUE;
}
Example #3
0
void 
CNdasEventPublisher::Publish(const PNDAS_EVENT_MESSAGE pMessage)
{
	DPInfo(_FT("Publishing Event: %s\n"), 
		NdasEventTypeString(pMessage->EventType));

	//
	// sent the message to the connected pipes
	//
	for (ClientDataVector::iterator itr = m_PipeData.begin(); 
		itr != m_PipeData.end();) 
		//
		// do not forward the iterator here when erasing some 
		// elements 
		// itr2 = v.erase(itr); 
		// itr2 has a forwarded iterator from itr
		//
	{
		CLIENT_DATA* pClientData = *itr;
		if (pClientData->bConnected) {

			DWORD cbWritten;

			BOOL fSuccess = ::WriteFile(
				pClientData->hPipe,
				pMessage,
				sizeof(NDAS_EVENT_MESSAGE),
				&cbWritten,
				&pClientData->overlapped);

			if (!fSuccess && ERROR_IO_PENDING != ::GetLastError()) {
				
				DPErrorEx(_FT("Writing to a pipe failed: "));
				DPInfo(_FT("Detaching an event subscriber.\n"));
				
				CleanupConnection(pClientData);
				//
				// erasing an element will automatically
				// forward the vector 
				// (actually, itr remains the same, but the itr is
				// a next elemen)
				itr = m_PipeData.erase(itr);

				//
				// create another instance
				//
				fSuccess = AcceptNewConnection();
				if (!fSuccess) {
					DPWarningEx(_FT("Creating another pipe instance failed: "));
					DPWarning(_FT("No more event subscribers can be accepted.\n"));
				}

			} else {
				//
				// forward the iterator if we did erase
				//
				DPInfo(_FT("Event written to a pipe %p.\n"), (*itr)->hPipe);
				++itr;
			}
		} else {
			//
			// forward the iterator if not connected
			//
			++itr;
		}
	}	
}