#pragma once #include "JsonCommand.h" #include "EDeviceCommandStatus.h" #include "VariantJsonCommandInfo.h" #include "ComplexCommand.h" #include "JsonCommandStatusCreator.h" #include namespace Incart::DeviceWebApi { class DeviceComplexJsonCommand : public Net::WebApi::JsonCommand { protected: // all inner commands (complex and simple) must be generated with id from commands queue id generator std::unordered_map> m_executedCommands; // JsonCommand может работать с любым количеством запущенных IComplexCommand public: DeviceComplexJsonCommand(std::shared_ptr description, QObject* parent = nullptr) : JsonCommand(description, parent) { } protected: void removeExecutedCommand(Usb::ComplexCommand* command) { auto it = m_executedCommands.find(command); if (it != m_executedCommands.end()) { m_executedCommands.erase(it); } } std::shared_ptr executeCommand(std::shared_ptr command) { std::shared_ptr status = command->execute(); if (status->status != Usb::DeviceCommand::EStatus::OK) { removeExecutedCommand(command.get()); } return DeviceWebApi::JsonCommandStatusCreator::create(status); } }; } // namespace Incart::DeviceWebApi