Skip to content

Commit

Permalink
Remove IJsonConfig virtual interface
Browse files Browse the repository at this point in the history
Using it consumes more flash than it was supposed to save.
  • Loading branch information
nhjschulz committed Nov 25, 2024
1 parent a990dd0 commit 1ac2af9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 123 deletions.
109 changes: 0 additions & 109 deletions lib/Common/src/IJsonConfig.h

This file was deleted.

2 changes: 1 addition & 1 deletion lib/DateTimePlugin/src/DateTimePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class DateTimePlugin : public PluginWithConfig
* @return true Keys needed merging.
* @return false Nothing needed merging.
*/
bool mergeConfiguration(JsonObject& jsonMerged, const JsonObjectConst& jsonSource) final;
bool mergeConfiguration(JsonObject& jsonMerged, const JsonObjectConst& jsonSource);

/**
* Get current date/time and update the text, which to be displayed.
Expand Down
27 changes: 17 additions & 10 deletions lib/Plugin/src/PluginWithConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
* Includes
*****************************************************************************/
#include "Plugin.hpp"
#include "IJsonConfig.h"

#include <SimpleTimer.hpp>
#include <JsonFile.h>
Expand All @@ -65,7 +64,7 @@
* Attention: Every derived class must call start(), stop() and process()
* of this base class to get the configuration file handling working!
*/
class PluginWithConfig : public Plugin, IJsonConfig
class PluginWithConfig : public Plugin
{
public:

Expand Down Expand Up @@ -191,6 +190,22 @@ class PluginWithConfig : public Plugin, IJsonConfig
{
}

/**
* Get configuration in JSON.
*
* @param[out] cfg Configuration
*/
virtual void getConfiguration(JsonObject& cfg) const = 0;

/**
* Set configuration in JSON.
*
* @param[in] cfg Configuration
*
* @return If successful set, it will return true otherwise false.
*/
virtual bool setConfiguration(const JsonObjectConst& cfg) = 0;

/**
* Request to store configuration to persistent memory.
*/
Expand Down Expand Up @@ -317,14 +332,6 @@ class PluginWithConfig : public Plugin, IJsonConfig
SimpleTimer m_cfgReloadTimer; /**< Timer is used to cyclic reload the configuration from persistent memory. */
bool m_storeConfigReq; /**< Is requested to store the configuration in persistent memory? */
bool m_reloadConfigReq; /**< Is requested to reload the configuration from persistent memory? */

/*TODO REMOVE if all plugins have it. Right now only in DateTimePlugin. */
bool mergeConfiguration(JsonObject& jsonMerged, const JsonObjectConst& jsonSource)
{
return true;
}


};

/******************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions lib/Utilities/library.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"owner": "bblanchon",
"name": "ArduinoJson",
"version": "~6.21.5"
}, {
"name": "YAGfx"
}, {
"name": "FS"
}, {
Expand Down
35 changes: 32 additions & 3 deletions lib/Views/src/IDateTimeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@
/******************************************************************************
* Includes
*****************************************************************************/
#include <ArduinoJson.h>
#include <YAGfx.h>
#include <Fonts.h>
#include <WString.h>
#include <time.h>

#include "IJsonConfig.h"

/******************************************************************************
* Macros
*****************************************************************************/
Expand All @@ -60,7 +59,7 @@
/**
* Interface for a view with date and time.
*/
class IDateTimeView : public IJsonConfig
class IDateTimeView
{
public:

Expand Down Expand Up @@ -195,6 +194,36 @@ class IDateTimeView : public IJsonConfig
*/
virtual void setCurrentTime(const tm& now) = 0;

/**
* Get current active configuration in JSON format.
*
* @param[out] cfg Configuration
*/
virtual void getConfiguration(JsonObject& jsonCfg) const = 0;

/**
* Apply configuration from JSON.
*
* @param[in] cfg Configuration
*
* @return If successful set, it will return true otherwise false.
*/
virtual bool setConfiguration(const JsonObjectConst& jsonCfg) = 0;

/**
* Merge JSON configuration with local settings to create a complete set.
*
* The received configuration may not contain all single key/value pair.
* Therefore create a complete internal configuration and overwrite it
* with the received one.
*
* @param[out] jsonMerged The complete config set with merge content from jsonSource.
* @param[in] jsonSource The recevied congi set, which may not cover all keys.
* @return true Keys needed merging.
* @return false Nothing needed merging.
*/
virtual bool mergeConfiguration(JsonObject& jsonMerged, const JsonObjectConst& jsonSource) = 0;

protected:

/**
Expand Down

0 comments on commit 1ac2af9

Please sign in to comment.