Improved execution efficiency

pull/41/head
Hieromon Ikasamo 6 years ago
parent e1815b82b6
commit b13b7db3d3
  1. 16
      src/AutoConnect.cpp
  2. 4
      src/AutoConnect.h
  3. 16
      src/AutoConnectAux.cpp
  4. 12
      src/AutoConnectElementBasisImpl.h

@ -350,11 +350,9 @@ void AutoConnect::join(AutoConnectAux& aux) {
* @param aux A vector of reference to AutoConnectAux that made up * @param aux A vector of reference to AutoConnectAux that made up
* the auxiliary page to be added. * the auxiliary page to be added.
*/ */
void AutoConnect::join(std::vector<std::reference_wrapper<AutoConnectAux>> aux) { void AutoConnect::join(AutoConnectAuxVT auxVector) {
for (std::size_t n = 0; n < aux.size(); n++) { for (std::reference_wrapper<AutoConnectAux> aux : auxVector)
AutoConnectAux& addon = aux[n].get(); join(aux.get());
join(addon);
}
} }
/** /**
@ -650,7 +648,7 @@ String AutoConnect::_induceReset(PageArgument& args) {
*/ */
String AutoConnect::_induceDisconnect(PageArgument& args) { String AutoConnect::_induceDisconnect(PageArgument& args) {
_rfDisconnect = true; _rfDisconnect = true;
return ""; return String("");
} }
/** /**
@ -691,7 +689,7 @@ String AutoConnect::_induceConnect(PageArgument& args) {
_webServer->client().stop(); _webServer->client().stop();
_responsePage->cancel(); _responsePage->cancel();
return ""; return String("");
} }
/** /**
@ -705,7 +703,7 @@ String AutoConnect::_invokeResult(PageArgument& args) {
_webServer->client().flush(); _webServer->client().flush();
_webServer->client().stop(); _webServer->client().stop();
_responsePage->cancel(); _responsePage->cancel();
return ""; return String("");
} }
/** /**
@ -794,7 +792,7 @@ bool AutoConnect::_isIP(String ipStr) {
* @retval MAC address string in XX:XX:XX:XX:XX:XX format. * @retval MAC address string in XX:XX:XX:XX:XX:XX format.
*/ */
String AutoConnect::_toMACAddressString(const uint8_t mac[]) { String AutoConnect::_toMACAddressString(const uint8_t mac[]) {
String macAddr = ""; String macAddr = String("");
for (uint8_t i = 0; i < 6; i++) { for (uint8_t i = 0; i < 6; i++) {
char buf[3]; char buf[3];
sprintf(buf, "%02X", mac[i]); sprintf(buf, "%02X", mac[i]);

@ -161,6 +161,8 @@ class AutoConnectConfig {
IPAddress dns2; /**< Secondary DNS server */ IPAddress dns2; /**< Secondary DNS server */
}; };
typedef std::vector<std::reference_wrapper<AutoConnectAux>> AutoConnectAuxVT;
class AutoConnect { class AutoConnect {
public: public:
AutoConnect(); AutoConnect();
@ -177,7 +179,7 @@ class AutoConnect {
void handleRequest(); void handleRequest();
WebServerClass& host(); WebServerClass& host();
void join(AutoConnectAux& aux); void join(AutoConnectAux& aux);
void join(std::vector<std::reference_wrapper<AutoConnectAux>> aux); void join(AutoConnectAuxVT auxVector);
bool on(const String& uri, const AuxHandlerFunctionT handler, AutoConnectExitOrder_t order = AC_EXIT_AHEAD); bool on(const String& uri, const AuxHandlerFunctionT handler, AutoConnectExitOrder_t order = AC_EXIT_AHEAD);
/** For AutoConnectAux described in JSON */ /** For AutoConnectAux described in JSON */

@ -6,6 +6,7 @@
* @date 2018-11-17 * @date 2018-11-17
* @copyright MIT license. * @copyright MIT license.
*/ */
#include <algorithm>
#include "AutoConnect.h" #include "AutoConnect.h"
#include "AutoConnectAux.h" #include "AutoConnectAux.h"
#include "AutoConnectElement.h" #include "AutoConnectElement.h"
@ -125,16 +126,11 @@ AutoConnectElement* AutoConnectAux::getElement(const String& name) {
* @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; auto itr = std::remove_if(_addonElm.begin(), _addonElm.end(),
for (std::size_t n = 0; n < _addonElm.size(); n++) { [&](std::reference_wrapper<AutoConnectElement> const elm) {
String elmName = _addonElm[n].get().name; return elm.get().name.equalsIgnoreCase(name);
if (name.equalsIgnoreCase(elmName)) { });
AC_DBG("%s release from %s\n", elmName.c_str(), uri()); return _addonElm.erase(itr, _addonElm.end()) != _addonElm.end();
_addonElm.erase(_addonElm.begin() + n);
rc = true;
}
}
return rc;
} }
/** /**

@ -102,8 +102,9 @@ const String AutoConnectRadioBasis::toHTML(void) const {
if (order == AC_Vertical) if (order == AC_Vertical)
html += String("<br>"); html += String("<br>");
} }
for (std::size_t n = 0; n < _values.size(); n++) { uint8_t n = 0;
String value = at(n); for (const String value : _values) {
n++;
String id = name + "_" + String(n); String id = name + "_" + String(n);
html += String(FPSTR("<input type=\"radio\" name=\"")) + name + String(FPSTR("\" id=\"")) + id + String(FPSTR("\" value=\"")) + value + String("\""); html += String(FPSTR("<input type=\"radio\" name=\"")) + name + String(FPSTR("\" id=\"")) + id + String(FPSTR("\" value=\"")) + value + String("\"");
if (n == checked - 1) if (n == checked - 1)
@ -142,11 +143,8 @@ const String AutoConnectSelectBasis::toHTML(void) const {
if (label.length()) if (label.length())
html = String(FPSTR("<label for=\"")) + name + String("\">") + label + String(FPSTR("</label>")); html = String(FPSTR("<label for=\"")) + name + String("\">") + label + String(FPSTR("</label>"));
html += String(FPSTR("<select name=\"")) + name + String("\" id=\"") + name + String("\">"); html += String(FPSTR("<select name=\"")) + name + String("\" id=\"") + name + String("\">");
std::size_t n = _options.size(); for (const String option : _options)
if (n) { html += String(FPSTR("<option value=\"")) + option + "\">" + option + String(FPSTR("</option>"));
for (std::size_t n = 0; n < _options.size(); n++)
html += String(FPSTR("<option value=\"")) + _options[n] + "\">" + _options[n] + String(FPSTR("</option>"));
}
html += String(FPSTR("</select>")); html += String(FPSTR("</select>"));
return html; return html;
} }

Loading…
Cancel
Save