50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
//
|
|
// Created by xtkuang on 2025/5/6.
|
|
//
|
|
|
|
#ifndef CMVR_ES_ABSTRACT_DEVICES_H
|
|
#define CMVR_ES_ABSTRACT_DEVICES_H
|
|
|
|
#include <string>
|
|
#include <thread>
|
|
#include <utility>
|
|
|
|
#include "device_types.h"
|
|
#include "state_define.h"
|
|
|
|
#pragma warning(disable:4996)
|
|
#define GLOG_USE_GLOG_EXPORT
|
|
#include "common/base/logging/logger.h"
|
|
|
|
|
|
namespace cmvr::device {
|
|
class AbstractDevice {
|
|
public:
|
|
AbstractDevice() = default;
|
|
explicit AbstractDevice(std::string id) : id_(std::move(id)) {}
|
|
virtual ~AbstractDevice() = default;
|
|
|
|
const std::string& id() const noexcept { return id_; }
|
|
|
|
virtual DeviceKind kind() const noexcept { return DeviceKind::Unknown; }
|
|
virtual std::string typeName() const = 0;
|
|
DeviceInfo info() const { return {id_, kind(), typeName()}; }
|
|
|
|
virtual bool init() { return true; }
|
|
virtual bool start() { return true; }
|
|
virtual bool stop() { return true; }
|
|
virtual bool update() { return true; }
|
|
virtual bool executeJsonCommand(const std::string& request_json, std::string& response_json) {
|
|
response_json = R"({"success":false,"error_message":"JSON command unsupported"})";
|
|
return false;
|
|
}
|
|
|
|
protected:
|
|
std::string id_; // 设备名称
|
|
};
|
|
}
|
|
|
|
|
|
|
|
#endif //CMVR_ES_ABSTRACT_DEVICES_H
|