Changed return type of detach

enhance/v120
Hieromon Ikasamo 4 years ago
parent 91f1c0fcf1
commit bef08e1be3
  1. 5
      mkdocs/advancedusage.md
  2. 9
      mkdocs/api.md
  3. 10
      src/AutoConnect.cpp
  4. 2
      src/AutoConnect.h
  5. 1
      src/AutoConnectAux.h

@ -285,8 +285,9 @@ portal.append("/hello", "HELLO", [](){
For more details, see section [Attach the menu](menuize.md) of Examples page.
!!! note "Necessary ESP8266WebServer/WebServer has materialized"
The WebServer must have instantiated for calling with a request handler parameter. AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the [AutoConnct::append](api.md#append) function with a request handler parameter must be after [AutoConnect::begin](api.md#begin).
!!! note "An instance of ESP8266WebServer/WebServer is needed"
When calling the append function with request handler parameters, an instance of the WebServer as the registration destination must exist.
AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the [AutoConnct::append](api.md#append) function with a request handler parameter must be after [AutoConnect::begin](api.md#begin).
### <i class="fa fa-caret-right"></i> Change the menu labels

@ -99,7 +99,7 @@ Returns the pointer to created AutoConnectAux instance, the `nullptr` if an Auto
<dd>A Pointer to a created AutoConnectAux instance.</dd>
</dl>
!!! note "Necessary ESP8266WebServer/WebServer has materialized"
!!! note "An instance of ESP8266WebServer/WebServer is needed"
The WebServer must have instantiated for calling with a request handler parameter. AutoConnect can instantiate and host a WebServer internally, but in that case, the point in time to call the append function with a request handler parameter must be after AutoConnect::begin.
### <i class="fa fa-caret-right"></i> aux
@ -162,18 +162,21 @@ Set SoftAP's WiFi configuration and static IP configuration.
### <i class="fa fa-caret-right"></i> detach
```cpp
AutoConnectAux* detach(const String& uri)
bool detach(const String& uri)
```
Detach the AutoConnectAux with the specified URI from the management of AutoConnect. An unmanaged AutoConnectAux will no longer appear in menu items, and its page handler will no longer respond even if the URI is accessed directly.
<dl class="apidl">
<dt>**Parameter**</dt>
<dd><span class="apidef">uri</span><span class="apidesc">URI of AutoConnectAux to be detached.</span></dd>
<dt>**Return value**</dt>
<dd><span class="apidef">true</span><span class="apidesc">Successfully detached.</span></dd>
<dd><span class="apidef">false</span><span class="aidesc">An AutoConnectAux with the specified URI does not exist.</span></dd>
</dl>
If the request handler registered in the detaching AutoConnectAux is for a legacy page of the ESP8266WebServer/WebServer, the URI is still valid after detaching. AutoConnect does not delete the request handler registered to ESP8266WebServer/WebServer with the `on` function. (It cannot be removed)
!!! hint "Deleting the AutoConnectAux"
You can use the return value from the AotoConnect::detach to delete the AutoConnectAux instance which dynamically created with the [AutoConnect::append](api.md#append).
If the AutoConnectAux to detach was added by [AutoConnect::append](api.md#append), it will be automatically removed and freed from memory.
### <i class="fa fa-caret-right"></i> disableMenu

@ -586,6 +586,7 @@ AutoConnectAux* AutoConnect::append(const String& uri, const String& title) {
AutoConnectAux* reg = aux(uri);
if (!reg) {
reg = new AutoConnectAux(uri, title);
reg->_deletable = true;
join(*reg);
return reg;
}
@ -611,6 +612,7 @@ AutoConnectAux* AutoConnect::append(const String& uri, const String& title, WebS
_webServer->on(uri, handler);
return reg;
}
AC_DBG("No WebServer instance\n");
return nullptr;
}
@ -620,19 +622,21 @@ AutoConnectAux* AutoConnect::append(const String& uri, const String& title, WebS
* @return true Specified AUX has released
* @return false Specified AUX not registered
*/
AutoConnectAux* AutoConnect::detach(const String &uri) {
bool AutoConnect::detach(const String &uri) {
AutoConnectAux** self = &_aux;
while (*self) {
if (!strcmp((*self)->uri(), uri.c_str())) {
AC_DBG("%s released\n", (*self)->uri());
AutoConnectAux* ref = *self;
*self = (*self)->_next;
return ref;
if (ref->_deletable)
delete ref;
return true;
}
self = &((*self)->_next);
}
AC_DBG("%s not listed\n", uri.c_str());
return nullptr;
return false;
}
/**

@ -232,7 +232,7 @@ class AutoConnect {
AutoConnectAux* aux(const String& uri) const;
AutoConnectAux* append(const String& uri, const String& title);
AutoConnectAux* append(const String& uri, const String& title, WebServerClass::THandlerFunction handler);
AutoConnectAux* detach(const String& uri);
bool detach(const String& uri);
inline void disableMenu(const uint16_t items) { _apConfig.menuItems &= (0xffff ^ items); }
inline void enableMenu(const uint16_t items) { _apConfig.menuItems |= items; }
void join(AutoConnectAux& aux);

@ -148,6 +148,7 @@ class AutoConnectAux : public PageBuilder {
String _title; /**< A title of the page */
bool _menu; /**< Switch for menu displaying */
bool _deletable = false; /**< Allow deleting itself. */
AC_AUTH_t _httpAuth = AC_AUTH_NONE; /**< Applying HTTP authentication */
String _uriStr; /**< uri as String */
AutoConnectElementVT _addonElm; /**< A vector set of AutoConnectElements placed on this auxiliary page */

Loading…
Cancel
Save