Skip to content

Commit

Permalink
Use direct member initialization instead of ctr initialisation (#7558)
Browse files Browse the repository at this point in the history
* Use direct member initialization instead of ctr initialisation

This removes a bit of code repetition.

* Add symbolic names for member initializers
  • Loading branch information
dirkmueller committed Oct 5, 2020
1 parent 8b8639e commit 4aeb0f5
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 132 deletions.
8 changes: 3 additions & 5 deletions cores/esp8266/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@

class Print {
private:
int write_error;
int write_error = 0;
template<typename T> size_t printNumber(T n, uint8_t base);
template<typename T, typename... P> inline size_t _println(T v, P... args);
protected:
protected:
void setWriteError(int err = 1) {
write_error = err;
}
public:
Print() :
write_error(0) {
}
Print() {}

int getWriteError() {
return write_error;
Expand Down
6 changes: 2 additions & 4 deletions cores/esp8266/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

class Stream: public Print {
protected:
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
unsigned long _timeout = 1000; // number of milliseconds to wait for the next char before aborting timed read
unsigned long _startMillis; // used for timeout measurement
int timedRead(); // private method to read stream with timeout
int timedPeek(); // private method to peek stream with timeout
Expand All @@ -48,9 +48,7 @@ class Stream: public Print {
virtual int read() = 0;
virtual int peek() = 0;

Stream() {
_timeout = 1000;
}
Stream() {}

// parsing methods

Expand Down
12 changes: 0 additions & 12 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ extern "C" uint32_t _FS_start;
extern "C" uint32_t _FS_end;

UpdaterClass::UpdaterClass()
: _async(false)
, _error(0)
, _buffer(0)
, _bufferLen(0)
, _size(0)
, _startAddress(0)
, _currentAddress(0)
, _command(U_FLASH)
, _ledPin(-1)
, _hash(nullptr)
, _verify(nullptr)
, _progress_callback(nullptr)
{
#if ARDUINO_SIGNING
installSignature(&esp8266::updaterSigningHash, &esp8266::updaterSigningVerifier);
Expand Down
26 changes: 13 additions & 13 deletions cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,27 +182,27 @@ class UpdaterClass {

void _setError(int error);

bool _async;
uint8_t _error;
uint8_t *_buffer;
size_t _bufferLen; // amount of data written into _buffer
size_t _bufferSize; // total size of _buffer
size_t _size;
uint32_t _startAddress;
uint32_t _currentAddress;
uint32_t _command;
bool _async = false;
uint8_t _error = 0;
uint8_t *_buffer = nullptr;
size_t _bufferLen = 0; // amount of data written into _buffer
size_t _bufferSize = 0; // total size of _buffer
size_t _size = 0;
uint32_t _startAddress = 0;
uint32_t _currentAddress = 0;
uint32_t _command = U_FLASH;

String _target_md5;
MD5Builder _md5;

int _ledPin;
int _ledPin = -1;
uint8_t _ledOn;

// Optional signed binary verification
UpdaterHashClass *_hash;
UpdaterVerifyClass *_verify;
UpdaterHashClass *_hash = nullptr;
UpdaterVerifyClass *_verify = nullptr;
// Optional progress callback function
THandlerFunction_Progress _progress_callback;
THandlerFunction_Progress _progress_callback = nullptr;
};

extern UpdaterClass Update;
Expand Down
6 changes: 0 additions & 6 deletions libraries/EEPROM/EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ extern "C" uint32_t _EEPROM_start;

EEPROMClass::EEPROMClass(uint32_t sector)
: _sector(sector)
, _data(0)
, _size(0)
, _dirty(false)
{
}

EEPROMClass::EEPROMClass(void)
: _sector((((uint32_t)&_EEPROM_start - 0x40200000) / SPI_FLASH_SEC_SIZE))
, _data(0)
, _size(0)
, _dirty(false)
{
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/EEPROM/EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class EEPROMClass {

protected:
uint32_t _sector;
uint8_t* _data;
size_t _size;
bool _dirty;
uint8_t* _data = nullptr;
size_t _size = 0;
bool _dirty = false;
};

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EEPROM)
Expand Down
17 changes: 2 additions & 15 deletions libraries/ESP8266SSDP/ESP8266SSDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ extern "C" {
#include "include/UdpContext.h"
//#define DEBUG_SSDP Serial

#define SSDP_INTERVAL 1200
#define SSDP_PORT 1900
#define SSDP_METHOD_SIZE 10
#define SSDP_URI_SIZE 2
#define SSDP_BUFFER_SIZE 64
#define SSDP_MULTICAST_TTL 2

// ssdp ipv6 is FF05::C
// lwip-v2's igmp_joingroup only supports IPv4
Expand Down Expand Up @@ -125,19 +123,8 @@ struct SSDPTimer {
ETSTimer timer;
};

SSDPClass::SSDPClass() :
_server(0),
_timer(0),
_port(80),
_ttl(SSDP_MULTICAST_TTL),
_interval(SSDP_INTERVAL),
_respondToAddr(0,0,0,0),
_respondToPort(0),
_pending(false),
_st_is_uuid(false),
_delay(0),
_process_time(0),
_notify_time(0)
SSDPClass::SSDPClass()
: _respondToAddr(0,0,0,0)
{
_uuid[0] = '\0';
_modelNumber[0] = '\0';
Expand Down
25 changes: 14 additions & 11 deletions libraries/ESP8266SSDP/ESP8266SSDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class UdpContext;
#define SSDP_MODEL_VERSION_SIZE 32
#define SSDP_MANUFACTURER_SIZE 64
#define SSDP_MANUFACTURER_URL_SIZE 128
#define SSDP_INTERVAL_SECONDS 1200
#define SSDP_MULTICAST_TTL 2
#define SSDP_HTTP_PORT 80

typedef enum {
NONE,
Expand Down Expand Up @@ -101,20 +104,20 @@ class SSDPClass{
void _stopTimer();
static void _onTimerStatic(SSDPClass* self);

UdpContext* _server;
SSDPTimer* _timer;
uint16_t _port;
uint8_t _ttl;
uint32_t _interval;
UdpContext* _server = nullptr;
SSDPTimer* _timer = nullptr;
uint16_t _port = SSDP_HTTP_PORT;
uint8_t _ttl = SSDP_MULTICAST_TTL;
uint32_t _interval = SSDP_INTERVAL_SECONDS;

IPAddress _respondToAddr;
uint16_t _respondToPort;
uint16_t _respondToPort = 0;

bool _pending;
bool _st_is_uuid;
unsigned short _delay;
unsigned long _process_time;
unsigned long _notify_time;
bool _pending = false;
bool _st_is_uuid = false;
unsigned short _delay = 0;
unsigned long _process_time = 0;
unsigned long _notify_time = 0;

char _schemaURL[SSDP_SCHEMA_URL_SIZE];
char _uuid[SSDP_UUID_SIZE];
Expand Down
35 changes: 0 additions & 35 deletions libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,47 +39,12 @@ namespace esp8266webserver {
template <typename ServerType>
ESP8266WebServerTemplate<ServerType>::ESP8266WebServerTemplate(IPAddress addr, int port)
: _server(addr, port)
, _currentMethod(HTTP_ANY)
, _currentVersion(0)
, _currentStatus(HC_NONE)
, _statusChange(0)
, _keepAlive(false)
, _currentHandler(nullptr)
, _firstHandler(nullptr)
, _lastHandler(nullptr)
, _currentArgCount(0)
, _currentArgs(nullptr)
, _currentArgsHavePlain(0)
, _postArgsLen(0)
, _postArgs(nullptr)
, _headerKeysCount(0)
, _currentHeaders(nullptr)
, _contentLength(0)
, _chunked(false)
, _corsEnabled(false)
{
}

template <typename ServerType>
ESP8266WebServerTemplate<ServerType>::ESP8266WebServerTemplate(int port)
: _server(port)
, _currentMethod(HTTP_ANY)
, _currentVersion(0)
, _currentStatus(HC_NONE)
, _statusChange(0)
, _currentHandler(nullptr)
, _firstHandler(nullptr)
, _lastHandler(nullptr)
, _currentArgCount(0)
, _currentArgs(nullptr)
, _currentArgsHavePlain(0)
, _postArgsLen(0)
, _postArgs(nullptr)
, _headerKeysCount(0)
, _currentHeaders(nullptr)
, _contentLength(0)
, _chunked(false)
, _corsEnabled(false)
{
}

Expand Down
38 changes: 19 additions & 19 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,35 +263,35 @@ class ESP8266WebServerTemplate

ServerType _server;
ClientType _currentClient;
HTTPMethod _currentMethod;
HTTPMethod _currentMethod = HTTP_ANY;
String _currentUri;
uint8_t _currentVersion;
HTTPClientStatus _currentStatus;
unsigned long _statusChange;
bool _keepAlive;

RequestHandlerType* _currentHandler;
RequestHandlerType* _firstHandler;
RequestHandlerType* _lastHandler;
uint8_t _currentVersion = 0;
HTTPClientStatus _currentStatus = HC_NONE;
unsigned long _statusChange = 0;

RequestHandlerType* _currentHandler = nullptr;
RequestHandlerType* _firstHandler = nullptr;
RequestHandlerType* _lastHandler = nullptr;
THandlerFunction _notFoundHandler;
THandlerFunction _fileUploadHandler;

int _currentArgCount;
RequestArgument* _currentArgs;
int _currentArgsHavePlain;
int _currentArgCount = 0;
RequestArgument* _currentArgs = nullptr;
int _currentArgsHavePlain = 0;
std::unique_ptr<HTTPUpload> _currentUpload;
int _postArgsLen;
RequestArgument* _postArgs;
int _postArgsLen = 0;
RequestArgument* _postArgs = nullptr;

int _headerKeysCount;
RequestArgument* _currentHeaders;
int _headerKeysCount = 0;
RequestArgument* _currentHeaders = nullptr;

size_t _contentLength;
size_t _contentLength = 0;
String _responseHeaders;

String _hostHeader;
bool _chunked;
bool _corsEnabled;
bool _chunked = false;
bool _corsEnabled = false;
bool _keepAlive = false;

String _snonce; // Store noance and opaque for future comparison
String _sopaque;
Expand Down
6 changes: 0 additions & 6 deletions libraries/ESP8266WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,12 @@ extern "C" {
WiFiServer::WiFiServer(const IPAddress& addr, uint16_t port)
: _port(port)
, _addr(addr)
, _listen_pcb(nullptr)
, _unclaimed(nullptr)
, _discarded(nullptr)
{
}

WiFiServer::WiFiServer(uint16_t port)
: _port(port)
, _addr(IP_ANY_TYPE)
, _listen_pcb(nullptr)
, _unclaimed(nullptr)
, _discarded(nullptr)
{
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/ESP8266WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class WiFiServer : public Server {
protected:
uint16_t _port;
IPAddress _addr;
tcp_pcb* _listen_pcb;
tcp_pcb* _listen_pcb = nullptr;

ClientContext* _unclaimed;
ClientContext* _discarded;
ClientContext* _unclaimed = nullptr;
ClientContext* _discarded = nullptr;
enum { _ndDefault, _ndFalse, _ndTrue } _noDelay = _ndDefault;

public:
Expand Down

0 comments on commit 4aeb0f5

Please sign in to comment.