Replies: 4 comments
-
|
API usage in Stormancer:
|
Beta Was this translation helpful? Give feedback.
-
|
The device identifier provider from the Stormancer Plugins sample needs access to the file system. The feature it needs are:
|
Beta Was this translation helpful? Give feedback.
-
|
The file provider should be a singleton dependency implementing an IFileSystem interface. Different platforms will register different implementations of this common interface in the dependecy resolver. An open file should be represented by a File struct, representing the file handle. This struct should have reference semantics, ensuring the file is properly closed once all copies of a specific File struct have been destroyed. Internally the struct will contain a pointer to a type implementing IFileImplementation depending on the platform and reference counting logic to ensure the closing is done at the proper time. |
Beta Was this translation helpful? Give feedback.
-
|
Current interface exposing the needed methods for the sample device identifier use case: class IFileImplementation
{
public:
virtual std::string getPath() const = 0;
virtual std::string getFileName() const = 0;
virtual ~IFileImplementation() = default;
};
class File
{
public:
File() : _file(nullptr) {};
File(std::shared_ptr<IFileImplementation> fileImpl) : _file(fileImpl) {};
bool isValid() const;
std::string getPath() const;
std::string getFileName() const;
private:
std::shared_ptr<IFileImplementation> _file;
};
class IFileSystem
{
public:
virtual bool createDirectory(const std::string& path);
virtual bool remove(const std::string& path);
virtual bool tryCreateFile(const std::string& path, File& file, bool overwrite) = 0;
};Platform specific providers need providing implementation for IFileSystem and IFileImplementation. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Accessing the file system on different platforms (useful in some plugins) can be tricky since it will often require calls to low level APIs.
We should add a FileSystem service inside our dependensy resolver to handle this. This service will not be feature complete at first, it will only implement the features currently used by actual components. It will only be available on a couple platforms at first and more will be added when the need arise.
Every interaction from a Stormancer plugin or sample should use this service. Features will be discussed here before adding them depending on the needs of the plugins or samples.
Beta Was this translation helpful? Give feedback.
All reactions