|
|
@ -282,50 +282,43 @@ AutoConnectElement* AutoConnectAux::_createElement(const JsonObject& json) { |
|
|
|
* Constructs an AutoConnectAux instance by reading all the |
|
|
|
* Constructs an AutoConnectAux instance by reading all the |
|
|
|
* AutoConnectElements of the specified URI from the elements defined JSON. |
|
|
|
* AutoConnectElements of the specified URI from the elements defined JSON. |
|
|
|
* @param in AutoConnectAux element data which is described by JSON. |
|
|
|
* @param in AutoConnectAux element data which is described by JSON. |
|
|
|
* @param uri AutoConnectAux uri to be loaded. |
|
|
|
|
|
|
|
* @return true The element collection successfully loaded. |
|
|
|
* @return true The element collection successfully loaded. |
|
|
|
* @return false Invalid JSON data occurred.
|
|
|
|
* @return false Invalid JSON data occurred.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool AutoConnectAux::load(const char* in, const String uri) { |
|
|
|
bool AutoConnectAux::load(const char* in) { |
|
|
|
DynamicJsonBuffer jsonBuffer; |
|
|
|
// DynamicJsonBuffer jsonBuffer();
|
|
|
|
|
|
|
|
const size_t bufferSize = 2*JSON_ARRAY_SIZE(2) + 3*JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(3) + 9*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + 1080; |
|
|
|
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
return _load(jb, uri); |
|
|
|
return _load(jb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool AutoConnectAux::load(const __FlashStringHelper* in, const String uri) { |
|
|
|
bool AutoConnectAux::load(const __FlashStringHelper* in) { |
|
|
|
DynamicJsonBuffer jsonBuffer; |
|
|
|
// DynamicJsonBuffer jsonBuffer();
|
|
|
|
|
|
|
|
const size_t bufferSize = 2*JSON_ARRAY_SIZE(2) + 3*JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(3) + 9*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + 1080; |
|
|
|
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
return _load(jb, uri); |
|
|
|
return _load(jb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool AutoConnectAux::load(Stream& in, const String uri) { |
|
|
|
bool AutoConnectAux::load(Stream& in) { |
|
|
|
DynamicJsonBuffer jsonBuffer; |
|
|
|
// DynamicJsonBuffer jsonBuffer();
|
|
|
|
|
|
|
|
const size_t bufferSize = 2*JSON_ARRAY_SIZE(2) + 3*JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(9) + JSON_OBJECT_SIZE(1) + 2*JSON_OBJECT_SIZE(3) + 9*JSON_OBJECT_SIZE(4) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(6) + 1080; |
|
|
|
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
return _load(jb, uri); |
|
|
|
return _load(jb); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool AutoConnectAux::_load(JsonObject& jb, const String uri) { |
|
|
|
bool AutoConnectAux::_load(JsonObject& jb) { |
|
|
|
bool rc = jb.success(); |
|
|
|
if (!jb.success()) |
|
|
|
if (rc) { |
|
|
|
return false; |
|
|
|
JsonArray& aux = jb[AUTOCONNECT_JSON_KEY_AUX]; |
|
|
|
|
|
|
|
if ((rc = aux.success())) { |
|
|
|
_title = jb.get<String>(F(AUTOCONNECT_JSON_KEY_TITLE)); |
|
|
|
rc = false; |
|
|
|
_uriStr = jb.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); |
|
|
|
for (JsonObject& page : aux) { |
|
|
|
_uri = _uriStr.c_str(); |
|
|
|
const String j_uri = page.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); |
|
|
|
_menu = jb.get<bool>(F(AUTOCONNECT_JSON_KEY_MENU)); |
|
|
|
if (uri == j_uri) { |
|
|
|
|
|
|
|
AC_DBG("Loading %s\n", j_uri.c_str()); |
|
|
|
|
|
|
|
_title = page.get<String>(F(AUTOCONNECT_JSON_KEY_TITLE)); |
|
|
|
|
|
|
|
_menu = page.get<bool>(F(AUTOCONNECT_JSON_KEY_MENU)); |
|
|
|
|
|
|
|
_uriStr = j_uri; |
|
|
|
|
|
|
|
setUri(_uriStr.c_str()); |
|
|
|
|
|
|
|
(void)_loadElement(jb, "*"); |
|
|
|
(void)_loadElement(jb, "*"); |
|
|
|
rc = true; |
|
|
|
return true; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return rc; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -333,7 +326,7 @@ bool AutoConnectAux::_load(JsonObject& jb, const String uri) { |
|
|
|
* described by JSON. Usually, the Stream is specified a storm file of |
|
|
|
* described by JSON. Usually, the Stream is specified a storm file of |
|
|
|
* SD or SPIFFS. The Stream must be opened before invoking the function. |
|
|
|
* SD or SPIFFS. The Stream must be opened before invoking the function. |
|
|
|
* @param in Reference of the Stream which contains the parameter |
|
|
|
* @param in Reference of the Stream which contains the parameter |
|
|
|
* file described by JSON. |
|
|
|
* data described by JSON. |
|
|
|
* @param name The element name to be loaded. '*'specifies that all |
|
|
|
* @param name The element name to be loaded. '*'specifies that all |
|
|
|
* elements are to be loaded. |
|
|
|
* elements are to be loaded. |
|
|
|
* @return A reference of loaded AutoConnectElement instance. |
|
|
|
* @return A reference of loaded AutoConnectElement instance. |
|
|
@ -363,23 +356,16 @@ AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String na |
|
|
|
if (!jb.success()) |
|
|
|
if (!jb.success()) |
|
|
|
return _nullElement(); |
|
|
|
return _nullElement(); |
|
|
|
|
|
|
|
|
|
|
|
JsonArray& aux = jb[AUTOCONNECT_JSON_KEY_AUX]; |
|
|
|
JsonArray& elements = jb[AUTOCONNECT_JSON_KEY_ELEMENT]; |
|
|
|
if (!aux.success()) |
|
|
|
for (JsonObject& element : elements) { |
|
|
|
return _nullElement(); |
|
|
|
String elmName = element.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); |
|
|
|
|
|
|
|
|
|
|
|
for (JsonObject& page : aux) { |
|
|
|
|
|
|
|
if (page[AUTOCONNECT_JSON_KEY_URI].as<String>() == String(uri())) { |
|
|
|
|
|
|
|
JsonArray& element = page[AUTOCONNECT_JSON_KEY_ELEMENT]; |
|
|
|
|
|
|
|
for (JsonObject& elm : element) { |
|
|
|
|
|
|
|
String elmName = elm.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); |
|
|
|
|
|
|
|
if (wc || name.equalsIgnoreCase(elmName)) { |
|
|
|
if (wc || name.equalsIgnoreCase(elmName)) { |
|
|
|
// The specified element is defined in the JSON stream.
|
|
|
|
// The specified element is defined in the JSON stream.
|
|
|
|
// Loads from JSON object.
|
|
|
|
// Loads from JSON object.
|
|
|
|
const String inType = elm[AUTOCONNECT_JSON_KEY_TYPE].as<String>(); |
|
|
|
|
|
|
|
auxElm = _getElement(elmName); |
|
|
|
auxElm = _getElement(elmName); |
|
|
|
// The element is not created yet, create new one.
|
|
|
|
// The element is not created yet, create new one.
|
|
|
|
if (!auxElm) { |
|
|
|
if (!auxElm) { |
|
|
|
if ((auxElm = _createElement(elm))) { |
|
|
|
if ((auxElm = _createElement(element))) { |
|
|
|
AC_DBG("%s<%d> of %s created\n", elmName.c_str(), (int)(auxElm->typeOf()), uri()); |
|
|
|
AC_DBG("%s<%d> of %s created\n", elmName.c_str(), (int)(auxElm->typeOf()), uri()); |
|
|
|
add(*auxElm); // Insert to AutoConnect
|
|
|
|
add(*auxElm); // Insert to AutoConnect
|
|
|
|
} |
|
|
|
} |
|
|
@ -388,9 +374,8 @@ AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String na |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (auxElm->loadElement(elm)) { |
|
|
|
if (auxElm->loadElement(element)) |
|
|
|
AC_DBG("%s<%d> of %s loaded\n", auxElm->name.c_str(), (int)auxElm->typeOf(), uri()); |
|
|
|
AC_DBG("%s<%d> of %s loaded\n", auxElm->name.c_str(), (int)auxElm->typeOf(), uri()); |
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
else { |
|
|
|
// Element type mismatch
|
|
|
|
// Element type mismatch
|
|
|
|
AC_DBG("Type of %s element mismatched\n", elmName.c_str()); |
|
|
|
AC_DBG("Type of %s element mismatched\n", elmName.c_str()); |
|
|
@ -398,8 +383,6 @@ AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String na |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return auxElm ? *auxElm : _nullElement(); |
|
|
|
return auxElm ? *auxElm : _nullElement(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -416,12 +399,12 @@ size_t AutoConnectAux::saveElement(Stream& out, const AutoConnectElement& elemen |
|
|
|
if (!jb.success()) |
|
|
|
if (!jb.success()) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
JsonArray& aux = jb[AUTOCONNECT_JSON_KEY_AUX]; |
|
|
|
JsonArray& aux = jb["aux"]; |
|
|
|
if (!aux.success()) |
|
|
|
if (!aux.success()) |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
for (JsonObject& page : aux) { |
|
|
|
for (JsonObject& page : aux) { |
|
|
|
if (page["uri"].as<String>() == String(uri())) { |
|
|
|
if (page["aux"].as<String>() == String(uri())) { |
|
|
|
JsonArray& element_j = page[AUTOCONNECT_JSON_KEY_ELEMENT]; |
|
|
|
JsonArray& element_j = page[AUTOCONNECT_JSON_KEY_ELEMENT]; |
|
|
|
for (JsonObject& elm : element_j) { |
|
|
|
for (JsonObject& elm : element_j) { |
|
|
|
if (elm[AUTOCONNECT_JSON_KEY_NAME].as<String>() == element.name) { |
|
|
|
if (elm[AUTOCONNECT_JSON_KEY_NAME].as<String>() == element.name) { |
|
|
|