Merge pull request #144 from Boldie/improvement_unique_ptr_webserver

Improvement unique ptr webserver
pull/169/head
Hieromon Ikasamo 5 years ago committed by GitHub
commit 56ba89649f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 109
      src/AutoConnect.cpp
  2. 22
      src/AutoConnect.h
  3. 3
      src/AutoConnectAux.cpp
  4. 24
      src/AutoConnectAuxImpl.h
  5. 27
      src/AutoConnectElementJson.h

@ -22,15 +22,17 @@
#define SET_HOSTNAME(x) do { WiFi.setHostname(x); } while(0) #define SET_HOSTNAME(x) do { WiFi.setHostname(x); } while(0)
#endif #endif
/** /**
* AutoConnect default constructor. This entry activates WebServer * AutoConnect default constructor. This entry activates WebServer
* internally and the web server is allocated internal. * internally and the web server is allocated internal.
*/ */
AutoConnect::AutoConnect() { AutoConnect::AutoConnect()
_initialize(); : _scanCount( 0 )
_webServer.reset(nullptr); , _connectTimeout( AUTOCONNECT_TIMEOUT )
_dnsServer.reset(nullptr); , _menuTitle( _apConfig.title )
_webServerAlloc = AC_WEBSERVER_HOSTED; {
memset(&_credential, 0x00, sizeof(station_config_t));
} }
/** /**
@ -38,28 +40,10 @@ AutoConnect::AutoConnect() {
* User's added URI handler response can be included in handleClient method. * User's added URI handler response can be included in handleClient method.
* @param webServer A reference of ESP8266WebServer instance. * @param webServer A reference of ESP8266WebServer instance.
*/ */
AutoConnect::AutoConnect(WebServerClass& webServer) { AutoConnect::AutoConnect(WebServerClass& webServer)
_initialize(); : AutoConnect()
_webServer.reset(&webServer); {
_dnsServer.reset(nullptr); _webServer = WebserverUP(&webServer, [](WebServerClass*){});
_webServerAlloc = AC_WEBSERVER_PARASITIC;
}
void AutoConnect::_initialize(void) {
_rfConnect = false;
_rfReset = false;
_rfDisconnect = false;
_responsePage = nullptr;
_currentPageElement = nullptr;
_menuTitle = _apConfig.title;
_connectTimeout = AUTOCONNECT_TIMEOUT;
_scanCount = 0;
memset(&_credential, 0x00, sizeof(station_config_t));
#ifdef ARDUINO_ARCH_ESP32
_disconnectEventId = -1; // The member available for ESP32 only
#endif
_aux = nullptr;
_auxUri = String("");
} }
/** /**
@ -296,8 +280,9 @@ bool AutoConnect::config(AutoConnectConfig& Config) {
* by Config method. * by Config method.
*/ */
bool AutoConnect::_config(void) { bool AutoConnect::_config(void) {
if (static_cast<uint32_t>(_apConfig.apip) == 0U || static_cast<uint32_t>(_apConfig.gateway) == 0U || static_cast<uint32_t>(_apConfig.netmask) == 0U) if (static_cast<uint32_t>(_apConfig.apip) == 0U || static_cast<uint32_t>(_apConfig.gateway) == 0U || static_cast<uint32_t>(_apConfig.netmask) == 0U) {
AC_DBG("Warning: Contains invalid SoftAPIP address(es).\n"); AC_DBG("Warning: Contains invalid SoftAPIP address(es).\n");
}
bool rc = WiFi.softAPConfig(_apConfig.apip, _apConfig.gateway, _apConfig.netmask); bool rc = WiFi.softAPConfig(_apConfig.apip, _apConfig.gateway, _apConfig.netmask);
AC_DBG("SoftAP configure %s, %s, %s %s\n", _apConfig.apip.toString().c_str(), _apConfig.gateway.toString().c_str(), _apConfig.netmask.toString().c_str(), rc ? "" : "failed"); AC_DBG("SoftAP configure %s, %s, %s %s\n", _apConfig.apip.toString().c_str(), _apConfig.gateway.toString().c_str(), _apConfig.netmask.toString().c_str(), rc ? "" : "failed");
return rc; return rc;
@ -317,8 +302,9 @@ bool AutoConnect::_configSTA(const IPAddress& ip, const IPAddress& gateway, cons
bool rc; bool rc;
AC_DBG("WiFi.config(IP=%s, Gateway=%s, Subnetmask=%s, DNS1=%s, DNS2=%s)\n", ip.toString().c_str(), gateway.toString().c_str(), netmask.toString().c_str(), dns1.toString().c_str(), dns2.toString().c_str()); AC_DBG("WiFi.config(IP=%s, Gateway=%s, Subnetmask=%s, DNS1=%s, DNS2=%s)\n", ip.toString().c_str(), gateway.toString().c_str(), netmask.toString().c_str(), dns1.toString().c_str(), dns2.toString().c_str());
if (!(rc = WiFi.config(ip, gateway, netmask, dns1, dns2))) if (!(rc = WiFi.config(ip, gateway, netmask, dns1, dns2))) {
AC_DBG("failed\n"); AC_DBG("failed\n");
}
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
AC_DBG("DHCP client(%s)\n", wifi_station_dhcpc_status() == DHCP_STOPPED ? "STOPPED" : "STARTED"); AC_DBG("DHCP client(%s)\n", wifi_station_dhcpc_status() == DHCP_STOPPED ? "STOPPED" : "STARTED");
#endif #endif
@ -374,32 +360,12 @@ void AutoConnect::home(const String& uri) {
* Stops AutoConnect captive portal service. * Stops AutoConnect captive portal service.
*/ */
void AutoConnect::end(void) { void AutoConnect::end(void) {
if (_responsePage != nullptr) { _responsePage.reset();
_responsePage->~PageBuilder(); _currentPageElement.reset();
delete _responsePage;
_responsePage = nullptr;
}
if (_currentPageElement != nullptr) {
_currentPageElement->~PageElement();
_currentPageElement = nullptr;
}
_stopPortal(); _stopPortal();
if (_webServer) { _dnsServer.reset();
switch (_webServerAlloc) { _webServer.reset();
case AC_WEBSERVER_HOSTED:
if (_dnsServer) {
_dnsServer->stop();
_dnsServer.reset();
}
_webServer.reset();
break;
case AC_WEBSERVER_PARASITIC:
_webServer.release();
break;
}
}
} }
/** /**
@ -455,8 +421,7 @@ void AutoConnect::_startWebServer(void) {
// Boot Web server // Boot Web server
if (!_webServer) { if (!_webServer) {
// Only when hosting WebServer internally // Only when hosting WebServer internally
_webServer.reset(new WebServerClass(AUTOCONNECT_HTTPPORT)); _webServer = WebserverUP(new WebServerClass(AUTOCONNECT_HTTPPORT), std::default_delete<WebServerClass>() );
_webServerAlloc = AC_WEBSERVER_HOSTED;
AC_DBG("WebServer allocated\n"); AC_DBG("WebServer allocated\n");
} }
// Discard the original the not found handler to redirect captive portal detection. // Discard the original the not found handler to redirect captive portal detection.
@ -464,7 +429,7 @@ void AutoConnect::_startWebServer(void) {
_webServer->onNotFound(std::bind(&AutoConnect::_handleNotFound, this)); _webServer->onNotFound(std::bind(&AutoConnect::_handleNotFound, this));
// here, Prepare PageBuilders for captive portal // here, Prepare PageBuilders for captive portal
if (!_responsePage) { if (!_responsePage) {
_responsePage = new PageBuilder(); _responsePage.reset( new PageBuilder() );
_responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2)); _responsePage->exitCanHandle(std::bind(&AutoConnect::_classifyHandle, this, std::placeholders::_1, std::placeholders::_2));
_responsePage->onUpload(std::bind(&AutoConnect::_handleUpload, this, std::placeholders::_1, std::placeholders::_2)); _responsePage->onUpload(std::bind(&AutoConnect::_handleUpload, this, std::placeholders::_1, std::placeholders::_2));
_responsePage->insert(*_webServer); _responsePage->insert(*_webServer);
@ -539,17 +504,20 @@ void AutoConnect::handleRequest(void) {
// Save current credential // Save current credential
if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) { if (_apConfig.autoSave == AC_SAVECREDENTIAL_AUTO) {
AutoConnectCredential credit(_apConfig.boundaryOffset); AutoConnectCredential credit(_apConfig.boundaryOffset);
if (credit.save(&_credential)) if (credit.save(&_credential)) {
AC_DBG("%.*s credential saved\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid)); AC_DBG("%.*s credential saved\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid));
else }
else {
AC_DBG("credential %.*s save failed\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid)); AC_DBG("credential %.*s save failed\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid));
}
} }
// Ensures that keeps a connection with the current AP while the portal behaves. // Ensures that keeps a connection with the current AP while the portal behaves.
_setReconnect(AC_RECONNECT_SET); _setReconnect(AC_RECONNECT_SET);
} }
else else {
AC_DBG("%.*s has no BSSID, saving is unavailable\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid)); AC_DBG("%.*s has no BSSID, saving is unavailable\n", sizeof(_credential.ssid), reinterpret_cast<const char*>(_credential.ssid));
}
// Activate AutoConnectUpdate if it is attached and incorporate // Activate AutoConnectUpdate if it is attached and incorporate
// it into the AutoConnect menu. // it into the AutoConnect menu.
@ -686,7 +654,7 @@ bool AutoConnect::_loadAvailCredential(const char* ssid) {
* Stops DNS server and flush tcp sending. * Stops DNS server and flush tcp sending.
*/ */
void AutoConnect::_stopPortal(void) { void AutoConnect::_stopPortal(void) {
if (_dnsServer && _webServerAlloc == AC_WEBSERVER_HOSTED) if (_dnsServer)
_dnsServer->stop(); _dnsServer->stop();
if (_webServer) { if (_webServer) {
@ -940,12 +908,13 @@ bool AutoConnect::_classifyHandle(HTTPMethod method, String uri) {
_purgePages(); _purgePages();
// Create the page dynamically // Create the page dynamically
if ((_currentPageElement = _setupPage(uri)) == nullptr) _currentPageElement.reset( _setupPage(uri) );
if (_aux) { if (!_currentPageElement && _aux) {
// Requested URL is not a normal page, exploring AUX pages // Requested URL is not a normal page, exploring AUX pages
_currentPageElement = _aux->_setupPage(uri); _currentPageElement.reset(_aux->_setupPage(uri));
} }
if (_currentPageElement != nullptr) {
if (_currentPageElement) {
AC_DBG_DUMB(",generated:%s", uri.c_str()); AC_DBG_DUMB(",generated:%s", uri.c_str());
_uri = uri; _uri = uri;
_responsePage->addElement(*_currentPageElement); _responsePage->addElement(*_currentPageElement);
@ -975,9 +944,8 @@ void AutoConnect::_handleUpload(const String& requestUri, const HTTPUpload& uplo
*/ */
void AutoConnect::_purgePages(void) { void AutoConnect::_purgePages(void) {
_responsePage->clearElement(); _responsePage->clearElement();
if (_currentPageElement != nullptr) { if (_currentPageElement) {
delete _currentPageElement; _currentPageElement.reset();
_currentPageElement = nullptr;
_uri = String(""); _uri = String("");
} }
} }
@ -1064,8 +1032,7 @@ void AutoConnect::_setReconnect(const AC_STARECONNECT_t order) {
if (order == AC_RECONNECT_SET) { if (order == AC_RECONNECT_SET) {
_disconnectEventId = WiFi.onEvent([](WiFiEvent_t e, WiFiEventInfo_t info) { _disconnectEventId = WiFi.onEvent([](WiFiEvent_t e, WiFiEventInfo_t info) {
AC_DBG("STA lost connection:%d\n", info.disconnected.reason); AC_DBG("STA lost connection:%d\n", info.disconnected.reason);
bool rst = WiFi.reconnect(); AC_DBG("STA connection %s\n", WiFi.reconnect() ? "restored" : "failed");
AC_DBG("STA connection %s\n", rst ? "restored" : "failed");
}, WiFiEvent_t::SYSTEM_EVENT_AP_STADISCONNECTED); }, WiFiEvent_t::SYSTEM_EVENT_AP_STADISCONNECTED);
AC_DBG("Event<%d> handler registered\n", static_cast<int>(WiFiEvent_t::SYSTEM_EVENT_AP_STADISCONNECTED)); AC_DBG("Event<%d> handler registered\n", static_cast<int>(WiFiEvent_t::SYSTEM_EVENT_AP_STADISCONNECTED));
} }

@ -218,16 +218,10 @@ class AutoConnect {
void onNotFound(WebServerClass::THandlerFunction fn); void onNotFound(WebServerClass::THandlerFunction fn);
protected: protected:
enum _webServerAllocateType {
AC_WEBSERVER_PARASITIC,
AC_WEBSERVER_HOSTED
};
typedef enum _webServerAllocateType AC_WEBSERVER_TYPE;
typedef enum { typedef enum {
AC_RECONNECT_SET, AC_RECONNECT_SET,
AC_RECONNECT_RESET AC_RECONNECT_RESET
} AC_STARECONNECT_t; } AC_STARECONNECT_t;
void _initialize(void);
bool _config(void); bool _config(void);
bool _configSTA(const IPAddress& ip, const IPAddress& gateway, const IPAddress& netmask, const IPAddress& dns1, const IPAddress& dns2); bool _configSTA(const IPAddress& ip, const IPAddress& gateway, const IPAddress& netmask, const IPAddress& dns1, const IPAddress& dns2);
bool _getConfigSTA(station_config_t* config); bool _getConfigSTA(station_config_t* config);
@ -271,17 +265,17 @@ class AutoConnect {
size_t _freeHeapSize; size_t _freeHeapSize;
/** Servers which works in concert. */ /** Servers which works in concert. */
std::unique_ptr<WebServerClass> _webServer; typedef std::unique_ptr<WebServerClass, std::function<void(WebServerClass *)> > WebserverUP;
WebserverUP _webServer = WebserverUP(nullptr, std::default_delete<WebServerClass>());
std::unique_ptr<DNSServer> _dnsServer; std::unique_ptr<DNSServer> _dnsServer;
AC_WEBSERVER_TYPE _webServerAlloc;
/** /**
* Dynamically hold one page of AutoConnect menu. * Dynamically hold one page of AutoConnect menu.
* Every time a GET/POST HTTP request occurs, an AutoConnect * Every time a GET/POST HTTP request occurs, an AutoConnect
* menu page corresponding to the URI is generated. * menu page corresponding to the URI is generated.
*/ */
PageBuilder* _responsePage; std::unique_ptr<PageBuilder> _responsePage;
PageElement* _currentPageElement; std::unique_ptr<PageElement> _currentPageElement;
/** Extended pages made up with AutoConnectAux */ /** Extended pages made up with AutoConnectAux */
AutoConnectAux* _aux = nullptr; /**< A top of registered AutoConnectAux */ AutoConnectAux* _aux = nullptr; /**< A top of registered AutoConnectAux */
@ -300,12 +294,12 @@ class AutoConnect {
unsigned long _portalAccessPeriod; unsigned long _portalAccessPeriod;
/** The control indicators */ /** The control indicators */
bool _rfConnect; /**< URI /connect requested */ bool _rfConnect = false; /**< URI /connect requested */
bool _rfDisconnect; /**< URI /disc requested */ bool _rfDisconnect = false; /**< URI /disc requested */
bool _rfReset; /**< URI /reset requested */ bool _rfReset = false; /**< URI /reset requested */
wl_status_t _rsConnect; /**< connection result */ wl_status_t _rsConnect; /**< connection result */
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
WiFiEventId_t _disconnectEventId; /**< STA disconnection event handler registered id */ WiFiEventId_t _disconnectEventId = -1; /**< STA disconnection event handler registered id */
#endif #endif
std::unique_ptr<AutoConnectTicker> _ticker; /**< */ std::unique_ptr<AutoConnectTicker> _ticker; /**< */

@ -303,8 +303,9 @@ void AutoConnectAux::upload(const String& requestUri, const HTTPUpload& upload)
_upload = _uploadHandler; _upload = _uploadHandler;
AC_DBG_DUMB("enabled\n"); AC_DBG_DUMB("enabled\n");
} }
else else {
AC_DBG_DUMB("missing\n"); AC_DBG_DUMB("missing\n");
}
} }
} }

@ -272,8 +272,9 @@ AutoConnectButtonJson& AutoConnectAux::getElement(const String& 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.c_str(), 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());
} }
@ -289,8 +290,9 @@ AutoConnectCheckboxJson& AutoConnectAux::getElement(const String& 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.c_str(), 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());
} }
@ -306,8 +308,9 @@ AutoConnectFileJson& AutoConnectAux::getElement(const String& name) {
if (elm) { if (elm) {
if (elm->typeOf() == AC_File) if (elm->typeOf() == AC_File)
return *(reinterpret_cast<AutoConnectFileJson*>(elm)); return *(reinterpret_cast<AutoConnectFileJson*>(elm));
else else {
AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf()); AC_DBG("Element<%s> type mismatch<%d>\n", name.c_str(), elm->typeOf());
}
} }
return reinterpret_cast<AutoConnectFileJson&>(_nullElement()); return reinterpret_cast<AutoConnectFileJson&>(_nullElement());
} }
@ -323,8 +326,9 @@ AutoConnectInputJson& AutoConnectAux::getElement(const String& 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.c_str(), 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());
} }
@ -340,8 +344,9 @@ AutoConnectRadioJson& AutoConnectAux::getElement(const String& 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.c_str(), 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());
} }
@ -357,8 +362,9 @@ AutoConnectSelectJson& AutoConnectAux::getElement(const String& 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.c_str(), 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());
} }
@ -374,8 +380,9 @@ AutoConnectSubmitJson& AutoConnectAux::getElement(const String& 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.c_str(), 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());
} }
@ -391,8 +398,9 @@ AutoConnectTextJson& AutoConnectAux::getElement(const String& 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.c_str(), 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());
} }

