introduce namespace

This commit is contained in:
Florian Hoss 2022-04-20 13:08:12 +02:00
parent 73533e5d15
commit beddd88653
7 changed files with 459 additions and 415 deletions

View file

@ -1,11 +1,26 @@
#include "esp32Eeprom.hpp" #include "esp32Eeprom.hpp"
esp32Eeprom::esp32Eeprom(const uint16_t eeprom_size) namespace firewall
{
Storage::Storage(const uint16_t eeprom_size)
{ {
this->eeprom_size = eeprom_size; this->eeprom_size = eeprom_size;
EEPROM.begin(this->eeprom_size); EEPROM.begin(this->eeprom_size);
set_amount_of_firewall_rules(EEPROM.read(this->settings_head));
log_i("Amount of Rules: %i", get_amount_of_firewall_rules());
} }
esp32Eeprom::~esp32Eeprom() Storage::~Storage()
{ {
} }
uint8_t Storage::get_amount_of_firewall_rules()
{
return this->amount_of_rules;
}
void Storage::set_amount_of_firewall_rules(const uint8_t new_amount)
{
this->amount_of_rules = new_amount;
}
}

View file

@ -2,15 +2,30 @@
#define ESP32_EEPROM_HPP #define ESP32_EEPROM_HPP
#include "EEPROM.h" #include "EEPROM.h"
#include "FirewallTypes.h"
class esp32Eeprom namespace firewall
{
class Storage
{ {
private: private:
uint16_t eeprom_size; uint16_t eeprom_size;
uint16_t settings_start = 0;
uint16_t settings_head = settings_start;
uint16_t rules_start = 1000;
uint16_t rules_head = rules_start;
uint16_t certificate_start = 3000;
uint16_t certificate_head = certificate_start;
protected:
uint8_t amount_of_rules;
uint8_t get_amount_of_firewall_rules();
void set_amount_of_firewall_rules(const uint8_t);
public: public:
esp32Eeprom(const uint16_t); Storage(const uint16_t = 4000);
~esp32Eeprom(); ~Storage();
}; };
}
#endif #endif

View file

@ -1,5 +1,7 @@
#include "esp32Firewall.hpp" #include "esp32Firewall.hpp"
namespace firewall
{
esp32Firewall::esp32Firewall() esp32Firewall::esp32Firewall()
{ {
this->setup_eeprom(); this->setup_eeprom();
@ -206,3 +208,4 @@ bool esp32Firewall::delete_rule_from_firewall(uint8_t key)
this->eeprom_write_firewall_rules(); this->eeprom_write_firewall_rules();
return true; return true;
} }
}

View file

@ -6,6 +6,8 @@
#define eeprom_start_firewall_rules 4 #define eeprom_start_firewall_rules 4
namespace firewall
{
class esp32Firewall class esp32Firewall
{ {
private: private:
@ -38,5 +40,6 @@ public:
esp32Firewall(); esp32Firewall();
~esp32Firewall(); ~esp32Firewall();
}; };
}
#endif #endif

View file

@ -1,5 +1,7 @@
#include "esp32FirewallAPI.hpp" #include "esp32FirewallAPI.hpp"
namespace firewall
{
esp32FirewallApi::esp32FirewallApi(const uint16_t port) esp32FirewallApi::esp32FirewallApi(const uint16_t port)
{ {
this->setup_certificate(); this->setup_certificate();
@ -195,3 +197,4 @@ String esp32FirewallApi::construct_json_firewall()
serializeJson(doc, response); serializeJson(doc, response);
return response; return response;
} }
}

View file

@ -11,6 +11,8 @@
using namespace httpsserver; using namespace httpsserver;
namespace firewall
{
class esp32FirewallApi : public esp32Firewall class esp32FirewallApi : public esp32Firewall
{ {
private: private:
@ -37,5 +39,6 @@ public:
~esp32FirewallApi(); ~esp32FirewallApi();
void handle_clients(); void handle_clients();
}; };
}
#endif #endif

View file

@ -1,10 +1,11 @@
#include "theSecrets.h" #include "theSecrets.h"
#include "WiFi.h" #include "WiFi.h"
#include "esp32Firewall.hpp"
#include "esp32FirewallAPI.hpp" #include "esp32FirewallAPI.hpp"
#include "esp32Eeprom.hpp"
esp32FirewallApi *firewall_api; firewall::esp32FirewallApi *firewall_api;
firewall::Storage *storage;
void setup_wifi() void setup_wifi()
{ {
@ -24,10 +25,11 @@ void setup_wifi()
void setup() void setup()
{ {
setup_wifi(); setup_wifi();
firewall_api = new esp32FirewallApi; // firewall_api = new esp32FirewallApi;
storage = new firewall::Storage;
} }
void loop() void loop()
{ {
firewall_api->handle_clients(); // firewall_api->handle_clients();
} }