CloudConfigRK
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
CloudConfigStorage Class Referenceabstract

Abstract base class of all storage methods. More...

#include <CloudConfigRK.h>

Inheritance diagram for CloudConfigStorage:
CloudConfigStorageData CloudConfigStorageStatic CloudConfigStorageEEPROM< SIZE > CloudConfigStorageFile< SIZE > CloudConfigStorageRetained

Public Member Functions

 CloudConfigStorage ()
 Constructor. Base class constructor is empty.
 
bool hasJsonData () const
 Returns true if there is JSON data field is not empty.
 
virtual CloudConfigDataHeadergetDataHeader ()
 Gets a pointer to the data header. More...
 
virtual const char *const getJsonData () const =0
 Gets a const pointer to the JSON data. More...
 
virtual void setup ()=0
 Called from setup(). Optional. Only needed if the storage method wants setup processing time.
 
virtual void parse ()
 Called after the JSON data is updated to parse the data using the JSON parser. More...
 
virtual void loop ()
 Called from loop(). Optional. Only needed if the storage method wants loop processing time.
 
JSONValue getJSONValue ()
 Gets the top level (outer) JSONValue object. More...
 
JSONValue getJSONValueForKey (const char *key)
 Gets the value for a given key in the top-level outer JSON object. More...
 
JSONValue getJSONValueAtIndex (size_t index)
 Gets the value for a given index in the a JSON array in the top-level outer JSON array. More...
 
virtual bool updateData (const char *json)
 This method is called to update the data in storage method and parse it again. More...
 

Static Public Member Functions

static JSONValue getJSONValueForKey (JSONValue parentObj, const char *key)
 Gets the value for a given key in the a JSON object. More...
 
static JSONValue getJSONValueAtIndex (JSONValue parentObj, size_t index)
 Gets the value for a given index in the a JSON array. More...
 

Protected Member Functions

virtual ~CloudConfigStorage ()
 Destructor. Base class destructor is empty. Also, you can't delete one of these.
 
 CloudConfigStorage (const CloudConfigStorage &)=delete
 This class is not copyable.
 
CloudConfigStorageoperator= (const CloudConfigStorage &)=delete
 This class is not copyable.
 

Protected Attributes

JSONValue jsonObj
 The JSONValue object for the outermost JSON object (or array) More...
 

Detailed Description

Abstract base class of all storage methods.

All storage methods are subclasses of either CloudStorage directly (CloudStorageStatic) or of CloudConfigStorageData (everything else, like CloudStorageEEPROM, CloudStorageRetained, or CloudStorageFile).

Member Function Documentation

◆ getDataHeader()

virtual CloudConfigDataHeader* CloudConfigStorage::getDataHeader ( )
inlinevirtual

Gets a pointer to the data header.

This is only available in classes derived from CloudConfigStorageData, which is all of them except CloudConfigDataStatic, which is not updateable and therefore does not need the structure.

Reimplemented in CloudConfigStorageData.

◆ getJsonData()

virtual const char* const CloudConfigStorage::getJsonData ( ) const
pure virtual

Gets a const pointer to the JSON data.

The CloudConfigStorageData class has an overload that can get a mutable pointer so the data can be updated, but this base class does not have one, because the CloudConfigDataStatic can't update the data in program flash from the device.

Implemented in CloudConfigStorageStatic, and CloudConfigStorageData.

◆ getJSONValue()

JSONValue CloudConfigStorage::getJSONValue ( )
inline

Gets the top level (outer) JSONValue object.

This is typically an object, but could be an array.

◆ getJSONValueAtIndex() [1/2]

JSONValue CloudConfigStorage::getJSONValueAtIndex ( JSONValue  parentObj,
size_t  index 
)
static

Gets the value for a given index in the a JSON array.

Parameters
parentObjA JSONValue for a JSON object to look in
index0 = first entry, 1 = second entry, ...
Returns
A JSONValue object for that key. If the key does not exist in that object, an empty JSONValue object that returns false for isValid() is returned.

There is no call to determine the length of the array; iterate until an invalid object is returned.

◆ getJSONValueAtIndex() [2/2]

JSONValue CloudConfigStorage::getJSONValueAtIndex ( size_t  index)
inline

Gets the value for a given index in the a JSON array in the top-level outer JSON array.

Parameters
index0 = first entry, 1 = second entry, ...
Returns
A JSONValue object for that key. If the key does not exist in that object, an empty JSONValue object that returns false for isValid() is returned.

This method is not commonly used because the top-level object is usually a JSON object (surrounded by { }) not a JSON array (surrounded by [ ]).

There is no call to determine the length of the array; iterate until an invalid object is returned.

◆ getJSONValueForKey() [1/2]

JSONValue CloudConfigStorage::getJSONValueForKey ( const char *  key)
inline

Gets the value for a given key in the top-level outer JSON object.

Parameters
keyThe name of the key-value pair
Returns
A JSONValue object for that key. If the key does not exist in that object, an empty JSONValue object that returns false for isValid() is returned.

◆ getJSONValueForKey() [2/2]

JSONValue CloudConfigStorage::getJSONValueForKey ( JSONValue  parentObj,
const char *  key 
)
static

Gets the value for a given key in the a JSON object.

Parameters
parentObjA JSONValue for a JSON object to look in
keyThe name of the key-value pair
Returns
A JSONValue object for that key. If the key does not exist in that object, an empty JSONValue object that returns false for isValid() is returned.

◆ parse()

virtual void CloudConfigStorage::parse ( )
inlinevirtual

Called after the JSON data is updated to parse the data using the JSON parser.

You normally don't need to override this, but it is virtual in case you do.

◆ updateData()

virtual bool CloudConfigStorage::updateData ( const char *  json)
inlinevirtual

This method is called to update the data in storage method and parse it again.

Parameters
jsonThe new JSON data to save

This is subclassed in CloudConfigStorageData.

Reimplemented in CloudConfigStorageData.

Field Documentation

◆ jsonObj

JSONValue CloudConfigStorage::jsonObj
protected

The JSONValue object for the outermost JSON object (or array)

The parse() method sets this. The parse() method is called from setup() and updateData().


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