Пример #1
0
MessageInterface* ComManager::getMessage()
{
	if (current_connection != 0)
	{
		delete current_connection;
		current_connection = 0;
	}
	if (messages.empty())
	{
		readSockets();
	}
	if(!messages.empty())
	{
		current_connection = new MessageContainer(messages.front().getSocket(),messages.front().getMessage());
		messages.pop();
		if (utility->validHeader(current_connection->getMessage()))
		{
			MessageInterface* msg = utility->buildIncomingMessage(current_connection->getMessage(),true);
			if(msg->getHeader()->getMsgType()!=Msg::VERSIONING)
				addClientConnection(msg->getHeader()->getClientID());
			return msg;
		}
		else
		{
			Message<StatusAndError>* return_msg = 
				new Message<StatusAndError>(CommonHeader(Msg::STATUS_AND_ERROR,Msg::Sub::UNKNOWN,0,0),
				StatusAndError(Status::MESSAGE_CORRUPTED,Msg::UNKNOWN,Msg::Sub::UNKNOWN,"Corrupted Message"));
			sendMessage(return_msg);
			delete return_msg;
			return 0;
		}
	}
	else
		return 0;
}
Пример #2
0
StatusAndError ParseStatus(Status innerStatus)
{
  switch (innerStatus)
  {
  case Status::EUndefined:
    return StatusAndError(NodeStatus::Undefined, NodeErrorCode::NoError);
  case Status::EOnDisk:
    return StatusAndError(NodeStatus::OnDisk, NodeErrorCode::NoError);
  case Status::ENotDownloaded:
    return StatusAndError(NodeStatus::NotDownloaded, NodeErrorCode::NoError);
  case Status::EDownloadFailed:
    return StatusAndError(NodeStatus::Error, NodeErrorCode::NoInetConnection);
  case Status::EDownloading:
    return StatusAndError(NodeStatus::Downloading, NodeErrorCode::NoError);
  case Status::EInQueue:
    return StatusAndError(NodeStatus::InQueue, NodeErrorCode::NoError);
  case Status::EUnknown:
    return StatusAndError(NodeStatus::Error, NodeErrorCode::UnknownError);
  case Status::EOnDiskOutOfDate:
    return StatusAndError(NodeStatus::OnDiskOutOfDate, NodeErrorCode::NoError);
  case Status::EOutOfMemFailed:
    return StatusAndError(NodeStatus::Error, NodeErrorCode::OutOfMemFailed);
  }
}