|
|
|
@ -93,7 +93,7 @@ void AutoConnectAux::add(AutoConnectElementVT addons) { |
|
|
|
|
* @param name Element name |
|
|
|
|
* @return A pointer to the registered AutoConnectElement. |
|
|
|
|
*/ |
|
|
|
|
AutoConnectElement* AutoConnectAux::getElement(const String name) { |
|
|
|
|
AutoConnectElement* AutoConnectAux::getElement(const String& name) { |
|
|
|
|
for (std::size_t n = 0; n < _addonElm.size(); n++) |
|
|
|
|
if (name.equalsIgnoreCase(_addonElm[n].get().name)) |
|
|
|
|
return &(_addonElm[n].get()); |
|
|
|
@ -109,7 +109,7 @@ AutoConnectElement* AutoConnectAux::getElement(const String name) { |
|
|
|
|
* @return true The specified AutoConnectElements have been released. |
|
|
|
|
* @return false The specified AutoConnectElement not found in AutoConnectAux. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectAux::release(const String name) { |
|
|
|
|
bool AutoConnectAux::release(const String& name) { |
|
|
|
|
bool rc = false; |
|
|
|
|
for (std::size_t n = 0; n < _addonElm.size(); n++) { |
|
|
|
|
String elmName = _addonElm[n].get().name; |
|
|
|
@ -130,7 +130,7 @@ bool AutoConnectAux::release(const String name) { |
|
|
|
|
* @return false An element specified name is not registered, |
|
|
|
|
* or its element value does not match storage type. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectAux::setElementValue(const String name, const String value) { |
|
|
|
|
bool AutoConnectAux::setElementValue(const String& name, const String value) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() != AC_Select && elm->typeOf() != AC_Radio) { |
|
|
|
@ -151,7 +151,7 @@ bool AutoConnectAux::setElementValue(const String name, const String value) { |
|
|
|
|
* @return false An element specified name is not registered, |
|
|
|
|
* or its element value must be array. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectAux::setElementValue(const String name, std::vector<String> values) { |
|
|
|
|
bool AutoConnectAux::setElementValue(const String& name, std::vector<String> values) { |
|
|
|
|
bool rc = false; |
|
|
|
|
|
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
@ -271,17 +271,17 @@ PageElement* AutoConnectAux::_setupPage(String uri) { |
|
|
|
|
elm = new PageElement(); |
|
|
|
|
// Construct the auxiliary page
|
|
|
|
|
elm->setMold(_PAGE_AUX); |
|
|
|
|
elm->addToken(PSTR("HEAD"), std::bind(&AutoConnect::_token_HEAD, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("AUX_TITLE"), std::bind(&AutoConnectAux::_injectTitle, this, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("CSS_BASE"), std::bind(&AutoConnect::_token_CSS_BASE, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("CSS_UL"), std::bind(&AutoConnect::_token_CSS_UL, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("CSS_INPUT_BUTTON"), std::bind(&AutoConnect::_token_CSS_INPUT_BUTTON, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("CSS_INPUT_TEXT"), std::bind(&AutoConnect::_token_CSS_INPUT_TEXT, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("CSS_LUXBAR"), std::bind(&AutoConnect::_token_CSS_LUXBAR, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("MENU_PRE"), std::bind(&AutoConnect::_token_MENU_PRE, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("MENU_AUX"), std::bind(&AutoConnect::_token_MENU_AUX, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("MENU_POST"), std::bind(&AutoConnect::_token_MENU_POST, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(PSTR("AUX_ELEMENT"), std::bind(&AutoConnectAux::_insertElement, this, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("HEAD")), std::bind(&AutoConnect::_token_HEAD, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("AUX_TITLE")), std::bind(&AutoConnectAux::_injectTitle, this, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("CSS_BASE")), std::bind(&AutoConnect::_token_CSS_BASE, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("CSS_UL")), std::bind(&AutoConnect::_token_CSS_UL, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("CSS_INPUT_BUTTON")), std::bind(&AutoConnect::_token_CSS_INPUT_BUTTON, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("CSS_INPUT_TEXT")), std::bind(&AutoConnect::_token_CSS_INPUT_TEXT, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("CSS_LUXBAR")), std::bind(&AutoConnect::_token_CSS_LUXBAR, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("MENU_PRE")), std::bind(&AutoConnect::_token_MENU_PRE, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("MENU_AUX")), std::bind(&AutoConnect::_token_MENU_AUX, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("MENU_POST")), std::bind(&AutoConnect::_token_MENU_POST, mother, std::placeholders::_1)); |
|
|
|
|
elm->addToken(String(FPSTR("AUX_ELEMENT")), std::bind(&AutoConnectAux::_insertElement, this, std::placeholders::_1)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return elm; |
|
|
|
@ -323,13 +323,13 @@ AutoConnectElement& AutoConnectAux::_nullElement() { |
|
|
|
|
* @return A reference of AutoConnectButton class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectButtonBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectButtonBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Button) |
|
|
|
|
return *(reinterpret_cast<AutoConnectButtonBasis*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectButtonBasis&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -340,13 +340,13 @@ AutoConnectButtonBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectCheckbox class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectCheckboxBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectCheckboxBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Checkbox) |
|
|
|
|
return *(reinterpret_cast<AutoConnectCheckboxBasis*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectCheckboxBasis&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -357,13 +357,13 @@ AutoConnectCheckboxBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectInput class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectInputBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectInputBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Input) |
|
|
|
|
return *(reinterpret_cast<AutoConnectInputBasis*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectInputBasis&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -374,13 +374,13 @@ AutoConnectInputBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectRadio class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectRadioBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectRadioBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Radio) |
|
|
|
|
return *(reinterpret_cast<AutoConnectRadioBasis*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectRadioBasis&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -391,13 +391,13 @@ AutoConnectRadioBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectSelect class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectSelectBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectSelectBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Select) |
|
|
|
|
return *(reinterpret_cast<AutoConnectSelectBasis*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectSelectBasis&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -408,13 +408,13 @@ AutoConnectSelectBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectSubmit class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectSubmitBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectSubmitBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Submit) |
|
|
|
|
return *(reinterpret_cast<AutoConnectSubmitBasis*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectSubmitBasis&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -425,13 +425,13 @@ AutoConnectSubmitBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectText class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectTextBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectTextBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Text) |
|
|
|
|
return *(reinterpret_cast<AutoConnectTextBasis*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectTextBasis&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -459,13 +459,13 @@ bool AutoConnectAux::_jbLiteral; /**< JSON object lexical status */ |
|
|
|
|
* @return A reference of AutoConnectButton class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectButtonJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectButtonJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Button) |
|
|
|
|
return *(reinterpret_cast<AutoConnectButtonJson*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectButtonJson&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -476,13 +476,13 @@ AutoConnectButtonJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectCheckbox class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectCheckboxJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectCheckboxJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Checkbox) |
|
|
|
|
return *(reinterpret_cast<AutoConnectCheckboxJson*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectCheckboxJson&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -493,13 +493,13 @@ AutoConnectCheckboxJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectInput class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectInputJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectInputJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Input) |
|
|
|
|
return *(reinterpret_cast<AutoConnectInputJson*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectInputJson&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -510,13 +510,13 @@ AutoConnectInputJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectRadio class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectRadioJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectRadioJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Radio) |
|
|
|
|
return *(reinterpret_cast<AutoConnectRadioJson*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectRadioJson&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -527,13 +527,13 @@ AutoConnectRadioJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectSelect class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectSelectJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectSelectJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Select) |
|
|
|
|
return *(reinterpret_cast<AutoConnectSelectJson*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectSelectJson&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -544,13 +544,13 @@ AutoConnectSelectJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectSubmit class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectSubmitJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectSubmitJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Submit) |
|
|
|
|
return *(reinterpret_cast<AutoConnectSubmitJson*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectSubmitJson&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -561,13 +561,13 @@ AutoConnectSubmitJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @return A reference of AutoConnectText class. |
|
|
|
|
*/ |
|
|
|
|
template<> |
|
|
|
|
AutoConnectTextJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
AutoConnectTextJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
|
if (elm) { |
|
|
|
|
if (elm->typeOf() == AC_Text) |
|
|
|
|
return *(reinterpret_cast<AutoConnectTextJson*>(elm)); |
|
|
|
|
else |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name, elm->typeOf()); |
|
|
|
|
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); |
|
|
|
|
} |
|
|
|
|
return reinterpret_cast<AutoConnectTextJson&>(_nullElement()); |
|
|
|
|
} |
|
|
|
@ -579,8 +579,8 @@ AutoConnectTextJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
|
* @param aux JSON description to be load. |
|
|
|
|
* @return true Successfully loaded. |
|
|
|
|
*/ |
|
|
|
|
bool AutoConnect::load(const char* aux) { |
|
|
|
|
const size_t bufferSize = AutoConnectAux::_calcJsonBufferSize(aux); |
|
|
|
|
bool AutoConnect::load(const String& aux) { |
|
|
|
|
const size_t bufferSize = AutoConnectAux::_calcJsonBufferSize(aux.c_str()); |
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
|
JsonVariant jv = jsonBuffer.parse(aux); |
|
|
|
|
return _load(jv); |
|
|
|
@ -704,8 +704,8 @@ AutoConnectElement* AutoConnectAux::_createElement(const JsonObject& json) { |
|
|
|
|
* @return true The element collection successfully loaded. |
|
|
|
|
* @return false Invalid JSON data occurred.
|
|
|
|
|
*/ |
|
|
|
|
bool AutoConnectAux::load(const char* in) { |
|
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in); |
|
|
|
|
bool AutoConnectAux::load(const String& in) { |
|
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in.c_str()); |
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
|
return _load(jb); |
|
|
|
@ -756,7 +756,8 @@ bool AutoConnectAux::_load(JsonObject& jb) { |
|
|
|
|
_uriStr = jb.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); |
|
|
|
|
_uri = _uriStr.c_str(); |
|
|
|
|
_menu = jb.get<bool>(F(AUTOCONNECT_JSON_KEY_MENU)); |
|
|
|
|
(void)_loadElement(jb, "*"); |
|
|
|
|
JsonVariant elements = jb[F(AUTOCONNECT_JSON_KEY_ELEMENT)]; |
|
|
|
|
(void)_loadElement(elements, ""); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -770,39 +771,53 @@ bool AutoConnectAux::_load(JsonObject& jb) { |
|
|
|
|
* elements are to be loaded. |
|
|
|
|
* @return A reference of loaded AutoConnectElement instance. |
|
|
|
|
*/ |
|
|
|
|
AutoConnectElement& AutoConnectAux::loadElement(const String in, const String name) { |
|
|
|
|
bool AutoConnectAux::loadElement(const String& in, const String& name) { |
|
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in.c_str()); |
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
|
JsonVariant jb = jsonBuffer.parse(in); |
|
|
|
|
return _loadElement(jb, name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AutoConnectElement& AutoConnectAux::loadElement(const __FlashStringHelper* in, const String name) { |
|
|
|
|
bool AutoConnectAux::loadElement(const __FlashStringHelper* in, const String& name) { |
|
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in); |
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
|
JsonVariant jb = jsonBuffer.parse(in); |
|
|
|
|
return _loadElement(jb, name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AutoConnectElement& AutoConnectAux::loadElement(Stream& in, const String name, const size_t bufferSize) { |
|
|
|
|
bool AutoConnectAux::loadElement(Stream& in, const String& name, const size_t bufferSize) { |
|
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
|
JsonVariant jb = jsonBuffer.parse(in); |
|
|
|
|
return _loadElement(jb, name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String name) { |
|
|
|
|
AutoConnectElement* auxElm = nullptr; |
|
|
|
|
bool wc = name == "*"; |
|
|
|
|
|
|
|
|
|
if (!jb.success()) { |
|
|
|
|
AC_DBG("json parse error\n"); |
|
|
|
|
return _nullElement(); |
|
|
|
|
bool AutoConnectAux::_loadElement(JsonVariant& jb, const String& name) { |
|
|
|
|
bool rc = jb.success(); |
|
|
|
|
if (rc) { |
|
|
|
|
if (jb.is<JsonArray>()) { |
|
|
|
|
JsonArray& elements = jb.as<JsonArray>(); |
|
|
|
|
for (JsonObject& element : elements) { |
|
|
|
|
AutoConnectElement& elm = _loadElement(element, name); |
|
|
|
|
if (!elm.name.length()) { |
|
|
|
|
rc = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
JsonObject& element = jb.as<JsonObject>(); |
|
|
|
|
AutoConnectElement& elm = _loadElement(element, name); |
|
|
|
|
if (!elm.name.length()) |
|
|
|
|
rc = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return rc; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
JsonArray& elements = jb[AUTOCONNECT_JSON_KEY_ELEMENT]; |
|
|
|
|
for (JsonObject& element : elements) { |
|
|
|
|
AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& element, const String& name) { |
|
|
|
|
AutoConnectElement* auxElm = nullptr; |
|
|
|
|
String elmName = element.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); |
|
|
|
|
if (wc || name.equalsIgnoreCase(elmName)) { |
|
|
|
|
if (!name.length() || name.equalsIgnoreCase(elmName)) { |
|
|
|
|
// The specified element is defined in the JSON stream.
|
|
|
|
|
// Loads from JSON object.
|
|
|
|
|
auxElm = getElement(elmName); |
|
|
|
@ -814,7 +829,6 @@ AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String na |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
AC_DBG("%s unknown element type\n", elmName.c_str()); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (auxElm->loadMember(element)) |
|
|
|
@ -822,8 +836,6 @@ AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String na |
|
|
|
|
else { |
|
|
|
|
// Element type mismatch
|
|
|
|
|
AC_DBG("Type of %s element mismatched\n", elmName.c_str()); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return auxElm ? *auxElm : _nullElement(); |
|
|
|
@ -864,7 +876,7 @@ size_t AutoConnectAux::save(Stream& out) { |
|
|
|
|
* @param name An element name to be output. |
|
|
|
|
* @return Number of bytes output |
|
|
|
|
*/ |
|
|
|
|
size_t AutoConnectAux::saveElement(const String name, Stream& out) { |
|
|
|
|
size_t AutoConnectAux::saveElement(const String& name, Stream& out) { |
|
|
|
|
for (std::size_t n = 0; n < _addonElm.size(); n++) { |
|
|
|
|
AutoConnectElement& elm = _addonElm[n]; |
|
|
|
|
if (elm.name == name) { |
|
|
|
@ -882,7 +894,7 @@ size_t AutoConnectAux::saveElement(const String name, Stream& out) { |
|
|
|
|
* @param type An element type as String |
|
|
|
|
* @return A type of ACElement_t |
|
|
|
|
*/ |
|
|
|
|
const ACElement_t AutoConnectAux::_asElementType(const String type) { |
|
|
|
|
const ACElement_t AutoConnectAux::_asElementType(const String& type) { |
|
|
|
|
typedef struct { |
|
|
|
|
const char* tName; |
|
|
|
|
ACElement_t tEnum; |
|
|
|
@ -900,7 +912,7 @@ const ACElement_t AutoConnectAux::_asElementType(const String type) { |
|
|
|
|
|
|
|
|
|
ACElement_t t = AC_Unknown; |
|
|
|
|
for (size_t n = 0; n < (sizeof(types) / sizeof(ACElementType_t)); n++) { |
|
|
|
|
if (type.equalsIgnoreCase(String(types[n].tName))) |
|
|
|
|
if (type.equalsIgnoreCase(String(FPSTR(types[n].tName)))) |
|
|
|
|
return types[n].tEnum; |
|
|
|
|
} |
|
|
|
|
return t; |
|
|
|
|