BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
FilesystemDeviceCache.h
1 #pragma once
2 
3 #include <string>
4 
5 #include <Poco/File.h>
6 #include <Poco/Path.h>
7 
8 #include "core/DeviceCache.h"
9 #include "util/Loggable.h"
10 
11 namespace BeeeOn {
12 
28  public DeviceCache,
29  Loggable {
30 public:
32 
33  void setCacheDir(const std::string &path);
34 
48  void markPaired(
49  const DevicePrefix &prefix,
50  const std::set<DeviceID> &devices) override;
51 
55  void markPaired(const DeviceID &device) override;
56 
60  void markUnpaired(const DeviceID &device) override;
61 
65  bool paired(const DeviceID &device) const override;
66 
71  std::set<DeviceID> paired(const DevicePrefix &prefix) const override;
72 
73 protected:
78  Poco::File locatePrefix(const DevicePrefix &prefix) const;
79 
83  Poco::File locateID(const DeviceID &id) const;
84 
92  bool decodeName(const std::string &name, DeviceID &id) const;
93 
98  void drop(const DeviceID &id) const;
99 
104  void write(const DeviceID &id) const;
105 
106 private:
107  Poco::Path m_cacheDir;
108 };
109 
110 }
void markPaired(const DevicePrefix &prefix, const std::set< DeviceID > &devices) override
Synchronize the contents of $cacheDir/$prefix with the given set of devices.
void drop(const DeviceID &id) const
Remove file $cacheDir/$prefix/$id from the filesystem if it does exist. No exceptions should be throw...
Definition: FilesystemDeviceCache.cpp:56
void write(const DeviceID &id) const
Create file $cacheDir/$prefix/$id in the filesystem if it does not exist. No exceptions should be thr...
Definition: FilesystemDeviceCache.cpp:76
bool paired(const DeviceID &device) const override
Definition: FilesystemDeviceCache.cpp:167
DeviceCache manages pairing status devices which allows to choose different caching strategies like: ...
Definition: DeviceCache.h:17
FilesystemDeviceCache implements DeviceCache by creating and removing files inside a filesystem direc...
Definition: FilesystemDeviceCache.h:27
Poco::File locatePrefix(const DevicePrefix &prefix) const
Definition: FilesystemDeviceCache.cpp:27
bool decodeName(const std::string &name, DeviceID &id) const
Parse file name and try to decode it as it is a device ID. The result is given in the referenced para...
Definition: FilesystemDeviceCache.cpp:40
Definition: Loggable.h:19
Poco::File locateID(const DeviceID &id) const
Definition: FilesystemDeviceCache.cpp:33
Definition: DeviceID.h:17
void markUnpaired(const DeviceID &device) override
Remove file $cacheDir/$prefix/$id (if exists).
Definition: FilesystemDeviceCache.cpp:154