- Optimize the dependency injection model for the API classes
- Removed the constructor params from the base-classes of APIServer
- Allocate data to the base-class members in the Constructor of APIServer
This commit is contained in:
ZanzyTHEbar 2022-08-28 15:02:58 +01:00
parent 37f501c442
commit d802b4a5d7
6 changed files with 15 additions and 36 deletions

View File

@ -1,14 +1,6 @@
#include "baseAPI.hpp"
BaseAPI::BaseAPI(int CONTROL_PORT,
WiFiHandler *network,
CameraHandler *camera,
StateManager<WiFiState_e> *stateManager,
std::string api_url) : API_Utilities(CONTROL_PORT,
network,
camera,
stateManager,
api_url) {}
BaseAPI::BaseAPI() {}
BaseAPI::~BaseAPI() {}

View File

@ -70,11 +70,7 @@ protected:
route_map_t route_map;
public:
BaseAPI(int CONTROL_PORT,
WiFiHandler *network,
CameraHandler *camera,
StateManager<WiFiState_e> *stateManager,
std::string api_url);
BaseAPI();
virtual ~BaseAPI();
virtual void begin();

View File

@ -18,15 +18,7 @@ bool API_Utilities::channel_write = false;
//! API Utilities
//*********************************************************************************************
API_Utilities::API_Utilities(int CONTROL_PORT,
WiFiHandler *network,
CameraHandler *camera,
StateManager<WiFiState_e> *stateManager,
std::string api_url) : server(new AsyncWebServer(CONTROL_PORT)),
stateManager(stateManager),
network(network),
camera(camera),
api_url(api_url) {}
API_Utilities::API_Utilities() : server(new AsyncWebServer(_control_port)) {}
API_Utilities::~API_Utilities() {}
std::string API_Utilities::shaEncoder(std::string data)

View File

@ -29,11 +29,7 @@
class API_Utilities
{
public:
API_Utilities(int CONTROL_PORT,
WiFiHandler *network,
CameraHandler *camera,
StateManager<WiFiState_e> *stateManager,
std::string api_url);
API_Utilities();
virtual ~API_Utilities();
static void printASCII();
@ -80,6 +76,7 @@ protected:
protected:
std::string api_url;
byte _control_port;
static bool ssid_write;
static bool pass_write;

View File

@ -4,15 +4,18 @@
//! API Server
//*********************************************************************************************
APIServer::APIServer(int CONTROL_PORT,
APIServer::APIServer(byte control_port,
WiFiHandler *network,
CameraHandler *camera,
StateManager<WiFiState_e> *stateManager,
std::string api_url) : BaseAPI(CONTROL_PORT,
network,
camera,
stateManager,
api_url) {}
std::string api_url)
{
this->_control_port = control_port;
this->network = network;
this->camera = camera;
this->stateManager = stateManager;
this->api_url = api_url;
}
APIServer::~APIServer() {}
@ -41,7 +44,6 @@ void APIServer::setupServer()
routes.emplace("deleteRoute", &APIServer::deleteRoute);
// Camera Routes
//! reserve enough memory for all routes - must be called after adding routes and before adding routes to route_map
indexes.reserve(routes.size()); // this is done to avoid reallocation of memory and copying of data

View File

@ -7,7 +7,7 @@
class APIServer : public BaseAPI
{
public:
APIServer(int CONTROL_PORT,
APIServer(byte control_port,
WiFiHandler *network,
CameraHandler *camera,
StateManager<WiFiState_e> *stateManager,