Add deserialization logic
This commit is contained in:
@@ -7,6 +7,10 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <fan/Fan.h>
|
||||
#include <sensor/Sensor.h>
|
||||
|
||||
#define SERIALIZATION_DIR "/etc/fantasize"
|
||||
#define FANS_JSON_FILENAME "fans.json"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@@ -14,9 +18,12 @@ class Serializer {
|
||||
public:
|
||||
Serializer();
|
||||
void Serialize(std::vector<std::shared_ptr<Fan>> fans);
|
||||
std::vector<std::shared_ptr<Fan>>
|
||||
Deserialize(std::vector<std::shared_ptr<Sensor>> availableSensors);
|
||||
|
||||
private:
|
||||
void WriteJson(json o);
|
||||
json ReadJson();
|
||||
};
|
||||
|
||||
#endif // SERIALIZER_H_
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#ifndef FAN_H_
|
||||
#define FAN_H_
|
||||
|
||||
#include <Printable.h>
|
||||
#include <Serializable.h>
|
||||
|
||||
class Fan : public Serializable {
|
||||
class Fan : public Serializable, public Printable {
|
||||
public:
|
||||
virtual void pwm(int percent) = 0;
|
||||
virtual int rpm() = 0;
|
||||
|
||||
@@ -18,6 +18,8 @@ public:
|
||||
|
||||
json toJson() const override;
|
||||
|
||||
const std::string toString() const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<PwmControl> mPwmControl;
|
||||
std::shared_ptr<Sensor> mRpmSensor;
|
||||
|
||||
Reference in New Issue
Block a user