|
|
@ -93,7 +93,7 @@ void AutoConnectAux::add(AutoConnectElementVT addons) { |
|
|
|
* @param name Element name |
|
|
|
* @param name Element name |
|
|
|
* @return A pointer to the registered AutoConnectElement. |
|
|
|
* @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++) |
|
|
|
for (std::size_t n = 0; n < _addonElm.size(); n++) |
|
|
|
if (name.equalsIgnoreCase(_addonElm[n].get().name)) |
|
|
|
if (name.equalsIgnoreCase(_addonElm[n].get().name)) |
|
|
|
return &(_addonElm[n].get()); |
|
|
|
return &(_addonElm[n].get()); |
|
|
@ -109,7 +109,7 @@ AutoConnectElement* AutoConnectAux::getElement(const String name) { |
|
|
|
* @return true The specified AutoConnectElements have been released. |
|
|
|
* @return true The specified AutoConnectElements have been released. |
|
|
|
* @return false The specified AutoConnectElement not found in AutoConnectAux. |
|
|
|
* @return false The specified AutoConnectElement not found in AutoConnectAux. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool AutoConnectAux::release(const String name) { |
|
|
|
bool AutoConnectAux::release(const String& name) { |
|
|
|
bool rc = false; |
|
|
|
bool rc = false; |
|
|
|
for (std::size_t n = 0; n < _addonElm.size(); n++) { |
|
|
|
for (std::size_t n = 0; n < _addonElm.size(); n++) { |
|
|
|
String elmName = _addonElm[n].get().name; |
|
|
|
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, |
|
|
|
* @return false An element specified name is not registered, |
|
|
|
* or its element value does not match storage type. |
|
|
|
* 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); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() != AC_Select && elm->typeOf() != AC_Radio) { |
|
|
|
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, |
|
|
|
* @return false An element specified name is not registered, |
|
|
|
* or its element value must be array. |
|
|
|
* 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; |
|
|
|
bool rc = false; |
|
|
|
|
|
|
|
|
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
@ -271,17 +271,17 @@ PageElement* AutoConnectAux::_setupPage(String uri) { |
|
|
|
elm = new PageElement(); |
|
|
|
elm = new PageElement(); |
|
|
|
// Construct the auxiliary page
|
|
|
|
// Construct the auxiliary page
|
|
|
|
elm->setMold(_PAGE_AUX); |
|
|
|
elm->setMold(_PAGE_AUX); |
|
|
|
elm->addToken(PSTR("HEAD"), std::bind(&AutoConnect::_token_HEAD, mother, std::placeholders::_1)); |
|
|
|
elm->addToken(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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(String(FPSTR("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("AUX_ELEMENT")), std::bind(&AutoConnectAux::_insertElement, this, std::placeholders::_1)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return elm; |
|
|
|
return elm; |
|
|
@ -323,13 +323,13 @@ AutoConnectElement& AutoConnectAux::_nullElement() { |
|
|
|
* @return A reference of AutoConnectButton class. |
|
|
|
* @return A reference of AutoConnectButton class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectButtonBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectButtonBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Button) |
|
|
|
if (elm->typeOf() == AC_Button) |
|
|
|
return *(reinterpret_cast<AutoConnectButtonBasis*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectButtonBasis*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectButtonBasis&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -340,13 +340,13 @@ AutoConnectButtonBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectCheckbox class. |
|
|
|
* @return A reference of AutoConnectCheckbox class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectCheckboxBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectCheckboxBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Checkbox) |
|
|
|
if (elm->typeOf() == AC_Checkbox) |
|
|
|
return *(reinterpret_cast<AutoConnectCheckboxBasis*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectCheckboxBasis*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectCheckboxBasis&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -357,13 +357,13 @@ AutoConnectCheckboxBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectInput class. |
|
|
|
* @return A reference of AutoConnectInput class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectInputBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectInputBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Input) |
|
|
|
if (elm->typeOf() == AC_Input) |
|
|
|
return *(reinterpret_cast<AutoConnectInputBasis*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectInputBasis*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectInputBasis&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -374,13 +374,13 @@ AutoConnectInputBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectRadio class. |
|
|
|
* @return A reference of AutoConnectRadio class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectRadioBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectRadioBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Radio) |
|
|
|
if (elm->typeOf() == AC_Radio) |
|
|
|
return *(reinterpret_cast<AutoConnectRadioBasis*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectRadioBasis*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectRadioBasis&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -391,13 +391,13 @@ AutoConnectRadioBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectSelect class. |
|
|
|
* @return A reference of AutoConnectSelect class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectSelectBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectSelectBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Select) |
|
|
|
if (elm->typeOf() == AC_Select) |
|
|
|
return *(reinterpret_cast<AutoConnectSelectBasis*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectSelectBasis*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectSelectBasis&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -408,13 +408,13 @@ AutoConnectSelectBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectSubmit class. |
|
|
|
* @return A reference of AutoConnectSubmit class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectSubmitBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectSubmitBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Submit) |
|
|
|
if (elm->typeOf() == AC_Submit) |
|
|
|
return *(reinterpret_cast<AutoConnectSubmitBasis*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectSubmitBasis*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectSubmitBasis&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -425,13 +425,13 @@ AutoConnectSubmitBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectText class. |
|
|
|
* @return A reference of AutoConnectText class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectTextBasis& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectTextBasis& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Text) |
|
|
|
if (elm->typeOf() == AC_Text) |
|
|
|
return *(reinterpret_cast<AutoConnectTextBasis*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectTextBasis*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectTextBasis&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -459,13 +459,13 @@ bool AutoConnectAux::_jbLiteral; /**< JSON object lexical status */ |
|
|
|
* @return A reference of AutoConnectButton class. |
|
|
|
* @return A reference of AutoConnectButton class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectButtonJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectButtonJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Button) |
|
|
|
if (elm->typeOf() == AC_Button) |
|
|
|
return *(reinterpret_cast<AutoConnectButtonJson*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectButtonJson*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectButtonJson&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -476,13 +476,13 @@ AutoConnectButtonJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectCheckbox class. |
|
|
|
* @return A reference of AutoConnectCheckbox class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectCheckboxJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectCheckboxJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Checkbox) |
|
|
|
if (elm->typeOf() == AC_Checkbox) |
|
|
|
return *(reinterpret_cast<AutoConnectCheckboxJson*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectCheckboxJson*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectCheckboxJson&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -493,13 +493,13 @@ AutoConnectCheckboxJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectInput class. |
|
|
|
* @return A reference of AutoConnectInput class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectInputJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectInputJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Input) |
|
|
|
if (elm->typeOf() == AC_Input) |
|
|
|
return *(reinterpret_cast<AutoConnectInputJson*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectInputJson*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectInputJson&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -510,13 +510,13 @@ AutoConnectInputJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectRadio class. |
|
|
|
* @return A reference of AutoConnectRadio class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectRadioJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectRadioJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Radio) |
|
|
|
if (elm->typeOf() == AC_Radio) |
|
|
|
return *(reinterpret_cast<AutoConnectRadioJson*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectRadioJson*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectRadioJson&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -527,13 +527,13 @@ AutoConnectRadioJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectSelect class. |
|
|
|
* @return A reference of AutoConnectSelect class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectSelectJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectSelectJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Select) |
|
|
|
if (elm->typeOf() == AC_Select) |
|
|
|
return *(reinterpret_cast<AutoConnectSelectJson*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectSelectJson*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectSelectJson&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -544,13 +544,13 @@ AutoConnectSelectJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectSubmit class. |
|
|
|
* @return A reference of AutoConnectSubmit class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectSubmitJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectSubmitJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Submit) |
|
|
|
if (elm->typeOf() == AC_Submit) |
|
|
|
return *(reinterpret_cast<AutoConnectSubmitJson*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectSubmitJson*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectSubmitJson&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -561,13 +561,13 @@ AutoConnectSubmitJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @return A reference of AutoConnectText class. |
|
|
|
* @return A reference of AutoConnectText class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
template<> |
|
|
|
template<> |
|
|
|
AutoConnectTextJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
AutoConnectTextJson& AutoConnectAux::getElement(const String& name) { |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
AutoConnectElement* elm = getElement(name); |
|
|
|
if (elm) { |
|
|
|
if (elm) { |
|
|
|
if (elm->typeOf() == AC_Text) |
|
|
|
if (elm->typeOf() == AC_Text) |
|
|
|
return *(reinterpret_cast<AutoConnectTextJson*>(elm)); |
|
|
|
return *(reinterpret_cast<AutoConnectTextJson*>(elm)); |
|
|
|
else |
|
|
|
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()); |
|
|
|
return reinterpret_cast<AutoConnectTextJson&>(_nullElement()); |
|
|
|
} |
|
|
|
} |
|
|
@ -579,20 +579,20 @@ AutoConnectTextJson& AutoConnectAux::getElement(const char* name) { |
|
|
|
* @param aux JSON description to be load. |
|
|
|
* @param aux JSON description to be load. |
|
|
|
* @return true Successfully loaded. |
|
|
|
* @return true Successfully loaded. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool AutoConnect::load(const char* aux) { |
|
|
|
bool AutoConnect::load(const String& aux) { |
|
|
|
const size_t bufferSize = AutoConnectAux::_calcJsonBufferSize(aux); |
|
|
|
const size_t bufferSize = AutoConnectAux::_calcJsonBufferSize(aux.c_str()); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonVariant jv = jsonBuffer.parse(aux); |
|
|
|
JsonVariant jv = jsonBuffer.parse(aux); |
|
|
|
return _load(jv); |
|
|
|
return _load(jv); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Load AutoConnectAux page from JSON description stored in PROGMEM. |
|
|
|
* Load AutoConnectAux page from JSON description stored in PROGMEM. |
|
|
|
* This function can load AutoConnectAux for multiple AUX pages written |
|
|
|
* This function can load AutoConnectAux for multiple AUX pages written |
|
|
|
* in JSON and is registered in AutoConnect. |
|
|
|
* in JSON and is registered in AutoConnect. |
|
|
|
* @param aux JSON description to be load. |
|
|
|
* @param aux JSON description to be load. |
|
|
|
* @return true Successfully loaded. |
|
|
|
* @return true Successfully loaded. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
bool AutoConnect::load(const __FlashStringHelper* aux) { |
|
|
|
bool AutoConnect::load(const __FlashStringHelper* aux) { |
|
|
|
const size_t bufferSize = AutoConnectAux::_calcJsonBufferSize(aux); |
|
|
|
const size_t bufferSize = AutoConnectAux::_calcJsonBufferSize(aux); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
@ -704,8 +704,8 @@ AutoConnectElement* AutoConnectAux::_createElement(const JsonObject& json) { |
|
|
|
* @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) { |
|
|
|
bool AutoConnectAux::load(const String& in) { |
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in); |
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in.c_str()); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
return _load(jb); |
|
|
|
return _load(jb); |
|
|
@ -756,7 +756,8 @@ bool AutoConnectAux::_load(JsonObject& jb) { |
|
|
|
_uriStr = jb.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); |
|
|
|
_uriStr = jb.get<String>(F(AUTOCONNECT_JSON_KEY_URI)); |
|
|
|
_uri = _uriStr.c_str(); |
|
|
|
_uri = _uriStr.c_str(); |
|
|
|
_menu = jb.get<bool>(F(AUTOCONNECT_JSON_KEY_MENU)); |
|
|
|
_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; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -770,39 +771,53 @@ bool AutoConnectAux::_load(JsonObject& jb) { |
|
|
|
* elements are to be loaded. |
|
|
|
* elements are to be loaded. |
|
|
|
* @return A reference of loaded AutoConnectElement instance. |
|
|
|
* @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()); |
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in.c_str()); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
JsonVariant jb = jsonBuffer.parse(in); |
|
|
|
return _loadElement(jb, name); |
|
|
|
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); |
|
|
|
const size_t bufferSize = _calcJsonBufferSize(in); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
JsonVariant jb = jsonBuffer.parse(in); |
|
|
|
return _loadElement(jb, name); |
|
|
|
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); |
|
|
|
DynamicJsonBuffer jsonBuffer(bufferSize); |
|
|
|
JsonObject& jb = jsonBuffer.parseObject(in); |
|
|
|
JsonVariant jb = jsonBuffer.parse(in); |
|
|
|
return _loadElement(jb, name); |
|
|
|
return _loadElement(jb, name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String name) { |
|
|
|
bool AutoConnectAux::_loadElement(JsonVariant& jb, const String& name) { |
|
|
|
AutoConnectElement* auxElm = nullptr; |
|
|
|
bool rc = jb.success(); |
|
|
|
bool wc = name == "*"; |
|
|
|
if (rc) { |
|
|
|
|
|
|
|
if (jb.is<JsonArray>()) { |
|
|
|
if (!jb.success()) { |
|
|
|
JsonArray& elements = jb.as<JsonArray>(); |
|
|
|
AC_DBG("json parse error\n"); |
|
|
|
for (JsonObject& element : elements) { |
|
|
|
return _nullElement(); |
|
|
|
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]; |
|
|
|
AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& element, const String& name) { |
|
|
|
for (JsonObject& element : elements) { |
|
|
|
AutoConnectElement* auxElm = nullptr; |
|
|
|
String elmName = element.get<String>(F(AUTOCONNECT_JSON_KEY_NAME)); |
|
|
|
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.
|
|
|
|
// The specified element is defined in the JSON stream.
|
|
|
|
// Loads from JSON object.
|
|
|
|
// Loads from JSON object.
|
|
|
|
auxElm = getElement(elmName); |
|
|
|
auxElm = getElement(elmName); |
|
|
@ -814,7 +829,6 @@ AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String na |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
AC_DBG("%s unknown element type\n", elmName.c_str()); |
|
|
|
AC_DBG("%s unknown element type\n", elmName.c_str()); |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (auxElm->loadMember(element)) |
|
|
|
if (auxElm->loadMember(element)) |
|
|
@ -822,8 +836,6 @@ AutoConnectElement& AutoConnectAux::_loadElement(JsonObject& jb, const String na |
|
|
|
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()); |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return auxElm ? *auxElm : _nullElement(); |
|
|
|
return auxElm ? *auxElm : _nullElement(); |
|
|
@ -864,7 +876,7 @@ size_t AutoConnectAux::save(Stream& out) { |
|
|
|
* @param name An element name to be output. |
|
|
|
* @param name An element name to be output. |
|
|
|
* @return Number of bytes 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++) { |
|
|
|
for (std::size_t n = 0; n < _addonElm.size(); n++) { |
|
|
|
AutoConnectElement& elm = _addonElm[n]; |
|
|
|
AutoConnectElement& elm = _addonElm[n]; |
|
|
|
if (elm.name == name) { |
|
|
|
if (elm.name == name) { |
|
|
@ -882,7 +894,7 @@ size_t AutoConnectAux::saveElement(const String name, Stream& out) { |
|
|
|
* @param type An element type as String |
|
|
|
* @param type An element type as String |
|
|
|
* @return A type of ACElement_t |
|
|
|
* @return A type of ACElement_t |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const ACElement_t AutoConnectAux::_asElementType(const String type) { |
|
|
|
const ACElement_t AutoConnectAux::_asElementType(const String& type) { |
|
|
|
typedef struct { |
|
|
|
typedef struct { |
|
|
|
const char* tName; |
|
|
|
const char* tName; |
|
|
|
ACElement_t tEnum; |
|
|
|
ACElement_t tEnum; |
|
|
@ -900,17 +912,17 @@ const ACElement_t AutoConnectAux::_asElementType(const String type) { |
|
|
|
|
|
|
|
|
|
|
|
ACElement_t t = AC_Unknown; |
|
|
|
ACElement_t t = AC_Unknown; |
|
|
|
for (size_t n = 0; n < (sizeof(types) / sizeof(ACElementType_t)); n++) { |
|
|
|
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 types[n].tEnum; |
|
|
|
} |
|
|
|
} |
|
|
|
return t; |
|
|
|
return t; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Calculate JSON dynamic buffer size. |
|
|
|
* Calculate JSON dynamic buffer size. |
|
|
|
* @param in JSON string |
|
|
|
* @param in JSON string |
|
|
|
* @return Estimated buffer size. |
|
|
|
* @return Estimated buffer size. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
size_t AutoConnectAux::_calcJsonBufferSize(const char* in) { |
|
|
|
size_t AutoConnectAux::_calcJsonBufferSize(const char* in) { |
|
|
|
_initJsonBufferSize(); |
|
|
|
_initJsonBufferSize(); |
|
|
|
while (*in) |
|
|
|
while (*in) |
|
|
@ -919,10 +931,10 @@ size_t AutoConnectAux::_calcJsonBufferSize(const char* in) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Calculate JSON dynamic buffer size. |
|
|
|
* Calculate JSON dynamic buffer size. |
|
|
|
* @param in JSON string stored in pgm_data. |
|
|
|
* @param in JSON string stored in pgm_data. |
|
|
|
* @return Estimated buffer size. |
|
|
|
* @return Estimated buffer size. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
size_t AutoConnectAux::_calcJsonBufferSize(const __FlashStringHelper* in) { |
|
|
|
size_t AutoConnectAux::_calcJsonBufferSize(const __FlashStringHelper* in) { |
|
|
|
_initJsonBufferSize(); |
|
|
|
_initJsonBufferSize(); |
|
|
|
uint8_t c = pgm_read_byte_near(reinterpret_cast<const char*>(in)); |
|
|
|
uint8_t c = pgm_read_byte_near(reinterpret_cast<const char*>(in)); |
|
|
@ -935,8 +947,8 @@ size_t AutoConnectAux::_calcJsonBufferSize(const __FlashStringHelper* in) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Initialize the stacks for JSON Dynamic buffer size calculation. |
|
|
|
* Initialize the stacks for JSON Dynamic buffer size calculation. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void AutoConnectAux::_initJsonBufferSize() { |
|
|
|
void AutoConnectAux::_initJsonBufferSize() { |
|
|
|
_jbSize = 0; |
|
|
|
_jbSize = 0; |
|
|
|
_jbByte = 0; |
|
|
|
_jbByte = 0; |
|
|
@ -950,8 +962,8 @@ void AutoConnectAux::_initJsonBufferSize() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Accumulate JSON Dynamic buffer size. |
|
|
|
* Accumulate JSON Dynamic buffer size. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void AutoConnectAux::_accJsonBufferSize(const char c) { |
|
|
|
void AutoConnectAux::_accJsonBufferSize(const char c) { |
|
|
|
if (_jbSize < 0) |
|
|
|
if (_jbSize < 0) |
|
|
|
return; |
|
|
|
return; |
|
|
@ -1029,9 +1041,9 @@ void AutoConnectAux::_accJsonBufferSize(const char c) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Retrieve accumulated result value of JSON dynamic buffer size. |
|
|
|
* Retrieve accumulated result value of JSON dynamic buffer size. |
|
|
|
* @return the JSON Dynamic Buffer Size |
|
|
|
* @return the JSON Dynamic Buffer Size |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
size_t AutoConnectAux::_resultJsonBufferSize() { |
|
|
|
size_t AutoConnectAux::_resultJsonBufferSize() { |
|
|
|
if (_jbSize < 0) { |
|
|
|
if (_jbSize < 0) { |
|
|
|
AC_DBG("json buffer calculation error\n"); |
|
|
|
AC_DBG("json buffer calculation error\n"); |
|
|
|