mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-07-23 07:40:11 +08:00
42 lines
915 B
C++
42 lines
915 B
C++
/*
|
|
* @Author: DI JUNKUN
|
|
* @Date: 2026-02-28
|
|
* Copyright (c) 2026 by DI JUNKUN, All Rights Reserved.
|
|
*/
|
|
|
|
#ifndef CROSSDESK_GUI_DEVICE_PRESENCE_CACHE_H_
|
|
#define CROSSDESK_GUI_DEVICE_PRESENCE_CACHE_H_
|
|
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
|
|
namespace crossdesk {
|
|
|
|
class DevicePresenceCache {
|
|
public:
|
|
void SetOnline(const std::string &device_id, bool online) {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
cache_[device_id] = online;
|
|
}
|
|
|
|
bool IsOnline(const std::string &device_id) const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
const auto it = cache_.find(device_id);
|
|
return it != cache_.end() && it->second;
|
|
}
|
|
|
|
void Clear() {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
cache_.clear();
|
|
}
|
|
|
|
private:
|
|
std::unordered_map<std::string, bool> cache_;
|
|
mutable std::mutex mutex_;
|
|
};
|
|
|
|
} // namespace crossdesk
|
|
|
|
#endif // CROSSDESK_GUI_DEVICE_PRESENCE_CACHE_H_
|