BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
Public Member Functions | Protected Member Functions
BeeeOn::FilesystemDeviceCache Class Reference

FilesystemDeviceCache implements DeviceCache by creating and removing files inside a filesystem directory. Each paired device has a file named by its ID created. Devices are categorized by the ID prefix. More...

#include <FilesystemDeviceCache.h>

Inheritance diagram for BeeeOn::FilesystemDeviceCache:
BeeeOn::DeviceCache BeeeOn::Loggable

Public Member Functions

void setCacheDir (const std::string &path)
 
void markPaired (const DevicePrefix &prefix, const std::set< DeviceID > &devices) override
 Synchronize the contents of $cacheDir/$prefix with the given set of devices. More...
 
void markPaired (const DeviceID &device) override
 Create file $cacheDir/$prefix/$id (if does not exist).
 
void markUnpaired (const DeviceID &device) override
 Remove file $cacheDir/$prefix/$id (if exists).
 
bool paired (const DeviceID &device) const override
 
std::set< DeviceIDpaired (const DevicePrefix &prefix) const override
 

Protected Member Functions

Poco::File locatePrefix (const DevicePrefix &prefix) const
 
Poco::File locateID (const DeviceID &id) const
 
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 parameter id. No exceptions should be thrown. More...
 
void drop (const DeviceID &id) const
 Remove file $cacheDir/$prefix/$id from the filesystem if it does exist. No exceptions should be thrown.
 
void write (const DeviceID &id) const
 Create file $cacheDir/$prefix/$id in the filesystem if it does not exist. No exceptions should be thrown.
 

Additional Inherited Members

- Public Types inherited from BeeeOn::DeviceCache
typedef Poco::SharedPtr
< DeviceCache
Ptr
 

Detailed Description

FilesystemDeviceCache implements DeviceCache by creating and removing files inside a filesystem directory. Each paired device has a file named by its ID created. Devices are categorized by the ID prefix.

The cache is created under the directory specified by property cacheDir. If such path does not exist, it is created when on demand.

The FilesystemDeviceCache uses global locking (Poco::NamedLock) for each set of ID of the same prefix. Such lock is named after the prefix.

Member Function Documentation

bool FilesystemDeviceCache::decodeName ( const std::string &  name,
DeviceID id 
) const
protected

Parse file name and try to decode it as it is a device ID. The result is given in the referenced parameter id. No exceptions should be thrown.

Returns
true if the decoding was successful
File FilesystemDeviceCache::locateID ( const DeviceID id) const
protected
Returns
Poco::File pointing to the file representing the given ID
File FilesystemDeviceCache::locatePrefix ( const DevicePrefix prefix) const
protected
Returns
Poco::File pointing to the directory where IDs of the given prefix are stored.
void BeeeOn::FilesystemDeviceCache::markPaired ( const DevicePrefix prefix,
const std::set< DeviceID > &  devices 
)
overridevirtual

Synchronize the contents of $cacheDir/$prefix with the given set of devices.

Existing files $cacheDir/$prefix/$id are preserved if they are present in the given set of devices, otherwise they are deleted. Missing files $cacheDir/$prefix/$id that are contained inside the given set of devices are created.

The operation is atomic from the application point of view. It is however not guaranteed that the state of the cache is consistent with the given set of devices when a serious failure occures.

Implements BeeeOn::DeviceCache.

bool FilesystemDeviceCache::paired ( const DeviceID device) const
overridevirtual
Returns
true if the file $cacheDir/$prefix/$id exists

Implements BeeeOn::DeviceCache.

set< DeviceID > FilesystemDeviceCache::paired ( const DevicePrefix prefix) const
overridevirtual
Returns
set of file names found in $cacheDir/$prefix that are represent valid device IDs

Implements BeeeOn::DeviceCache.


The documentation for this class was generated from the following files: