add abstraction layer for webserver
This commit is contained in:
20
webserver/AbstractWebServer.h
Normal file
20
webserver/AbstractWebServer.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "EthernetWebServer.h"
|
||||
|
||||
class AbstractWebServer
|
||||
{
|
||||
public:
|
||||
explicit AbstractWebServer(int port) {};
|
||||
|
||||
virtual void begin() = 0;
|
||||
virtual bool authenticate(const char * username, const char * password) = 0;
|
||||
virtual void requestAuthentication(HTTPAuthMethod mode, const char* realm, const String& authFailMsg) = 0;
|
||||
virtual void requestAuthentication() = 0;
|
||||
virtual void send(int code, const char* content_type, const String& content) = 0;
|
||||
virtual void on(const Uri &uri, EthernetWebServer::THandlerFunction handler) = 0;
|
||||
virtual int args() = 0;
|
||||
virtual String arg(int i) = 0;
|
||||
virtual String argName(int i) = 0;
|
||||
virtual void handleClient() = 0;
|
||||
};
|
||||
58
webserver/EthWebServer.cpp
Normal file
58
webserver/EthWebServer.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "EthWebServer.h"
|
||||
|
||||
|
||||
EthWebServer::EthWebServer(int port)
|
||||
: AbstractWebServer(port),
|
||||
_server(port)
|
||||
{}
|
||||
|
||||
|
||||
void EthWebServer::begin()
|
||||
{
|
||||
_server.begin();
|
||||
}
|
||||
|
||||
bool EthWebServer::authenticate(const char *username, const char *password)
|
||||
{
|
||||
return _server.authenticate(username, password);
|
||||
}
|
||||
|
||||
void EthWebServer::requestAuthentication(HTTPAuthMethod mode, const char *realm, const String &authFailMsg)
|
||||
{
|
||||
return _server.requestAuthentication(mode, realm, authFailMsg);
|
||||
}
|
||||
|
||||
void EthWebServer::send(int code, const char *content_type, const String &content)
|
||||
{
|
||||
_server.send(code, content_type, content);
|
||||
}
|
||||
|
||||
void EthWebServer::on(const Uri &uri, EthernetWebServer::THandlerFunction handler)
|
||||
{
|
||||
_server.on(uri, handler);
|
||||
}
|
||||
|
||||
void EthWebServer::requestAuthentication()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int EthWebServer::args()
|
||||
{
|
||||
return _server.args();
|
||||
}
|
||||
|
||||
String EthWebServer::arg(int i)
|
||||
{
|
||||
return _server.arg(i);
|
||||
}
|
||||
|
||||
String EthWebServer::argName(int i)
|
||||
{
|
||||
return _server.argName(i);
|
||||
}
|
||||
|
||||
void EthWebServer::handleClient()
|
||||
{
|
||||
_server.handleClient();
|
||||
}
|
||||
27
webserver/EthWebServer.h
Normal file
27
webserver/EthWebServer.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "AbstractWebServer.h"
|
||||
|
||||
class EthWebServer : public AbstractWebServer
|
||||
{
|
||||
public:
|
||||
explicit EthWebServer(int port);
|
||||
|
||||
virtual void begin();
|
||||
virtual bool authenticate(const char *username, const char *password);
|
||||
virtual void requestAuthentication(HTTPAuthMethod mode, const char *realm, const String &authFailMsg);
|
||||
virtual void requestAuthentication();
|
||||
virtual void send(int code, const char *content_type, const String &content);
|
||||
virtual void on(const Uri &uri, EthernetWebServer::THandlerFunction handler);
|
||||
|
||||
virtual int args();
|
||||
|
||||
virtual String arg(int i);
|
||||
|
||||
virtual String argName(int i);
|
||||
|
||||
virtual void handleClient();
|
||||
|
||||
private:
|
||||
EthernetWebServer _server;
|
||||
};
|
||||
Reference in New Issue
Block a user