cmvr-es/include/device_manager/device_manager.h
2025-08-21 13:56:39 +08:00

78 lines
2.2 KiB
C++

//
// Created by xtkuang on 2025/5/6.
//
#ifndef CMVR_ES_DEVICE_MANAGER_H
#define CMVR_ES_DEVICE_MANAGER_H
#include <list>
#include <variant>
#include <sys/utsname.h>
#include <unordered_map>
#include "device_factory.h"
#include "system_monitor.h"
#include "../utils/base/thread_pool.h"
namespace cmvr::device {
using DeviceVariant = std::variant<
std::shared_ptr<AbstractAGV>,
std::shared_ptr<AbstractBattery>,
std::shared_ptr<AbstractCamera>,
std::shared_ptr<AbstractDexHand>,
std::shared_ptr<AbstractGripper>,
std::shared_ptr<AbstractMicrophone>,
std::shared_ptr<AbstractRobot>,
std::shared_ptr<AbstractSpeaker>,
std::shared_ptr<AbstractBiohead>
>;
typedef struct {
std::string version;
std::string name;
std::string description;
std::string os;
std::string kernel_version;
std::string architecture;
} SystemInfo;
class DeviceManager {
public:
DeviceManager(const DeviceManager&) = delete;
DeviceManager& operator=(const DeviceManager&) = delete;
static DeviceManager& getInstance(const XmlNode &cfg);
static DeviceManager& getInstance();
static void destroyInstance();
void start();
void restart();
void stop();
void updateParam(const std::string& id, const std::pair<std::string, std::string> &param);
void getDeviceList(std::list<std::pair<std::string, std::string>> &device_list);
void getSystemInfo(SystemInfo &info) const;
void getSystemStatus(device::SystemStatus &status) const;
template <class DeviceType>
std::shared_ptr<DeviceType> getDevice(const std::string &device_id);
private:
static std::once_flag init_flag_;
static std::shared_ptr<DeviceManager> instance_;
XmlNode cfg_;
SystemInfo info_;
std::unordered_map<std::string, DeviceVariant> devices_;
std::unique_ptr<DeviceFactory> dev_factory_;
std::unique_ptr<device::SystemMonitor> sys_monitor_;
explicit DeviceManager(const XmlNode &cfg);
void init_devices_();
void get_os_info_();
};
} // cmvr
#endif //CMVR_ES_DEVICE_MANAGER_H