Remove _initialize method and replace it by delegating constructor.

* This is more straight forward with C++11 and the way todo.
* Also move some initializations to the header file.
* Remove assignment of empty String("") since this is an assignment with
  a default constructed object which is already default constructed.
* Remove reset of unique_ptr: They are per default initialized as empty nullptr.
pull/144/head
Sven Steckmann 5 years ago
parent 908d6771c2
commit 6d37959fb3
  1. 33
      src/AutoConnect.cpp
  2. 13
      src/AutoConnect.h

@ -27,10 +27,12 @@
* AutoConnect default constructor. This entry activates WebServer
* internally and the web server is allocated internal.
*/
AutoConnect::AutoConnect() {
_initialize();
_webServer.reset(nullptr);
_dnsServer.reset(nullptr);
AutoConnect::AutoConnect()
: _scanCount( 0 )
, _connectTimeout( AUTOCONNECT_TIMEOUT )
, _menuTitle( _apConfig.title )
{
memset(&_credential, 0x00, sizeof(station_config_t));
}
/**
@ -38,27 +40,10 @@ AutoConnect::AutoConnect() {
* User's added URI handler response can be included in handleClient method.
* @param webServer A reference of ESP8266WebServer instance.
*/
AutoConnect::AutoConnect(WebServerClass& webServer) {
_initialize();
AutoConnect::AutoConnect(WebServerClass& webServer)
: AutoConnect()
{
_webServer = WebserverUP(&webServer, [](WebServerClass*){});
_dnsServer.reset(nullptr);
}
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("");
}
/**

@ -222,7 +222,6 @@ class AutoConnect {
AC_RECONNECT_SET,
AC_RECONNECT_RESET
} AC_STARECONNECT_t;
void _initialize(void);
bool _config(void);
bool _configSTA(const IPAddress& ip, const IPAddress& gateway, const IPAddress& netmask, const IPAddress& dns1, const IPAddress& dns2);
bool _getConfigSTA(station_config_t* config);
@ -275,8 +274,8 @@ class AutoConnect {
* Every time a GET/POST HTTP request occurs, an AutoConnect
* menu page corresponding to the URI is generated.
*/
PageBuilder* _responsePage;
PageElement* _currentPageElement;
PageBuilder* _responsePage = nullptr;
PageElement* _currentPageElement = nullptr;
/** Extended pages made up with AutoConnectAux */
AutoConnectAux* _aux = nullptr; /**< A top of registered AutoConnectAux */
@ -295,12 +294,12 @@ class AutoConnect {
unsigned long _portalAccessPeriod;
/** The control indicators */
bool _rfConnect; /**< URI /connect requested */
bool _rfDisconnect; /**< URI /disc requested */
bool _rfReset; /**< URI /reset requested */
bool _rfConnect = false; /**< URI /connect requested */
bool _rfDisconnect = false; /**< URI /disc requested */
bool _rfReset = false; /**< URI /reset requested */
wl_status_t _rsConnect; /**< connection result */
#ifdef ARDUINO_ARCH_ESP32
WiFiEventId_t _disconnectEventId; /**< STA disconnection event handler registered id */
WiFiEventId_t _disconnectEventId = -1; /**< STA disconnection event handler registered id */
#endif
std::unique_ptr<AutoConnectTicker> _ticker; /**< */

Loading…
Cancel
Save