cmvr-es/cmvr-es/devices/abstract_device.h
xtkuang 428ee328de feat: complete QUIC edge integration
Vendor MsQuic with build and install support, add DeviceManager status to configurable heartbeats, and report only enabled devices.

Add the local QUIC gateway, protocol coverage, real MsQuic E2E tests, process smoke tests, and updated integration documentation.
2026-07-24 12:35:04 +08:00

63 lines
2.0 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;
}
// This hook is sampled by DeviceManager while building heartbeats. It
// must be thread-safe and complete in bounded time while only copying
// in-memory state through atomics or a dedicated short-held state
// lock. Implementations must not perform device I/O, network requests,
// or wait on a lifecycle lock held across such I/O.
//
// The method is intentionally non-const because several legacy device
// categories expose non-const state getters. The returned object is a
// value and does not expose the device lifetime to callers.
virtual DeviceHealthSnapshot healthSnapshot() {
return {};
}
protected:
std::string id_; // 设备名称
};
}
#endif //CMVR_ES_ABSTRACT_DEVICES_H