Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jan 30, 2025
1 parent 9a0ccd2 commit f441a90
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/core/Auth/CustomAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace firebase_ns
#endif
}

~CustomAuth() { data.clear(); };
~CustomAuth() { data.clear(); }

user_auth_data &get()
{
Expand Down
5 changes: 1 addition & 4 deletions src/core/Auth/Token/AppToken.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ namespace firebase_ns
{
struct app_token_t
{
private:
StringUtil sut;

public:
String val[app_tk_ns::max_type];
uint32_t expire = 0, auth_ts = 0;
Expand All @@ -20,7 +17,7 @@ namespace firebase_ns
void clear()
{
for (size_t i = 0; i < app_tk_ns::max_type; i++)
sut.clear(val[i]);
val[i].remove(0, val[i].length());
expire = FIREBASE_DEFAULT_TOKEN_TTL;
authenticated = false;
auth_type = auth_unknown_token;
Expand Down
15 changes: 10 additions & 5 deletions src/core/Auth/UserAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,34 @@ namespace firebase_ns
data.user.val[user_ns::api_key] = apiKey;
setType(auth_user_id_token, user_auth_data_user_data);
}

~UserAccount() { data.clear(); };

UserAccount &email(const String &email)
{
data.user.val[user_ns::em] = email;
return setType(auth_user_id_token, user_auth_data_user_data);
};
}

UserAccount &password(const String &password)
{
data.user.val[user_ns::psw] = password;
return setType(auth_user_id_token, user_auth_data_user_data);
};
}

UserAccount &idToken(const String &idToken)
{
data.user.val[user_ns::id_token] = idToken;
return setType(auth_user_id_token, user_auth_data_user_data);
};
}

~UserAccount() { data.clear(); };
void clear() { data.clear(); }

user_auth_data &get() { return data; }

private:
user_auth_data data;

UserAccount &setType(auth_token_type auth_type, user_auth_data_type data_type)
{
data.auth_type = auth_type;
Expand All @@ -47,7 +53,6 @@ namespace firebase_ns
return *this;
}
};

#endif
}
#endif
4 changes: 3 additions & 1 deletion src/core/Auth/UserAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ namespace firebase_ns
return ret;
}

~UserAuth() { data.clear(); };
~UserAuth() { data.clear(); }

void clear() { data.clear(); }

