bool FNetworkFileServerClientConnection::ProcessPayload(FArchive& Ar)
{
	FBufferArchive Out;
	bool Result = true;

	// first part of the payload is always the command
	uint32 Cmd;
	Ar << Cmd;

	UE_LOG(LogFileServer, Verbose, TEXT("Processing payload with Cmd %d"), Cmd);

	// what type of message is this?
	NFS_Messages::Type Msg = NFS_Messages::Type(Cmd);

	// make sure the first thing is GetFileList which initializes the game/platform
	checkf(Msg == NFS_Messages::GetFileList || Msg == NFS_Messages::Heartbeat || Sandbox != NULL, TEXT("The first client message MUST be GetFileList, not %d"), (int32)Msg);

	// process the message!
	bool bSendUnsolicitedFiles = false;

	{
		FScopeLock SocketLock(&SocketCriticalSection);

		switch (Msg)
		{
		case NFS_Messages::OpenRead:
			ProcessOpenFile(Ar, Out, false);
			break;

		case NFS_Messages::OpenWrite:
			ProcessOpenFile(Ar, Out, true);
			break;

		case NFS_Messages::Read:
			ProcessReadFile(Ar, Out);
			break;

		case NFS_Messages::Write:
			ProcessWriteFile(Ar, Out);
			break;

		case NFS_Messages::Seek:
			ProcessSeekFile(Ar, Out);
			break;

		case NFS_Messages::Close:
			ProcessCloseFile(Ar, Out);
			break;

		case NFS_Messages::MoveFile:
			ProcessMoveFile(Ar, Out);
			break;

		case NFS_Messages::DeleteFile:
			ProcessDeleteFile(Ar, Out);
			break;

		case NFS_Messages::GetFileInfo:
			ProcessGetFileInfo(Ar, Out);
			break;

		case NFS_Messages::CopyFile:
			ProcessCopyFile(Ar, Out);
			break;

		case NFS_Messages::SetTimeStamp:
			ProcessSetTimeStamp(Ar, Out);
			break;

		case NFS_Messages::SetReadOnly:
			ProcessSetReadOnly(Ar, Out);
			break;

		case NFS_Messages::CreateDirectory:
			ProcessCreateDirectory(Ar, Out);
			break;

		case NFS_Messages::DeleteDirectory:
			ProcessDeleteDirectory(Ar, Out);
			break;

		case NFS_Messages::DeleteDirectoryRecursively:
			ProcessDeleteDirectoryRecursively(Ar, Out);
			break;

		case NFS_Messages::ToAbsolutePathForRead:
			ProcessToAbsolutePathForRead(Ar, Out);
			break;

		case NFS_Messages::ToAbsolutePathForWrite:
			ProcessToAbsolutePathForWrite(Ar, Out);
			break;

		case NFS_Messages::ReportLocalFiles:
			ProcessReportLocalFiles(Ar, Out);
			break;

		case NFS_Messages::GetFileList:
			Result = ProcessGetFileList(Ar, Out);
			break;

		case NFS_Messages::Heartbeat:
			ProcessHeartbeat(Ar, Out);
			break;

		case NFS_Messages::SyncFile:
			ProcessSyncFile(Ar, Out);
			bSendUnsolicitedFiles = true;
			break;

		case NFS_Messages::RecompileShaders:
			ProcessRecompileShaders(Ar, Out);
			break;

		default:

			UE_LOG(LogFileServer, Error, TEXT("Bad incomming message tag (%d)."), (int32)Msg);
		}
	}


	// send back a reply if the command wrote anything back out
	if (Out.Num() && Result )
	{
		int32 NumUnsolictedFiles = UnsolictedFiles.Num();
		if (bSendUnsolicitedFiles)
		{
			Out << NumUnsolictedFiles;
		}

		UE_LOG(LogFileServer, Verbose, TEXT("Returning payload with %d bytes"), Out.Num());

		// send back a reply
		Result &= SendPayload( Out );

		if (bSendUnsolicitedFiles && Result )
		{
			for (int32 Index = 0; Index < NumUnsolictedFiles; Index++)
			{
				FBufferArchive OutUnsolicitedFile;
				PackageFile(UnsolictedFiles[Index], OutUnsolicitedFile);

				UE_LOG(LogFileServer, Display, TEXT("Returning unsolicited file %s with %d bytes"), *UnsolictedFiles[Index], OutUnsolicitedFile.Num());

				Result &= SendPayload(OutUnsolicitedFile);
			}

			UnsolictedFiles.Empty();
		}
	}

	UE_LOG(LogFileServer, Verbose, TEXT("Done Processing payload with Cmd %d Total Size sending %d "), Cmd,Out.TotalSize());

	return Result;
}
Exemplo n.º 2
0
void MavLinkInterpreter::Receive()
{
	while (_MavLinkSerial.available())
	{
		uint8_t c = _MavLinkSerial.read();
		int msgReady = mavlink_parse_char(MAVLINK_COMM_0, c, &_msg, &_status);
		if (msgReady)
		{
			if (AP_SYSID == _msg.sysid && AP_CMPID == _msg.compid) // only proceed with autopilot messages
			{
				switch (_msg.msgid)
				{
				case MAVLINK_MSG_ID_HEARTBEAT: //0
					ProcessHeartbeat();
					break;
				case MAVLINK_MSG_ID_SYS_STATUS: //1
					ProcessSystemStatus();
					break;
				case MAVLINK_MSG_ID_GPS_RAW_INT: //24
					ProcessGpsRaw();
					break;
				case MAVLINK_MSG_ID_RAW_IMU: //27
					ProcessImu();
					break;
				case MAVLINK_MSG_ID_ATTITUDE: //30
					ProcessAttitude();
					break;
				case MAVLINK_MSG_ID_GLOBAL_POSITION_INT: //33
					ProcessGpsIntegrated();
					break;
				case MAVLINK_MSG_ID_GPS_GLOBAL_ORIGIN: // 49
					ProcessGpsOrigin();
					break;
				case MAVLINK_MSG_ID_GLOBAL_POSITION_INT_COV: // 63
					ProcessGpsTime();
					break;
				case MAVLINK_MSG_ID_RC_CHANNELS: //65
					ProcessRCChannels();
					break;
				case MAVLINK_MSG_ID_VFR_HUD: //74
					ProcessHUD();
					break;
				case MAVLINK_MSG_ID_BATTERY_STATUS: //147
					ProcessBattery();
					break;
				case MAVLINK_MSG_ID_STATUSTEXT: //253
					ProcessStatusText();
					break;
				default:
#ifdef DEBUG_APM_MAVLINK_MSGS
					debugSerial.printf("%d \tMSG: %d - not processed.\r\n", millis(), _msg.msgid);
#endif
					break;
				}
			}
			else
			{
#ifdef DEBUG_GIMBAL_HEARTBEAT				
					debugSerial.printf("%d\tGIMBAL MESSAGE: %d, custom_mode: %d\r\n", millis(),
						(mavlink_msg_heartbeat_get_base_mode(&_msg) & 0x80) > 7, mavlink_msg_heartbeat_get_custom_mode(&_msg));
#endif
			}
		}
		else
		{			
#ifdef DEBUG_PROCESSING_STATE
				debugSerial.printf("%d\tPARSING: msgid: %d, parse_state: %d, msg_rcvd: %d, sysid: %d, compid: %d, base_mode: %d, custom_mode: %d\r\n",
					millis(),
					_msg.msgid,
					_status.parse_state,
					_status.msg_received,
					_msg.sysid,
					_msg.compid,
					(mavlink_msg_heartbeat_get_base_mode(&_msg) & 0x80) > 7,
					mavlink_msg_heartbeat_get_custom_mode(&_msg));
#endif
		}
	}
}