Skip to content

Commit

Permalink
Fixcompilation error in v1.0.7.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Apr 6, 2024
1 parent dcdc906 commit 5081b29
Show file tree
Hide file tree
Showing 75 changed files with 149 additions and 9,938 deletions.
51 changes: 40 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ This library is [Firebase-ESP-Client](https://github.com/mobizt/Firebase-ESP-Cli

- [Send and Read Timeouts for Sync and Async Tasks](#send-and-read-timeouts-for-sync-and-async-tasks)

- [The Static Async Result Instances Required for Async Operation](#the-static-async-result-instances-required-for-async-operation)
- [Async Result](#async-result)

- [Dangling Pointers Prevention](#dangling-pointers-prevention)
- [App Events](#app-events)

- [Result Data](#result-data)

- [App Initialization](#app-initialization)

Expand Down Expand Up @@ -380,16 +382,17 @@ The SSL Client is a kind of sync or blocking Client that takes time during estab

The async SSL client can be assigned to the async client class constructor but currently experimental.

The async operation can be cancelled and removed from the queue by calling `AsyncClientClass` member functions, i.e. `stopAsync()` for currently processed task or `stopAsync(true)` for stopping all tasks.

### Send and Read Timeouts for Sync and Async Tasks

The default send and read timeouts for async task are 30 seconds and cannot be changed.

For sync task, the timeout in seconds can be set via the `AsyncClientClass` member functions, `setSyncSendTimeout` and `setSyncReadTimeout`.

### Async Result

### The Static Async Result Instances Required for Async Operation

Library provided the class object called AsyncResult that keeps the server response data, debug and error information.
Library provides the class object called `AsyncResult` that keeps the server response data, debug and error information.

There are two sources of async result in this library:

Expand All @@ -411,19 +414,44 @@ From source 1, the async result (`aResult`) shall be defined globally to use in

From source 2, the async client (`aClient`) shall be defined globally to use in async application too to make sure the instance of async result was existed or valid while running the sync task.

If async result was destroyed (destructed or not existed) before it was used by async task handler, the danglig pointer problem will be occurred.
The async result from source 2 can be accessed from the async result callback.

Note that, the async client object used in authentication task shoul be defined globally as it is async task.

### Dangling Pointers Prevention
The aync result provides two types of information, `app events` and `result data`.

### App Events

The app event information of authentication task handler can be obtained from `aResult.appEvent().code()` and `aResult.appEvent().message()` respectively.

Note that `aResult` is the async result object (`AsyncResult`) in this case.

The following event code (`firebase_auth_event_type`), `auth_event_uninitialized`, `auth_event_initializing`, `auth_event_signup`, `auth_event_send_verify_email`, `auth_event_delete_user`, `auth_event_reset_password`, `auth_event_token_signing`, `auth_event_authenticating`, `auth_event_auth_request_sent`, `auth_event_auth_response_received`, `auth_event_ready` and `auth_event_error` are available.

The following event strings `"undefined"`, `"initializing"`, `"sign up"`, `"send verification email"`, `"delete user"`, `"reset password"`, `"token signing"`, `"authenticating"`, `"auth request sent"`, `"auth response received"`, `"ready"` and `"error"` are available.

### Result Data

The async result, async client and Firebase main app are the managed classes that have dangling pointer prevention feature.
The result data can be obtained from `AsyncResult` object via `aResult.payload()`, `aResult.available()`, `aResult.path()`, `aResult.etag()`, `RTDB.isStream()`, `RTDB.event()`, `RTDB.dataPath()`, `RTDB.type()` and `RTDB.name()` where `RTDB` is the `RealtimeDatabaseResult `object that obtained from `aResult.to<RealtimeDatabaseResult>()`.

The reference to these deleted or destructed objects will be blocked in all Firebase main app (FirebaseApp) and services apps (Realtime database, Firestore database, Cloud Messaging, Cloud Functions, Storage and Google Cloud Storage) to prevent device freeze or crashed due to dangling pointer.
The function `aResult.payload()` returns server serponse payload.

The exception is the deleted or destructed SSL client that assigned to async client still cause the dangling pointer issue.
The function `aResult.available()` returns the size of data that is ready to read.

The function `aResult.path()` returns the resource path that the request was sent.

The function `aResult.etag()` returns the ETag from server response header.

The function `RTDB.name()` returns the name (random UID) of node that will be creaated after calling push.

The function `RTDB.type()` returns the following realtime data type enum.

`realtime_database_data_type_undefined` (-1), `realtime_database_data_type_null` (0), `realtime_database_data_type_integer` (1), `realtime_database_data_type_float` (2), `realtime_database_data_type_double` (3), `realtime_database_data_type_boolean` (4), `realtime_database_data_type_string` (5), `realtime_database_data_type_json` (6), and `realtime_database_data_type_array` (7).

The `RTDB.dataPath()` and `RTDB.event()` are the Realtime database node path that data has changed and type of event in server-sent events (stream) mode.

The server response payload in `AsyncResult` can be converted to the the values e.g. boolean, integer, float, double and string via `RTDB.to<T>()`.

Then the SSL client should be defined in the same usage scope as async client to avoid the problem.

## App Initialization

Expand Down Expand Up @@ -629,6 +657,7 @@ LegacyToken legacy_token(<database_secret>);
`<database_secret>` The Realtime database secret key.
### Working with Filesystems and BLOB
The file config class ([FileConfig](examples/App/AppInitialization/SaveAndLoad/)) will be used to hold the SD/Flash file information and the file operation callback when file upload or download is required.
Expand Down
159 changes: 1 addition & 158 deletions examples/CloudStorage/Delete/Delete.ino
Original file line number Diff line number Diff line change
@@ -1,77 +1,4 @@
// Created by K. Suwatchai (Mobizt)
// Email: [email protected]
// Github: https://github.com/mobizt/FirebaseClient
// Copyright (c) 2024 mobizt

/**
* PRE REQUISITE
* =============
*
* IAM owner permission required for service account,
* https://github.com/mobizt/Firebase-ESP-Client#iam-permission-and-api-enable
*/

/**
* APP INITIALIZATION
* ==================
*
* This library provides the APIs covers the different types of authentication and services.
*
* The FirebaseApp class was introduced as user authentication provider which provides the credentials data
* used for accessing the Firebase services.
*
* The Database, Firestore, Functions, Messaging, Storage and Cloud Storage apps provided the functions based on
* the specific Firebase services which take the auth credentials data from FirebaseApp.
*
* The FirebaseApp should be initialized first before use via static function initializeApp.
*
* SYNTAXES:
*
* initializeApp(<AsyncClient>, <FirebaseApp>, <user_auth_data>);
*
* The AsyncClient stores the user, server and network data which can be initialized as.
*
* WiFiClientSecure ssl_client;
* DefaultNetwork network;
* AsyncClient aClient(ssl_client, getNetwork(network));
*
* The FirebaseApp manage and stores the authentication data;
*
* The user_auth_data store the user credentials which can be obtained from one of following Auth classes.
* UserAuth, ServiceAuth, CustomAuth, IDToken, AccessToken, CustomToken, LegacyToken and NoAuth via static function getAuth.
*
* SYNTAX:
*
* UserAuth user_auth(<api_key>, <user_email>, <user_password>, <expire>);
*
* <api_key> - API key can be obtained from Firebase console > Project Overview > Project settings.
* <user_email> - The user Email that in the project.
* <user_password> - The user password in the project.
* <expire> - The expiry period in seconds (less than or equal to 3600).
*
* To use other network interfaces, network data from one of the following Network classes
* can be assigned.
*
* DefaultNetwork, GenericNetwork, EthernetNetwork and GSMNetwork.
*
* The network data (network_config_data) can be obtained from these Network classes via static function getNetwork.
*
* Please see examples/App/NetworkInterfaces for the usage guidelines.
*
* The auth credential data can be set to Services App e.g. Database to initialize via function getApp.
*
* SYNTAX:
*
* app.getApp<T>(<services_app>);
*
* Deallocation of FirebaseApp causes these services apps uninitialized and cannot be used.
*
*/

/**
* DELETE OBJECT FUNCTIONS
* =======================
*
* SYNTAXES:
*
* cstorage.deleteObject(<AsyncClient>, <FirebaseStorage::Parent>, <GoogleCloudStorage::DeleteOptions>);
Expand All @@ -93,91 +20,7 @@
*
* The uid can later get from AsyncResult object of AsyncResultCallback function via aResult.uid().
*
*/

/**
* ASYNC QUEUE
* ===========
*
* Each sync and async requests data consume memory up to 1k. When many async operations are added to queue (FIFO), the memory usage was increased.
*
* Each AsyncClient handles this queue separately. Then in order to limit the memory used for each AsyncClient,
* this library allows 10 async operations (called slots) can be stored in the queue at a time.
*
* The maximum queue size can be set via the build flag FIREBASE_ASYNC_QUEUE_LIMIT or macro in
* src/Config.h or created your own config in src/UserConfig.h.
*
* If the authentication async operation was required, it will insert to the first slot of the queue.
*
* If the sync operation was called, it will insert to the first slot in the queue too but after the authentication task slot.
*
* When async Get operation in SSE mode (HTTP Streaming) was currently stored in queue, the new sync and async operations will be inserted before
* the async SSE (HTTP Streaming) slot.
*
* When the async operation queue is full, the new sync and async operations will be cancelled.
*
* The finished and time out operating slot will be removed from the queue unless the async SSE and allow the vacant slot for the new async operation.
*
* The async SSE operation will run continuously and repeatedly as long as the FirebaseApp and the services app
* (Database, Firestore, Messaging, Functions, Storage and CloudStorage) objects was run in the loop via app.loop() or database.loop().
*
* STOP QUEUE
* ===========
*
* SYNTAX:
*
* The async operation will be cancelled and remove from the queue by calling thes functions.
*
* asyncClient.stopAsync() - stop the last async operation in the queue.
*
* asyncClient.stopAsync(true) - stop all async operation in the queue.
*
* asyncClient.stopAsync("xxxx") - stop the async operation in the queue that has the async result UID xxxx.
*
* ASYNC CLIENT
* ============
*
* The async client stores the async operating data in its queue and holds the pointer of SSL Client that assigned with it.
*
* The SSL Client should be existed in the AsyncClient usage scope in case of sync or should defined as global object for async usage.
*
* The SSL Client should not be shared among various AsyncClients because of interferences in async operations.
*
* Only one SSL Client should be assigned to or used with only one AsyncClient.
*
* SSL Client can force to stop by user or calling stop() from asyncClient.
*
* SYNTAX:
*
* asyncClient.stop() - stop the SSL Client to terminate the server connection.
*
*
* THE STATIC ASYNC RESULT REQUIRED FOR ASYNC OPERATION
* ====================================================
*
* Library provided the class object called AsyncResult that keeps the server response data, debug and error information.
*
* There are two sources of async result in this library:
*
* 1. From user provided with async application (function).
*
* For example:
*
* `Database.get(aClient, "/test/int", options, aResult);`
*
* 2. From dynamic allocation in the async client.
*
* For example:
*
* `Database.get(aClient, "/test/int", options, asyncCB);`
*
* From source 1, the async result (`aResult`) shall be defined globally to use in async application because of the static data is needed for use while running the sync task.
*
* From source 2, the async client (`aClient`) shall be defined globally to use in async application too to make sure the instance of async result was existed or valid while running the sync task.
*
* If async result was destroyed (destructed or not existed) before it was used by async task handler, the danglig pointer problem will be occurred.
*
* Note that, the async client object used in authentication task shoul be defined globally as it is async task.
* The complete usage guidelines, please visit https://github.com/mobizt/FirebaseClient
*/

#include <Arduino.h>
Expand Down
Loading

0 comments on commit 5081b29

Please sign in to comment.