user_auth_data &get()
{
#if defined(ENABLE_FS)
Expand Down
3 changes: 3 additions & 0 deletions src/core/Auth/UserAuthData.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ namespace firebase_ns

public:
user_auth_data() {}

~user_auth_data() { clear(); }

user_auth_data &operator=(const user_auth_data &rhs)
{
copy(rhs);
return *this;
}

void copy(const user_auth_data &rhs)
{
this->user.copy(rhs.user);
Expand Down
1 change: 0 additions & 1 deletion src/core/File/BlobConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class BlobConfig
{

public:
/**
* BLOB config class.
Expand Down
1 change: 1 addition & 0 deletions src/core/File/BlobWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct firebase_blob_writer
{
public:
firebase_blob_writer() {}

void init(uint8_t *data, size_t size)
{
this->data = data;
Expand Down
2 changes: 2 additions & 0 deletions src/core/File/DefaultFileConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class DefaultFileConfig
public:
template <typename T = const char *>
DefaultFileConfig() {}

~DefaultFileConfig() {}

file_config_data &get() { return data; }

private:
Expand Down
5 changes: 1 addition & 4 deletions src/core/File/FileConfigData.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ struct file_config_data
firebase_blob_writer outB;
StringUtil sut;
Memory mem;

void clearInternalData()
{
if (internal_data && data && data_size > 0)
mem.release(&data);
data_size = 0;
internal_data = false;
}

void initBlobWriter(size_t size)
{
clearInternalData();
Expand All @@ -69,7 +68,6 @@ struct file_config_data
copy(rhs);
return *this;
}

void copy(const file_config_data &rhs)
{
#if defined(ENABLE_FS)
Expand All @@ -91,7 +89,6 @@ struct file_config_data
}
this->initialized = rhs.initialized;
}

void clear()
{
#if defined(ENABLE_FS)
Expand Down
6 changes: 6 additions & 0 deletions src/core/Network/Data/NetworkConfigData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static unsigned long wifi_reconnection_ms = 0;
static uint32_t gsm_network_owner_addr = 0;
static uint32_t ethernet_network_owner_addr = 0;
static uint32_t generic_network_owner_addr = 0;

typedef void (*NetworkConnectionCallback)(void);
typedef void (*NetworkStatusCallback)(bool &);

Expand Down Expand Up @@ -49,6 +50,7 @@ struct network_config_data
this->net_con_cb = rhs.net_con_cb;
this->net_status_cb = rhs.net_status_cb;
}

void clear()
{
net_con_cb = NULL;
Expand Down Expand Up @@ -80,6 +82,7 @@ struct network_config_data
this->user = rhs.user;
this->password = rhs.password;
}

void clear()
{
modem = nullptr;
Expand Down Expand Up @@ -116,7 +119,9 @@ struct network_config_data

public:
ethernet_data() { ethernet_mac = new uint8_t[6]; }

~ethernet_data() { clear(); }

void copy(const ethernet_data &rhs)
{
this->ethernet_reset_pin = rhs.ethernet_reset_pin;
Expand Down Expand Up @@ -183,6 +188,7 @@ struct network_config_data

public:
~network_config_data() { clear(); }

network_config_data &operator=(const network_config_data &rhs)
{
copy(rhs);
Expand Down
2 changes: 1 addition & 1 deletion src/core/Network/Data/StaticAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct firebase_client_static_address
this->optional = optional;
};

firebase_client_static_address() {};
firebase_client_static_address() {}

private:
IPAddress ipAddress, netMask, defaultGateway, dnsServer;
Expand Down
3 changes: 1 addition & 2 deletions src/core/Updater/OTAUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#if defined(FIREBASE_OTA_STORAGE)

OTAUpdaterClass::OTAUpdaterClass() {}

OTAUpdaterClass::~OTAUpdaterClass() {}

bool OTAUpdaterClass::begin(int size)
Expand Down Expand Up @@ -59,7 +60,5 @@ void OTAUpdaterClass::apply()
}

OTAUpdaterClass OTAUpdater;

#endif

#endif
3 changes: 0 additions & 3 deletions src/core/Updater/OTAUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

class OTAUpdaterClass
{

public:
OTAUpdaterClass();
~OTAUpdaterClass();
Expand All @@ -38,7 +37,5 @@ class OTAUpdaterClass
};

extern OTAUpdaterClass OTAUpdater;

#endif

#endif
3 changes: 2 additions & 1 deletion src/core/Utils/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace firebase_ns
{
public:
List() {}

~List() {}

void addRemoveList(std::vector<uint32_t> &vec, uint32_t addr, bool add)
Expand Down Expand Up @@ -38,5 +39,5 @@ namespace firebase_ns
return false;
}
};
};
}
#endif
7 changes: 1 addition & 6 deletions src/core/Utils/OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ class OTAUtil
}

#if defined(FIREBASE_OTA_STORAGE)
void setOTAStorage(uint32_t addr)
{
OTAUpdater.setOTAStorage(addr);
}
void setOTAStorage(uint32_t addr) { OTAUpdater.setOTAStorage(addr); }
#endif

void prepareDownloadOTA(size_t payloadLen, bool base64, int16_t &code)
Expand Down Expand Up @@ -89,9 +86,7 @@ class OTAUtil
if (!FIREBASE_OTA_UPDATER.end())
code = FIREBASE_ERROR_FW_UPDATE_END_FAILED;
}

return code == 0;

#endif
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Utils/StringUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

class StringUtil
{

public:
StringUtil() {}

~StringUtil() {}

#if defined(FIREBASE_USE_STRSEP_IMPL)
Expand Down
10 changes: 10 additions & 0 deletions src/core/Utils/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ class Timer

public:
explicit Timer(unsigned long sec = 60) { setInterval(sec); }

~Timer() {}

void reset() { end = ts + period; }

void start()
{
enable = true;
loop();
reset();
}

void stop() { enable = false; }

void setInterval(unsigned long sec)
{
loop();
period = sec;
reset();
}

void feed(unsigned long sec)
{
feed_count++;
Expand All @@ -37,6 +43,7 @@ class Timer
setInterval(sec);
start();
}

void loop()
{
if (enable && (unsigned long)(millis() - now) > 100)
Expand All @@ -53,8 +60,11 @@ class Timer
}

unsigned long remaining() { return ready() ? 0 : end - ts; }

uint8_t feedCount() const { return feed_count; }

bool isRunning() const { return enable; };

bool ready()
{
loop();
Expand Down
5 changes: 4 additions & 1 deletion src/core/Utils/URL.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class URLUtil
return false;

String _key(key);

if (!hasParam && _key[0] == '&')
_key[0] = '?';
else if (hasParam && _key[0] == '?')
Expand All @@ -34,6 +33,7 @@ class URLUtil
hasParam = true;
return true;
}

/* Append the comma separated tokens as URL parameters */
void addParamsTokens(String &url, const String &key, String val, bool &hasParam)
{
Expand All @@ -60,6 +60,7 @@ class URLUtil
// release memory
mem.release(&p);
}

/* Append the path to URL */
void addPath(String &url, const String &path)
{
Expand All @@ -73,6 +74,7 @@ class URLUtil

url += path;
}

/* Append the string with google storage URL */
void addGStorageURL(String &uri, const String &bucketID, const String &storagePath)
{
Expand All @@ -82,6 +84,7 @@ class URLUtil
uri += '/';
uri += storagePath;
}

/* Append the string with cloudfunctions project host */
void addFunctionsHost(String &uri, const String &locationId, const String &projectId, const String &path, bool url)
{
Expand Down

0 comments on commit f441a90

Please sign in to comment.