48 lines
916 B
C++
48 lines
916 B
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <vector>
|
|
|
|
#include <QObject>
|
|
|
|
#include "device_bus/monitor/DeviceEvent.h"
|
|
|
|
namespace softbus::device_bus::monitor
|
|
{
|
|
|
|
class IDeviceMonitor : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
using EventCallback = std::function<void(const DeviceEvent&)>;
|
|
|
|
explicit IDeviceMonitor(QObject* parent = nullptr)
|
|
: QObject(parent)
|
|
{
|
|
}
|
|
~IDeviceMonitor() override = default;
|
|
|
|
virtual bool start() = 0;
|
|
virtual void stop() = 0;
|
|
virtual std::vector<DeviceEvent> snapshotExisting() = 0;
|
|
|
|
void setCallback(EventCallback cb) { m_cb = std::move(cb); }
|
|
|
|
protected:
|
|
void emitEvent(const DeviceEvent& ev)
|
|
{
|
|
if (m_cb) {
|
|
m_cb(ev);
|
|
}
|
|
emit event(ev);
|
|
}
|
|
|
|
signals:
|
|
void event(const softbus::device_bus::monitor::DeviceEvent& ev);
|
|
|
|
private:
|
|
EventCallback m_cb;
|
|
};
|
|
|
|
} // namespace softbus::device_bus::monitor
|