CloudConfigRK
Public Member Functions | Protected Attributes
CloudConfigStorageData Class Referenceabstract

Abstract base class of all storage methods that use a CloudConfigData structure. More...

#include <CloudConfigRK.h>

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

Public Member Functions

 CloudConfigStorageData ()
 Default constructor.
 
 CloudConfigStorageData (CloudConfigDataHeader *header, size_t dataSize)
 Constructor with header. More...
 
CloudConfigStorageDatawithData (CloudConfigDataHeader *header, size_t dataSize)
 Specify the data header and data location. More...
 
virtual CloudConfigDataHeadergetDataHeader ()
 Gets a pointer to the CloudConfigDataHeader structure.
 
void validate ()
 Validate the CloudConfigDataHeader. More...
 
const char *const getJsonData () const
 Gets a pointer to the JSON data for reading (const) More...
 
size_t getMaxJsonDataSize () const
 Returns the maximum size of the JSON data in characters. More...
 
char * getJsonData ()
 Gets a pointer to the JSON data for writing (not const) More...
 
size_t getTotalSize () const
 Gets the total size of the buffer including both the header and the JSON data. More...
 
virtual bool updateData (const char *json)
 This method is called after subclasses update the JSON data. More...
 
virtual bool save ()=0
 Save the data in the storage subclass. Must be implemented in subclasses! More...
 
- Public Member Functions inherited from CloudConfigStorage
 CloudConfigStorage ()
 Constructor. Base class constructor is empty.
 
bool hasJsonData () const
 Returns true if there is JSON data field is not empty.
 
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...
 

Protected Attributes

CloudConfigDataHeaderheader
 Pointer to the header with data after it.
 
size_t dataSize
 Size of the JSON data, not including sizeof(CloudConfigDataHeader)
 
- Protected Attributes inherited from CloudConfigStorage
JSONValue jsonObj
 The JSONValue object for the outermost JSON object (or array) More...
 

Additional Inherited Members

- Static Public Member Functions inherited from CloudConfigStorage
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 inherited from CloudConfigStorage
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.
 

Detailed Description

Abstract base class of all storage methods that use a CloudConfigData structure.

Classes that include a CloudConfigDataHeader (Retained, EEPROM, File) all use this class as a base class as it contains handy common features that simplify those implementations.

Constructor & Destructor Documentation

◆ CloudConfigStorageData()

CloudConfigStorageData::CloudConfigStorageData ( CloudConfigDataHeader header,
size_t  dataSize 
)

Constructor with header.

This constructor is basically the same as using the default contructor then using withData()

Parameters
headerThe pointer to the CloudConfigDataHeader structure
dataSizeThe size of the data after the header. The total size is sizeof(CloudConfigDataHeader) + dataSize.

Member Function Documentation

◆ getJsonData() [1/2]

char* CloudConfigStorageData::getJsonData ( )

Gets a pointer to the JSON data for writing (not const)

This is right after the CloudConfigDataHeader structure. This method is not available on all storage classes. For example, CloudStorageStatic stores the data in program flash, so it can't be written to.

◆ getJsonData() [2/2]

char * CloudConfigStorageData::getJsonData ( ) const
virtual

Gets a pointer to the JSON data for reading (const)

This is right after the CloudConfigDataHeader structure.

Implements CloudConfigStorage.

◆ getMaxJsonDataSize()

size_t CloudConfigStorageData::getMaxJsonDataSize ( ) const
inline

Returns the maximum size of the JSON data in characters.

The buffer is one byte larger than this because there is always a trailling null to make it a c-string.

Returns
Maximum number of characters of JSON data

◆ getTotalSize()

size_t CloudConfigStorageData::getTotalSize ( ) const
inline

Gets the total size of the buffer including both the header and the JSON data.

This is the buffer size; the actual JSON string could be shorter as it's variable length.

◆ save()

virtual bool CloudConfigStorageData::save ( )
pure virtual

Save the data in the storage subclass. Must be implemented in subclasses!

Returns
true on success or false on failure.

Implemented in CloudConfigStorageFile< SIZE >, CloudConfigStorageEEPROM< SIZE >, and CloudConfigStorageRetained.

◆ updateData()

bool CloudConfigStorageData::updateData ( const char *  json)
virtual

This method is called after subclasses update the JSON data.

The default implementation in this class is usually sufficient, but it can be overridden by subclasses if necessary.

  • Checks to make sure json will fit in dataSize
  • Copies the JSON data (with trailing null)
  • Calls parse() to run the JSMN JSON parser on it and update jsonObj in the parent class
  • Calls save() to save the data in this storage method

Reimplemented from CloudConfigStorage.

◆ validate()

void CloudConfigStorageData::validate ( )

Validate the CloudConfigDataHeader.

If not valid, then resets the entire structure to default values. This is common when the structure is first initialized.

◆ withData()

CloudConfigStorageData & CloudConfigStorageData::withData ( CloudConfigDataHeader header,
size_t  dataSize 
)

Specify the data header and data location.

Parameters
headerThe pointer to the CloudConfigDataHeader structure
dataSizeThe size of the data after the header. The total size is sizeof(CloudConfigDataHeader) + dataSize.
Returns
Returns *this so you can chain calls, fluent-style.

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