public ICommandResponseAsync Execute(ICommand command) { bool enableBroadcast = commandType == ECommandType.Broadcast; ICommandResponseAsync job = null; for (var i = 0; i < mCommandHandlers.Count; ++i) { var h = mCommandHandlers[i]; if (h.Verify(command)) { DebugUtility.Log(LoggerTags.Online, "Try to execute command in component {0} - {1}", h, command); var result = h.Execute(command); if (result != null) { if (job == null) { job = new CommandResponseAsync(); } job.AddResponse(result); // 不是广播模式,立即停止 if (!enableBroadcast) { break; } } } else { DebugUtility.Log(LoggerTags.Online, "Fail to verify command in component {0} - {1}", h, command); } } return(job); }
public void AddResponse(ICommandResponseAsync job) { // 回应列表 >= 等待列表,外部不断去检索是否已经done,如果已经done,等待列表为空 mResponses.Union(job); if (!job.done) { // 如果这个任务没有完成则继续检索 mWaiting.Union(job); } }
private void HandleMessage(ICommand cmd, IRobot robot) { DebugUtility.Log(LoggerTags.Online, "{0} Handling message : {1}", robot, cmd); ICommandResponseAsync waiting = robot.Execute(cmd); if (waiting == null) { DebugUtility.LogError(LoggerTags.Online, "Can't handle message : {0}", cmd); return; } if (mConnInfos.TryGetValue(robot, out var conn)) { DebugUtility.Log(LoggerTags.Online, "Waiting : {0}", waiting); conn.waitings.Add(waiting); } else if (mAcitivedConn != null) { mAcitivedConn.waitings.Add(waiting); } }
public override ICommandResponseAsync Execute(ICommand command) { bool resImme = false; IProtocol result = null; switch (command.commandID) { case ECommand.UKitCommand: { resImme = ExecuteUKitCommands(command, out result); break; } } if (result == null) { DebugUtility.LogError(LoggerTags.Project, "Failure to execute command : {0}", command); } ICommandResponseAsync cra = null; if (resImme) { DebugUtility.Log(LoggerTags.Project, "Success to execute command : {0} - Immediately", command); var cra2 = new CommandResponseAsync(result); cra2.host = command.host; cra2.context = command.context; cra = cra2; } else if (result != null) { DebugUtility.Log(LoggerTags.Project, "Success to execute command : {0} - Delay", command); waitingInputAsync = new TriggerCommandResponseAsync(result); waitingInputAsync.host = command.host; waitingInputAsync.context = command.context; cra = waitingInputAsync; } return(cra); }
public virtual ICommandResponseAsync Execute(ICommand command) { bool enableBroadcast = commandType == ECommandType.Broadcast; bool exitResponse = false; ICommandResponseAsync job = null; for (var i = 0; i < parts.Count; ++i) { var h = parts[i]; if (h.Verify(command)) { DebugUtility.Log(LoggerTags.Online, "Try to execute command in part {0} - {1}", h.gameObject.name, command); var result = h.Execute(command); if (result != null) { if (job == null) { job = new CommandResponseAsync(); } job.AddResponse(result); exitResponse = true; // 不是广播模式,立即停止 if (!enableBroadcast) { break; } } } else { // DebugUtility.Log(LoggerTags.Online, "Fail to verify command : {0} - {1}", h.gameObject.name, command); } } return(job); }
public void AddResponse(ICommandResponseAsync job) { }