42 lines
968 B
C++
42 lines
968 B
C++
//
|
|
// Created by xtkuang on 2025/5/13.
|
|
//
|
|
|
|
#ifndef CMVR_ES_DEVICE_FACTORY_H
|
|
#define CMVR_ES_DEVICE_FACTORY_H
|
|
#pragma once
|
|
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
#include "../../devices/abstract_device.h"
|
|
#include "cmvr/config/device_manager_config/device_manager_config.pb.h"
|
|
|
|
namespace cmvr::device {
|
|
|
|
struct DeviceRecord {
|
|
std::string id;
|
|
DeviceKind kind = DeviceKind::Unknown;
|
|
std::string type_name;
|
|
std::shared_ptr<AbstractDevice> device;
|
|
};
|
|
|
|
class DeviceFactory {
|
|
public:
|
|
using Creator = std::function<DeviceRecord(const config::DeviceConfigEntry& entry)>;
|
|
|
|
DeviceFactory();
|
|
|
|
void registerCreator(config::DeviceConfigEntry::DeviceType type, Creator creator);
|
|
DeviceRecord create(const config::DeviceConfigEntry& entry) const;
|
|
|
|
private:
|
|
std::unordered_map<int, Creator> creators_;
|
|
};
|
|
}
|
|
|
|
|
|
#endif //CMVR_ES_DEVICE_FACTORY_H
|