Exemple #1
0
bool StopNovad()
{
	bool retSuccess;
	//Keep the scope of the following Ticket out of the call to Disconnect
	{
		Ticket ticket = MessageManager::Instance().StartConversation(IPCSocketFD);

		ControlMessage killRequest(CONTROL_EXIT_REQUEST);
		if(!MessageManager::Instance().WriteMessage(ticket, &killRequest))
		{
			LOG(ERROR, "Error sending command to NOVAD (CONTROL_EXIT_REQUEST)", "");
			return false;
		}

		Message *reply = MessageManager::Instance().ReadMessage(ticket);
		if(reply->m_messageType == ERROR_MESSAGE && ((ErrorMessage*)reply)->m_errorType == ERROR_TIMEOUT)
		{
			LOG(ERROR, "Timeout error when waiting for message reply", "");
			delete ((ErrorMessage*)reply);
			return false;
		}
		if(reply->m_messageType != CONTROL_MESSAGE )
		{
			LOG(ERROR, "Received the wrong kind of reply message", "");
			reply->DeleteContents();
			delete reply;
			return false;
		}

		ControlMessage *killReply = (ControlMessage*)reply;
		if( killReply->m_controlType != CONTROL_EXIT_REPLY )
		{
			LOG(ERROR, "Received the wrong kind of control message", "");
			reply->DeleteContents();
			delete reply;
			return false;
		}
		retSuccess = killReply->m_success;
		delete killReply;

		LOG(DEBUG, "Call to StopNovad complete", "");
	}
	DisconnectFromNovad();

	return retSuccess;
}
Exemple #2
0
bool StopNovad()
{
	Lock lock = MessageManager::Instance().UseSocket(IPCSocketFD);

	ControlMessage killRequest(CONTROL_EXIT_REQUEST, DIRECTION_TO_NOVAD);
	if(!Message::WriteMessage(&killRequest, IPCSocketFD) )
	{
		//There was an error in sending the message
		//TODO: Log this fact
		return false;
	}

	Message *reply = Message::ReadMessage(IPCSocketFD, DIRECTION_TO_NOVAD);
	if(reply->m_messageType == ERROR_MESSAGE && ((ErrorMessage*)reply)->m_errorType == ERROR_TIMEOUT)
	{
		LOG(ERROR, "Timeout error when waiting for message reply", "");
		delete ((ErrorMessage*)reply);
		return false;
	}
	if(reply->m_messageType != CONTROL_MESSAGE )
	{
		//Received the wrong kind of message
		delete reply;
		return false;
	}

	ControlMessage *killReply = (ControlMessage*)reply;
	if( killReply->m_controlType != CONTROL_EXIT_REPLY )
	{
		//Received the wrong kind of control message
		delete killReply;
		return false;
	}
	bool retSuccess = killReply->m_success;
	delete killReply;

	LOG(DEBUG, "Call to StopNovad complete", "");
	MessageManager::Instance().CloseSocket(IPCSocketFD);

	return retSuccess;
}