#pragma once #include "SimpleCommandInfo.h" #include #include "StringExtensions.h" namespace Incart::Usb { struct LaunchedSimpleCommandInfo final { std::string name; uint32_t uid; std::vector data; LaunchedSimpleCommandInfo(const std::string& name_, uint32_t uid_, const std::vector& data_) : name(name_) , uid(uid_) , data(data_) { } bool isValid(const DevicesInfo::SimpleCommandInfo& commandInfo) { if (!Common::StringExtensions::isEqualsInsensitive(name, commandInfo.name)) return false; switch (commandInfo.data.sourceType) { case DevicesInfo::ESourceType::Fixed: if (data.size() > 0) { return false; } break; case DevicesInfo::ESourceType::Dynamic: if ((commandInfo.data.width >= 0) && (static_cast(data.size()) != commandInfo.data.width)) { return false; } if ((commandInfo.data.options.size() > 0) && !containsOption(commandInfo.data.options, data)) { return false; } break; } return true; } private: bool containsOption(const std::vector>& options, const std::vector& option) { for (auto it = options.begin(); it != options.end(); it++) { if (std::equal(it->begin(), it->end(), option.begin())) { return true; } } return false; } }; } // namespace Incart::Usb