#ifndef CMVR_ES_TOUCH_FACTORY_H #define CMVR_ES_TOUCH_FACTORY_H #include #include "cmvr/config/touch_config/touch_config.pb.h" #include "devices/touch/px_6ax_gen3/include/px_6ax_gen3.h" #include "devices/touch/px_6ax_genx_can/include/px_6ax_genx_can.h" #include "devices/touch/zero_sim_touch/include/zero_sim_touch.h" namespace cmvr::device { class TouchFactory { public: static std::shared_ptr create(const config::TouchDeviceConfig& cfg) { if (cfg.id().empty()) { CMVR_LOG(ERROR) << "[TouchFactory] Touch id is empty"; return nullptr; } switch (cfg.backend_case()) { case config::TouchDeviceConfig::kPx6AxGen3: return createBackend_(cfg.id(), cfg.px_6ax_gen3()); case config::TouchDeviceConfig::kZeroSim: return createBackend_(cfg.id(), cfg.zero_sim()); case config::TouchDeviceConfig::kPx6AxGenxCan: return createBackend_(cfg.id(), cfg.px_6ax_genx_can()); default: CMVR_LOG(ERROR) << "[TouchFactory] Touch backend is not configured: " << cfg.id(); return nullptr; } } private: template static std::shared_ptr createBackend_(const std::string& id, Config cfg) { if (!cfg.id().empty() && cfg.id() != id) { CMVR_LOG(ERROR) << "[TouchFactory] Touch id does not match backend id: " << id; return nullptr; } cfg.set_id(id); return std::make_shared(cfg); } }; } // namespace cmvr::device #endif // CMVR_ES_TOUCH_FACTORY_H