@ -309,64 +309,73 @@ class AutoConnectTextJson : public AutoConnectElementJson, public AutoConnectTex
*/ */
template<> template<>
inline AutoConnectButtonJson& AutoConnectElementJson::as<AutoConnectButtonJson>(void) { inline AutoConnectButtonJson& AutoConnectElementJson::as<AutoConnectButtonJson>(void) {
if (typeOf() != AC_Button) if (typeOf() != AC_Button) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectButtonJson*>(this)); return *(reinterpret_cast<AutoConnectButtonJson*>(this));
} }
template<> template<>
inline AutoConnectCheckboxJson& AutoConnectElementJson::as<AutoConnectCheckboxJson>(void) { inline AutoConnectCheckboxJson& AutoConnectElementJson::as<AutoConnectCheckboxJson>(void) {
if (typeOf() != AC_Checkbox) if (typeOf() != AC_Checkbox) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectCheckboxJson*>(this)); return *(reinterpret_cast<AutoConnectCheckboxJson*>(this));
} }
template<> template<>
inline AutoConnectFileJson& AutoConnectElementJson::as<AutoConnectFileJson>(void) { inline AutoConnectFileJson& AutoConnectElementJson::as<AutoConnectFileJson>(void) {
if (typeOf() != AC_File) if (typeOf() != AC_File) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectFileJson*>(this)); return *(reinterpret_cast<AutoConnectFileJson*>(this));
} }
template<> template<>
inline AutoConnectInputJson& AutoConnectElementJson::as<AutoConnectInputJson>(void) { inline AutoConnectInputJson& AutoConnectElementJson::as<AutoConnectInputJson>(void) {
if (typeOf() != AC_Input) if (typeOf() != AC_Input) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectInputJson*>(this)); return *(reinterpret_cast<AutoConnectInputJson*>(this));
} }
template<> template<>
inline AutoConnectRadioJson& AutoConnectElementJson::as<AutoConnectRadioJson>(void) { inline AutoConnectRadioJson& AutoConnectElementJson::as<AutoConnectRadioJson>(void) {
if (typeOf() != AC_Radio) if (typeOf() != AC_Radio) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectRadioJson*>(this)); return *(reinterpret_cast<AutoConnectRadioJson*>(this));
} }
template<> template<>
inline AutoConnectSelectJson& AutoConnectElementJson::as<AutoConnectSelectJson>(void) { inline AutoConnectSelectJson& AutoConnectElementJson::as<AutoConnectSelectJson>(void) {
if (typeOf() != AC_Select) if (typeOf() != AC_Select) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectSelectJson*>(this)); return *(reinterpret_cast<AutoConnectSelectJson*>(this));
} }
template<> template<>
inline AutoConnectStyleJson& AutoConnectElementJson::as<AutoConnectStyleJson>(void) { inline AutoConnectStyleJson& AutoConnectElementJson::as<AutoConnectStyleJson>(void) {
if (typeOf() != AC_Style) if (typeOf() != AC_Style) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectStyleJson*>(this)); return *(reinterpret_cast<AutoConnectStyleJson*>(this));
} }
template<> template<>
inline AutoConnectSubmitJson& AutoConnectElementJson::as<AutoConnectSubmitJson>(void) { inline AutoConnectSubmitJson& AutoConnectElementJson::as<AutoConnectSubmitJson>(void) {
if (typeOf() != AC_Submit) if (typeOf() != AC_Submit) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectSubmitJson*>(this)); return *(reinterpret_cast<AutoConnectSubmitJson*>(this));
} }
template<> template<>
inline AutoConnectTextJson& AutoConnectElementJson::as<AutoConnectTextJson>(void) { inline AutoConnectTextJson& AutoConnectElementJson::as<AutoConnectTextJson>(void) {
if (typeOf() != AC_Text) if (typeOf() != AC_Text) {
AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf()); AC_DBG("%s mismatched type as <%d>\n", name.c_str(), (int)typeOf());
}
return *(reinterpret_cast<AutoConnectTextJson*>(this)); return *(reinterpret_cast<AutoConnectTextJson*>(this));
} }

Loading…
Cancel
Save