From 68812edbe8cb7024f91734b07f5deb49080fa3c6 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 11 Jul 2024 08:26:09 +0700 Subject: [PATCH] Update `BlobConfig` and `FileConfig` classes --- README.md | 14 +++-- .../Async/Callback/Download/Download.ino | 2 +- .../Async/Callback/Upload/Upload.ino | 2 +- .../Async/NoCallback/Download/Download.ino | 2 +- .../Async/NoCallback/Upload/Upload.ino | 2 +- .../CloudStorage/Sync/Download/Download.ino | 2 +- examples/CloudStorage/Sync/Upload/Upload.ino | 2 +- .../Async/Callback/BLOB/BLOB.ino | 4 +- .../Async/Callback/File/File.ino | 4 +- .../Async/NoCallback/BLOB/BLOB.ino | 4 +- .../Async/NoCallback/File/File.ino | 4 +- .../Async/Callback/Download/Download.ino | 2 +- .../Storage/Async/Callback/Upload/Upload.ino | 2 +- .../Async/NoCallback/Download/Download.ino | 2 +- .../Async/NoCallback/Upload/Upload.ino | 2 +- examples/Storage/Sync/Download/Download.ino | 2 +- examples/Storage/Sync/Upload/Upload.ino | 2 +- keywords.txt | 2 + library.json | 2 +- library.properties | 2 +- resources/docs/file_config.md | 51 +++++++++++++----- src/core/Core.h | 2 +- src/core/FileConfig.h | 53 ++++++++++++++----- 23 files changed, 115 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index a753e26b..7e5333b0 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mobizt/FirebaseClient/.github%2Fworkflows%2Fcompile_library.yml?logo=github&label=compile) [![Github Stars](https://img.shields.io/github/stars/mobizt/FirebaseClient?logo=github)](https://github.com/mobizt/FirebaseClient/stargazers) ![Github Issues](https://img.shields.io/github/issues/mobizt/FirebaseClient?logo=github) -![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.3.4-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient) +![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.3.5-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient) [![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt) -Revision `2024-07-06T17:01:03Z` +Revision `2024-07-11T01:22:56Z` ## Table of Contents @@ -1215,6 +1215,12 @@ The `FileConfig` class parameters are included the following. ```cpp FileConfig::FileConfig(, ) + +void FileConfig::setFile(, ) + +FileConfig &FileConfig::setFilename() + +FileConfig &FileConfig::setCallback() ``` `` The full file name included its path. @@ -1290,10 +1296,12 @@ void download() The blob config class ([BlobConfig](examples/RealtimeDatabase/Async/Callback/BLOB/)) provides the in/out data for upload and download functions. -The `BlobConfig` class constructor parameters class parameters are included the following. +The `BlobConfig` class constructor and function parameters are included the following. ```cpp BlobConfig::BlobConfig(, ) + +void BlobConfig::setBlob(, ); ``` `` The BLOB data (byte array). diff --git a/examples/CloudStorage/Async/Callback/Download/Download.ino b/examples/CloudStorage/Async/Callback/Download/Download.ino index 2fe91802..e3c27740 100644 --- a/examples/CloudStorage/Async/Callback/Download/Download.ino +++ b/examples/CloudStorage/Async/Callback/Download/Download.ino @@ -89,7 +89,7 @@ void printResult(AsyncResult &aResult); #if defined(ENABLE_FS) void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/CloudStorage/Async/Callback/Upload/Upload.ino b/examples/CloudStorage/Async/Callback/Upload/Upload.ino index 934c3178..47fbeb59 100644 --- a/examples/CloudStorage/Async/Callback/Upload/Upload.ino +++ b/examples/CloudStorage/Async/Callback/Upload/Upload.ino @@ -91,7 +91,7 @@ void printResult(AsyncResult &aResult); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/CloudStorage/Async/NoCallback/Download/Download.ino b/examples/CloudStorage/Async/NoCallback/Download/Download.ino index 9d49609e..1a2bd3b0 100644 --- a/examples/CloudStorage/Async/NoCallback/Download/Download.ino +++ b/examples/CloudStorage/Async/NoCallback/Download/Download.ino @@ -86,7 +86,7 @@ void printResult(AsyncResult &aResult); #if defined(ENABLE_FS) void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/CloudStorage/Async/NoCallback/Upload/Upload.ino b/examples/CloudStorage/Async/NoCallback/Upload/Upload.ino index b0d00875..0aaa6d32 100644 --- a/examples/CloudStorage/Async/NoCallback/Upload/Upload.ino +++ b/examples/CloudStorage/Async/NoCallback/Upload/Upload.ino @@ -88,7 +88,7 @@ void printResult(AsyncResult &aResult); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/CloudStorage/Sync/Download/Download.ino b/examples/CloudStorage/Sync/Download/Download.ino index 6ab3877d..335bfee4 100644 --- a/examples/CloudStorage/Sync/Download/Download.ino +++ b/examples/CloudStorage/Sync/Download/Download.ino @@ -91,7 +91,7 @@ void printError(int code, const String &msg); #if defined(ENABLE_FS) void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/CloudStorage/Sync/Upload/Upload.ino b/examples/CloudStorage/Sync/Upload/Upload.ino index 88364dd7..fbd0ffde 100644 --- a/examples/CloudStorage/Sync/Upload/Upload.ino +++ b/examples/CloudStorage/Sync/Upload/Upload.ino @@ -93,7 +93,7 @@ void printError(int code, const String &msg); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/RealtimeDatabase/Async/Callback/BLOB/BLOB.ino b/examples/RealtimeDatabase/Async/Callback/BLOB/BLOB.ino index a63b08e3..8ffdebf0 100644 --- a/examples/RealtimeDatabase/Async/Callback/BLOB/BLOB.ino +++ b/examples/RealtimeDatabase/Async/Callback/BLOB/BLOB.ino @@ -81,8 +81,8 @@ RealtimeDatabase Database; uint8_t source[2048]; uint8_t dest[2048]; -BlobConfig upload_data(source, 2048); -BlobConfig download_data(dest, 2048); +BlobConfig upload_data(source, 2048); // Can be set later with upload_data.setBlob(source, 2048); +BlobConfig download_data(dest, 2048); // Can be set later with download_data.setBlob(dest, 2048); bool taskComplete = false; diff --git a/examples/RealtimeDatabase/Async/Callback/File/File.ino b/examples/RealtimeDatabase/Async/Callback/File/File.ino index d62e4216..f31dd32d 100644 --- a/examples/RealtimeDatabase/Async/Callback/File/File.ino +++ b/examples/RealtimeDatabase/Async/Callback/File/File.ino @@ -99,9 +99,9 @@ AsyncClient aClient(ssl_client, getNetwork(network)); RealtimeDatabase Database; #if defined(ENABLE_FS) -FileConfig upload_data("/upload.bin", fileCallback); +FileConfig upload_data("/upload.bin", fileCallback); // Can be set later with upload_data.setFile("/upload.bin", fileCallback); -FileConfig download_data("/download.bin", fileCallback); +FileConfig download_data("/download.bin", fileCallback); // Can be set later with download_data.setFile("/download.bin", fileCallback); #endif bool taskComplete = false; diff --git a/examples/RealtimeDatabase/Async/NoCallback/BLOB/BLOB.ino b/examples/RealtimeDatabase/Async/NoCallback/BLOB/BLOB.ino index d14c8b45..b386cebc 100644 --- a/examples/RealtimeDatabase/Async/NoCallback/BLOB/BLOB.ino +++ b/examples/RealtimeDatabase/Async/NoCallback/BLOB/BLOB.ino @@ -81,8 +81,8 @@ AsyncResult aResult_no_callback; uint8_t source[2048]; uint8_t dest[2048]; -BlobConfig upload_data(source, 2048); -BlobConfig download_data(dest, 2048); +BlobConfig upload_data(source, 2048); // Can be set later with upload_data.setBlob(source, 2048); +BlobConfig download_data(dest, 2048); // Can be set later with download_data.setBlob(dest, 2048); bool taskComplete = false; diff --git a/examples/RealtimeDatabase/Async/NoCallback/File/File.ino b/examples/RealtimeDatabase/Async/NoCallback/File/File.ino index 365f41c0..fbd15f29 100644 --- a/examples/RealtimeDatabase/Async/NoCallback/File/File.ino +++ b/examples/RealtimeDatabase/Async/NoCallback/File/File.ino @@ -99,9 +99,9 @@ RealtimeDatabase Database; AsyncResult aResult_no_callback; #if defined(ENABLE_FS) -FileConfig upload_data("/upload.bin", fileCallback); +FileConfig upload_data("/upload.bin", fileCallback); // Can be set later with upload_data.setFile("/upload.bin", fileCallback); -FileConfig download_data("/download.bin", fileCallback); +FileConfig download_data("/download.bin", fileCallback); // Can be set later with download_data.setFile("/download.bin", fileCallback); #endif bool taskComplete = false; diff --git a/examples/Storage/Async/Callback/Download/Download.ino b/examples/Storage/Async/Callback/Download/Download.ino index 280ccb13..6e0ee188 100644 --- a/examples/Storage/Async/Callback/Download/Download.ino +++ b/examples/Storage/Async/Callback/Download/Download.ino @@ -80,7 +80,7 @@ void printResult(AsyncResult &aResult); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/Storage/Async/Callback/Upload/Upload.ino b/examples/Storage/Async/Callback/Upload/Upload.ino index 5e75a3cc..6ad8b27a 100644 --- a/examples/Storage/Async/Callback/Upload/Upload.ino +++ b/examples/Storage/Async/Callback/Upload/Upload.ino @@ -80,7 +80,7 @@ void printResult(AsyncResult &aResult); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/Storage/Async/NoCallback/Download/Download.ino b/examples/Storage/Async/NoCallback/Download/Download.ino index c4762cd3..1941664c 100644 --- a/examples/Storage/Async/NoCallback/Download/Download.ino +++ b/examples/Storage/Async/NoCallback/Download/Download.ino @@ -77,7 +77,7 @@ void printResult(AsyncResult &aResult); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/Storage/Async/NoCallback/Upload/Upload.ino b/examples/Storage/Async/NoCallback/Upload/Upload.ino index 621c21dc..37c650b8 100644 --- a/examples/Storage/Async/NoCallback/Upload/Upload.ino +++ b/examples/Storage/Async/NoCallback/Upload/Upload.ino @@ -77,7 +77,7 @@ void printResult(AsyncResult &aResult); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/Storage/Sync/Download/Download.ino b/examples/Storage/Sync/Download/Download.ino index f91fe38a..1487f4c7 100644 --- a/examples/Storage/Sync/Download/Download.ino +++ b/examples/Storage/Sync/Download/Download.ino @@ -82,7 +82,7 @@ void printError(int code, const String &msg); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/examples/Storage/Sync/Upload/Upload.ino b/examples/Storage/Sync/Upload/Upload.ino index 07a51e10..ddcf2315 100644 --- a/examples/Storage/Sync/Upload/Upload.ino +++ b/examples/Storage/Sync/Upload/Upload.ino @@ -82,7 +82,7 @@ void printError(int code, const String &msg); void fileCallback(File &file, const char *filename, file_operating_mode mode); -FileConfig media_file("/media.mp4", fileCallback); +FileConfig media_file("/media.mp4", fileCallback); // Can be set later with media_file.setFile("/media.mp4", fileCallback); #endif diff --git a/keywords.txt b/keywords.txt index 841207cf..90012104 100644 --- a/keywords.txt +++ b/keywords.txt @@ -302,6 +302,8 @@ setJWTProcessor KEYWORD2 setSessionTimeout KEYWORD2 setOTAStorage KEYWORD2 setNetwork KEYWORD2 +setBlob KEYWORD2 +setFile KEYWORD2 ################### # Struct (KEYWORD3) diff --git a/library.json b/library.json index ad41bbd8..aa554c3f 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "FirebaseClient", - "version": "1.3.4", + "version": "1.3.5", "keywords": "communication, REST, esp32, esp8266, arduino", "description": "Async Firebase Client library for Arduino.", "repository": { diff --git a/library.properties b/library.properties index df1d5880..a5d09bab 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=FirebaseClient -version=1.3.4 +version=1.3.5 author=Mobizt diff --git a/resources/docs/file_config.md b/resources/docs/file_config.md index 4bdbf18a..54a2c1d3 100644 --- a/resources/docs/file_config.md +++ b/resources/docs/file_config.md @@ -17,11 +17,11 @@ class FileConfig ## Constructors -1. ### 🔹 FileConfig(const String &filename, FileConfigCallback cb) +1. ### 🔹 FileConfig(const String &filename = "", FileConfigCallback cb = NULL) ```cpp - FileConfig(const String &filename, FileConfigCallback cb) + FileConfig(const String &filename = "", FileConfigCallback cb = NULL) ``` **Params:** @@ -34,7 +34,23 @@ class FileConfig ## Functions -1. ### 🔹 void clear() +1. ### 🔹 void setFile(const String &filename, FileConfigCallback cb) + + Set the File config. + + ```cpp + void setFile(const String &filename, FileConfigCallback cb) + ``` + + **Params:** + + - `filename` - The file name of file to be read and write. + + - `cb` - The FileConfigCallback function that accepts File object, file name and `file_operating_mode` to be processed. + + The `file_operating_mode` enums are included `file_mode_open_read`, `file_mode_open_write`, `file_mode_open_append`, and `file_mode_remove`. + +2. ### 🔹 void clear() Clear the internal data. @@ -42,7 +58,7 @@ class FileConfig void clear() ``` -2. ### 🔹 FileConfig &setFilename(const String &filename) +3. ### 🔹 FileConfig &setFilename(const String &filename) Set the file name. @@ -58,7 +74,7 @@ class FileConfig - `FileConfig &` - The reference to the `FileConfig` itself. -3. ### 🔹 FileConfig &setFilename(const String &filename) +4. ### 🔹 FileConfig &setFilename(const String &filename) Set the file name. @@ -77,7 +93,7 @@ class FileConfig - `FileConfig &` - The reference to the `FileConfig` itself. -4. ### 🔹 file_config_data &get() +5. ### 🔹 file_config_data &get() Get the reference to the internal `file_config_data`. @@ -108,8 +124,6 @@ class BlobConfig 1. ### 🔹 BlobConfig(uint8_t *data = nullptr, size_t size = 0) - In the networkConnectionCB function, the complete operations for the carier (network) and internet connection should be performed - ```cpp BlobConfig(uint8_t *data = nullptr, size_t size = 0) ``` @@ -121,7 +135,20 @@ class BlobConfig ## Functions -1. ### 🔹 void clear() +1. ### 🔹 void setBlob(uint8_t *data, size_t size) + + Set the BLOB config. + + ```cpp + void setBlob(uint8_t *data, size_t size) + ``` + + **Params:** + + - `data` - The pointer to the uint8_t data array. + - `size` - The size of data in bytes. + +2. ### 🔹 void clear() Clear the internal data. @@ -129,7 +156,7 @@ class BlobConfig void clear() ``` -2. ### 🔹 uint8_t *blob() const +3. ### 🔹 uint8_t *blob() const Get the pointer to the internal BLOB data. @@ -141,7 +168,7 @@ class BlobConfig - `uint8_t *` - The pointer to uint8_t data array. -3. ### 🔹 size_t size() +4. ### 🔹 size_t size() Get the size of data. @@ -153,7 +180,7 @@ class BlobConfig - `size_t` - The size of data in bytes. -4. ### 🔹 file_config_data &getData() +5. ### 🔹 file_config_data &getData() Get the reference to the internal file_config_data. diff --git a/src/core/Core.h b/src/core/Core.h index 10030351..a083f3db 100644 --- a/src/core/Core.h +++ b/src/core/Core.h @@ -7,7 +7,7 @@ #undef FIREBASE_CLIENT_VERSION #endif -#define FIREBASE_CLIENT_VERSION "1.3.4" +#define FIREBASE_CLIENT_VERSION "1.3.5" static void sys_idle() { diff --git a/src/core/FileConfig.h b/src/core/FileConfig.h index 55cd84d3..1351bc11 100644 --- a/src/core/FileConfig.h +++ b/src/core/FileConfig.h @@ -1,5 +1,5 @@ /** - * Created June 12, 2024 + * Created July 11, 2024 * * The MIT License (MIT) * Copyright (c) 2024 K. Suwatchai (Mobizt) @@ -468,14 +468,28 @@ class FileConfig * * The file_operating_mode enums are included file_mode_open_read, file_mode_open_write, file_mode_open_append, and file_mode_remove. */ - explicit FileConfig(const String &filename, FileConfigCallback cb) + explicit FileConfig(const String &filename = "", FileConfigCallback cb = NULL) { setFile(filename, cb); } + + ~FileConfig() {} + + /** + * Set the File config. + * + * @param filename The file name of file to be read and write. + * @param cb The FileConfigCallback function that accepts File object, file name and file_operating_mode to be processed. + * + * The file_operating_mode enums are included file_mode_open_read, file_mode_open_write, file_mode_open_append, and file_mode_remove. + */ + void setFile(const String &filename, FileConfigCallback cb) { clear(); - setFilename(filename); - setCallback(cb); - data.initialized = true; + if (cb && filename.length()) + { + setFilename(filename); + setCallback(cb); + data.initialized = true; + } } - ~FileConfig() {} /** * Clear the internal data. @@ -492,6 +506,8 @@ class FileConfig if (filename.length() > 0 && filename[0] != '/') data.filename += '/'; data.filename += filename; + if (data.cb && data.filename.length()) + data.initialized = true; return *this; } @@ -505,6 +521,8 @@ class FileConfig FileConfig &setCallback(FileConfigCallback cb) { data.cb = cb; + if (data.cb && data.filename.length()) + data.initialized = true; return *this; } @@ -543,7 +561,17 @@ class BlobConfig * @param data The pointer to the uint8_t data array. * @param size The size of data in bytes. */ - explicit BlobConfig(uint8_t *data = nullptr, size_t size = 0) + explicit BlobConfig(uint8_t *data = nullptr, size_t size = 0) { setBlob(data, size); } + + ~BlobConfig() {} + + /** + * Set the BLOB config. + * + * @param data The pointer to the uint8_t data array. + * @param size The size of data in bytes. + */ + void setBlob(uint8_t *data, size_t size) { clear(); if (data && size > 0) @@ -555,7 +583,6 @@ class BlobConfig this->data.initialized = true; } - ~BlobConfig() {} /** * Clear the internal data. @@ -564,21 +591,21 @@ class BlobConfig /** * Get the pointer to the internal BLOB data. - * + * * @return uint8_t* The pointer to uint8_t data array. */ uint8_t *blob() const { return data.data; } /** * Get the data size. - * + * * @return size_t The size of data in bytes. */ size_t size() const { return data.data_size; } /** * Get the reference to the internal file_config_data. - * + * * @return file_config_data & The reference to the internal file_config_data. */ file_config_data &getData() { return data; } @@ -589,7 +616,7 @@ class BlobConfig /** * The static function to get the reference of file_config_data from FileConfig. - * + * * @return file_config_data & The reference to the internal file_config_data. */ template @@ -597,7 +624,7 @@ static file_config_data &getFile(T &file) { return file.get(); } /** * The static function to get the reference of file_config_data from BlobConfig. - * + * * @return file_config_data & The reference to the internal file_config_data. */ template