mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 06:23:07 +01:00
add registerRequestHandler to the API with examples
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
#include "GWConfig.h"
|
||||
#include "GwBoatData.h"
|
||||
#include "GwXDRMappings.h"
|
||||
#include "GwSynchronized.h"
|
||||
#include <map>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
class GwApi;
|
||||
typedef void (*GwUserTaskFunction)(GwApi *);
|
||||
//API to be used for additional tasks
|
||||
@@ -171,6 +173,20 @@ class GwApi{
|
||||
virtual void remove(int idx){}
|
||||
virtual TaskInterfaces * taskInterfaces()=0;
|
||||
|
||||
/**
|
||||
* register handler for web URLs
|
||||
* Please be aware that this handler function will always be called from a separate
|
||||
* task. So you must ensure proper synchronization!
|
||||
*/
|
||||
using HandlerFunction=std::function<void(AsyncWebServerRequest *)>;
|
||||
/**
|
||||
* @param url: the url of that will trigger the handler.
|
||||
* it will be prefixed with /api/user/<taskname>
|
||||
* taskname is the name that you used in addUserTask
|
||||
* @param handler: the handler function (see remark above about thread synchronization)
|
||||
*/
|
||||
virtual void registerRequestHandler(const String &url,HandlerFunction handler)=0;
|
||||
|
||||
/**
|
||||
* only allowed during init methods
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user