From 6072f19af9da623a28936ef2a3934f29172947cb Mon Sep 17 00:00:00 2001 From: Kevin Lee Date: Wed, 8 Feb 2017 22:39:40 -0700 Subject: [PATCH 01/68] Fixed a code comment --- src/Firebase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index 95cbecc8..b3d72d32 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -174,7 +174,7 @@ FirebasePush::FirebasePush(const std::string& host, const std::string& auth, } } -// FirebasePush +// FirebaseRemove FirebaseRemove::FirebaseRemove(const std::string& host, const std::string& auth, const std::string& path, FirebaseHttpClient* http) From 53aaae103a1f6d8b6916392897b8465aa79ebe91 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Mon, 10 Apr 2017 01:59:07 -0700 Subject: [PATCH 02/68] FirebaseHttpClient: add forceReuse Fixes #230 --- src/FirebaseHttpClient_Esp8266.cpp | 36 ++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/FirebaseHttpClient_Esp8266.cpp b/src/FirebaseHttpClient_Esp8266.cpp index 7643db1e..74be1f1f 100644 --- a/src/FirebaseHttpClient_Esp8266.cpp +++ b/src/FirebaseHttpClient_Esp8266.cpp @@ -15,12 +15,44 @@ #define USE_ESP_ARDUINO_CORE_2_0_0 #endif +// Firebase now returns `Connection: close` after REST streaming redirection. +// +// Override the built-in ESP8266HTTPClient to *not* close the +// connection if forceReuse it set to `true`. +class ForceReuseHTTPClient : public HTTPClient { +public: + void end() { + if(connected()) { + if(_tcp->available() > 0) { + DEBUG_HTTPCLIENT("[HTTP-Client][end] still data in buffer (%d), clean up.\n", _tcp->available()); + while(_tcp->available() > 0) { + _tcp->read(); + } + } + if(_reuse && (_canReuse || _forceReuse)) { + DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n"); + } else { + DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp stop\n"); + _tcp->stop(); + } + } else { + DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp is closed\n"); + } + } + void forceReuse(bool forceReuse) { + _forceReuse = forceReuse; + } +protected: + bool _forceReuse = false; +}; + class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { public: FirebaseHttpClientEsp8266() {} - void setReuseConnection(bool reuse) override { + void setReuseConnection(bool reuse) override { http_.setReuse(reuse); + http_.forceReuse(reuse); } void begin(const std::string& url) override { @@ -64,7 +96,7 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { } private: - HTTPClient http_; + ForceReuseHTTPClient http_; }; FirebaseHttpClient* FirebaseHttpClient::create() { From 3a68e6c5a55250db479d05385f2a100d5a6e78ef Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Mon, 10 Apr 2017 02:03:49 -0700 Subject: [PATCH 03/68] FirebaseHttpClient_Esp8266: fix trailing space --- src/FirebaseHttpClient_Esp8266.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseHttpClient_Esp8266.cpp b/src/FirebaseHttpClient_Esp8266.cpp index 74be1f1f..837b6ab1 100644 --- a/src/FirebaseHttpClient_Esp8266.cpp +++ b/src/FirebaseHttpClient_Esp8266.cpp @@ -50,7 +50,7 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { public: FirebaseHttpClientEsp8266() {} - void setReuseConnection(bool reuse) override { + void setReuseConnection(bool reuse) override { http_.setReuse(reuse); http_.forceReuse(reuse); } From 1d1830e4c5acd887998507593c569dcc3c7ae863 Mon Sep 17 00:00:00 2001 From: salqadri Date: Mon, 24 Apr 2017 17:37:58 -0700 Subject: [PATCH 04/68] The signature for Firebase seems to have changed --- src/FirebaseHttpClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 106538e6..951e7ebf 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -38,6 +38,6 @@ class FirebaseHttpClient { }; static const char kFirebaseFingerprint[] = - "7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A"; + "9A E1 A3 B7 88 E0 C9 A3 3F 13 72 4E B5 CB C7 27 41 B2 0F 6A"; #endif // FIREBASE_HTTP_CLIENT_H From a23fb4e0a15e554e401150e25fc742f6a302b4c7 Mon Sep 17 00:00:00 2001 From: Raemond Bergstrom-Wood Date: Fri, 18 Aug 2017 09:48:43 -0700 Subject: [PATCH 05/68] updated the firebase sha1 fingerprint. --- src/FirebaseHttpClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 951e7ebf..055699c7 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -38,6 +38,6 @@ class FirebaseHttpClient { }; static const char kFirebaseFingerprint[] = - "9A E1 A3 B7 88 E0 C9 A3 3F 13 72 4E B5 CB C7 27 41 B2 0F 6A"; + "B8 4F 40 70 0C 63 90 E0 07 E8 7D BD B4 11 D0 4A EA 9C 90 F6"; #endif // FIREBASE_HTTP_CLIENT_H From df523c084abb599234f332d8e45aec824d061c61 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Fri, 27 Oct 2017 21:40:57 +0900 Subject: [PATCH 06/68] reuse HTTPClient::end --- src/FirebaseHttpClient_Esp8266.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/FirebaseHttpClient_Esp8266.cpp b/src/FirebaseHttpClient_Esp8266.cpp index 837b6ab1..92dbe92d 100644 --- a/src/FirebaseHttpClient_Esp8266.cpp +++ b/src/FirebaseHttpClient_Esp8266.cpp @@ -22,22 +22,10 @@ class ForceReuseHTTPClient : public HTTPClient { public: void end() { - if(connected()) { - if(_tcp->available() > 0) { - DEBUG_HTTPCLIENT("[HTTP-Client][end] still data in buffer (%d), clean up.\n", _tcp->available()); - while(_tcp->available() > 0) { - _tcp->read(); - } - } - if(_reuse && (_canReuse || _forceReuse)) { - DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n"); - } else { - DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp stop\n"); - _tcp->stop(); - } - } else { - DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp is closed\n"); - } + if (_forceReuse) { + _canReuse = true; + } + HTTPClient::end(); } void forceReuse(bool forceReuse) { _forceReuse = forceReuse; From d62b9cbe2699d92ed7c7bc5cc3fe1f8e562f3c5a Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Thu, 2 Nov 2017 17:11:41 +0900 Subject: [PATCH 07/68] FirebaseArduino: allow mixing stream and non-stream commands With this change non-streaming operation will stop the stream and reuse the underlying http client. Call FirebaseArduino::stream again in order to reuse the stream. Fixes: #48 --- src/Firebase.cpp | 17 ++++++++++++++++- src/FirebaseArduino.cpp | 3 +++ src/FirebaseArduino.h | 3 --- src/FirebaseHttpClient.h | 11 +++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index b3d72d32..d00787d1 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -92,6 +92,15 @@ FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth, const char* method, const std::string& path, const std::string& data, FirebaseHttpClient* http) : http_(http) { std::string path_with_auth = makeFirebaseURL(path, auth); + if ((method == "STREAM") && (path == http->getStreamingPath())){ + // already streaming requested path. + return; + } + if (http_->isStreaming()) { + // closing streaming connection. + http_->setReuseConnection(false); + http_->end(); + } http_->setReuseConnection(true); http_->begin(host, path_with_auth); @@ -130,11 +139,14 @@ FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth, // if not streaming. if (!followRedirect) { response_ = http_->getString(); + http_->setStreaming(""); + } else { + http_->setStreaming(path); } } FirebaseCall::~FirebaseCall() { - if (http_) { + if (http_ && !http_->isStreaming()) { http_->end(); } } @@ -189,6 +201,9 @@ FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth, } bool FirebaseStream::available() { + if (http_->getStreamPtr() == nullptr) { + return false; + } return http_->getStreamPtr()->available(); } diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index bdf5105c..44dc056f 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -131,6 +131,9 @@ void FirebaseArduino::stream(const String& path) { } bool FirebaseArduino::available() { + if (http_->getStreamPtr() == nullptr) { + return false; + } return http_->getStreamPtr()->available(); } diff --git a/src/FirebaseArduino.h b/src/FirebaseArduino.h index a69f4e16..a0bcca27 100644 --- a/src/FirebaseArduino.h +++ b/src/FirebaseArduino.h @@ -189,9 +189,6 @@ class FirebaseArduino { * You should check success() after calling. * This changes the state of this object. Once this is called you may start * monitoring available() and calling readEvent() to get new events. - * WARNING: Currently you cannot make another call while the stream is - * running, otherwise you will crash due to memory issues. See: - * https://github.com/googlesamples/firebase-arduino/issues/48 * \param path The path inside of your db to the node you wish to monitor. */ void stream(const String& path); diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 055699c7..1752ba2f 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -33,7 +33,18 @@ class FirebaseHttpClient { virtual std::string errorToString(int error_code) = 0; + bool isStreaming() const { + return _streaming != ""; + } + std::string getStreamingPath() const { + return _streaming; + } + void setStreaming(const std::string& path) { + _streaming = path; + } protected: + std::string _streaming = ""; + static const uint16_t kFirebasePort = 443; }; From d7aebba787c4793360224e353f4881be3d701630 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Mon, 6 Nov 2017 21:44:25 -0500 Subject: [PATCH 08/68] Add ability to detect null string (happens when nodes gets deleted) --- src/FirebaseObject.cpp | 7 ++++++- src/FirebaseObject.h | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/FirebaseObject.cpp b/src/FirebaseObject.cpp index 44d07f00..68b0f1b6 100644 --- a/src/FirebaseObject.cpp +++ b/src/FirebaseObject.cpp @@ -54,13 +54,18 @@ float FirebaseObject::getFloat(const String& path) const { String FirebaseObject::getString(const String& path) const { JsonVariant variant = getJsonVariant(path); - if (!variant.is()) { + if (!variant.is() || isNullString(path)) { error_ = "failed to convert to string"; return ""; } return static_cast(variant); } +bool FirebaseObject::isNullString(const String& path) const { + JsonVariant variant = getJsonVariant(path); + return variant.is() && variant.asString() == NULL; +} + JsonVariant FirebaseObject::getJsonVariant(const String& path) const { String key(path); char* start = &key[0]; diff --git a/src/FirebaseObject.h b/src/FirebaseObject.h index 2e1aae44..db23a373 100644 --- a/src/FirebaseObject.h +++ b/src/FirebaseObject.h @@ -43,6 +43,14 @@ class FirebaseObject { */ bool getBool(const String& path = "") const; + /** + * Returns true if specified path is NULL string. + * Useful to detect tree deletions. + * \param optional path in the JSON object. + * \return result as a bool. + */ + bool isNullString(const String& path = "") const; + /** * Return the value as an int. * \param optional path in the JSON object. From d2138bf3e4317e0d6edc070a2e36369fa80b6b9f Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Tue, 7 Nov 2017 00:09:53 -0500 Subject: [PATCH 09/68] Crazy update to use shared_ptr and get rid of old ArduinoJson library and use latest one. --- src/Firebase.cpp | 56 +-- src/Firebase.h | 29 +- src/FirebaseArduino.cpp | 18 +- src/FirebaseArduino.h | 2 +- src/FirebaseCloudMessaging.cpp | 2 +- src/FirebaseCloudMessaging.h | 3 +- src/FirebaseObject.cpp | 5 +- src/FirebaseObject.h | 80 ++-- src/third-party/README.md | 2 - .../arduino-json-5.6.7/ArduinoJson.h | 8 - .../arduino-json-5.6.7/CHANGELOG.md | 323 --------------- src/third-party/arduino-json-5.6.7/LICENSE.md | 10 - src/third-party/arduino-json-5.6.7/README.md | 128 ------ .../IndentedPrintExample.ino | 35 -- .../JsonGeneratorExample.ino | 70 ---- .../JsonHttpClient/JsonHttpClient.ino | 195 --------- .../JsonParserExample/JsonParserExample.ino | 67 ---- .../examples/JsonServer/JsonServer.ino | 74 ---- .../examples/JsonUdpBeacon/JsonUdpBeacon.ino | 55 --- .../arduino-json-5.6.7/include/ArduinoJson.h | 9 - .../include/ArduinoJson.hpp | 22 - .../include/ArduinoJson/Configuration.hpp | 89 ----- .../include/ArduinoJson/DynamicJsonBuffer.hpp | 18 - .../ArduinoJson/Internals/BlockJsonBuffer.hpp | 115 ------ .../ArduinoJson/Internals/Comments.hpp | 56 --- .../ArduinoJson/Internals/DummyPrint.hpp | 21 - .../Internals/DynamicStringBuilder.hpp | 33 -- .../ArduinoJson/Internals/Encoding.hpp | 42 -- .../ArduinoJson/Internals/IndentedPrint.hpp | 65 --- .../Internals/JsonBufferAllocated.hpp | 25 -- .../ArduinoJson/Internals/JsonFloat.hpp | 21 - .../ArduinoJson/Internals/JsonInteger.hpp | 26 -- .../ArduinoJson/Internals/JsonParser.hpp | 66 --- .../ArduinoJson/Internals/JsonParser.ipp | 191 --------- .../ArduinoJson/Internals/JsonPrintable.hpp | 100 ----- .../ArduinoJson/Internals/JsonSerializer.hpp | 33 -- .../ArduinoJson/Internals/JsonSerializer.ipp | 101 ----- .../ArduinoJson/Internals/JsonVariantAs.hpp | 45 --- .../Internals/JsonVariantContent.hpp | 30 -- .../ArduinoJson/Internals/JsonVariantType.hpp | 39 -- .../ArduinoJson/Internals/JsonWriter.hpp | 184 --------- .../include/ArduinoJson/Internals/List.hpp | 94 ----- .../Internals/ListConstIterator.hpp | 41 -- .../ArduinoJson/Internals/ListIterator.hpp | 44 -- .../ArduinoJson/Internals/ListNode.hpp | 27 -- .../include/ArduinoJson/Internals/Parse.hpp | 66 --- .../ArduinoJson/Internals/Prettyfier.hpp | 130 ------ .../ArduinoJson/Internals/ReferenceType.hpp | 35 -- .../Internals/StaticStringBuilder.hpp | 37 -- .../Internals/StreamPrintAdapter.hpp | 39 -- .../include/ArduinoJson/JsonArray.hpp | 251 ------------ .../include/ArduinoJson/JsonArray.ipp | 80 ---- .../ArduinoJson/JsonArraySubscript.hpp | 94 ----- .../include/ArduinoJson/JsonBuffer.hpp | 163 -------- .../include/ArduinoJson/JsonBuffer.ipp | 46 --- .../include/ArduinoJson/JsonObject.hpp | 182 --------- .../include/ArduinoJson/JsonObject.ipp | 68 ---- .../include/ArduinoJson/JsonObjectKey.hpp | 27 -- .../ArduinoJson/JsonObjectSubscript.hpp | 123 ------ .../include/ArduinoJson/JsonPair.hpp | 20 - .../include/ArduinoJson/JsonVariant.hpp | 376 ------------------ .../include/ArduinoJson/JsonVariant.ipp | 142 ------- .../include/ArduinoJson/JsonVariantBase.hpp | 150 ------- .../ArduinoJson/Polyfills/attributes.hpp | 16 - .../include/ArduinoJson/Polyfills/math.hpp | 111 ------ .../ArduinoJson/Polyfills/normalize.hpp | 47 --- .../include/ArduinoJson/Print.hpp | 44 -- .../include/ArduinoJson/RawJson.hpp | 21 - .../include/ArduinoJson/StaticJsonBuffer.hpp | 58 --- .../include/ArduinoJson/String.hpp | 24 -- .../ArduinoJson/TypeTraits/EnableIf.hpp | 22 - .../TypeTraits/IsFloatingPoint.hpp | 21 - .../ArduinoJson/TypeTraits/IsIntegral.hpp | 26 -- .../ArduinoJson/TypeTraits/IsReference.hpp | 24 -- .../include/ArduinoJson/TypeTraits/IsSame.hpp | 24 -- .../TypeTraits/IsSignedIntegral.hpp | 33 -- .../TypeTraits/IsUnsignedIntegral.hpp | 33 -- .../ArduinoJson/TypeTraits/RemoveConst.hpp | 23 -- .../TypeTraits/RemoveReference.hpp | 23 -- .../arduino-json-5.6.7/keywords.txt | 14 - .../arduino-json-5.6.7/library.properties | 9 - 81 files changed, 85 insertions(+), 5216 deletions(-) delete mode 100644 src/third-party/README.md delete mode 100644 src/third-party/arduino-json-5.6.7/ArduinoJson.h delete mode 100644 src/third-party/arduino-json-5.6.7/CHANGELOG.md delete mode 100644 src/third-party/arduino-json-5.6.7/LICENSE.md delete mode 100644 src/third-party/arduino-json-5.6.7/README.md delete mode 100644 src/third-party/arduino-json-5.6.7/examples/IndentedPrintExample/IndentedPrintExample.ino delete mode 100644 src/third-party/arduino-json-5.6.7/examples/JsonGeneratorExample/JsonGeneratorExample.ino delete mode 100644 src/third-party/arduino-json-5.6.7/examples/JsonHttpClient/JsonHttpClient.ino delete mode 100644 src/third-party/arduino-json-5.6.7/examples/JsonParserExample/JsonParserExample.ino delete mode 100644 src/third-party/arduino-json-5.6.7/examples/JsonServer/JsonServer.ino delete mode 100644 src/third-party/arduino-json-5.6.7/examples/JsonUdpBeacon/JsonUdpBeacon.ino delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson.h delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Configuration.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/DynamicJsonBuffer.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/BlockJsonBuffer.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Comments.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DummyPrint.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DynamicStringBuilder.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Encoding.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/IndentedPrint.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonBufferAllocated.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonFloat.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonInteger.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.ipp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonPrintable.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.ipp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantAs.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantContent.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantType.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonWriter.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/List.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListConstIterator.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListIterator.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListNode.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Parse.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Prettyfier.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ReferenceType.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StaticStringBuilder.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StreamPrintAdapter.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.ipp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArraySubscript.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.ipp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.ipp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectKey.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectSubscript.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonPair.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.ipp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariantBase.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/attributes.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/math.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/normalize.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/Print.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/RawJson.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/StaticJsonBuffer.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/String.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/EnableIf.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsFloatingPoint.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsIntegral.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsReference.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSame.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSignedIntegral.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveConst.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveReference.hpp delete mode 100644 src/third-party/arduino-json-5.6.7/keywords.txt delete mode 100644 src/third-party/arduino-json-5.6.7/library.properties diff --git a/src/Firebase.cpp b/src/Firebase.cpp index b3d72d32..9975f3f8 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -16,6 +16,7 @@ #include "Firebase.h" using std::unique_ptr; +using std::shared_ptr; namespace { std::string makeFirebaseURL(const std::string& path, const std::string& auth) { @@ -42,55 +43,30 @@ const std::string& Firebase::auth() const { } FirebaseGet Firebase::get(const std::string& path) { - return FirebaseGet(host_, auth_, path, http_.get()); -} - -unique_ptr Firebase::getPtr(const std::string& path) { - return unique_ptr(new FirebaseGet(host_, auth_, path, http_.get())); + return FirebaseGet(host_, auth_, path, http_); } FirebaseSet Firebase::set(const std::string& path, const std::string& value) { - return FirebaseSet(host_, auth_, path, value, http_.get()); -} - -unique_ptr Firebase::setPtr(const std::string& path, - const std::string& value) { - return unique_ptr( - new FirebaseSet(host_, auth_, path, value, http_.get())); + return FirebaseSet(host_, auth_, path, value, http_); } FirebasePush Firebase::push(const std::string& path, const std::string& value) { - return FirebasePush(host_, auth_, path, value, http_.get()); -} -unique_ptr Firebase::pushPtr(const std::string& path, const std::string& value) { - return unique_ptr( - new FirebasePush(host_, auth_, path, value, http_.get())); + return FirebasePush(host_, auth_, path, value, http_); } FirebaseRemove Firebase::remove(const std::string& path) { - return FirebaseRemove(host_, auth_, path, http_.get()); -} - -unique_ptr Firebase::removePtr(const std::string& path) { - return unique_ptr( - new FirebaseRemove(host_, auth_, path, http_.get())); + return FirebaseRemove(host_, auth_, path, http_); } FirebaseStream Firebase::stream(const std::string& path) { // TODO: create new client dedicated to stream. - return FirebaseStream(host_, auth_, path, http_.get()); -} - -unique_ptr Firebase::streamPtr(const std::string& path) { - // TODO: create new client dedicated to stream. - return unique_ptr( - new FirebaseStream(host_, auth_, path, http_.get())); + return FirebaseStream(host_, auth_, path, http_); } // FirebaseCall FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth, const char* method, const std::string& path, - const std::string& data, FirebaseHttpClient* http) : http_(http) { + const std::string& data, const std::shared_ptr http) : http_(http) { std::string path_with_auth = makeFirebaseURL(path, auth); http_->setReuseConnection(true); http_->begin(host, path_with_auth); @@ -141,22 +117,24 @@ FirebaseCall::~FirebaseCall() { const JsonObject& FirebaseCall::json() { //TODO(edcoyne): This is not efficient, we should do something smarter with - //the buffers. - buffer_ = DynamicJsonBuffer(); - return buffer_.parseObject(response().c_str()); + //the buffers. kotl: Is this still valid? + if (buffer_.get() == NULL) { + buffer_.reset(new StaticJsonBuffer()); + } + return buffer_.get()->parseObject(response().c_str()); } // FirebaseGet FirebaseGet::FirebaseGet(const std::string& host, const std::string& auth, const std::string& path, - FirebaseHttpClient* http) + const std::shared_ptr http) : FirebaseCall(host, auth, "GET", path, "", http) { } // FirebaseSet FirebaseSet::FirebaseSet(const std::string& host, const std::string& auth, const std::string& path, const std::string& value, - FirebaseHttpClient* http) + const std::shared_ptr http) : FirebaseCall(host, auth, "PUT", path, value, http) { if (!error()) { // TODO: parse json @@ -167,7 +145,7 @@ FirebaseSet::FirebaseSet(const std::string& host, const std::string& auth, // FirebasePush FirebasePush::FirebasePush(const std::string& host, const std::string& auth, const std::string& path, const std::string& value, - FirebaseHttpClient* http) + const std::shared_ptr http) : FirebaseCall(host, auth, "POST", path, value, http) { if (!error()) { name_ = json()["name"].as(); @@ -177,14 +155,14 @@ FirebasePush::FirebasePush(const std::string& host, const std::string& auth, // FirebaseRemove FirebaseRemove::FirebaseRemove(const std::string& host, const std::string& auth, const std::string& path, - FirebaseHttpClient* http) + const std::shared_ptr http) : FirebaseCall(host, auth, "DELETE", path, "", http) { } // FirebaseStream FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth, const std::string& path, - FirebaseHttpClient* http) + const std::shared_ptr http) : FirebaseCall(host, auth, "STREAM", path, "", http) { } diff --git a/src/Firebase.h b/src/Firebase.h index 8a352045..1f3f3338 100644 --- a/src/Firebase.h +++ b/src/Firebase.h @@ -22,10 +22,11 @@ #include #include +#include + #include "FirebaseHttpClient.h" #include "FirebaseError.h" -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include "FirebaseObject.h" class FirebaseGet; class FirebaseSet; @@ -42,30 +43,24 @@ class Firebase { // Fetch json encoded `value` at `path`. FirebaseGet get(const std::string& path); - virtual std::unique_ptr getPtr(const std::string& path); - // Set json encoded `value` at `path`. FirebaseSet set(const std::string& path, const std::string& json); - virtual std::unique_ptr setPtr(const std::string& path, const std::string& json); // Add new json encoded `value` to list at `path`. FirebasePush push(const std::string& path, const std::string& json); - virtual std::unique_ptr pushPtr(const std::string& path, const std::string& json); // Delete value at `path`. FirebaseRemove remove(const std::string& path); - virtual std::unique_ptr removePtr(const std::string& path); // Start a stream of events that affect value at `path`. FirebaseStream stream(const std::string& path); - virtual std::unique_ptr streamPtr(const std::string& path); protected: // Used for testing. Firebase() {} private: - std::unique_ptr http_; + std::shared_ptr http_; std::string host_; std::string auth_; }; @@ -76,7 +71,7 @@ class FirebaseCall { FirebaseCall(const std::string& host, const std::string& auth, const char* method, const std::string& path, const std::string& data = "", - FirebaseHttpClient* http = NULL); + const std::shared_ptr http = NULL); virtual ~FirebaseCall(); virtual const FirebaseError& error() const { @@ -90,17 +85,17 @@ class FirebaseCall { const JsonObject& json(); protected: - FirebaseHttpClient* http_; + const std::shared_ptr http_; FirebaseError error_; std::string response_; - DynamicJsonBuffer buffer_; + std::shared_ptr> buffer_; }; class FirebaseGet : public FirebaseCall { public: FirebaseGet() {} FirebaseGet(const std::string& host, const std::string& auth, - const std::string& path, FirebaseHttpClient* http = NULL); + const std::string& path, const std::shared_ptr http = NULL); private: std::string json_; @@ -110,7 +105,7 @@ class FirebaseSet: public FirebaseCall { public: FirebaseSet() {} FirebaseSet(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, FirebaseHttpClient* http = NULL); + const std::string& path, const std::string& value, const std::shared_ptr http = NULL); private: @@ -121,7 +116,7 @@ class FirebasePush : public FirebaseCall { public: FirebasePush() {} FirebasePush(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, FirebaseHttpClient* http = NULL); + const std::string& path, const std::string& value, const std::shared_ptr http = NULL); virtual ~FirebasePush() {} virtual const std::string& name() const { @@ -136,7 +131,7 @@ class FirebaseRemove : public FirebaseCall { public: FirebaseRemove() {} FirebaseRemove(const std::string& host, const std::string& auth, - const std::string& path, FirebaseHttpClient* http = NULL); + const std::string& path, const std::shared_ptr http = NULL); }; @@ -144,7 +139,7 @@ class FirebaseStream : public FirebaseCall { public: FirebaseStream() {} FirebaseStream(const std::string& host, const std::string& auth, - const std::string& path, FirebaseHttpClient* http = NULL); + const std::string& path, const std::shared_ptr http = NULL); virtual ~FirebaseStream() {} // Return if there is any event available to read. diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index bdf5105c..ffd51fbc 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -46,7 +46,7 @@ String FirebaseArduino::pushString(const String& path, const String& value) { String FirebaseArduino::push(const String& path, const JsonVariant& value) { String buf; value.printTo(buf); - auto push = FirebasePush(host_, auth_, path.c_str(), buf.c_str(), http_.get()); + auto push = FirebasePush(host_, auth_, path.c_str(), buf.c_str(), http_); error_ = push.error(); return push.name().c_str(); } @@ -71,12 +71,12 @@ void FirebaseArduino::setString(const String& path, const String& value) { void FirebaseArduino::set(const String& path, const JsonVariant& value) { String buf; value.printTo(buf); - auto set = FirebaseSet(host_, auth_, path.c_str(), buf.c_str(), http_.get()); + auto set = FirebaseSet(host_, auth_, path.c_str(), buf.c_str(), http_); error_ = set.error(); } FirebaseObject FirebaseArduino::get(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); + auto get = FirebaseGet(host_, auth_, path.c_str(), http_); error_ = get.error(); if (failed()) { return FirebaseObject{""}; @@ -85,7 +85,7 @@ FirebaseObject FirebaseArduino::get(const String& path) { } int FirebaseArduino::getInt(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); + auto get = FirebaseGet(host_, auth_, path.c_str(), http_); error_ = get.error(); if (failed()) { return 0; @@ -95,7 +95,7 @@ int FirebaseArduino::getInt(const String& path) { float FirebaseArduino::getFloat(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); + auto get = FirebaseGet(host_, auth_, path.c_str(), http_); error_ = get.error(); if (failed()) { return 0.0f; @@ -104,7 +104,7 @@ float FirebaseArduino::getFloat(const String& path) { } String FirebaseArduino::getString(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); + auto get = FirebaseGet(host_, auth_, path.c_str(), http_); error_ = get.error(); if (failed()) { return ""; @@ -113,7 +113,7 @@ String FirebaseArduino::getString(const String& path) { } bool FirebaseArduino::getBool(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_.get()); + auto get = FirebaseGet(host_, auth_, path.c_str(), http_); error_ = get.error(); if (failed()) { return ""; @@ -121,12 +121,12 @@ bool FirebaseArduino::getBool(const String& path) { return FirebaseObject(get.response().c_str()).getBool(); } void FirebaseArduino::remove(const String& path) { - auto remove = FirebaseRemove(host_, auth_, path.c_str(), http_.get()); + auto remove = FirebaseRemove(host_, auth_, path.c_str(), http_); error_ = remove.error(); } void FirebaseArduino::stream(const String& path) { - auto stream = FirebaseStream(host_, auth_, path.c_str(), http_.get()); + auto stream = FirebaseStream(host_, auth_, path.c_str(), http_); error_ = stream.error(); } diff --git a/src/FirebaseArduino.h b/src/FirebaseArduino.h index a69f4e16..0e1f53c3 100644 --- a/src/FirebaseArduino.h +++ b/src/FirebaseArduino.h @@ -229,7 +229,7 @@ class FirebaseArduino { std::string host_; std::string auth_; FirebaseError error_; - std::unique_ptr http_; + std::shared_ptr http_; }; extern FirebaseArduino Firebase; diff --git a/src/FirebaseCloudMessaging.cpp b/src/FirebaseCloudMessaging.cpp index b774fbeb..e88727ab 100644 --- a/src/FirebaseCloudMessaging.cpp +++ b/src/FirebaseCloudMessaging.cpp @@ -63,7 +63,7 @@ const FirebaseError FirebaseCloudMessaging::SendMessageToTopic( const FirebaseError FirebaseCloudMessaging::SendPayload( const char* payload) { - std::unique_ptr client(FirebaseHttpClient::create()); + std::shared_ptr client(FirebaseHttpClient::create()); client->begin("http://fcm.googleapis.com/fcm/send"); client->addHeader("Authorization", auth_header_.c_str()); client->addHeader("Content-Type", "application/json"); diff --git a/src/FirebaseCloudMessaging.h b/src/FirebaseCloudMessaging.h index 7f716b2f..519946c6 100644 --- a/src/FirebaseCloudMessaging.h +++ b/src/FirebaseCloudMessaging.h @@ -26,8 +26,7 @@ #include #include "FirebaseHttpClient.h" #include "FirebaseError.h" -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include // Defines the actual message to the client, for more detail on // options and settings see: diff --git a/src/FirebaseObject.cpp b/src/FirebaseObject.cpp index 68b0f1b6..44fa5c37 100644 --- a/src/FirebaseObject.cpp +++ b/src/FirebaseObject.cpp @@ -19,7 +19,8 @@ // We need to make a copy of data here, even though it may be large. // It will need to be long lived. FirebaseObject::FirebaseObject(const char* data) : data_{data} { - json_ = buffer_.parse(&data_[0]); + buffer_.reset(new StaticJsonBuffer); + json_ = buffer_.get()->parse(&data_[0]); // TODO(proppy): find a way to check decoding error, tricky because // ArduinoJson doesn't surface error for variant parsing. // See: https://github.com/bblanchon/ArduinoJson/issues/279 @@ -83,7 +84,7 @@ JsonVariant FirebaseObject::getJsonVariant(const String& path) const { // make `start` a C string. *p = 0; // return json variant at `start`. - json = json.asObject().get(start); + json = json.asObject().get(start); // advance to next path element. start = p + 1; } diff --git a/src/FirebaseObject.h b/src/FirebaseObject.h index db23a373..b22a087d 100644 --- a/src/FirebaseObject.h +++ b/src/FirebaseObject.h @@ -17,92 +17,94 @@ #ifndef FIREBASE_OBJECT_H #define FIREBASE_OBJECT_H -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include +#include #ifndef FIREBASE_JSONBUFFER_SIZE #define FIREBASE_JSONBUFFER_SIZE JSON_OBJECT_SIZE(32) #endif // FIREBASE_JSONBUFFER_SIZE +using std::shared_ptr; + /** * Represents value stored in firebase, may be a singular value (leaf node) or * a tree structure. */ class FirebaseObject { - public: - /** + public: + /** * Construct from json. * \param data JSON formatted string. - */ - FirebaseObject(const char* data); + */ + FirebaseObject(const char* data); - /** + /** * Return the value as a boolean. * \param optional path in the JSON object. * \return result as a bool. - */ - bool getBool(const String& path = "") const; + */ + bool getBool(const String& path = "") const; - /** + /** * Returns true if specified path is NULL string. * Useful to detect tree deletions. * \param optional path in the JSON object. * \return result as a bool. - */ - bool isNullString(const String& path = "") const; + */ + bool isNullString(const String& path = "") const; - /** + /** * Return the value as an int. * \param optional path in the JSON object. * \return result as an integer. - */ - int getInt(const String& path = "") const; + */ + int getInt(const String& path = "") const; - /** + /** * Return the value as a float. * \param optional path in the JSON object. * \return result as a float. - */ - float getFloat(const String& path = "") const; + */ + float getFloat(const String& path = "") const; - /** + /** * Return the value as a String. * \param optional path in the JSON object. * \return result as a String. - */ - String getString(const String& path = "") const; + */ + String getString(const String& path = "") const; - /** + /** * Return the value as a JsonVariant. * \param optional path in the JSON object. * \return result as a JsonVariant. - */ - JsonVariant getJsonVariant(const String& path = "") const; + */ + JsonVariant getJsonVariant(const String& path = "") const; - /** + /** * * \return Whether there was an error decoding or accessing the JSON object. - */ - bool success() const; + */ + bool success() const; - /** + /** * * \return Whether there was an error decoding or accessing the JSON object. - */ - bool failed() const; + */ + bool failed() const; - /** + /** * * \return Error message if failed() is true. - */ - const String& error() const; - - private: - String data_; - StaticJsonBuffer buffer_; - JsonVariant json_; - mutable String error_; + */ + const String& error() const; + + private: + String data_; + std::shared_ptr> buffer_; + JsonVariant json_; + mutable String error_; }; #endif // FIREBASE_OBJECT_H diff --git a/src/third-party/README.md b/src/third-party/README.md deleted file mode 100644 index 76816743..00000000 --- a/src/third-party/README.md +++ /dev/null @@ -1,2 +0,0 @@ -These are packages that we depend upon. They may need to be trimmed, all .cpp -files in them will be compiled by the arduino IDE. diff --git a/src/third-party/arduino-json-5.6.7/ArduinoJson.h b/src/third-party/arduino-json-5.6.7/ArduinoJson.h deleted file mode 100644 index e18b432e..00000000 --- a/src/third-party/arduino-json-5.6.7/ArduinoJson.h +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include "include/ArduinoJson.h" diff --git a/src/third-party/arduino-json-5.6.7/CHANGELOG.md b/src/third-party/arduino-json-5.6.7/CHANGELOG.md deleted file mode 100644 index 070cdcf5..00000000 --- a/src/third-party/arduino-json-5.6.7/CHANGELOG.md +++ /dev/null @@ -1,323 +0,0 @@ -ArduinoJson: change log -======================= - -v5.6.7 ------- - -* Fixed `array[idx].as()` and `object[key].as()` -* Fixed return value of `JsonObject::set()` (issue #350) -* Fixed undefined behavior in `Prettyfier` and `Print` (issue #354) -* Fixed parser that incorrectly rejected floats containing a `+` (issue #349) - -v5.6.6 ------- - -* Fixed `-Wparentheses` warning introduced in v5.6.5 (PR #335 by @nuket) -* Added `.mbedignore` for ARM mbdeb (PR #334 by @nuket) -* Fixed `JsonVariant::success()` which didn't propagate `JsonArray::success()` nor `JsonObject::success()` (issue #342). - -v5.6.5 ------- - -* `as()` now returns `true` when input is `null` (issue #330) - -v5.6.4 ------- - -* Fixed error in float serialization (issue #324) - -v5.6.3 ------- - -* Improved speed of float serialization (about twice faster) -* Added `as()` as a synonym for `as()`... (issue #291) -* Fixed `call of overloaded isinf(double&) is ambiguous` (issue #284) - -v5.6.2 ------- - -* Fixed build when another lib does `#undef isnan` (issue #284) - -v5.6.1 ------- - -* Added missing `#pragma once` (issue #310) - -v5.6.0 ------- - -* ArduinoJson is now a header-only library (issue #199) - -v5.5.1 ------- - -* Fixed compilation error with Intel Galileo (issue #299) - -v5.5.0 ------- - -* Added `JsonVariant::success()` (issue #279) -* Renamed `JsonVariant::invalid()` to `JsonVariant::defaultValue()` - -v5.4.0 ------- - -* Changed `::String` to `ArduinoJson::String` (issue #275) -* Changed `::Print` to `ArduinoJson::Print` too - -v5.3.0 ------- - -* Added custom implementation of `ftoa` (issues #266, #267, #269 and #270) -* Added `JsonVariant JsonBuffer::parse()` (issue #265) -* Fixed `unsigned long` printed as `signed long` (issue #170) - -v5.2.0 ------- - -* Added `JsonVariant::as()` as a synonym for `JsonVariant::as()` (issue #257) -* Added example `JsonHttpClient` (issue #256) -* Added `JsonArray::copyTo()` and `JsonArray::copyFrom()` (issue #254) -* Added `RawJson()` to insert pregenerated JSON portions (issue #259) - -v5.1.1 ------- - -* Removed `String` duplication when one replaces a value in a `JsonObject` (PR #232 by @ulion) - -v5.1.0 ------- - -* Added support of `long long` (issue #171) -* Moved all build settings to `ArduinoJson/Configuration.hpp` - -**BREAKING CHANGE**: -If you defined `ARDUINOJSON_ENABLE_STD_STREAM`, you now need to define it to `1`. - -v5.0.8 ------- - -* Made the library compatible with [PlatformIO](http://platformio.org/) (issue #181) -* Fixed `JsonVariant::is()` that was incorrectly returning false (issue #214) - -v5.0.7 ------- - -* Made library easier to use from a CMake project: simply `add_subdirectory(ArduinoJson/src)` -* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161) - -**BREAKING CHANGES**: -- `JsonVariant(true).as()` now returns `"true"` instead of `"1"` -- `JsonVariant(false).as()` now returns `"false"` instead of `"0"` - -v5.0.6 ------- - -* Added parameter to `DynamicJsonBuffer` constructor to set initial size (issue #152) -* Fixed warning about library category in Arduino 1.6.6 (issue #147) -* Examples: Added a loop to wait for serial port to be ready (issue #156) - -v5.0.5 ------- - -* Added overload `JsonObjectSuscript::set(value, decimals)` (issue #143) -* Use `float` instead of `double` to reduce the size of `JsonVariant` (issue #134) - -v5.0.4 ------- - -* Fixed ambiguous overload with `JsonArraySubscript` and `JsonObjectSubscript` (issue #122) - -v5.0.3 ------- - -* Fixed `printTo(String)` which wrote numbers instead of strings (issue #120) -* Fixed return type of `JsonArray::is()` and some others (issue #121) - -v5.0.2 ------- - -* Fixed segmentation fault in `parseObject(String)` and `parseArray(String)`, when the - `StaticJsonBuffer` is too small to hold a copy of the string -* Fixed Clang warning "register specifier is deprecated" (issue #102) -* Fixed GCC warning "declaration shadows a member" (issue #103) -* Fixed memory alignment, which made ESP8266 crash (issue #104) -* Fixed compilation on Visual Studio 2010 and 2012 (issue #107) - -v5.0.1 ------- - -* Fixed compilation with Arduino 1.0.6 (issue #99) - -v5.0.0 ------- - -* Added support of `String` class (issues #55, #56, #70, #77) -* Added `JsonBuffer::strdup()` to make a copy of a string (issues #10, #57) -* Implicitly call `strdup()` for `String` but not for `char*` (issues #84, #87) -* Added support of non standard JSON input (issue #44) -* Added support of comments in JSON input (issue #88) -* Added implicit cast between numerical types (issues #64, #69, #93) -* Added ability to read number values as string (issue #90) -* Redesigned `JsonVariant` to leverage converting constructors instead of assignment operators (issue #66) -* Switched to new the library layout (requires Arduino 1.0.6 or above) - -**BREAKING CHANGES**: -- `JsonObject::add()` was renamed to `set()` -- `JsonArray::at()` and `JsonObject::at()` were renamed to `get()` -- Number of digits of floating point value are now set with `double_with_n_digits()` - -**Personal note about the `String` class**: -Support of the `String` class has been added to the library because many people use it in their programs. -However, you should not see this as an invitation to use the `String` class. -The `String` class is **bad** because it uses dynamic memory allocation. -Compared to static allocation, it compiles to a bigger, slower program, and is less predictable. -You certainly don't want that in an embedded environment! - -v4.6 ----- - -* Fixed segmentation fault in `DynamicJsonBuffer` when memory allocation fails (issue #92) - -v4.5 ----- - -* Fixed buffer overflow when input contains a backslash followed by a terminator (issue #81) - -**Upgrading is recommended** since previous versions contain a potential security risk. - -Special thanks to [Giancarlo Canales Barreto](https://github.com/gcanalesb) for finding this nasty bug. - -v4.4 ----- - -* Added `JsonArray::measureLength()` and `JsonObject::measureLength()` (issue #75) - -v4.3 ----- - -* Added `JsonArray::removeAt()` to remove an element of an array (issue #58) -* Fixed stack-overflow in `DynamicJsonBuffer` when parsing huge JSON files (issue #65) -* Fixed wrong return value of `parseArray()` and `parseObject()` when allocation fails (issue #68) - -v4.2 ----- - -* Switched back to old library layout (issues #39, #43 and #45) -* Removed global new operator overload (issue #40, #45 and #46) -* Added an example with EthernetServer - -v4.1 ----- - -* Added DynamicJsonBuffer (issue #19) - -v4.0 ----- - -* Unified parser and generator API (issue #23) -* Updated library layout, now requires Arduino 1.0.6 or newer - -**BREAKING CHANGE**: API changed significantly, see [Migrating code to the new API](https://github.com/bblanchon/ArduinoJson/wiki/Migrating-code-to-the-new-API). - - -v3.4 ----- - -* Fixed escaped char parsing (issue #16) - - -v3.3 ----- - -* Added indented output for the JSON generator (issue #11), see example bellow. -* Added `IndentedPrint`, a decorator for `Print` to allow indented output - -Example: - - JsonOject<2> json; - json["key"] = "value"; - json.prettyPrintTo(Serial); - -v3.2 ----- - -* Fixed a bug when adding nested object in `JsonArray` (bug introduced in v3.1). - -v3.1 ----- - -* Calling `Generator::JsonObject::add()` twice with the same `key` now replaces the `value` -* Added `Generator::JsonObject::operator[]`, see bellow the new API -* Added `Generator::JsonObject::remove()` (issue #9) - -Old generator API: - - JsonObject<3> root; - root.add("sensor", "gps"); - root.add("time", 1351824120); - root.add("data", array); - -New generator API: - - JsonObject<3> root; - root["sensor"] = "gps"; - root["time"] = 1351824120; - root["data"] = array; - -v3.0 ----- - -* New parser API, see bellow -* Renamed `JsonHashTable` into `JsonObject` -* Added iterators for `JsonArray` and `JsonObject` (issue #4) - -Old parser API: - - JsonHashTable root = parser.parseHashTable(json); - - char* sensor = root.getString("sensor"); - long time = root.getLong("time"); - double latitude = root.getArray("data").getDouble(0); - double longitude = root.getArray("data").getDouble(1); - -New parser API: - - JsonObject root = parser.parse(json); - - char* sensor = root["sensor"]; - long time = root["time"]; - double latitude = root["data"][0]; - double longitude = root["data"][1]; - -v2.1 ----- - -* Fixed case `#include "jsmn.cpp"` which caused an error in Linux (issue #6) -* Fixed a buffer overrun in JSON Parser (issue #5) - -v2.0 ----- - -* Added JSON encoding (issue #2) -* Renamed the library `ArduinoJsonParser` becomes `ArduinoJson` - -**Breaking change**: you need to add the following line at the top of your program. - - using namespace ArduinoJson::Parser; - -v1.2 ----- - -* Fixed error in JSON parser example (issue #1) - -v1.1 ----- - -* Example: changed `char* json` into `char[] json` so that the bytes are not write protected -* Fixed parsing bug when the JSON contains multi-dimensional arrays - -v1.0 ----- - -Initial release diff --git a/src/third-party/arduino-json-5.6.7/LICENSE.md b/src/third-party/arduino-json-5.6.7/LICENSE.md deleted file mode 100644 index fea79d80..00000000 --- a/src/third-party/arduino-json-5.6.7/LICENSE.md +++ /dev/null @@ -1,10 +0,0 @@ -The MIT License (MIT) ---------------------- - -Copyright © 2014-2016 Benoit BLANCHON - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/third-party/arduino-json-5.6.7/README.md b/src/third-party/arduino-json-5.6.7/README.md deleted file mode 100644 index f578c008..00000000 --- a/src/third-party/arduino-json-5.6.7/README.md +++ /dev/null @@ -1,128 +0,0 @@ -Arduino JSON library -==================== - -[![Build status](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/master?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/master) [![Build Status](https://travis-ci.org/bblanchon/ArduinoJson.svg?branch=master)](https://travis-ci.org/bblanchon/ArduinoJson) [![Coverage Status](https://img.shields.io/coveralls/bblanchon/ArduinoJson.svg)](https://coveralls.io/r/bblanchon/ArduinoJson?branch=master) [![Star this project](http://githubbadges.com/star.svg?user=bblanchon&repo=ArduinoJson&style=flat&color=fff&background=007ec6)](https://github.com/bblanchon/ArduinoJson) - -*An elegant and efficient JSON library for embedded systems.* - -It's designed to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc). - -It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project. - -Features --------- - -* JSON decoding (comments are supported) -* JSON encoding (with optional indentation) -* Elegant API, very easy to use -* Fixed memory allocation (zero malloc) -* No data duplication (zero copy) -* Portable (written in C++98) -* Self-contained (no external dependency) -* Small footprint -* Header-only library -* MIT License - -Works on --------- - -* All Arduino boards (Uno, Due, Mini, Micro, Yun...) -* ESP8266 -* Teensy -* Intel Edison and Galileo -* PlatformIO -* Energia -* RedBearLab boards (BLE Nano...) -* Computers (Windows, Linux, OSX...) - -See [FAQ: Compatibility issues](https://github.com/bblanchon/ArduinoJson/wiki/Compatibility-issues) - -Quick start ------------ - -#### Decoding / Parsing - -```c++ -char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - -StaticJsonBuffer<200> jsonBuffer; - -JsonObject& root = jsonBuffer.parseObject(json); - -const char* sensor = root["sensor"]; -long time = root["time"]; -double latitude = root["data"][0]; -double longitude = root["data"][1]; -``` - -#### Encoding / Generating - -```c++ -StaticJsonBuffer<200> jsonBuffer; - -JsonObject& root = jsonBuffer.createObject(); -root["sensor"] = "gps"; -root["time"] = 1351824120; - -JsonArray& data = root.createNestedArray("data"); -data.add(48.756080, 6); // 6 is the number of decimals to print -data.add(2.302038, 6); // if not specified, 2 digits are printed - -root.printTo(Serial); -// This prints: -// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} -``` - - -Documentation -------------- - -The documentation is available online in the [Arduino JSON wiki](https://github.com/bblanchon/ArduinoJson/wiki) - -Testimonials ------------- - -From Arduino's Forum user `jflaplante`: -> I tried aJson json-arduino before trying your library. I always ran into memory problem after a while. -> I have no such problem so far with your library. It is working perfectly with my web services. - -From StackOverflow user `thegreendroid`: -> It has a really elegant, simple API and it works like a charm on embedded and Windows/Linux platforms. We recently started using this on an embedded project and I can vouch for its quality. - -From GitHub user `zacsketches`: -> Thanks for a great library!!! -> I've been watching you consistently develop this library over the past six months, and I used it today for a publish and subscribe architecture designed to help hobbyists move into more advanced robotics. Your library allowed me to implement remote subscription in order to facilitate multi-processor robots. -> ArduinoJson saved me a week's worth of time!! - -[From Reddit user `erm_what_`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusjk8c): -> This is a great library and I wouldn't be able to do the project I'm doing without it. I completely recommend it. - -[From Reddit user `makerhacks`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusqg7b): -> I am just starting an ESP8266 clock project and now I can output JSON from my server script and interpret it painlessly. - -[From Twitter user `@hemalchevli`](https://twitter.com/hemalchevli/status/715788439397011456): -> ArduinoJson library should be used as a benchmark/reference for making libraries. Truly elegant. - -Donators --------- - -Special thanks to the following persons and companies who made generous donations to the library author: - -* Robert Murphy USA -* Surge Communications USA -* Alex Scott United Kingdom -* Firepick Services LLC USA -* A B Doodkorte Netherlands -* Scott Smith USA -* Johann Stieger Austria -* Gustavo Donizeti Gini Brazil -* Charles-Henri Hallard France -* Martijn van den Burg Netherlands -* Nick Koumaris Greece -* Jon Williams USA -* Kestutis Liaugminas Lithuania -* Darlington Adibe Nigeria - ---- - -Found this library useful? Please star this project or [help me back with a donation!](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donate%40benoitblanchon%2efr&lc=GB&item_name=Benoit%20Blanchon&item_number=Arduino%20JSON¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted) :smile: diff --git a/src/third-party/arduino-json-5.6.7/examples/IndentedPrintExample/IndentedPrintExample.ino b/src/third-party/arduino-json-5.6.7/examples/IndentedPrintExample/IndentedPrintExample.ino deleted file mode 100644 index 9e86f0f5..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/IndentedPrintExample/IndentedPrintExample.ino +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include - -using namespace ArduinoJson::Internals; - -void setup() { - Serial.begin(9600); - while (!Serial) { - // wait serial port initialization - } - - IndentedPrint serial(Serial); - serial.setTabSize(4); - - serial.println("This is at indentation 0"); - serial.indent(); - serial.println("This is at indentation 1"); - serial.println("This is also at indentation 1"); - serial.indent(); - serial.println("This is at indentation 2"); - - serial.unindent(); - serial.unindent(); - serial.println("This is back at indentation 0"); -} - -void loop() { - // not used in this example -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonGeneratorExample/JsonGeneratorExample.ino b/src/third-party/arduino-json-5.6.7/examples/JsonGeneratorExample/JsonGeneratorExample.ino deleted file mode 100644 index 717a2276..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonGeneratorExample/JsonGeneratorExample.ino +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include - -void setup() { - Serial.begin(9600); - while (!Serial) { - // wait serial port initialization - } - - // Memory pool for JSON object tree. - // - // Inside the brackets, 200 is the size of the pool in bytes. - // If the JSON object is more complex, you need to increase that value. - StaticJsonBuffer<200> jsonBuffer; - - // StaticJsonBuffer allocates memory on the stack, it can be - // replaced by DynamicJsonBuffer which allocates in the heap. - // It's simpler but less efficient. - // - // DynamicJsonBuffer jsonBuffer; - - // Create the root of the object tree. - // - // It's a reference to the JsonObject, the actual bytes are inside the - // JsonBuffer with all the other nodes of the object tree. - // Memory is freed when jsonBuffer goes out of scope. - JsonObject& root = jsonBuffer.createObject(); - - // Add values in the object - // - // Most of the time, you can rely on the implicit casts. - // In other case, you can do root.set("time", 1351824120); - root["sensor"] = "gps"; - root["time"] = 1351824120; - - // Add a nested array. - // - // It's also possible to create the array separately and add it to the - // JsonObject but it's less efficient. - JsonArray& data = root.createNestedArray("data"); - data.add(double_with_n_digits(48.756080, 6)); - data.add(double_with_n_digits(2.302038, 6)); - - root.printTo(Serial); - // This prints: - // {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} - - Serial.println(); - - root.prettyPrintTo(Serial); - // This prints: - // { - // "sensor": "gps", - // "time": 1351824120, - // "data": [ - // 48.756080, - // 2.302038 - // ] - // } -} - -void loop() { - // not used in this example -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonHttpClient/JsonHttpClient.ino b/src/third-party/arduino-json-5.6.7/examples/JsonHttpClient/JsonHttpClient.ino deleted file mode 100644 index 6bb3175d..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonHttpClient/JsonHttpClient.ino +++ /dev/null @@ -1,195 +0,0 @@ -// Sample Arduino Json Web Client -// Downloads and parse http://jsonplaceholder.typicode.com/users/1 -// -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include -#include -#include - -EthernetClient client; - -const char* server = "jsonplaceholder.typicode.com"; // server's address -const char* resource = "/users/1"; // http resource -const unsigned long BAUD_RATE = 9600; // serial connection speed -const unsigned long HTTP_TIMEOUT = 10000; // max respone time from server -const size_t MAX_CONTENT_SIZE = 512; // max size of the HTTP response - -// The type of data that we want to extract from the page -struct UserData { - char name[32]; - char company[32]; -}; - -// ARDUINO entry point #1: runs once when you press reset or power the board -void setup() { - initSerial(); - initEthernet(); -} - -// ARDUINO entry point #2: runs over and over again forever -void loop() { - if (connect(server)) { - if (sendRequest(server, resource) && skipResponseHeaders()) { - char response[MAX_CONTENT_SIZE]; - readReponseContent(response, sizeof(response)); - - UserData userData; - if (parseUserData(response, &userData)) { - printUserData(&userData); - } - } - disconnect(); - } - wait(); -} - -// Initialize Serial port -void initSerial() { - Serial.begin(BAUD_RATE); - while (!Serial) { - ; // wait for serial port to initialize - } - Serial.println("Serial ready"); -} - -// Initialize Ethernet library -void initEthernet() { - byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; - if (!Ethernet.begin(mac)) { - Serial.println("Failed to configure Ethernet"); - return; - } - Serial.println("Ethernet ready"); - delay(1000); -} - -// Open connection to the HTTP server -bool connect(const char* hostName) { - Serial.print("Connect to "); - Serial.println(hostName); - - bool ok = client.connect(hostName, 80); - - Serial.println(ok ? "Connected" : "Connection Failed!"); - return ok; -} - -// Send the HTTP GET request to the server -bool sendRequest(const char* host, const char* resource) { - Serial.print("GET "); - Serial.println(resource); - - client.print("GET "); - client.print(resource); - client.println(" HTTP/1.1"); - client.print("Host: "); - client.println(server); - client.println("Connection: close"); - client.println(); - - return true; -} - -// Skip HTTP headers so that we are at the beginning of the response's body -bool skipResponseHeaders() { - // HTTP headers end with an empty line - char endOfHeaders[] = "\r\n\r\n"; - - client.setTimeout(HTTP_TIMEOUT); - bool ok = client.find(endOfHeaders); - - if (!ok) { - Serial.println("No response or invalid response!"); - } - - return ok; -} - -// Read the body of the response from the HTTP server -void readReponseContent(char* content, size_t maxSize) { - size_t length = client.readBytes(content, maxSize); - content[length] = 0; - Serial.println(content); -} - -// Parse the JSON from the input string and extract the interesting values -// Here is the JSON we need to parse -// { -// "id": 1, -// "name": "Leanne Graham", -// "username": "Bret", -// "email": "Sincere@april.biz", -// "address": { -// "street": "Kulas Light", -// "suite": "Apt. 556", -// "city": "Gwenborough", -// "zipcode": "92998-3874", -// "geo": { -// "lat": "-37.3159", -// "lng": "81.1496" -// } -// }, -// "phone": "1-770-736-8031 x56442", -// "website": "hildegard.org", -// "company": { -// "name": "Romaguera-Crona", -// "catchPhrase": "Multi-layered client-server neural-net", -// "bs": "harness real-time e-markets" -// } -// } -bool parseUserData(char* content, struct UserData* userData) { - // Compute optimal size of the JSON buffer according to what we need to parse. - // This is only required if you use StaticJsonBuffer. - const size_t BUFFER_SIZE = - JSON_OBJECT_SIZE(8) // the root object has 8 elements - + JSON_OBJECT_SIZE(5) // the "address" object has 5 elements - + JSON_OBJECT_SIZE(2) // the "geo" object has 2 elements - + JSON_OBJECT_SIZE(3); // the "company" object has 3 elements - - // Allocate a temporary memory pool on the stack - StaticJsonBuffer jsonBuffer; - // If the memory pool is too big for the stack, use this instead: - // DynamicJsonBuffer jsonBuffer; - - JsonObject& root = jsonBuffer.parseObject(content); - - if (!root.success()) { - Serial.println("JSON parsing failed!"); - return false; - } - - // Here were copy the strings we're interested in - strcpy(userData->name, root["name"]); - strcpy(userData->company, root["company"]["name"]); - // It's not mandatory to make a copy, you could just use the pointers - // Since, they are pointing inside the "content" buffer, so you need to make - // sure it's still in memory when you read the string - - return true; -} - -// Print the data extracted from the JSON -void printUserData(const struct UserData* userData) { - Serial.print("Name = "); - Serial.println(userData->name); - Serial.print("Company = "); - Serial.println(userData->company); -} - -// Close the connection with the HTTP server -void disconnect() { - Serial.println("Disconnect"); - client.stop(); -} - -// Pause for a 1 minute -void wait() { - Serial.println("Wait 60 seconds"); - delay(60000); -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonParserExample/JsonParserExample.ino b/src/third-party/arduino-json-5.6.7/examples/JsonParserExample/JsonParserExample.ino deleted file mode 100644 index 13536019..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonParserExample/JsonParserExample.ino +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include - -void setup() { - Serial.begin(9600); - while (!Serial) { - // wait serial port initialization - } - - // Memory pool for JSON object tree. - // - // Inside the brackets, 200 is the size of the pool in bytes, - // If the JSON object is more complex, you need to increase that value. - StaticJsonBuffer<200> jsonBuffer; - - // StaticJsonBuffer allocates memory on the stack, it can be - // replaced by DynamicJsonBuffer which allocates in the heap. - // It's simpler but less efficient. - // - // DynamicJsonBuffer jsonBuffer; - - // JSON input string. - // - // It's better to use a char[] as shown here. - // If you use a const char* or a String, ArduinoJson will - // have to make a copy of the input in the JsonBuffer. - char json[] = - "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}"; - - // Root of the object tree. - // - // It's a reference to the JsonObject, the actual bytes are inside the - // JsonBuffer with all the other nodes of the object tree. - // Memory is freed when jsonBuffer goes out of scope. - JsonObject& root = jsonBuffer.parseObject(json); - - // Test if parsing succeeds. - if (!root.success()) { - Serial.println("parseObject() failed"); - return; - } - - // Fetch values. - // - // Most of the time, you can rely on the implicit casts. - // In other case, you can do root["time"].as(); - const char* sensor = root["sensor"]; - long time = root["time"]; - double latitude = root["data"][0]; - double longitude = root["data"][1]; - - // Print values. - Serial.println(sensor); - Serial.println(time); - Serial.println(latitude, 6); - Serial.println(longitude, 6); -} - -void loop() { - // not used in this example -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonServer/JsonServer.ino b/src/third-party/arduino-json-5.6.7/examples/JsonServer/JsonServer.ino deleted file mode 100644 index 895b6729..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonServer/JsonServer.ino +++ /dev/null @@ -1,74 +0,0 @@ -// Sample Arduino Json Web Server -// Created by Benoit Blanchon. -// Heavily inspired by "Web Server" from David A. Mellis and Tom Igoe - -#include -#include -#include - -byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; -IPAddress ip(192, 168, 0, 177); -EthernetServer server(80); - -bool readRequest(EthernetClient& client) { - bool currentLineIsBlank = true; - while (client.connected()) { - if (client.available()) { - char c = client.read(); - if (c == '\n' && currentLineIsBlank) { - return true; - } else if (c == '\n') { - currentLineIsBlank = true; - } else if (c != '\r') { - currentLineIsBlank = false; - } - } - } - return false; -} - -JsonObject& prepareResponse(JsonBuffer& jsonBuffer) { - JsonObject& root = jsonBuffer.createObject(); - - JsonArray& analogValues = root.createNestedArray("analog"); - for (int pin = 0; pin < 6; pin++) { - int value = analogRead(pin); - analogValues.add(value); - } - - JsonArray& digitalValues = root.createNestedArray("digital"); - for (int pin = 0; pin < 14; pin++) { - int value = digitalRead(pin); - digitalValues.add(value); - } - - return root; -} - -void writeResponse(EthernetClient& client, JsonObject& json) { - client.println("HTTP/1.1 200 OK"); - client.println("Content-Type: application/json"); - client.println("Connection: close"); - client.println(); - - json.prettyPrintTo(client); -} - -void setup() { - Ethernet.begin(mac, ip); - server.begin(); -} - -void loop() { - EthernetClient client = server.available(); - if (client) { - bool success = readRequest(client); - if (success) { - StaticJsonBuffer<500> jsonBuffer; - JsonObject& json = prepareResponse(jsonBuffer); - writeResponse(client, json); - } - delay(1); - client.stop(); - } -} diff --git a/src/third-party/arduino-json-5.6.7/examples/JsonUdpBeacon/JsonUdpBeacon.ino b/src/third-party/arduino-json-5.6.7/examples/JsonUdpBeacon/JsonUdpBeacon.ino deleted file mode 100644 index 7d0fa38a..00000000 --- a/src/third-party/arduino-json-5.6.7/examples/JsonUdpBeacon/JsonUdpBeacon.ino +++ /dev/null @@ -1,55 +0,0 @@ -// Send a JSON object on UDP at regular interval -// -// You can easily test this program with netcat: -// $ nc -ulp 8888 -// -// by Benoit Blanchon, MIT License 2015-2016 - -#include -#include -#include - -byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; -IPAddress localIp(192, 168, 0, 177); -IPAddress remoteIp(192, 168, 0, 109); -unsigned int remotePort = 8888; -unsigned localPort = 8888; -EthernetUDP udp; - -JsonObject& buildJson(JsonBuffer& jsonBuffer) { - JsonObject& root = jsonBuffer.createObject(); - - JsonArray& analogValues = root.createNestedArray("analog"); - for (int pin = 0; pin < 6; pin++) { - int value = analogRead(pin); - analogValues.add(value); - } - - JsonArray& digitalValues = root.createNestedArray("digital"); - for (int pin = 0; pin < 14; pin++) { - int value = digitalRead(pin); - digitalValues.add(value); - } - - return root; -} - -void sendJson(JsonObject& json) { - udp.beginPacket(remoteIp, remotePort); - json.printTo(udp); - udp.println(); - udp.endPacket(); -} - -void setup() { - Ethernet.begin(mac, localIp); - udp.begin(localPort); -} - -void loop() { - delay(1000); - - StaticJsonBuffer<300> jsonBuffer; - JsonObject& json = buildJson(jsonBuffer); - sendJson(json); -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.h b/src/third-party/arduino-json-5.6.7/include/ArduinoJson.h deleted file mode 100644 index 6bed176a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#include "ArduinoJson.hpp" -using namespace ArduinoJson; diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson.hpp deleted file mode 100644 index 8ade581d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "ArduinoJson/DynamicJsonBuffer.hpp" -#include "ArduinoJson/JsonArray.hpp" -#include "ArduinoJson/JsonObject.hpp" -#include "ArduinoJson/StaticJsonBuffer.hpp" - -#include "ArduinoJson/Internals/JsonParser.ipp" -#include "ArduinoJson/Internals/JsonSerializer.ipp" -#include "ArduinoJson/JsonArray.ipp" -#include "ArduinoJson/JsonBuffer.ipp" -#include "ArduinoJson/JsonObject.ipp" -#include "ArduinoJson/JsonVariant.ipp" - -using namespace ArduinoJson; diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Configuration.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Configuration.hpp deleted file mode 100644 index 599b85f1..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Configuration.hpp +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#ifdef ARDUINO // assume this is an embedded platform - -// store using float instead of double to reduce the memory usage (issue #134) -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 0 -#endif - -// store using a long because it usually match the size of a float. -#ifndef ARDUINOJSON_USE_LONG_LONG -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif -#ifndef ARDUINOJSON_USE_INT64 -#define ARDUINOJSON_USE_INT64 0 -#endif - -// arduino has its own implementation of String to replace std::string -#ifndef ARDUINOJSON_USE_ARDUINO_STRING -#define ARDUINOJSON_USE_ARDUINO_STRING 1 -#endif - -// arduino doesn't support STL stream -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 0 -#endif - -#ifndef ARDUINOJSON_ENABLE_ALIGNMENT -#ifdef ARDUINO_ARCH_AVR -// alignment isn't needed for 8-bit AVR -#define ARDUINOJSON_ENABLE_ALIGNMENT 0 -#else -// but must processor needs pointer to be align on word size -#define ARDUINOJSON_ENABLE_ALIGNMENT 1 -#endif -#endif - -#else // assume this is a computer - -// on a computer we have plenty of memory so we can use doubles -#ifndef ARDUINOJSON_USE_DOUBLE -#define ARDUINOJSON_USE_DOUBLE 1 -#endif - -// use long long when available -#ifndef ARDUINOJSON_USE_LONG_LONG -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) -#define ARDUINOJSON_USE_LONG_LONG 1 -#else -#define ARDUINOJSON_USE_LONG_LONG 0 -#endif -#endif - -// use _int64 on old versions of Visual Studio -#ifndef ARDUINOJSON_USE_INT64 -#if defined(_MSC_VER) && _MSC_VER <= 1700 -#define ARDUINOJSON_USE_INT64 1 -#else -#define ARDUINOJSON_USE_INT64 0 -#endif -#endif - -// on a computer, we can use std::string -#ifndef ARDUINOJSON_USE_ARDUINO_STRING -#define ARDUINOJSON_USE_ARDUINO_STRING 0 -#endif - -// on a computer, we can assume that the STL is there -#ifndef ARDUINOJSON_ENABLE_STD_STREAM -#define ARDUINOJSON_ENABLE_STD_STREAM 1 -#endif - -#ifndef ARDUINOJSON_ENABLE_ALIGNMENT -// even if not required, most cpu's are faster with aligned pointers -#define ARDUINOJSON_ENABLE_ALIGNMENT 1 -#endif - -#endif - -#if ARDUINOJSON_USE_LONG_LONG && ARDUINOJSON_USE_INT64 -#error ARDUINOJSON_USE_LONG_LONG and ARDUINOJSON_USE_INT64 cannot be set together -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/DynamicJsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/DynamicJsonBuffer.hpp deleted file mode 100644 index 2e02b097..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/DynamicJsonBuffer.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/BlockJsonBuffer.hpp" - -namespace ArduinoJson { -// Implements a JsonBuffer with dynamic memory allocation. -// You are strongly encouraged to consider using StaticJsonBuffer which is much -// more suitable for embedded systems. -typedef Internals::BlockJsonBuffer - DynamicJsonBuffer; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/BlockJsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/BlockJsonBuffer.hpp deleted file mode 100644 index 33873608..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/BlockJsonBuffer.hpp +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" - -#include - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnon-virtual-dtor" -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#endif - -namespace ArduinoJson { -namespace Internals { -class DefaultAllocator { - public: - void* allocate(size_t size) { - return malloc(size); - } - void deallocate(void* pointer) { - free(pointer); - } -}; - -template -class BlockJsonBuffer : public JsonBuffer { - struct Block; - struct EmptyBlock { - Block* next; - size_t capacity; - size_t size; - }; - struct Block : EmptyBlock { - uint8_t data[1]; - }; - - public: - BlockJsonBuffer(size_t initialSize = 256) - : _head(NULL), _nextBlockSize(initialSize) {} - - ~BlockJsonBuffer() { - Block* currentBlock = _head; - - while (currentBlock != NULL) { - Block* nextBlock = currentBlock->next; - _allocator.deallocate(currentBlock); - currentBlock = nextBlock; - } - } - - size_t size() const { - size_t total = 0; - for (const Block* b = _head; b; b = b->next) total += b->size; - return total; - } - - virtual void* alloc(size_t bytes) { - return canAllocInHead(bytes) ? allocInHead(bytes) : allocInNewBlock(bytes); - } - - private: - bool canAllocInHead(size_t bytes) const { - return _head != NULL && _head->size + bytes <= _head->capacity; - } - - void* allocInHead(size_t bytes) { - void* p = _head->data + _head->size; - _head->size += round_size_up(bytes); - return p; - } - - void* allocInNewBlock(size_t bytes) { - size_t capacity = _nextBlockSize; - if (bytes > capacity) capacity = bytes; - if (!addNewBlock(capacity)) return NULL; - _nextBlockSize *= 2; - return allocInHead(bytes); - } - - bool addNewBlock(size_t capacity) { - size_t bytes = sizeof(EmptyBlock) + capacity; - Block* block = static_cast(_allocator.allocate(bytes)); - if (block == NULL) return false; - block->capacity = capacity; - block->size = 0; - block->next = _head; - _head = block; - return true; - } - - TAllocator _allocator; - Block* _head; - size_t _nextBlockSize; -}; -} -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Comments.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Comments.hpp deleted file mode 100644 index 968625ff..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Comments.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Internals { -inline const char *skipCStyleComment(const char *ptr) { - ptr += 2; - for (;;) { - if (ptr[0] == '\0') return ptr; - if (ptr[0] == '*' && ptr[1] == '/') return ptr + 2; - ptr++; - } -} - -inline const char *skipCppStyleComment(const char *ptr) { - ptr += 2; - for (;;) { - if (ptr[0] == '\0' || ptr[0] == '\n') return ptr; - ptr++; - } -} - -inline const char *skipSpacesAndComments(const char *ptr) { - for (;;) { - switch (ptr[0]) { - case ' ': - case '\t': - case '\r': - case '\n': - ptr++; - continue; - case '/': - switch (ptr[1]) { - case '*': - ptr = skipCStyleComment(ptr); - break; - case '/': - ptr = skipCppStyleComment(ptr); - break; - default: - return ptr; - } - break; - default: - return ptr; - } - } -} -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DummyPrint.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DummyPrint.hpp deleted file mode 100644 index dfd5a327..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DummyPrint.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A dummy Print implementation used in JsonPrintable::measureLength() -class DummyPrint : public Print { - public: - virtual size_t write(uint8_t) { return 1; } -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DynamicStringBuilder.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DynamicStringBuilder.hpp deleted file mode 100644 index 07536f2e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/DynamicStringBuilder.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" -#include "../String.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A Print implementation that allows to write in a String -class DynamicStringBuilder : public Print { - public: - DynamicStringBuilder(String &str) : _str(str) {} - - virtual size_t write(uint8_t c) { - // Need to cast to char, otherwise String will print a number (issue #120) - _str += static_cast(c); - return 1; - } - - private: - DynamicStringBuilder &operator=(const DynamicStringBuilder &); - - String &_str; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Encoding.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Encoding.hpp deleted file mode 100644 index 8dd7a44e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Encoding.hpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -class Encoding { - public: - // Optimized for code size on a 8-bit AVR - static char escapeChar(char c) { - const char *p = escapeTable(false); - while (p[0] && p[1] != c) { - p += 2; - } - return p[0]; - } - - // Optimized for code size on a 8-bit AVR - static char unescapeChar(char c) { - const char *p = escapeTable(true); - for (;;) { - if (p[0] == '\0') return c; - if (p[0] == c) return p[1]; - p += 2; - } - } - - private: - static const char *escapeTable(bool excludeIdenticals) { - return &"\"\"\\\\b\bf\fn\nr\rt\t"[excludeIdenticals ? 4 : 0]; - } -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/IndentedPrint.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/IndentedPrint.hpp deleted file mode 100644 index 94dd6f33..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/IndentedPrint.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Decorator on top of Print to allow indented output. -// This class is used by JsonPrintable::prettyPrintTo() but can also be used -// for your own purpose, like logging. -class IndentedPrint : public Print { - public: - explicit IndentedPrint(Print &p) : sink(&p) { - level = 0; - tabSize = 2; - isNewLine = true; - } - - virtual size_t write(uint8_t c) { - size_t n = 0; - if (isNewLine) n += writeTabs(); - n += sink->write(c); - isNewLine = c == '\n'; - return n; - } - - // Adds one level of indentation - void indent() { - if (level < MAX_LEVEL) level++; - } - - // Removes one level of indentation - void unindent() { - if (level > 0) level--; - } - - // Set the number of space printed for each level of indentation - void setTabSize(uint8_t n) { - if (n < MAX_TAB_SIZE) tabSize = n & MAX_TAB_SIZE; - } - - private: - Print *sink; - uint8_t level : 4; - uint8_t tabSize : 3; - bool isNewLine : 1; - - size_t writeTabs() { - size_t n = 0; - for (int i = 0; i < level * tabSize; i++) n += sink->write(' '); - return n; - } - - static const int MAX_LEVEL = 15; // because it's only 4 bits - static const int MAX_TAB_SIZE = 7; // because it's only 3 bits -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonBufferAllocated.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonBufferAllocated.hpp deleted file mode 100644 index 97328faf..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonBufferAllocated.hpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" - -namespace ArduinoJson { -namespace Internals { - -class JsonBufferAllocated { - public: - void *operator new(size_t n, JsonBuffer *jsonBuffer) throw() { - if (!jsonBuffer) return NULL; - return jsonBuffer->alloc(n); - } - - void operator delete(void *, JsonBuffer *) throw() {} -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonFloat.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonFloat.hpp deleted file mode 100644 index b6dc20f0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonFloat.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" - -namespace ArduinoJson { -namespace Internals { - -#if ARDUINOJSON_USE_DOUBLE -typedef double JsonFloat; -#else -typedef float JsonFloat; -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonInteger.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonInteger.hpp deleted file mode 100644 index 4b64f5c5..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonInteger.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" - -namespace ArduinoJson { -namespace Internals { - -#if ARDUINOJSON_USE_LONG_LONG -typedef long long JsonInteger; -typedef unsigned long long JsonUInt; -#elif ARDUINOJSON_USE_INT64 -typedef __int64 JsonInteger; -typedef unsigned _int64 JsonUInt; -#else -typedef long JsonInteger; -typedef unsigned long JsonUInt; -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.hpp deleted file mode 100644 index 3bd0f937..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" -#include "../JsonVariant.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Parse JSON string to create JsonArrays and JsonObjects -// This internal class is not indended to be used directly. -// Instead, use JsonBuffer.parseArray() or .parseObject() -class JsonParser { - public: - JsonParser(JsonBuffer *buffer, char *json, uint8_t nestingLimit) - : _buffer(buffer), - _readPtr(json ? json : ""), - _writePtr(json), - _nestingLimit(nestingLimit) {} - - JsonArray &parseArray(); - JsonObject &parseObject(); - - JsonVariant parseVariant() { - JsonVariant result; - parseAnythingTo(&result); - return result; - } - - private: - bool skip(char charToSkip); - - const char *parseString(); - bool parseAnythingTo(JsonVariant *destination); - FORCE_INLINE bool parseAnythingToUnsafe(JsonVariant *destination); - - inline bool parseArrayTo(JsonVariant *destination); - inline bool parseObjectTo(JsonVariant *destination); - inline bool parseStringTo(JsonVariant *destination); - - static inline bool isInRange(char c, char min, char max) { - return min <= c && c <= max; - } - - static inline bool isLetterOrNumber(char c) { - return isInRange(c, '0', '9') || isInRange(c, 'a', 'z') || - isInRange(c, 'A', 'Z') || c == '+' || c == '-' || c == '.'; - } - - static inline bool isQuote(char c) { - return c == '\'' || c == '\"'; - } - - JsonBuffer *_buffer; - const char *_readPtr; - char *_writePtr; - uint8_t _nestingLimit; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.ipp deleted file mode 100644 index 6a4e1b85..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonParser.ipp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Comments.hpp" -#include "JsonParser.hpp" - -inline bool ArduinoJson::Internals::JsonParser::skip(char charToSkip) { - const char *ptr = skipSpacesAndComments(_readPtr); - if (*ptr != charToSkip) return false; - ptr++; - _readPtr = skipSpacesAndComments(ptr); - return true; -} - -inline bool ArduinoJson::Internals::JsonParser::parseAnythingTo( - JsonVariant *destination) { - if (_nestingLimit == 0) return false; - _nestingLimit--; - bool success = parseAnythingToUnsafe(destination); - _nestingLimit++; - return success; -} - -inline bool ArduinoJson::Internals::JsonParser::parseAnythingToUnsafe( - JsonVariant *destination) { - _readPtr = skipSpacesAndComments(_readPtr); - - switch (*_readPtr) { - case '[': - return parseArrayTo(destination); - - case '{': - return parseObjectTo(destination); - - default: - return parseStringTo(destination); - } -} - -inline ArduinoJson::JsonArray & -ArduinoJson::Internals::JsonParser::parseArray() { - // Create an empty array - JsonArray &array = _buffer->createArray(); - - // Check opening braket - if (!skip('[')) goto ERROR_MISSING_BRACKET; - if (skip(']')) goto SUCCESS_EMPTY_ARRAY; - - // Read each value - for (;;) { - // 1 - Parse value - JsonVariant value; - if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE; - if (!array.add(value)) goto ERROR_NO_MEMORY; - - // 2 - More values? - if (skip(']')) goto SUCCES_NON_EMPTY_ARRAY; - if (!skip(',')) goto ERROR_MISSING_COMMA; - } - -SUCCESS_EMPTY_ARRAY: -SUCCES_NON_EMPTY_ARRAY: - return array; - -ERROR_INVALID_VALUE: -ERROR_MISSING_BRACKET: -ERROR_MISSING_COMMA: -ERROR_NO_MEMORY: - return JsonArray::invalid(); -} - -inline bool ArduinoJson::Internals::JsonParser::parseArrayTo( - JsonVariant *destination) { - JsonArray &array = parseArray(); - if (!array.success()) return false; - - *destination = array; - return true; -} - -inline ArduinoJson::JsonObject & -ArduinoJson::Internals::JsonParser::parseObject() { - // Create an empty object - JsonObject &object = _buffer->createObject(); - - // Check opening brace - if (!skip('{')) goto ERROR_MISSING_BRACE; - if (skip('}')) goto SUCCESS_EMPTY_OBJECT; - - // Read each key value pair - for (;;) { - // 1 - Parse key - const char *key = parseString(); - if (!key) goto ERROR_INVALID_KEY; - if (!skip(':')) goto ERROR_MISSING_COLON; - - // 2 - Parse value - JsonVariant value; - if (!parseAnythingTo(&value)) goto ERROR_INVALID_VALUE; - if (!object.set(key, value)) goto ERROR_NO_MEMORY; - - // 3 - More keys/values? - if (skip('}')) goto SUCCESS_NON_EMPTY_OBJECT; - if (!skip(',')) goto ERROR_MISSING_COMMA; - } - -SUCCESS_EMPTY_OBJECT: -SUCCESS_NON_EMPTY_OBJECT: - return object; - -ERROR_INVALID_KEY: -ERROR_INVALID_VALUE: -ERROR_MISSING_BRACE: -ERROR_MISSING_COLON: -ERROR_MISSING_COMMA: -ERROR_NO_MEMORY: - return JsonObject::invalid(); -} - -inline bool ArduinoJson::Internals::JsonParser::parseObjectTo( - JsonVariant *destination) { - JsonObject &object = parseObject(); - if (!object.success()) return false; - - *destination = object; - return true; -} - -inline const char *ArduinoJson::Internals::JsonParser::parseString() { - const char *readPtr = _readPtr; - char *writePtr = _writePtr; - - char c = *readPtr; - - if (isQuote(c)) { // quotes - char stopChar = c; - for (;;) { - c = *++readPtr; - if (c == '\0') break; - - if (c == stopChar) { - readPtr++; - break; - } - - if (c == '\\') { - // replace char - c = Encoding::unescapeChar(*++readPtr); - if (c == '\0') break; - } - - *writePtr++ = c; - } - } else { // no quotes - for (;;) { - if (!isLetterOrNumber(c)) break; - *writePtr++ = c; - c = *++readPtr; - } - } - // end the string here - *writePtr++ = '\0'; - - const char *startPtr = _writePtr; - - // update end ptr - _readPtr = readPtr; - _writePtr = writePtr; - - // return pointer to unquoted string - return startPtr; -} - -inline bool ArduinoJson::Internals::JsonParser::parseStringTo( - JsonVariant *destination) { - bool hasQuotes = isQuote(_readPtr[0]); - const char *value = parseString(); - if (value == NULL) return false; - if (hasQuotes) { - *destination = value; - } else { - *destination = RawJson(value); - } - return true; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonPrintable.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonPrintable.hpp deleted file mode 100644 index 45b6a942..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonPrintable.hpp +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "DummyPrint.hpp" -#include "DynamicStringBuilder.hpp" -#include "IndentedPrint.hpp" -#include "JsonSerializer.hpp" -#include "JsonWriter.hpp" -#include "Prettyfier.hpp" -#include "StaticStringBuilder.hpp" - -#if ARDUINOJSON_ENABLE_STD_STREAM -#include "StreamPrintAdapter.hpp" -#endif - -namespace ArduinoJson { -namespace Internals { - -// Implements all the overloads of printTo() and prettyPrintTo() -// Caution: this class use a template parameter to avoid virtual methods. -// This is a bit curious but allows to reduce the size of JsonVariant, JsonArray -// and JsonObject. -template -class JsonPrintable { - public: - size_t printTo(Print &print) const { - JsonWriter writer(print); - JsonSerializer::serialize(downcast(), writer); - return writer.bytesWritten(); - } - -#if ARDUINOJSON_ENABLE_STD_STREAM - std::ostream &printTo(std::ostream &os) const { - StreamPrintAdapter adapter(os); - printTo(adapter); - return os; - } -#endif - - size_t printTo(char *buffer, size_t bufferSize) const { - StaticStringBuilder sb(buffer, bufferSize); - return printTo(sb); - } - - size_t printTo(String &str) const { - DynamicStringBuilder sb(str); - return printTo(sb); - } - - size_t prettyPrintTo(IndentedPrint &print) const { - Prettyfier p(print); - return printTo(p); - } - - size_t prettyPrintTo(char *buffer, size_t bufferSize) const { - StaticStringBuilder sb(buffer, bufferSize); - return prettyPrintTo(sb); - } - - size_t prettyPrintTo(Print &print) const { - IndentedPrint indentedPrint = IndentedPrint(print); - return prettyPrintTo(indentedPrint); - } - - size_t prettyPrintTo(String &str) const { - DynamicStringBuilder sb(str); - return prettyPrintTo(sb); - } - - size_t measureLength() const { - DummyPrint dp; - return printTo(dp); - } - - size_t measurePrettyLength() const { - DummyPrint dp; - return prettyPrintTo(dp); - } - - private: - const T &downcast() const { - return *static_cast(this); - } -}; - -#if ARDUINOJSON_ENABLE_STD_STREAM -template -inline std::ostream &operator<<(std::ostream &os, const JsonPrintable &v) { - return v.printTo(os); -} -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.hpp deleted file mode 100644 index 1b00c654..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonWriter.hpp" - -namespace ArduinoJson { - -class JsonArray; -class JsonArraySubscript; -class JsonObject; -template -class JsonObjectSubscript; -class JsonVariant; - -namespace Internals { - -class JsonSerializer { - public: - static void serialize(const JsonArray &, JsonWriter &); - static void serialize(const JsonArraySubscript &, JsonWriter &); - static void serialize(const JsonObject &, JsonWriter &); - template - static void serialize(const JsonObjectSubscript &, JsonWriter &); - static void serialize(const JsonVariant &, JsonWriter &); -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.ipp deleted file mode 100644 index 5b8343b0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonSerializer.ipp +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonArray.hpp" -#include "../JsonArraySubscript.hpp" -#include "../JsonObject.hpp" -#include "../JsonObjectSubscript.hpp" -#include "../JsonVariant.hpp" -#include "JsonSerializer.hpp" - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonArray& array, JsonWriter& writer) { - writer.beginArray(); - - JsonArray::const_iterator it = array.begin(); - while (it != array.end()) { - serialize(*it, writer); - - ++it; - if (it == array.end()) break; - - writer.writeComma(); - } - - writer.endArray(); -} - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonArraySubscript& arraySubscript, JsonWriter& writer) { - serialize(arraySubscript.as(), writer); -} - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonObject& object, JsonWriter& writer) { - writer.beginObject(); - - JsonObject::const_iterator it = object.begin(); - while (it != object.end()) { - writer.writeString(it->key); - writer.writeColon(); - serialize(it->value, writer); - - ++it; - if (it == object.end()) break; - - writer.writeComma(); - } - - writer.endObject(); -} - -template -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonObjectSubscript& objectSubscript, JsonWriter& writer) { - serialize(objectSubscript.template as(), writer); -} - -inline void ArduinoJson::Internals::JsonSerializer::serialize( - const JsonVariant& variant, JsonWriter& writer) { - switch (variant._type) { - case JSON_UNDEFINED: - return; - - case JSON_ARRAY: - serialize(*variant._content.asArray, writer); - return; - - case JSON_OBJECT: - serialize(*variant._content.asObject, writer); - return; - - case JSON_STRING: - writer.writeString(variant._content.asString); - return; - - case JSON_UNPARSED: - writer.writeRaw(variant._content.asString); - return; - - case JSON_NEGATIVE_INTEGER: - writer.writeRaw('-'); - case JSON_POSITIVE_INTEGER: - writer.writeInteger(variant._content.asInteger); - return; - - case JSON_BOOLEAN: - writer.writeBoolean(variant._content.asInteger != 0); - return; - - default: - uint8_t decimals = - static_cast(variant._type - JSON_FLOAT_0_DECIMALS); - writer.writeFloat(variant._content.asFloat, decimals); - } -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantAs.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantAs.hpp deleted file mode 100644 index 97c968ed..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantAs.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Internals { - -// A metafunction that returns the type of the value returned by -// JsonVariant::as() -template -struct JsonVariantAs { - typedef T type; -}; - -template <> -struct JsonVariantAs { - typedef const char* type; -}; - -template <> -struct JsonVariantAs { - typedef JsonArray& type; -}; - -template <> -struct JsonVariantAs { - typedef const JsonArray& type; -}; - -template <> -struct JsonVariantAs { - typedef JsonObject& type; -}; - -template <> -struct JsonVariantAs { - typedef const JsonObject& type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantContent.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantContent.hpp deleted file mode 100644 index 5cd75ab7..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantContent.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonFloat.hpp" -#include "JsonInteger.hpp" - -namespace ArduinoJson { - -// Forward declarations -class JsonArray; -class JsonObject; - -namespace Internals { -// A union that defines the actual content of a JsonVariant. -// The enum JsonVariantType determines which member is in use. -union JsonVariantContent { - JsonFloat asFloat; // used for double and float - JsonUInt asInteger; // used for bool, char, short, int and longs - const char* asString; // asString can be null - JsonArray* asArray; // asArray cannot be null - JsonObject* asObject; // asObject cannot be null -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantType.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantType.hpp deleted file mode 100644 index 5bb7ef7b..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonVariantType.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -class JsonArray; -class JsonObject; - -namespace Internals { - -// Enumerated type to know the current type of a JsonVariant. -// The value determines which member of JsonVariantContent is used. -enum JsonVariantType { - JSON_UNDEFINED, // JsonVariant has not been initialized - JSON_UNPARSED, // JsonVariant contains an unparsed string - JSON_STRING, // JsonVariant stores a const char* - JSON_BOOLEAN, // JsonVariant stores a bool - JSON_POSITIVE_INTEGER, // JsonVariant stores an unsigned long - JSON_NEGATIVE_INTEGER, // JsonVariant stores an unsigned long that must be - // negated - JSON_ARRAY, // JsonVariant stores a pointer to a JsonArray - JSON_OBJECT, // JsonVariant stores a pointer to a JsonObject - - // The following values are reserved for float values - // Multiple values are used for double, depending on the number of decimal - // digits that must be printed in the JSON output. - // This little trick allow to save one extra member in JsonVariant - JSON_FLOAT_0_DECIMALS - // JSON_FLOAT_1_DECIMAL - // JSON_FLOAT_2_DECIMALS - // ... -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonWriter.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonWriter.hpp deleted file mode 100644 index c832b15a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/JsonWriter.hpp +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Polyfills/attributes.hpp" -#include "../Polyfills/math.hpp" -#include "../Polyfills/normalize.hpp" -#include "../Print.hpp" -#include "Encoding.hpp" -#include "JsonFloat.hpp" -#include "JsonInteger.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Writes the JSON tokens to a Print implementation -// This class is used by: -// - JsonArray::writeTo() -// - JsonObject::writeTo() -// - JsonVariant::writeTo() -// Its derived by PrettyJsonWriter that overrides some members to add -// indentation. -class JsonWriter { - public: - explicit JsonWriter(Print &sink) : _sink(sink), _length(0) {} - - // Returns the number of bytes sent to the Print implementation. - // This is very handy for implementations of printTo() that must return the - // number of bytes written. - size_t bytesWritten() const { - return _length; - } - - void beginArray() { - writeRaw('['); - } - void endArray() { - writeRaw(']'); - } - - void beginObject() { - writeRaw('{'); - } - void endObject() { - writeRaw('}'); - } - - void writeColon() { - writeRaw(':'); - } - void writeComma() { - writeRaw(','); - } - - void writeBoolean(bool value) { - writeRaw(value ? "true" : "false"); - } - - void writeString(const char *value) { - if (!value) { - writeRaw("null"); - } else { - writeRaw('\"'); - while (*value) writeChar(*value++); - writeRaw('\"'); - } - } - - void writeChar(char c) { - char specialChar = Encoding::escapeChar(c); - if (specialChar) { - writeRaw('\\'); - writeRaw(specialChar); - } else { - writeRaw(c); - } - } - - void writeFloat(JsonFloat value, uint8_t digits = 2) { - if (Polyfills::isNaN(value)) return writeRaw("NaN"); - - if (value < 0.0) { - writeRaw('-'); - value = -value; - } - - if (Polyfills::isInfinity(value)) return writeRaw("Infinity"); - - short powersOf10; - if (value > 1000 || value < 0.001) { - powersOf10 = Polyfills::normalize(value); - } else { - powersOf10 = 0; - } - - // Round up last digit (so that print(1.999, 2) prints as "2.00") - value += getRoundingBias(digits); - - // Extract the integer part of the value and print it - JsonUInt int_part = static_cast(value); - JsonFloat remainder = value - static_cast(int_part); - writeInteger(int_part); - - // Print the decimal point, but only if there are digits beyond - if (digits > 0) { - writeRaw('.'); - } - - // Extract digits from the remainder one at a time - while (digits-- > 0) { - // Extract digit - remainder *= 10.0; - char currentDigit = char(remainder); - remainder -= static_cast(currentDigit); - - // Print - writeRaw(char('0' + currentDigit)); - } - - if (powersOf10 < 0) { - writeRaw("e-"); - writeInteger(-powersOf10); - } - - if (powersOf10 > 0) { - writeRaw('e'); - writeInteger(powersOf10); - } - } - - void writeInteger(JsonUInt value) { - char buffer[22]; - char *ptr = buffer + sizeof(buffer) - 1; - - *ptr = 0; - do { - *--ptr = static_cast(value % 10 + '0'); - value /= 10; - } while (value); - - writeRaw(ptr); - } - - void writeRaw(const char *s) { - _length += _sink.print(s); - } - void writeRaw(char c) { - _length += _sink.write(c); - } - - protected: - Print &_sink; - size_t _length; - - private: - JsonWriter &operator=(const JsonWriter &); // cannot be assigned - - static JsonFloat getLastDigit(uint8_t digits) { - // Designed as a compromise between code size and speed - switch (digits) { - case 0: - return 1e-0; - case 1: - return 1e-1; - case 2: - return 1e-2; - case 3: - return 1e-3; - default: - return getLastDigit(uint8_t(digits - 4)) * 1e-4; - } - } - - FORCE_INLINE static JsonFloat getRoundingBias(uint8_t digits) { - return 0.5 * getLastDigit(digits); - } -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/List.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/List.hpp deleted file mode 100644 index 6072292e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/List.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../JsonBuffer.hpp" -#include "ListConstIterator.hpp" -#include "ListIterator.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A singly linked list of T. -// The linked list is composed of ListNode. -// It is derived by JsonArray and JsonObject -template -class List { - public: - typedef T value_type; - typedef ListNode node_type; - typedef ListIterator iterator; - typedef ListConstIterator const_iterator; - - // Creates an empty List attached to a JsonBuffer. - // The JsonBuffer allows to allocate new nodes. - // When buffer is NULL, the List is not able to grow and success() returns - // false. This is used to identify bad memory allocations and parsing - // failures. - explicit List(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {} - - // Returns true if the object is valid - // Would return false in the following situation: - // - the memory allocation failed (StaticJsonBuffer was too small) - // - the JSON parsing failed - bool success() const { - return _buffer != NULL; - } - - // Returns the numbers of elements in the list. - // For a JsonObject, it would return the number of key-value pairs - size_t size() const { - size_t nodeCount = 0; - for (node_type *node = _firstNode; node; node = node->next) nodeCount++; - return nodeCount; - } - - iterator begin() { - return iterator(_firstNode); - } - iterator end() { - return iterator(NULL); - } - - const_iterator begin() const { - return const_iterator(_firstNode); - } - const_iterator end() const { - return const_iterator(NULL); - } - - protected: - node_type *addNewNode() { - node_type *newNode = new (_buffer) node_type(); - - if (_firstNode) { - node_type *lastNode = _firstNode; - while (lastNode->next) lastNode = lastNode->next; - lastNode->next = newNode; - } else { - _firstNode = newNode; - } - - return newNode; - } - - void removeNode(node_type *nodeToRemove) { - if (!nodeToRemove) return; - if (nodeToRemove == _firstNode) { - _firstNode = nodeToRemove->next; - } else { - for (node_type *node = _firstNode; node; node = node->next) - if (node->next == nodeToRemove) node->next = nodeToRemove->next; - } - } - - JsonBuffer *_buffer; - node_type *_firstNode; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListConstIterator.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListConstIterator.hpp deleted file mode 100644 index f6b7ca53..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListConstIterator.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "ListNode.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A read-only forward itertor for List -template -class ListConstIterator { - public: - explicit ListConstIterator(const ListNode *node = NULL) : _node(node) {} - - const T &operator*() const { return _node->content; } - const T *operator->() { return &_node->content; } - - bool operator==(const ListConstIterator &other) const { - return _node == other._node; - } - - bool operator!=(const ListConstIterator &other) const { - return _node != other._node; - } - - ListConstIterator &operator++() { - if (_node) _node = _node->next; - return *this; - } - - private: - const ListNode *_node; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListIterator.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListIterator.hpp deleted file mode 100644 index 17342971..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListIterator.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "ListNode.hpp" -#include "ListConstIterator.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A read-write forward iterator for List -template -class ListIterator { - public: - explicit ListIterator(ListNode *node = NULL) : _node(node) {} - - T &operator*() const { return _node->content; } - T *operator->() { return &_node->content; } - - bool operator==(const ListIterator &other) const { - return _node == other._node; - } - - bool operator!=(const ListIterator &other) const { - return _node != other._node; - } - - ListIterator &operator++() { - if (_node) _node = _node->next; - return *this; - } - - operator ListConstIterator() const { return ListConstIterator(_node); } - - private: - ListNode *_node; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListNode.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListNode.hpp deleted file mode 100644 index 3c94662d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ListNode.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include // for NULL - -#include "JsonBufferAllocated.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A node for a singly-linked list. -// Used by List and its iterators. -template -struct ListNode : public Internals::JsonBufferAllocated { - ListNode() : next(NULL) {} - - ListNode *next; - T content; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Parse.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Parse.hpp deleted file mode 100644 index 0068d91f..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Parse.hpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include - -namespace ArduinoJson { -namespace Internals { -template -TFloat parse(const char *); - -template <> -inline float parse(const char *s) { - return static_cast(strtod(s, NULL)); -} - -template <> -inline double parse(const char *s) { - return strtod(s, NULL); -} - -template <> -inline long parse(const char *s) { - return strtol(s, NULL, 10); -} - -template <> -inline unsigned long parse(const char *s) { - return strtoul(s, NULL, 10); -} - -template <> -inline int parse(const char *s) { - return atoi(s); -} - -#if ARDUINOJSON_USE_LONG_LONG -template <> -inline long long parse(const char *s) { - return strtoll(s, NULL, 10); -} - -template <> -inline unsigned long long parse(const char *s) { - return strtoull(s, NULL, 10); -} -#endif - -#if ARDUINOJSON_USE_INT64 -template <> -inline __int64 parse<__int64>(const char *s) { - return _strtoi64(s, NULL, 10); -} - -template <> -inline unsigned __int64 parse(const char *s) { - return _strtoui64(s, NULL, 10); -} -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Prettyfier.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Prettyfier.hpp deleted file mode 100644 index f3609e92..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/Prettyfier.hpp +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "IndentedPrint.hpp" - -namespace ArduinoJson { -namespace Internals { - -// Converts a compact JSON string into an indented one. -class Prettyfier : public Print { - public: - explicit Prettyfier(IndentedPrint& p) : _sink(p) { - _previousChar = 0; - _inString = false; - } - - virtual size_t write(uint8_t c) { - size_t n = _inString ? handleStringChar(c) : handleMarkupChar(c); - _previousChar = c; - return n; - } - - private: - Prettyfier& operator=(const Prettyfier&); // cannot be assigned - - bool inEmptyBlock() { - return _previousChar == '{' || _previousChar == '['; - } - - size_t handleStringChar(uint8_t c) { - bool isQuote = c == '"' && _previousChar != '\\'; - - if (isQuote) _inString = false; - - return _sink.write(c); - } - - size_t handleMarkupChar(uint8_t c) { - switch (c) { - case '{': - case '[': - return writeBlockOpen(c); - - case '}': - case ']': - return writeBlockClose(c); - - case ':': - return writeColon(); - - case ',': - return writeComma(); - - case '"': - return writeQuoteOpen(); - - default: - return writeNormalChar(c); - } - } - - size_t writeBlockClose(uint8_t c) { - size_t n = 0; - n += unindentIfNeeded(); - n += _sink.write(c); - return n; - } - - size_t writeBlockOpen(uint8_t c) { - size_t n = 0; - n += indentIfNeeded(); - n += _sink.write(c); - return n; - } - - size_t writeColon() { - size_t n = 0; - n += _sink.write(':'); - n += _sink.write(' '); - return n; - } - - size_t writeComma() { - size_t n = 0; - n += _sink.write(','); - n += _sink.println(); - return n; - } - - size_t writeQuoteOpen() { - _inString = true; - size_t n = 0; - n += indentIfNeeded(); - n += _sink.write('"'); - return n; - } - - size_t writeNormalChar(uint8_t c) { - size_t n = 0; - n += indentIfNeeded(); - n += _sink.write(c); - return n; - } - - size_t indentIfNeeded() { - if (!inEmptyBlock()) return 0; - - _sink.indent(); - return _sink.println(); - } - - size_t unindentIfNeeded() { - if (inEmptyBlock()) return 0; - - _sink.unindent(); - return _sink.println(); - } - - uint8_t _previousChar; - IndentedPrint& _sink; - bool _inString; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ReferenceType.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ReferenceType.hpp deleted file mode 100644 index a5cf507a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/ReferenceType.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Internals { - -// A type that is meant to be used by reference only (JsonArray and JsonObject) -class ReferenceType { - public: - bool operator==(const ReferenceType& other) const { - // two JsonArray are equal if they are the same instance - // (we don't compare the content) - return this == &other; - } - - bool operator!=(const ReferenceType& other) const { return this != &other; } - - protected: - ReferenceType() {} - - private: - // copy constructor is private - ReferenceType(const ReferenceType&); - - // copy operator is private - ReferenceType& operator=(const ReferenceType&); -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StaticStringBuilder.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StaticStringBuilder.hpp deleted file mode 100644 index 8fdcf88a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StaticStringBuilder.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Print.hpp" - -namespace ArduinoJson { -namespace Internals { - -// A Print implementation that allows to write in a char[] -class StaticStringBuilder : public Print { - public: - StaticStringBuilder(char *buf, size_t size) - : buffer(buf), capacity(size - 1), length(0) { - buffer[0] = '\0'; - } - - virtual size_t write(uint8_t c) { - if (length >= capacity) return 0; - - buffer[length++] = c; - buffer[length] = '\0'; - return 1; - } - - private: - char *buffer; - size_t capacity; - size_t length; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StreamPrintAdapter.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StreamPrintAdapter.hpp deleted file mode 100644 index 0f17291d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Internals/StreamPrintAdapter.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" - -#if ARDUINOJSON_ENABLE_STD_STREAM - -#include "../Print.hpp" - -#include - -namespace ArduinoJson { -namespace Internals { - -class StreamPrintAdapter : public Print { - public: - explicit StreamPrintAdapter(std::ostream& os) : _os(os) {} - - virtual size_t write(uint8_t c) { - _os << static_cast(c); - return 1; - } - - private: - // cannot be assigned - StreamPrintAdapter& operator=(const StreamPrintAdapter&); - - std::ostream& _os; -}; -} -} - -#endif // ARDUINOJSON_ENABLE_STD_STREAM diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.hpp deleted file mode 100644 index b9c03662..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.hpp +++ /dev/null @@ -1,251 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/JsonBufferAllocated.hpp" -#include "Internals/JsonPrintable.hpp" -#include "Internals/List.hpp" -#include "Internals/ReferenceType.hpp" -#include "JsonVariant.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsReference.hpp" -#include "TypeTraits/IsSame.hpp" - -// Returns the size (in bytes) of an array with n elements. -// Can be very handy to determine the size of a StaticJsonBuffer. -#define JSON_ARRAY_SIZE(NUMBER_OF_ELEMENTS) \ - (sizeof(JsonArray) + (NUMBER_OF_ELEMENTS) * sizeof(JsonArray::node_type)) - -namespace ArduinoJson { - -// Forward declarations -class JsonObject; -class JsonBuffer; -class JsonArraySubscript; - -// An array of JsonVariant. -// -// The constructor is private, instances must be created via -// JsonBuffer::createArray() or JsonBuffer::parseArray(). -// A JsonArray can be serialized to a JSON string via JsonArray::printTo(). -// It can also be deserialized from a JSON string via JsonBuffer::parseArray(). -class JsonArray : public Internals::JsonPrintable, - public Internals::ReferenceType, - public Internals::List, - public Internals::JsonBufferAllocated { - public: - // A meta-function that returns true if type T can be used in - // JsonArray::set() - template - struct CanSet { - static const bool value = JsonVariant::IsConstructibleFrom::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value; - }; - - // Create an empty JsonArray attached to the specified JsonBuffer. - // You should not call this constructor directly. - // Instead, use JsonBuffer::createArray() or JsonBuffer::parseArray(). - explicit JsonArray(JsonBuffer *buffer) - : Internals::List(buffer) {} - - // Gets the value at the specified index - JsonVariant operator[](size_t index) const { - return get(index); - } - - // Gets or sets the value at specified index - JsonArraySubscript operator[](size_t index); - - // Adds the specified value at the end of the array. - // - // bool add(bool); - // bool add(char); - // bool add(long); - // bool add(int); - // bool add(short); - // bool add(float value); - // bool add(double value); - // bool add(const char*); - template - bool add( - T value, - typename TypeTraits::EnableIf< - CanSet::value && !TypeTraits::IsReference::value>::type * = 0) { - return addNode(value); - } - // bool add(const String&) - // bool add(const JsonVariant&); - // bool add(JsonArray&); - // bool add(JsonObject&); - template - bool add(const T &value, - typename TypeTraits::EnableIf::value>::type * = 0) { - return addNode(const_cast(value)); - } - // bool add(float value, uint8_t decimals); - // bool add(double value, uint8_t decimals); - template - bool add(T value, uint8_t decimals, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type * = 0) { - return addNode(JsonVariant(value, decimals)); - } - - // Sets the value at specified index. - // - // bool set(size_t index, bool value); - // bool set(size_t index, long value); - // bool set(size_t index, int value); - // bool set(size_t index, short value); - template - bool set( - size_t index, T value, - typename TypeTraits::EnableIf< - CanSet::value && !TypeTraits::IsReference::value>::type * = 0) { - return setNodeAt(index, value); - } - // bool set(size_t index, const String&) - // bool set(size_t index, const JsonVariant&); - // bool set(size_t index, JsonArray&); - // bool set(size_t index, JsonObject&); - template - bool set(size_t index, const T &value, - typename TypeTraits::EnableIf::value>::type * = 0) { - return setNodeAt(index, const_cast(value)); - } - // bool set(size_t index, float value, uint8_t decimals = 2); - // bool set(size_t index, double value, uint8_t decimals = 2); - template - bool set(size_t index, T value, uint8_t decimals, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type * = 0) { - return setNodeAt(index, JsonVariant(value, decimals)); - } - - // Gets the value at the specified index. - JsonVariant get(size_t index) const { - node_type *node = getNodeAt(index); - return node ? node->content : JsonVariant(); - } - - // Gets the value at the specified index. - template - typename Internals::JsonVariantAs::type get(size_t index) const { - node_type *node = getNodeAt(index); - return node ? node->content.as() : JsonVariant::defaultValue(); - } - - // Check the type of the value at specified index. - template - bool is(size_t index) const { - node_type *node = getNodeAt(index); - return node ? node->content.is() : false; - } - - // Creates a JsonArray and adds a reference at the end of the array. - // It's a shortcut for JsonBuffer::createArray() and JsonArray::add() - JsonArray &createNestedArray(); - - // Creates a JsonObject and adds a reference at the end of the array. - // It's a shortcut for JsonBuffer::createObject() and JsonArray::add() - JsonObject &createNestedObject(); - - // Removes element at specified index. - void removeAt(size_t index) { - removeNode(getNodeAt(index)); - } - - // Returns a reference an invalid JsonArray. - // This object is meant to replace a NULL pointer. - // This is used when memory allocation or JSON parsing fail. - static JsonArray &invalid() { - static JsonArray instance(NULL); - return instance; - } - - // Imports a 1D array - template - bool copyFrom(T(&array)[N]) { - return copyFrom(array, N); - } - - // Imports a 1D array - template - bool copyFrom(T *array, size_t len) { - bool ok = true; - for (size_t i = 0; i < len; i++) { - ok &= add(array[i]); - } - return ok; - } - - // Imports a 2D array - template - bool copyFrom(T(&array)[N1][N2]) { - bool ok = true; - for (size_t i = 0; i < N1; i++) { - JsonArray &nestedArray = createNestedArray(); - for (size_t j = 0; j < N2; j++) { - ok &= nestedArray.add(array[i][j]); - } - } - return ok; - } - - // Exports a 1D array - template - size_t copyTo(T(&array)[N]) const { - return copyTo(array, N); - } - - // Exports a 1D array - template - size_t copyTo(T *array, size_t len) const { - size_t i = 0; - for (const_iterator it = begin(); it != end() && i < len; ++it) - array[i++] = *it; - return i; - } - - // Exports a 2D array - template - void copyTo(T(&array)[N1][N2]) const { - size_t i = 0; - for (const_iterator it = begin(); it != end() && i < N1; ++it) { - it->asArray().copyTo(array[i++]); - } - } - - private: - node_type *getNodeAt(size_t index) const { - node_type *node = _firstNode; - while (node && index--) node = node->next; - return node; - } - - template - bool setNodeAt(size_t index, TValue value) { - node_type *node = getNodeAt(index); - return node != NULL && setNodeValue(node, value); - } - - template - bool addNode(TValue value) { - node_type *node = addNewNode(); - return node != NULL && setNodeValue(node, value); - } - - template - bool setNodeValue(node_type *node, T value) { - node->content = value; - return true; - } -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.ipp deleted file mode 100644 index 08257ecd..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArray.ipp +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonArray.hpp" -#include "JsonArraySubscript.hpp" -#include "JsonObject.hpp" - -namespace ArduinoJson { - -inline JsonVariant::JsonVariant(JsonArray &array) { - if (array.success()) { - _type = Internals::JSON_ARRAY; - _content.asArray = &array; - } else { - _type = Internals::JSON_UNDEFINED; - } -} - -inline JsonVariant::JsonVariant(JsonObject &object) { - if (object.success()) { - _type = Internals::JSON_OBJECT; - _content.asObject = &object; - } else { - _type = Internals::JSON_UNDEFINED; - } -} - -template <> -inline bool JsonArray::setNodeValue(node_type *node, String &value) { - const char *copy = _buffer->strdup(value); - if (!copy) return false; - node->content = copy; - return true; -} - -template <> -inline JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -template <> -inline JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -template <> -inline const JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -template <> -inline const JsonArray &JsonVariant::defaultValue() { - return JsonArray::invalid(); -} - -inline JsonArray &JsonVariant::asArray() const { - if (_type == Internals::JSON_ARRAY) return *_content.asArray; - return JsonArray::invalid(); -} - -inline JsonArray &JsonArray::createNestedArray() { - if (!_buffer) return JsonArray::invalid(); - JsonArray &array = _buffer->createArray(); - add(array); - return array; -} - -inline JsonArray &JsonObject::createNestedArray(JsonObjectKey key) { - if (!_buffer) return JsonArray::invalid(); - JsonArray &array = _buffer->createArray(); - setNodeAt(key, array); - return array; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArraySubscript.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArraySubscript.hpp deleted file mode 100644 index f622a6c8..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonArraySubscript.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" -#include "JsonVariantBase.hpp" - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) -#endif - -namespace ArduinoJson { -class JsonArraySubscript : public JsonVariantBase { - public: - FORCE_INLINE JsonArraySubscript(JsonArray& array, size_t index) - : _array(array), _index(index) {} - - JsonArraySubscript& operator=(const JsonArraySubscript& src) { - _array.set(_index, src); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonArraySubscript>::type& - operator=(const T& src) { - _array.set(_index, const_cast(src)); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonArraySubscript>::type& - operator=(T src) { - _array.set(_index, src); - return *this; - } - - FORCE_INLINE bool success() const { - return _index < _array.size(); - } - - FORCE_INLINE operator JsonVariant() const { - return _array.get(_index); - } - - template - FORCE_INLINE typename Internals::JsonVariantAs::type as() const { - return _array.get(_index); - } - - template - FORCE_INLINE bool is() const { - return _array.is(_index); - } - - template - void set(TValue value) { - _array.set(_index, value); - } - - private: - JsonArray& _array; - const size_t _index; -}; - -#if ARDUINOJSON_ENABLE_STD_STREAM -inline std::ostream& operator<<(std::ostream& os, - const JsonArraySubscript& source) { - return source.printTo(os); -} -#endif - -inline JsonArraySubscript JsonArray::operator[](size_t index) { - return JsonArraySubscript(*this, index); -} - -template -inline const JsonArraySubscript JsonVariantBase::operator[]( - int index) const { - return asArray()[index]; -} - -} // namespace ArduinoJson - -#ifdef _MSC_VER -#pragma warning(pop) -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.hpp deleted file mode 100644 index eb61069a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include // for size_t -#include // for uint8_t -#include - -#include "JsonVariant.hpp" -#include "String.hpp" - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnon-virtual-dtor" -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#endif - -namespace ArduinoJson { -class JsonArray; -class JsonObject; - -// Entry point for using the library. -// -// Handle the memory management (done in derived classes) and calls the parser. -// This abstract class is implemented by StaticJsonBuffer which implements a -// fixed memory allocation. -class JsonBuffer { - public: - // CAUTION: NO VIRTUAL DESTRUCTOR! - // If we add a virtual constructor the Arduino compiler will add malloc() and - // free() to the binary, adding 706 useless bytes. - // virtual ~JsonBuffer() {} - - // Allocates an empty JsonArray. - // - // Returns a reference to the new JsonArray or JsonArray::invalid() if the - // allocation fails. - JsonArray &createArray(); - - // Allocates an empty JsonObject. - // - // Returns a reference to the new JsonObject or JsonObject::invalid() if the - // allocation fails. - JsonObject &createObject(); - - // Allocates and populate a JsonArray from a JSON string. - // - // The First argument is a pointer to the JSON string, the memory must be - // writable - // because the parser will insert null-terminators and replace escaped chars. - // - // The second argument set the nesting limit (see comment on DEFAULT_LIMIT) - // - // Returns a reference to the new JsonObject or JsonObject::invalid() if the - // allocation fails. - JsonArray &parseArray(char *json, uint8_t nestingLimit = DEFAULT_LIMIT); - - // Same with a const char*. - // With this overload, the JsonBuffer will make a copy of the string - JsonArray &parseArray(const char *json, uint8_t nesting = DEFAULT_LIMIT) { - return parseArray(strdup(json), nesting); - } - - // Same as above with a String class - JsonArray &parseArray(const String &json, uint8_t nesting = DEFAULT_LIMIT) { - return parseArray(json.c_str(), nesting); - } - - // Allocates and populate a JsonObject from a JSON string. - // - // The First argument is a pointer to the JSON string, the memory must be - // writable - // because the parser will insert null-terminators and replace escaped chars. - // - // The second argument set the nesting limit (see comment on DEFAULT_LIMIT) - // - // Returns a reference to the new JsonObject or JsonObject::invalid() if the - // allocation fails. - JsonObject &parseObject(char *json, uint8_t nestingLimit = DEFAULT_LIMIT); - - // Same with a const char*. - // With this overload, the JsonBuffer will make a copy of the string - JsonObject &parseObject(const char *json, uint8_t nesting = DEFAULT_LIMIT) { - return parseObject(strdup(json), nesting); - } - - // Same as above with a String class - JsonObject &parseObject(const String &json, uint8_t nesting = DEFAULT_LIMIT) { - return parseObject(json.c_str(), nesting); - } - - // Generalized version of parseArray() and parseObject(), also works for - // integral types. - JsonVariant parse(char *json, uint8_t nestingLimit = DEFAULT_LIMIT); - - // Same with a const char*. - // With this overload, the JsonBuffer will make a copy of the string - JsonVariant parse(const char *json, uint8_t nesting = DEFAULT_LIMIT) { - return parse(strdup(json), nesting); - } - - // Same as above with a String class - JsonVariant parse(const String &json, uint8_t nesting = DEFAULT_LIMIT) { - return parse(json.c_str(), nesting); - } - - // Duplicate a string - char *strdup(const char *src) { - return src ? strdup(src, strlen(src)) : NULL; - } - char *strdup(const String &src) { return strdup(src.c_str(), src.length()); } - - // Allocates n bytes in the JsonBuffer. - // Return a pointer to the allocated memory or NULL if allocation fails. - virtual void *alloc(size_t size) = 0; - - protected: - // Preserve aligment if nessary - static FORCE_INLINE size_t round_size_up(size_t bytes) { -#if ARDUINOJSON_ENABLE_ALIGNMENT - const size_t x = sizeof(void *) - 1; - return (bytes + x) & ~x; -#else - return bytes; -#endif - } - - private: - char *strdup(const char *, size_t); - - // Default value of nesting limit of parseArray() and parseObject(). - // - // The nesting limit is a contain on the level of nesting allowed in the - // JSON - // string. - // If set to 0, only a flat array or objects can be parsed. - // If set to 1, the object can contain nested arrays or objects but only 1 - // level deep. - // And bigger values will allow more level of nesting. - // - // The purpose of this feature is to prevent stack overflow that could - // lead to - // a security risk. - static const uint8_t DEFAULT_LIMIT = 10; -}; -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.ipp deleted file mode 100644 index ed89bd9e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonBuffer.ipp +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/JsonParser.hpp" - -inline ArduinoJson::JsonArray &ArduinoJson::JsonBuffer::createArray() { - JsonArray *ptr = new (this) JsonArray(this); - return ptr ? *ptr : JsonArray::invalid(); -} - -inline ArduinoJson::JsonObject &ArduinoJson::JsonBuffer::createObject() { - JsonObject *ptr = new (this) JsonObject(this); - return ptr ? *ptr : JsonObject::invalid(); -} - -inline ArduinoJson::JsonArray &ArduinoJson::JsonBuffer::parseArray( - char *json, uint8_t nestingLimit) { - Internals::JsonParser parser(this, json, nestingLimit); - return parser.parseArray(); -} - -inline ArduinoJson::JsonObject &ArduinoJson::JsonBuffer::parseObject( - char *json, uint8_t nestingLimit) { - Internals::JsonParser parser(this, json, nestingLimit); - return parser.parseObject(); -} - -inline ArduinoJson::JsonVariant ArduinoJson::JsonBuffer::parse( - char *json, uint8_t nestingLimit) { - Internals::JsonParser parser(this, json, nestingLimit); - return parser.parseVariant(); -} - -inline char *ArduinoJson::JsonBuffer::strdup(const char *source, - size_t length) { - size_t size = length + 1; - char *dest = static_cast(alloc(size)); - if (dest != NULL) memcpy(dest, source, size); - return dest; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.hpp deleted file mode 100644 index 8daf1029..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.hpp +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "String.hpp" -#include "Internals/JsonBufferAllocated.hpp" -#include "Internals/JsonPrintable.hpp" -#include "Internals/List.hpp" -#include "Internals/ReferenceType.hpp" -#include "JsonPair.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsReference.hpp" -#include "TypeTraits/IsSame.hpp" - -// Returns the size (in bytes) of an object with n elements. -// Can be very handy to determine the size of a StaticJsonBuffer. -#define JSON_OBJECT_SIZE(NUMBER_OF_ELEMENTS) \ - (sizeof(JsonObject) + (NUMBER_OF_ELEMENTS) * sizeof(JsonObject::node_type)) - -namespace ArduinoJson { - -// Forward declarations -class JsonArray; -class JsonBuffer; - -// A dictionary of JsonVariant indexed by string (char*) -// -// The constructor is private, instances must be created via -// JsonBuffer::createObject() or JsonBuffer::parseObject(). -// A JsonObject can be serialized to a JSON string via JsonObject::printTo(). -// It can also be deserialized from a JSON string via JsonBuffer::parseObject(). -class JsonObject : public Internals::JsonPrintable, - public Internals::ReferenceType, - public Internals::List, - public Internals::JsonBufferAllocated { - public: - // A meta-function that returns true if type T can be used in - // JsonObject::set() - template - struct CanSet { - static const bool value = JsonVariant::IsConstructibleFrom::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value; - }; - - // Create an empty JsonArray attached to the specified JsonBuffer. - // You should not use this constructor directly. - // Instead, use JsonBuffer::createObject() or JsonBuffer.parseObject(). - explicit JsonObject(JsonBuffer* buffer) : Internals::List(buffer) {} - - // Gets or sets the value associated with the specified key. - JsonObjectSubscript operator[](const char* key); - JsonObjectSubscript operator[](const String& key); - - // Gets the value associated with the specified key. - JsonVariant operator[](JsonObjectKey key) const { - return get(key); - } - - // Sets the specified key with the specified value. - // bool set(TKey key, bool value); - // bool set(TKey key, char value); - // bool set(TKey key, long value); - // bool set(TKey key, int value); - // bool set(TKey key, short value); - // bool set(TKey key, float value); - // bool set(TKey key, double value); - // bool set(TKey key, const char* value); - // bool set(TKey key, RawJson value); - template - bool set( - JsonObjectKey key, T value, - typename TypeTraits::EnableIf< - CanSet::value && !TypeTraits::IsReference::value>::type* = 0) { - return setNodeAt(key, value); - } - // bool set(Key, String&); - // bool set(Key, JsonArray&); - // bool set(Key, JsonObject&); - // bool set(Key, JsonVariant&); - template - bool set(JsonObjectKey key, const T& value, - typename TypeTraits::EnableIf::value>::type* = 0) { - return setNodeAt(key, const_cast(value)); - } - // bool set(Key, float value, uint8_t decimals); - // bool set(Key, double value, uint8_t decimals); - template - bool set(JsonObjectKey key, TValue value, uint8_t decimals, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type* = 0) { - return setNodeAt(key, JsonVariant(value, decimals)); - } - - // Gets the value associated with the specified key. - JsonVariant get(JsonObjectKey key) const { - node_type* node = getNodeAt(key.c_str()); - return node ? node->content.value : JsonVariant(); - } - - // Gets the value associated with the specified key. - template - typename Internals::JsonVariantAs::type get(JsonObjectKey key) const { - node_type* node = getNodeAt(key.c_str()); - return node ? node->content.value.as() : JsonVariant::defaultValue(); - } - - // Checks the type of the value associated with the specified key. - template - bool is(JsonObjectKey key) const { - node_type* node = getNodeAt(key.c_str()); - return node ? node->content.value.is() : false; - } - - // Creates and adds a JsonArray. - // This is a shortcut for JsonBuffer::createArray() and JsonObject::add(). - JsonArray& createNestedArray(JsonObjectKey key); - - // Creates and adds a JsonObject. - // This is a shortcut for JsonBuffer::createObject() and JsonObject::add(). - JsonObject& createNestedObject(JsonObjectKey key); - - // Tells weither the specified key is present and associated with a value. - bool containsKey(JsonObjectKey key) const { - return getNodeAt(key.c_str()) != NULL; - } - - // Removes the specified key and the associated value. - void remove(JsonObjectKey key) { - removeNode(getNodeAt(key.c_str())); - } - - // Returns a reference an invalid JsonObject. - // This object is meant to replace a NULL pointer. - // This is used when memory allocation or JSON parsing fail. - static JsonObject& invalid() { - static JsonObject instance(NULL); - return instance; - } - - private: - // Returns the list node that matches the specified key. - node_type* getNodeAt(const char* key) const { - for (node_type* node = _firstNode; node; node = node->next) { - if (!strcmp(node->content.key, key)) return node; - } - return NULL; - } - - template - bool setNodeAt(JsonObjectKey key, T value) { - node_type* node = getNodeAt(key.c_str()); - if (!node) { - node = addNewNode(); - if (!node || !setNodeKey(node, key)) return false; - } - return setNodeValue(node, value); - } - - bool setNodeKey(node_type* node, JsonObjectKey key) { - if (key.needs_copy()) { - node->content.key = _buffer->strdup(key.c_str()); - if (node->content.key == NULL) return false; - } else { - node->content.key = key.c_str(); - } - return true; - } - - template - bool setNodeValue(node_type* node, T value) { - node->content.value = value; - return true; - } -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.ipp deleted file mode 100644 index d421ca94..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObject.ipp +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonArray.hpp" -#include "JsonObject.hpp" -#include "JsonObjectSubscript.hpp" - -namespace ArduinoJson { - -template <> -inline bool JsonObject::setNodeValue(node_type *node, String &value) { - const char *dup = _buffer->strdup(value); - node->content.value = dup; - return dup != NULL; -} - -template <> -inline bool JsonObject::setNodeValue(node_type *node, const String &value) { - const char *dup = _buffer->strdup(value); - node->content.value = dup; - return dup != NULL; -} - -template <> -inline const JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -template <> -inline const JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -template <> -inline JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -template <> -inline JsonObject &JsonVariant::defaultValue() { - return JsonObject::invalid(); -} - -inline JsonObject &JsonVariant::asObject() const { - if (_type == Internals::JSON_OBJECT) return *_content.asObject; - return JsonObject::invalid(); -} - -inline JsonObject &JsonObject::createNestedObject(JsonObjectKey key) { - if (!_buffer) return JsonObject::invalid(); - JsonObject &array = _buffer->createObject(); - setNodeAt(key, array); - return array; -} - -inline JsonObject &JsonArray::createNestedObject() { - if (!_buffer) return JsonObject::invalid(); - JsonObject &object = _buffer->createObject(); - add(object); - return object; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectKey.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectKey.hpp deleted file mode 100644 index b713f39e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectKey.hpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "String.hpp" - -namespace ArduinoJson { - -// Represents a key in a JsonObject -class JsonObjectKey { - public: - JsonObjectKey(const char* key) : _value(key), _needs_copy(false) {} - JsonObjectKey(const String& key) : _value(key.c_str()), _needs_copy(true) {} - - const char* c_str() const { return _value; } - bool needs_copy() const { return _needs_copy; } - - private: - const char* _value; - bool _needs_copy; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectSubscript.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectSubscript.hpp deleted file mode 100644 index 0f7a71bb..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonObjectSubscript.hpp +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" -#include "JsonVariantBase.hpp" -#include "TypeTraits/EnableIf.hpp" - -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4522) -#endif - -namespace ArduinoJson { - -template -class JsonObjectSubscript : public JsonVariantBase > { - public: - FORCE_INLINE JsonObjectSubscript(JsonObject& object, TKey key) - : _object(object), _key(key) {} - - JsonObjectSubscript& operator=(const JsonObjectSubscript& src) { - _object.set(_key, src); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonObjectSubscript >::type& - operator=(const T& src) { - _object.set(_key, const_cast(src)); - return *this; - } - - template - typename TypeTraits::EnableIf::value, - JsonObjectSubscript >::type& - operator=(T src) { - _object.set(_key, src); - return *this; - } - - FORCE_INLINE bool success() const { - return _object.containsKey(_key); - } - - FORCE_INLINE operator JsonVariant() const { - return _object.get(_key); - } - - template - FORCE_INLINE typename Internals::JsonVariantAs::type as() const { - return _object.get(_key); - } - - template - FORCE_INLINE bool is() const { - return _object.is(_key); - } - - template - FORCE_INLINE bool set(TValue value) { - return _object.set(_key, value); - } - - template - FORCE_INLINE bool set(TValue value, uint8_t decimals) { - return _object.set(_key, value, decimals); - } - - FORCE_INLINE JsonVariant get() { - return _object.get(_key); - } - - private: - JsonObject& _object; - TKey _key; -}; - -#if ARDUINOJSON_ENABLE_STD_STREAM -inline std::ostream& operator<<( - std::ostream& os, const JsonObjectSubscript& source) { - return source.printTo(os); -} - -inline std::ostream& operator<<( - std::ostream& os, const JsonObjectSubscript& source) { - return source.printTo(os); -} -#endif - -inline JsonObjectSubscript JsonObject::operator[]( - const char* key) { - return JsonObjectSubscript(*this, key); -} - -inline JsonObjectSubscript JsonObject::operator[]( - const String& key) { - return JsonObjectSubscript(*this, key); -} - -template -inline const JsonObjectSubscript JsonVariantBase:: -operator[](const char* key) const { - return asObject()[key]; -} - -template -inline const JsonObjectSubscript JsonVariantBase:: -operator[](const String& key) const { - return asObject()[key]; -} - -} // namespace ArduinoJson - -#ifdef _MSC_VER -#pragma warning(pop) -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonPair.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonPair.hpp deleted file mode 100644 index 49ebed8d..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonPair.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonObjectKey.hpp" -#include "JsonVariant.hpp" - -namespace ArduinoJson { - -// A key value pair for JsonObject. -struct JsonPair { - const char* key; - JsonVariant value; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.hpp deleted file mode 100644 index f4093376..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.hpp +++ /dev/null @@ -1,376 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include -#include // for uint8_t - -#include "Internals/JsonPrintable.hpp" -#include "Internals/JsonVariantContent.hpp" -#include "Internals/JsonVariantType.hpp" -#include "JsonVariantBase.hpp" -#include "RawJson.hpp" -#include "TypeTraits/EnableIf.hpp" -#include "TypeTraits/IsFloatingPoint.hpp" -#include "TypeTraits/IsIntegral.hpp" -#include "TypeTraits/IsSame.hpp" -#include "TypeTraits/RemoveConst.hpp" -#include "TypeTraits/RemoveReference.hpp" - -namespace ArduinoJson { - -// Forward declarations. -class JsonArray; -class JsonObject; - -// A variant that can be a any value serializable to a JSON value. -// -// It can be set to: -// - a boolean -// - a char, short, int or a long (signed or unsigned) -// - a string (const char*) -// - a reference to a JsonArray or JsonObject -class JsonVariant : public JsonVariantBase { - friend void Internals::JsonSerializer::serialize(const JsonVariant &, - JsonWriter &); - - public: - template - struct IsConstructibleFrom; - - // Creates an uninitialized JsonVariant - JsonVariant() : _type(Internals::JSON_UNDEFINED) {} - - // Create a JsonVariant containing a boolean value. - // It will be serialized as "true" or "false" in JSON. - JsonVariant(bool value) { - using namespace Internals; - _type = JSON_BOOLEAN; - _content.asInteger = static_cast(value); - } - - // Create a JsonVariant containing a floating point value. - // The second argument specifies the number of decimal digits to write in - // the JSON string. - // JsonVariant(double value, uint8_t decimals); - // JsonVariant(float value, uint8_t decimals); - template - JsonVariant(T value, uint8_t decimals = 2, - typename TypeTraits::EnableIf< - TypeTraits::IsFloatingPoint::value>::type * = 0) { - using namespace Internals; - _type = static_cast(JSON_FLOAT_0_DECIMALS + decimals); - _content.asFloat = static_cast(value); - } - - // Create a JsonVariant containing an integer value. - // JsonVariant(signed short) - // JsonVariant(signed int) - // JsonVariant(signed long) - template - JsonVariant(T value, - typename TypeTraits::EnableIf< - TypeTraits::IsSignedIntegral::value>::type * = 0) { - using namespace Internals; - if (value >= 0) { - _type = JSON_POSITIVE_INTEGER; - _content.asInteger = static_cast(value); - } else { - _type = JSON_NEGATIVE_INTEGER; - _content.asInteger = static_cast(-value); - } - } - // JsonVariant(unsigned short) - // JsonVariant(unsigned int) - // JsonVariant(unsigned long) - template - JsonVariant(T value, - typename TypeTraits::EnableIf< - TypeTraits::IsUnsignedIntegral::value>::type * = 0) { - using namespace Internals; - _type = JSON_POSITIVE_INTEGER; - _content.asInteger = static_cast(value); - } - - // Create a JsonVariant containing a string. - JsonVariant(const char *value) { - _type = Internals::JSON_STRING; - _content.asString = value; - } - - // Create a JsonVariant containing an unparsed string - JsonVariant(RawJson value) { - _type = Internals::JSON_UNPARSED; - _content.asString = value; - } - - // Create a JsonVariant containing a reference to an array. - JsonVariant(JsonArray &array); - - // Create a JsonVariant containing a reference to an object. - JsonVariant(JsonObject &object); - - // Get the variant as the specified type. - // - // short as() const; - // int as() const; - // long as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return static_cast(asInteger()); - } - // - // short as() const; - // int as() const; - // long as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return static_cast(asUnsignedInteger()); - } - // - // double as() const; - // float as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return static_cast(asFloat()); - } - // - // const String as() const; - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return toString(); - } - // - // const char* as() const; - // const char* as() const; - template - typename TypeTraits::EnableIf::value || - TypeTraits::IsSame::value, - const char *>::type - as() const { - return asString(); - } - // - // const bool as() const - template - const typename TypeTraits::EnableIf::value, - T>::type - as() const { - return asInteger() != 0; - } - // - // JsonArray& as const; - // JsonArray& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - JsonArray>::value, - JsonArray &>::type - as() const { - return asArray(); - } - // - // const JsonArray& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - const JsonArray>::value, - const JsonArray &>::type - as() const { - return asArray(); - } - // - // JsonObject& as const; - // JsonObject& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - JsonObject>::value, - JsonObject &>::type - as() const { - return asObject(); - } - // - // JsonObject& as const; - // JsonObject& as const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame::type, - const JsonObject>::value, - const JsonObject &>::type - as() const { - return asObject(); - } - // - // JsonVariant as const; - template - typename TypeTraits::EnableIf::value, - T>::type - as() const { - return *this; - } - - // Tells weither the variant has the specified type. - // Returns true if the variant has type type T, false otherwise. - // - // short as() const; - // int as() const; - // long as() const; - template - const typename TypeTraits::EnableIf::value, - bool>::type - is() const { - return isInteger(); - } - // - // double is() const; - // float is() const; - template - const typename TypeTraits::EnableIf::value, - bool>::type - is() const { - return isFloat(); - } - // - // const bool is() const - template - const typename TypeTraits::EnableIf::value, - bool>::type - is() const { - return isBoolean(); - } - // - // bool is() const; - // bool is() const; - template - typename TypeTraits::EnableIf::value || - TypeTraits::IsSame::value, - bool>::type - is() const { - return isString(); - } - // - // bool is const; - // bool is const; - // bool is const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame< - typename TypeTraits::RemoveConst< - typename TypeTraits::RemoveReference::type>::type, - JsonArray>::value, - bool>::type - is() const { - return isArray(); - } - // - // bool is const; - // bool is const; - // bool is const; - template - typename TypeTraits::EnableIf< - TypeTraits::IsSame< - typename TypeTraits::RemoveConst< - typename TypeTraits::RemoveReference::type>::type, - JsonObject>::value, - bool>::type - is() const { - return isObject(); - } - - // Returns true if the variant has a value - bool success() const { - return _type != Internals::JSON_UNDEFINED; - } - - // Value returned if the variant has an incompatible type - template - static typename Internals::JsonVariantAs::type defaultValue() { - return T(); - } - - // DEPRECATED: use as() instead - const char *asString() const; - - // DEPRECATED: use as() instead - JsonArray &asArray() const; - - // DEPRECATED: use as() instead - JsonObject &asObject() const; - - private: - // It's not allowed to store a char - template - JsonVariant(T value, typename TypeTraits::EnableIf< - TypeTraits::IsSame::value>::type * = 0); - - String toString() const; - Internals::JsonFloat asFloat() const; - Internals::JsonInteger asInteger() const; - Internals::JsonUInt asUnsignedInteger() const; - bool isBoolean() const; - bool isFloat() const; - bool isInteger() const; - bool isArray() const { - return _type == Internals::JSON_ARRAY; - } - bool isObject() const { - return _type == Internals::JSON_OBJECT; - } - bool isString() const { - return _type == Internals::JSON_STRING || - (_type == Internals::JSON_UNPARSED && _content.asString && - !strcmp("null", _content.asString)); - } - - // The current type of the variant - Internals::JsonVariantType _type; - - // The various alternatives for the value of the variant. - Internals::JsonVariantContent _content; -}; - -inline JsonVariant float_with_n_digits(float value, uint8_t digits) { - return JsonVariant(value, digits); -} - -inline JsonVariant double_with_n_digits(double value, uint8_t digits) { - return JsonVariant(value, digits); -} - -template -struct JsonVariant::IsConstructibleFrom { - static const bool value = - TypeTraits::IsIntegral::value || - TypeTraits::IsFloatingPoint::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame &>::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.ipp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.ipp deleted file mode 100644 index f0c0d33b..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariant.ipp +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" -#include "JsonVariant.hpp" -#include "Internals/Parse.hpp" -#include "JsonArray.hpp" -#include "JsonObject.hpp" - -#include // for strcmp -#include // for errno -#include // for strtol, strtod - -namespace ArduinoJson { - -inline Internals::JsonInteger JsonVariant::asInteger() const { - using namespace Internals; - switch (_type) { - case JSON_UNDEFINED: - return 0; - case JSON_POSITIVE_INTEGER: - case JSON_BOOLEAN: - return _content.asInteger; - case JSON_NEGATIVE_INTEGER: - return -static_cast(_content.asInteger); - case JSON_STRING: - case JSON_UNPARSED: - if (!_content.asString) return 0; - if (!strcmp("true", _content.asString)) return 1; - return parse(_content.asString); - default: - return static_cast(_content.asFloat); - } -} - -inline Internals::JsonUInt JsonVariant::asUnsignedInteger() const { - using namespace Internals; - switch (_type) { - case JSON_UNDEFINED: - return 0; - case JSON_POSITIVE_INTEGER: - case JSON_BOOLEAN: - case JSON_NEGATIVE_INTEGER: - return _content.asInteger; - case JSON_STRING: - case JSON_UNPARSED: - if (!_content.asString) return 0; - if (!strcmp("true", _content.asString)) return 1; - return parse(_content.asString); - default: - return static_cast(_content.asFloat); - } -} - -inline const char *JsonVariant::asString() const { - using namespace Internals; - if (_type == JSON_UNPARSED && _content.asString && - !strcmp("null", _content.asString)) - return NULL; - if (_type == JSON_STRING || _type == JSON_UNPARSED) return _content.asString; - return NULL; -} - -inline Internals::JsonFloat JsonVariant::asFloat() const { - using namespace Internals; - switch (_type) { - case JSON_UNDEFINED: - return 0; - case JSON_POSITIVE_INTEGER: - case JSON_BOOLEAN: - return static_cast(_content.asInteger); - case JSON_NEGATIVE_INTEGER: - return -static_cast(_content.asInteger); - case JSON_STRING: - case JSON_UNPARSED: - return _content.asString ? parse(_content.asString) : 0; - default: - return _content.asFloat; - } -} - -inline String JsonVariant::toString() const { - using namespace Internals; - String s; - if ((_type == JSON_STRING || _type == JSON_UNPARSED) && - _content.asString != NULL) - s = _content.asString; - else - printTo(s); - return s; -} - -inline bool JsonVariant::isBoolean() const { - using namespace Internals; - if (_type == JSON_BOOLEAN) return true; - - if (_type != JSON_UNPARSED || _content.asString == NULL) return false; - - return !strcmp(_content.asString, "true") || - !strcmp(_content.asString, "false"); -} - -inline bool JsonVariant::isInteger() const { - using namespace Internals; - if (_type == JSON_POSITIVE_INTEGER || _type == JSON_NEGATIVE_INTEGER) - return true; - - if (_type != JSON_UNPARSED || _content.asString == NULL) return false; - - char *end; - errno = 0; - strtol(_content.asString, &end, 10); - - return *end == '\0' && errno == 0; -} - -inline bool JsonVariant::isFloat() const { - using namespace Internals; - if (_type >= JSON_FLOAT_0_DECIMALS) return true; - - if (_type != JSON_UNPARSED || _content.asString == NULL) return false; - - char *end; - errno = 0; - strtod(_content.asString, &end); - - return *end == '\0' && errno == 0 && !is(); -} - -#if ARDUINOJSON_ENABLE_STD_STREAM -inline std::ostream &operator<<(std::ostream &os, const JsonVariant &source) { - return source.printTo(os); -} -#endif - -} // namespace ArduinoJson diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariantBase.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariantBase.hpp deleted file mode 100644 index 14fc0cd8..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/JsonVariantBase.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Internals/JsonVariantAs.hpp" -#include "JsonObjectKey.hpp" -#include "Polyfills/attributes.hpp" - -namespace ArduinoJson { - -// Forward declarations. -class JsonArraySubscript; -template -class JsonObjectSubscript; - -template -class JsonVariantBase : public Internals::JsonPrintable { - public: - // DEPRECATED: use as() instead - FORCE_INLINE const char *asString() const { - return as(); - } - - // Gets the variant as an array. - // Returns a reference to the JsonArray or JsonArray::invalid() if the - // variant - // is not an array. - FORCE_INLINE operator JsonArray &() const { - return as(); - } - - // DEPRECATED: use as() instead - FORCE_INLINE JsonArray &asArray() const { - return as(); - } - - // Gets the variant as an object. - // Returns a reference to the JsonObject or JsonObject::invalid() if the - // variant is not an object. - FORCE_INLINE operator JsonObject &() const { - return as(); - } - - // DEPRECATED: use as() instead - FORCE_INLINE JsonObject &asObject() const { - return as(); - } - - template - FORCE_INLINE operator T() const { - return as(); - } - - template - FORCE_INLINE const typename Internals::JsonVariantAs::type as() const { - return impl()->template as(); - } - - // Mimics an array or an object. - // Returns the size of the array or object if the variant has that type. - // Returns 0 if the variant is neither an array nor an object - size_t size() const { - return asArray().size() + asObject().size(); - } - - // Mimics an array. - // Returns the element at specified index if the variant is an array. - // Returns JsonVariant::invalid() if the variant is not an array. - FORCE_INLINE const JsonArraySubscript operator[](int index) const; - - // Mimics an object. - // Returns the value associated with the specified key if the variant is - // an object. - // Return JsonVariant::invalid() if the variant is not an object. - FORCE_INLINE const JsonObjectSubscript operator[]( - const char *key) const; - FORCE_INLINE const JsonObjectSubscript operator[]( - const String &key) const; - - private: - const TImpl *impl() const { - return static_cast(this); - } -}; - -template -inline bool operator==(const JsonVariantBase &left, TComparand right) { - return left.template as() == right; -} - -template -inline bool operator==(TComparand left, const JsonVariantBase &right) { - return left == right.template as(); -} - -template -inline bool operator!=(const JsonVariantBase &left, TComparand right) { - return left.template as() != right; -} - -template -inline bool operator!=(TComparand left, const JsonVariantBase &right) { - return left != right.template as(); -} - -template -inline bool operator<=(const JsonVariantBase &left, TComparand right) { - return left.template as() <= right; -} - -template -inline bool operator<=(TComparand left, const JsonVariantBase &right) { - return left <= right.template as(); -} - -template -inline bool operator>=(const JsonVariantBase &left, TComparand right) { - return left.template as() >= right; -} - -template -inline bool operator>=(TComparand left, const JsonVariantBase &right) { - return left >= right.template as(); -} - -template -inline bool operator<(const JsonVariantBase &left, TComparand right) { - return left.template as() < right; -} - -template -inline bool operator<(TComparand left, const JsonVariantBase &right) { - return left < right.template as(); -} - -template -inline bool operator>(const JsonVariantBase &left, TComparand right) { - return left.template as() > right; -} - -template -inline bool operator>(TComparand left, const JsonVariantBase &right) { - return left > right.template as(); -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/attributes.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/attributes.hpp deleted file mode 100644 index c428fe1a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/attributes.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#ifdef _MSC_VER -#define FORCE_INLINE __forceinline -#define NO_INLINE __declspec(noinline) -#else -#define FORCE_INLINE __attribute__((always_inline)) -#define NO_INLINE __attribute__((noinline)) -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/math.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/math.hpp deleted file mode 100644 index 3535c486..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/math.hpp +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -// If Visual Studo <= 2012 -#if defined(_MSC_VER) && _MSC_VER <= 1700 - -#include - -namespace ArduinoJson { -namespace Polyfills { -template -bool isNaN(T x) { - return _isnan(x) != 0; -} - -template -bool isInfinity(T x) { - return !_finite(x); -} -} -} - -#else - -#include - -// GCC warning: "conversion to 'float' from 'double' may alter its value" -#ifdef __GNUC__ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9) -#pragma GCC diagnostic ignored "-Wfloat-conversion" -#else -#pragma GCC diagnostic ignored "-Wconversion" -#endif -#endif - -// Workaround for libs that #undef isnan or isinf -// https://github.com/bblanchon/ArduinoJson/issues/284 -#if !defined(isnan) || !defined(isinf) -namespace std {} -#endif - -namespace ArduinoJson { -namespace Polyfills { - -template -bool isNaN(T x) { -// Workaround for libs that #undef isnan -// https://github.com/bblanchon/ArduinoJson/issues/284 -#ifndef isnan - using namespace std; -#endif - - return isnan(x); -} - -#if defined(_GLIBCXX_HAVE_ISNANL) && _GLIBCXX_HAVE_ISNANL -template <> -inline bool isNaN(double x) { - return isnanl(x); -} -#endif - -#if defined(_GLIBCXX_HAVE_ISNANF) && _GLIBCXX_HAVE_ISNANF -template <> -inline bool isNaN(float x) { - return isnanf(x); -} -#endif - -template -bool isInfinity(T x) { -// Workaround for libs that #undef isinf -// https://github.com/bblanchon/ArduinoJson/issues/284 -#ifndef isinf - using namespace std; -#endif - - return isinf(x); -} - -#if defined(_GLIBCXX_HAVE_ISINFL) && _GLIBCXX_HAVE_ISINFL -template <> -inline bool isInfinity(double x) { - return isinfl(x); -} -#endif - -#if defined(_GLIBCXX_HAVE_ISINFF) && _GLIBCXX_HAVE_ISINFF -template <> -inline bool isInfinity(float x) { - return isinff(x); -} -#endif - -#if defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif -} -} -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/normalize.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/normalize.hpp deleted file mode 100644 index 9b0f6bb9..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Polyfills/normalize.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace Polyfills { - -#ifdef ARDUINO - -// on embedded platform, favor code size over speed - -template -short normalize(T& value) { - short powersOf10 = 0; - while (value && value < 1) { - powersOf10--; - value *= 10; - } - while (value > 10) { - powersOf10++; - value /= 10; - } - return powersOf10; -} - -#else - -// on non-embedded platform, favor speed over code size - -template -short normalize(T& value) { - if (value == 0.0) return 0; - - short powersOf10 = static_cast(floor(log10(value))); - value /= pow(T(10), powersOf10); - - return powersOf10; -} - -#endif -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Print.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Print.hpp deleted file mode 100644 index 73a6d33a..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/Print.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#ifndef ARDUINO - -#include -#include - -namespace ArduinoJson { -// This class reproduces Arduino's Print class -class Print { - public: - virtual ~Print() {} - - virtual size_t write(uint8_t) = 0; - - size_t print(const char* s) { - size_t n = 0; - while (*s) { - n += write(static_cast(*s++)); - } - return n; - } - - size_t println() { - size_t n = 0; - n += write('\r'); - n += write('\n'); - return n; - } -}; -} - -#else - -#include - -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/RawJson.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/RawJson.hpp deleted file mode 100644 index 9b1f40dd..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/RawJson.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { - -// A special type of data that can be used to insert pregenerated JSON portions. -class RawJson { - public: - explicit RawJson(const char* str) : _str(str) {} - operator const char*() const { return _str; } - - private: - const char* _str; -}; -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/StaticJsonBuffer.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/StaticJsonBuffer.hpp deleted file mode 100644 index 783eea27..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/StaticJsonBuffer.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "JsonBuffer.hpp" - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnon-virtual-dtor" -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" -#endif - -namespace ArduinoJson { - -// Implements a JsonBuffer with fixed memory allocation. -// The template paramenter CAPACITY specifies the capacity of the buffer in -// bytes. -template -class StaticJsonBuffer : public JsonBuffer { - public: - explicit StaticJsonBuffer() : _size(0) {} - - size_t capacity() const { - return CAPACITY; - } - size_t size() const { - return _size; - } - - virtual void* alloc(size_t bytes) { - if (_size + bytes > CAPACITY) return NULL; - void* p = &_buffer[_size]; - _size += round_size_up(bytes); - return p; - } - - private: - uint8_t _buffer[CAPACITY]; - size_t _size; -}; -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#elif defined(__GNUC__) -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/String.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/String.hpp deleted file mode 100644 index 3c030f55..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/String.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "Configuration.hpp" - -#if ARDUINOJSON_USE_ARDUINO_STRING - -#include - -#else - -#include - -namespace ArduinoJson { -typedef std::string String; -} - -#endif diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/EnableIf.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/EnableIf.hpp deleted file mode 100644 index 408e8bb0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/EnableIf.hpp +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that return the type T if Condition is true. -template -struct EnableIf {}; - -template -struct EnableIf { - typedef T type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsFloatingPoint.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsFloatingPoint.hpp deleted file mode 100644 index 42a13ec6..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsFloatingPoint.hpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is a floating point type -template -struct IsFloatingPoint { - static const bool value = IsSame::value || IsSame::value; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsIntegral.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsIntegral.hpp deleted file mode 100644 index fab6b2c7..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsIntegral.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" -#include "IsSignedIntegral.hpp" -#include "IsUnsignedIntegral.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is an integral type. -template -struct IsIntegral { - static const bool value = TypeTraits::IsSignedIntegral::value || - TypeTraits::IsUnsignedIntegral::value || - TypeTraits::IsSame::value; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsReference.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsReference.hpp deleted file mode 100644 index 436a25db..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsReference.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is a reference -template -struct IsReference { - static const bool value = false; -}; - -template -struct IsReference { - static const bool value = true; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSame.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSame.hpp deleted file mode 100644 index 0b68d3c3..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSame.hpp +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if types T and U are the same. -template -struct IsSame { - static const bool value = false; -}; - -template -struct IsSame { - static const bool value = true; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSignedIntegral.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSignedIntegral.hpp deleted file mode 100644 index 0430a8a0..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsSignedIntegral.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is an integral type. -template -struct IsSignedIntegral { - static const bool value = TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || -#if ARDUINOJSON_USE_LONG_LONG - TypeTraits::IsSame::value || -#endif - -#if ARDUINOJSON_USE_INT64 - TypeTraits::IsSame::value || -#endif - false; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp deleted file mode 100644 index 690c6a34..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/IsUnsignedIntegral.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -#include "../Configuration.hpp" -#include "IsSame.hpp" - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that returns true if T is an integral type. -template -struct IsUnsignedIntegral { - static const bool value = TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || - TypeTraits::IsSame::value || -#if ARDUINOJSON_USE_LONG_LONG - TypeTraits::IsSame::value || -#endif - -#if ARDUINOJSON_USE_INT64 - TypeTraits::IsSame::value || -#endif - false; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveConst.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveConst.hpp deleted file mode 100644 index cf7b3af2..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveConst.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that return the type T without the const modifier -template -struct RemoveConst { - typedef T type; -}; -template -struct RemoveConst { - typedef T type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveReference.hpp b/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveReference.hpp deleted file mode 100644 index d77eb85e..00000000 --- a/src/third-party/arduino-json-5.6.7/include/ArduinoJson/TypeTraits/RemoveReference.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Benoit Blanchon 2014-2016 -// MIT License -// -// Arduino JSON library -// https://github.com/bblanchon/ArduinoJson -// If you like this project, please add a star! - -#pragma once - -namespace ArduinoJson { -namespace TypeTraits { - -// A meta-function that return the type T without the reference modifier. -template -struct RemoveReference { - typedef T type; -}; -template -struct RemoveReference { - typedef T type; -}; -} -} diff --git a/src/third-party/arduino-json-5.6.7/keywords.txt b/src/third-party/arduino-json-5.6.7/keywords.txt deleted file mode 100644 index 913b6aa6..00000000 --- a/src/third-party/arduino-json-5.6.7/keywords.txt +++ /dev/null @@ -1,14 +0,0 @@ -JsonArray KEYWORD1 -JsonObject KEYWORD1 -JsonVariant KEYWORD1 -StaticJsonBuffer KEYWORD1 -add KEYWORD2 -createArray KEYWORD2 -createNestedArray KEYWORD2 -createNestedObject KEYWORD2 -createObject KEYWORD2 -parseArray KEYWORD2 -parseObject KEYWORD2 -prettyPrintTo KEYWORD2 -printTo KEYWORD2 -success KEYWORD2 diff --git a/src/third-party/arduino-json-5.6.7/library.properties b/src/third-party/arduino-json-5.6.7/library.properties deleted file mode 100644 index 57989b0c..00000000 --- a/src/third-party/arduino-json-5.6.7/library.properties +++ /dev/null @@ -1,9 +0,0 @@ -name=ArduinoJson -version=5.6.7 -author=Benoit Blanchon -maintainer=Benoit Blanchon -sentence=An efficient and elegant JSON library for Arduino. -paragraph=Like this project? Please star it on GitHub! -category=Data Processing -url=https://github.com/bblanchon/ArduinoJson -architectures=* From ae903b077db11c970cee6a06d786cfc5a2092430 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Fri, 10 Nov 2017 22:59:17 -0500 Subject: [PATCH 10/68] Add changes/info needed to pass CI build. --- .travis.yml | 5 +++-- README.rst | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9d30c387..6325b99a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,8 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino -- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - ( cd ${HOME} && wget https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz && tar xf arduino-${ARDUINO_VERSION}-linux64.tar.xz ) @@ -17,6 +17,7 @@ install: - ( LIB=Adafruit_NeoPixel VERSION=${LIB_NEOPIXEL_VERSION} && cd ${HOME} && wget https://github.com/adafruit/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) - ( LIB=Adafruit-GFX-Library VERSION=${LIB_GFX_VERSION} && cd ${HOME} && wget https://github.com/adafruit/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) - ( LIB=Adafruit_SSD1306 VERSION=${LIB_SSD1306_VERSION} && cd ${HOME} && wget https://github.com/adafruit/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) +- ( LIB=ArduinoJson VERSION=${LIB_JSON_VERSION} && cd ${HOME} && wget https://github.com/bblanchon/${LIB}/archive/${VERSION}.zip -q -O ${LIB}.zip && unzip -q ${LIB}.zip && rm ${LIB}.zip && mv ${LIB}-* ${LIB} ) - git clone --branch ${ARDUINO_ESP8266_VERSION} https://github.com/esp8266/Arduino.git ${ARDUINO_ESP8266_ROOT} - git submodule init && git submodule update - ( cd ${ARDUINO_ESP8266_ROOT}/tools && python get.py ) diff --git a/README.rst b/README.rst index 93f9d299..434da0f5 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,10 @@ FirebaseArduino is a library to simplify connecting to the Firebase database fro arduino clients. It is a full abstraction of Firebase's REST API exposed through C++ calls in a wiring -friendly way. All Json parsing is handled by the library and you may deal in pure C/Arduino -types. +friendly way. + +ArduinoJson is no longer part of this library and you will have to install latest version +in Arduino environment yourself. (through Board manager or download+unpack from master: +https://github.com/bblanchon/ArduinoJson ) ---------------------------------- From b6712d2777c1286ff1421d86ea690fc020481b25 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Fri, 10 Nov 2017 23:09:33 -0500 Subject: [PATCH 11/68] Forgot to add symbolic link. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6325b99a..19e6ff12 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ install: - ( cd ${ARDUINO_ESP8266_ROOT}/tools && python get.py ) before_script: - mkdir -p ${ARDUINO_HOME}/libraries -- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${TRAVIS_BUILD_DIR}/src/third-party/arduino-json-5.6.7 ArduinoJson && ln -s ${HOME}/SoftwareSerial ./ && ln -s ${HOME}/Adafruit_NeoPixel ./ && ln -s ${HOME}/Adafruit-GFX-Library ./ && ln -s ${HOME}/Adafruit_SSD1306 ./) +- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${TRAVIS_BUILD_DIR}/src/third-party/arduino-json-5.6.7 ArduinoJson && ln -s ${HOME}/SoftwareSerial ./ && ln -s ${HOME}/Adafruit_NeoPixel ./ && ln -s ${HOME}/Adafruit-GFX-Library ./ && ln -s ${HOME}/Adafruit_SSD1306 ./ && ln -s ${HOME}/ArduinoJson ./) script: - ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino - ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseNeoPixel_ESP8266/FirebaseNeoPixel_ESP8266.ino From e1751105ec830acd9cb282a8bd3e8f06d4104d2e Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Fri, 10 Nov 2017 23:24:42 -0500 Subject: [PATCH 12/68] And finally removing symbolic link created for json library previously shipped with repo. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 19e6ff12..b55f6a10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ install: - ( cd ${ARDUINO_ESP8266_ROOT}/tools && python get.py ) before_script: - mkdir -p ${ARDUINO_HOME}/libraries -- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${TRAVIS_BUILD_DIR}/src/third-party/arduino-json-5.6.7 ArduinoJson && ln -s ${HOME}/SoftwareSerial ./ && ln -s ${HOME}/Adafruit_NeoPixel ./ && ln -s ${HOME}/Adafruit-GFX-Library ./ && ln -s ${HOME}/Adafruit_SSD1306 ./ && ln -s ${HOME}/ArduinoJson ./) +- ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${HOME}/SoftwareSerial ./ && ln -s ${HOME}/Adafruit_NeoPixel ./ && ln -s ${HOME}/Adafruit-GFX-Library ./ && ln -s ${HOME}/Adafruit_SSD1306 ./ && ln -s ${HOME}/ArduinoJson ./) script: - ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino - ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseNeoPixel_ESP8266/FirebaseNeoPixel_ESP8266.ino From 6b768f974419a7ced497e4fe5a6a286ac9277559 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Fri, 10 Nov 2017 23:43:41 -0500 Subject: [PATCH 13/68] Fix contrib directory to use external ArduinoJson library. --- contrib/src/thing/Config.cpp | 2 +- contrib/src/thing/Config.h | 2 +- contrib/src/thing/Portal.cpp | 2 +- contrib/test/Makefile | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/src/thing/Config.cpp b/contrib/src/thing/Config.cpp index d810630e..133c527a 100644 --- a/contrib/src/thing/Config.cpp +++ b/contrib/src/thing/Config.cpp @@ -1,6 +1,6 @@ #include "Arduino.h" #include "thing/Config.h" -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include namespace thing { diff --git a/contrib/src/thing/Config.h b/contrib/src/thing/Config.h index 3acf3ed1..0cabf61c 100644 --- a/contrib/src/thing/Config.h +++ b/contrib/src/thing/Config.h @@ -4,7 +4,7 @@ #include "Arduino.h" #include #include -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include namespace thing { diff --git a/contrib/src/thing/Portal.cpp b/contrib/src/thing/Portal.cpp index cf70a363..5a105a79 100644 --- a/contrib/src/thing/Portal.cpp +++ b/contrib/src/thing/Portal.cpp @@ -1,5 +1,5 @@ #include "thing/Portal.h" -#include "third-party/arduino-json-5.6.7/include/ArduinoJson.h" +#include namespace thing { diff --git a/contrib/test/Makefile b/contrib/test/Makefile index 71f5f589..f9063cb6 100644 --- a/contrib/test/Makefile +++ b/contrib/test/Makefile @@ -16,7 +16,7 @@ FIREBASE_DIR=../.. GTEST_DIR=googletest/googletest -ARDUINOJSON_DIR=../../src/third-party/arduino-json-5.6.7 +ARDUINOJSON_DIR=${ARDUINO_HOME}/libraries/ArduinoJson FIREBASE_SRCS=${FIREBASE_DIR}/src/FirebaseObject.cpp GTEST_SRCS=${GTEST_DIR}/src/gtest-all.cpp @@ -27,7 +27,7 @@ SRCS=FirebaseArduino_test.cpp\ OBJS=${SRCS:.cpp=.o} -CXXFLAGS=-I. -I${FIREBASE_DIR}/src -Igoogletest/googletest/include -Igoogletest/googletest -std=c++11 -g +CXXFLAGS=-I. -I${FIREBASE_DIR}/src -I${ARDUINOJSON_DIR}/src -Igoogletest/googletest/include -Igoogletest/googletest -std=c++11 -g LDFLAGS=-lpthread all: check From 651a5b9d6e708112f66fc47d2cc79d48c289607b Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sat, 11 Nov 2017 00:01:58 -0500 Subject: [PATCH 14/68] More fixes for contrib test to use external JSON library. --- contrib/test/FirebaseArduino_test.cpp | 1 + contrib/test/modem/Makefile | 2 ++ 2 files changed, 3 insertions(+) diff --git a/contrib/test/FirebaseArduino_test.cpp b/contrib/test/FirebaseArduino_test.cpp index c2624d8a..a9c86885 100644 --- a/contrib/test/FirebaseArduino_test.cpp +++ b/contrib/test/FirebaseArduino_test.cpp @@ -16,6 +16,7 @@ #include "FirebaseObject.h" #include "gtest/gtest.h" +#include "WString.h" TEST(FirebaseObjectTest, GetBool) { FirebaseObject obj("true"); diff --git a/contrib/test/modem/Makefile b/contrib/test/modem/Makefile index a8e15853..06b07175 100644 --- a/contrib/test/modem/Makefile +++ b/contrib/test/modem/Makefile @@ -34,6 +34,7 @@ FIREBASE_ROOT = ../../.. PROJECT_ROOT = ../.. SRC_ROOT = $(PROJECT_ROOT)/src FIREBASE_SRC_ROOT = $(FIREBASE_ROOT)/src +ARDUINOJSON_DIR=$(ARDUINO_HOME)/libraries/ArduinoJson # Flags passed to the preprocessor. # Set Google Test and Google Mock's header directories as system @@ -45,6 +46,7 @@ CPPFLAGS += -isystem $(GTEST_DIR)/include -isystem $(GMOCK_DIR)/include \ -I$(PROJECT_ROOT)/test/dummies \ -I$(PROJECT_ROOT)/src \ -I$(FIREBASE_ROOT)/src \ + -I$(ARDUINOJSON_DIR)/src \ -I$(PROJECT_ROOT) # Flags passed to the C++ compiler. From 7c89e0df95fc1c6c7c76d69ce02bed5cea416368 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sun, 12 Nov 2017 01:48:49 +0000 Subject: [PATCH 15/68] fix issues with travis build --- contrib/test/FirebaseArduino_test.cpp | 2 +- src/FirebaseObject.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contrib/test/FirebaseArduino_test.cpp b/contrib/test/FirebaseArduino_test.cpp index a9c86885..9f18865e 100644 --- a/contrib/test/FirebaseArduino_test.cpp +++ b/contrib/test/FirebaseArduino_test.cpp @@ -16,7 +16,7 @@ #include "FirebaseObject.h" #include "gtest/gtest.h" -#include "WString.h" + TEST(FirebaseObjectTest, GetBool) { FirebaseObject obj("true"); diff --git a/src/FirebaseObject.h b/src/FirebaseObject.h index b22a087d..01caeb5c 100644 --- a/src/FirebaseObject.h +++ b/src/FirebaseObject.h @@ -17,14 +17,18 @@ #ifndef FIREBASE_OBJECT_H #define FIREBASE_OBJECT_H -#include + +#include "WString.h" #include +#include + + #ifndef FIREBASE_JSONBUFFER_SIZE #define FIREBASE_JSONBUFFER_SIZE JSON_OBJECT_SIZE(32) #endif // FIREBASE_JSONBUFFER_SIZE -using std::shared_ptr; + /** * Represents value stored in firebase, may be a singular value (leaf node) or From 1f8746daf7124a50d927f31e3c488d2acc1f6fcf Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sat, 11 Nov 2017 21:00:39 -0500 Subject: [PATCH 16/68] Add back getPtr functions. --- src/Firebase.cpp | 26 ++++++++++++++++++++++++++ src/Firebase.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index 9975f3f8..9a0e0c64 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -46,23 +46,49 @@ FirebaseGet Firebase::get(const std::string& path) { return FirebaseGet(host_, auth_, path, http_); } +unique_ptr Firebase::getPtr(const std::string& path) { + return unique_ptr(new FirebaseGet(host_, auth_, path, http_)); +} + FirebaseSet Firebase::set(const std::string& path, const std::string& value) { return FirebaseSet(host_, auth_, path, value, http_); } +unique_ptr Firebase::setPtr(const std::string& path, + const std::string& value) { + return unique_ptr( + new FirebaseSet(host_, auth_, path, value, http_)); +} + FirebasePush Firebase::push(const std::string& path, const std::string& value) { return FirebasePush(host_, auth_, path, value, http_); } +unique_ptr Firebase::pushPtr(const std::string& path, const std::string& value) { + return unique_ptr( + new FirebasePush(host_, auth_, path, value, http_)); +} + FirebaseRemove Firebase::remove(const std::string& path) { return FirebaseRemove(host_, auth_, path, http_); } +unique_ptr Firebase::removePtr(const std::string& path) { + return unique_ptr( + new FirebaseRemove(host_, auth_, path, http_)); +} + FirebaseStream Firebase::stream(const std::string& path) { // TODO: create new client dedicated to stream. return FirebaseStream(host_, auth_, path, http_); } +unique_ptr Firebase::streamPtr(const std::string& path) { + // TODO: create new client dedicated to stream. + return unique_ptr( + new FirebaseStream(host_, auth_, path, http_)); +} + // FirebaseCall FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth, const char* method, const std::string& path, diff --git a/src/Firebase.h b/src/Firebase.h index 1f3f3338..d077a3e3 100644 --- a/src/Firebase.h +++ b/src/Firebase.h @@ -43,17 +43,23 @@ class Firebase { // Fetch json encoded `value` at `path`. FirebaseGet get(const std::string& path); + virtual std::unique_ptr getPtr(const std::string& path); + // Set json encoded `value` at `path`. FirebaseSet set(const std::string& path, const std::string& json); + virtual std::unique_ptr setPtr(const std::string& path, const std::string& json); // Add new json encoded `value` to list at `path`. FirebasePush push(const std::string& path, const std::string& json); + virtual std::unique_ptr pushPtr(const std::string& path, const std::string& json); // Delete value at `path`. FirebaseRemove remove(const std::string& path); + virtual std::unique_ptr removePtr(const std::string& path); // Start a stream of events that affect value at `path`. FirebaseStream stream(const std::string& path); + virtual std::unique_ptr streamPtr(const std::string& path); protected: // Used for testing. From 02cfb98e77dae2860b5a678feea0f8e68775d8a9 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sun, 12 Nov 2017 02:28:35 +0000 Subject: [PATCH 17/68] Fixing modem tests --- contrib/src/modem/db/stream-command.cpp | 2 +- contrib/test/modem/WString.h | 3 +++ src/Firebase.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 contrib/test/modem/WString.h diff --git a/contrib/src/modem/db/stream-command.cpp b/contrib/src/modem/db/stream-command.cpp index 23c94d61..f8259bc6 100644 --- a/contrib/src/modem/db/stream-command.cpp +++ b/contrib/src/modem/db/stream-command.cpp @@ -32,7 +32,7 @@ bool StreamCommand::execute(const String& command, out->print(FirebaseStream::EventToName(event).c_str()); out->print(" "); const auto& object = buffer.parseObject(json.c_str()); - String data = object["data"]; + String data = object["data"].asString(); out->println(object["path"].asString()); out->println(data.length()); out->println(data); diff --git a/contrib/test/modem/WString.h b/contrib/test/modem/WString.h new file mode 100644 index 00000000..4724d8b6 --- /dev/null +++ b/contrib/test/modem/WString.h @@ -0,0 +1,3 @@ +#include + +typedef std::string String; diff --git a/src/Firebase.h b/src/Firebase.h index d077a3e3..f0943f12 100644 --- a/src/Firebase.h +++ b/src/Firebase.h @@ -20,6 +20,7 @@ #ifndef firebase_h #define firebase_h +#include "WString.h" #include #include #include From 57df59e17071d822c6dd8f5b01156e48a1e7123c Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sun, 12 Nov 2017 04:13:51 +0000 Subject: [PATCH 18/68] add build.f_cpu preference --- .travis.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index b55f6a10..01f58db6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ addons: - g++-4.8 env: - ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino -- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - ( cd ${HOME} && wget https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz && tar xf arduino-${ARDUINO_VERSION}-linux64.tar.xz ) @@ -25,10 +24,10 @@ before_script: - mkdir -p ${ARDUINO_HOME}/libraries - ( cd ${ARDUINO_HOME}/libraries && ln -s ${TRAVIS_BUILD_DIR} firebase-arduino && ln -s ${HOME}/SoftwareSerial ./ && ln -s ${HOME}/Adafruit_NeoPixel ./ && ln -s ${HOME}/Adafruit-GFX-Library ./ && ln -s ${HOME}/Adafruit_SSD1306 ./ && ln -s ${HOME}/ArduinoJson ./) script: -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseNeoPixel_ESP8266/FirebaseNeoPixel_ESP8266.ino -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino -- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M examples/FirebaseRoom_ESP8266/FirebaseRoom_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseDemo_ESP8266/FirebaseDemo_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseNeoPixel_ESP8266/FirebaseNeoPixel_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseStream_ESP8266/FirebaseStream_ESP8266.ino +- ${ARDUINO_ROOT}/arduino-builder -verbose -hardware ${ARDUINO_ROOT}/hardware/ -tools ${ARDUINO_ESP8266_ROOT}/tools/ -tools ${ARDUINO_ROOT}/tools-builder/ -fqbn esp8266com:esp8266:nodemcuv2 -libraries ${ARDUINO_HOME}/libraries/ -prefs build.flash_ld=${ARDUINO_ESP8266_ROOT}/tools/sdk/ld/eagle.flash.4m.ld -prefs build.flash_freq=40 -prefs build.flash_size=4M -prefs build.f_cpu=80000000 examples/FirebaseRoom_ESP8266/FirebaseRoom_ESP8266.ino - ( cd contrib/test && make check ) - ( cd contrib/test/modem/ && make test ) - contrib/test/travis/check_all_examples_use_standard_init.sh From 90ce6f1e0377f12e3a2c05d8461db2f4c804a318 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sun, 12 Nov 2017 22:16:53 -0500 Subject: [PATCH 19/68] Avoid crashes when .available() is called by detecting that underlying stream has closed. --- src/Firebase.cpp | 6 +++++- src/FirebaseArduino.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index 9a0e0c64..033f1f68 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -193,11 +193,15 @@ FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth, } bool FirebaseStream::available() { - return http_->getStreamPtr()->available(); + auto client = http_->getStreamPtr(); + return (client == nullptr) ? false : client->available(); } FirebaseStream::Event FirebaseStream::read(std::string& event) { auto client = http_->getStreamPtr(); + if (client == nullptr) { + return Event(); + } Event type; std::string typeStr = client->readStringUntil('\n').substring(7).c_str(); if (typeStr == "put") { diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index ffd51fbc..d2c9ed8a 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -131,11 +131,15 @@ void FirebaseArduino::stream(const String& path) { } bool FirebaseArduino::available() { - return http_->getStreamPtr()->available(); + auto client = http_->getStreamPtr(); + return (client == nullptr) ? false : client->available(); } FirebaseObject FirebaseArduino::readEvent() { auto client = http_->getStreamPtr(); + if (client == nullptr) { + return FirebaseObject(""); + } String type = client->readStringUntil('\n').substring(7);; String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator From 702d9f3fd343bc75fc25113a00408b7869664c20 Mon Sep 17 00:00:00 2001 From: Kshitij Date: Wed, 27 Dec 2017 15:25:00 +0530 Subject: [PATCH 20/68] remove duplicates --- examples/FirebaseRoom_ESP8266/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/FirebaseRoom_ESP8266/README.md b/examples/FirebaseRoom_ESP8266/README.md index 7f1620db..37a38512 100644 --- a/examples/FirebaseRoom_ESP8266/README.md +++ b/examples/FirebaseRoom_ESP8266/README.md @@ -58,7 +58,7 @@ sensor data to Firebase, and trigger actuators from Firebase. - Add Grove modules to modules interactions. - Connect other Grove modules to the room and submit new [PRs](https://github.com/googlesamples/firebase-arduino/pulls) - Reduce the number of Firebase API calls using `FirebaseObject` or `FirebaseStream`. -- Watch or star the [GitHub repo repo](https://github.com/googlesamples/firebase-arduino) +- Watch or star the [GitHub repo](https://github.com/googlesamples/firebase-arduino) - Give [feedback](https://gitter.im/googlesamples/firebase-arduino) - Report [bugs](https://github.com/googlesamples/firebase-arduino/issues/new) - [Fork](https://github.com/googlesamples/firebase-arduino#fork-destination-box) and [contribute](https://github.com/googlesamples/firebase-arduino/blob/master/CONTRIBUTING.md) From 09cd329f29a9d9eb48cb65bd13ba10b6295d59ff Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Mon, 22 Jan 2018 00:04:02 -0500 Subject: [PATCH 21/68] Add back nightly build environment --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 01f58db6..7c9131df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ addons: - g++-4.8 env: - ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - ( cd ${HOME} && wget https://downloads.arduino.cc/arduino-${ARDUINO_VERSION}-linux64.tar.xz && tar xf arduino-${ARDUINO_VERSION}-linux64.tar.xz ) From bdfe2bc8e71306f6081e7a8724a02f73f209f98b Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Mon, 22 Jan 2018 00:10:02 -0500 Subject: [PATCH 22/68] Added section about ArduinoJson dependency --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9cea7625..dc9420f8 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ The Arduino library is [under heavy development](https://github.com/googlesample - [FirebaseArduino API Reference](http://firebase-arduino.readthedocs.io/) +## Dependencies +- FirebaseArduino now depends on [ArduinoJson library](https://github.com/bblanchon/ArduinoJson) instead of containing it's own version of it. Please either use Library Manager or download specific version of the library from github. + ## Disclaimer *This is not an official Google product*. From ed756829f0e43f1fee0f50e511baa93a44254e45 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Mon, 29 Jan 2018 15:23:22 -0500 Subject: [PATCH 23/68] Remove trailing space from the comment --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 434da0f5..3b34df98 100644 --- a/README.rst +++ b/README.rst @@ -6,6 +6,6 @@ friendly way. ArduinoJson is no longer part of this library and you will have to install latest version in Arduino environment yourself. (through Board manager or download+unpack from master: -https://github.com/bblanchon/ArduinoJson ) +https://github.com/bblanchon/ArduinoJson) ---------------------------------- From 3d05b41c312808ba19514f78d9b0f701f8314b78 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 11 Apr 2018 00:03:44 -0400 Subject: [PATCH 24/68] Refactoring into on-demand classes and http connections --- src/Firebase.cpp | 168 ++++++++------------------------------- src/Firebase.h | 96 +++++----------------- src/FirebaseArduino.cpp | 78 +++++++++++------- src/FirebaseArduino.h | 9 ++- src/FirebaseHttpClient.h | 11 --- 5 files changed, 109 insertions(+), 253 deletions(-) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index fe8e13c3..8cdf72f8 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -42,115 +42,16 @@ const std::string& Firebase::auth() const { return auth_; } -FirebaseGet Firebase::get(const std::string& path) { - return FirebaseGet(host_, auth_, path, http_); -} - -unique_ptr Firebase::getPtr(const std::string& path) { - return unique_ptr(new FirebaseGet(host_, auth_, path, http_)); -} - -FirebaseSet Firebase::set(const std::string& path, const std::string& value) { - return FirebaseSet(host_, auth_, path, value, http_); -} - -unique_ptr Firebase::setPtr(const std::string& path, - const std::string& value) { - return unique_ptr( - new FirebaseSet(host_, auth_, path, value, http_)); -} - -FirebasePush Firebase::push(const std::string& path, const std::string& value) { - return FirebasePush(host_, auth_, path, value, http_); -} - -unique_ptr Firebase::pushPtr(const std::string& path, const std::string& value) { - return unique_ptr( - new FirebasePush(host_, auth_, path, value, http_)); -} - -FirebaseRemove Firebase::remove(const std::string& path) { - return FirebaseRemove(host_, auth_, path, http_); -} - -unique_ptr Firebase::removePtr(const std::string& path) { - return unique_ptr( - new FirebaseRemove(host_, auth_, path, http_)); -} - -FirebaseStream Firebase::stream(const std::string& path) { - // TODO: create new client dedicated to stream. - return FirebaseStream(host_, auth_, path, http_); -} - -unique_ptr Firebase::streamPtr(const std::string& path) { - // TODO: create new client dedicated to stream. - return unique_ptr( - new FirebaseStream(host_, auth_, path, http_)); -} - -// FirebaseCall -FirebaseCall::FirebaseCall(const std::string& host, const std::string& auth, - const char* method, const std::string& path, - const std::string& data, const std::shared_ptr http) : http_(http) { - std::string path_with_auth = makeFirebaseURL(path, auth); - if ((method == "STREAM") && (path == http->getStreamingPath())){ - // already streaming requested path. - return; - } - if (http_->isStreaming()) { - // closing streaming connection. - http_->setReuseConnection(false); - http_->end(); - } - http_->setReuseConnection(true); - http_->begin(host, path_with_auth); - - bool followRedirect = false; - if (std::string(method) == "STREAM") { - method = "GET"; - http_->addHeader("Accept", "text/event-stream"); - followRedirect = true; - } - - if (followRedirect) { - const char* headers[] = {"Location"}; - http_->collectHeaders(headers, 1); - } - - int status = http_->sendRequest(method, data); - - // TODO: Add a max redirect check - if (followRedirect) { - while (status == HttpStatus::TEMPORARY_REDIRECT) { - std::string location = http_->header("Location"); - http_->setReuseConnection(false); - http_->end(); - http_->setReuseConnection(true); - http_->begin(location); - status = http_->sendRequest("GET", std::string()); - } - } - - if (status != 200) { +void FirebaseCall::analyzeError(char* method, int status, const std::string& path_with_auth) { + if (status != 200) { error_ = FirebaseError(status, std::string(method) + " " + path_with_auth + ": " + http_->errorToString(status)); } - - // if not streaming. - if (!followRedirect) { - response_ = http_->getString(); - http_->setStreaming(""); - } else { - http_->setStreaming(path); - } } FirebaseCall::~FirebaseCall() { - if (http_ && !http_->isStreaming()) { - http_->end(); - } + http_->end(); } const JsonObject& FirebaseCall::json() { @@ -162,46 +63,39 @@ const JsonObject& FirebaseCall::json() { return buffer_.get()->parseObject(response().c_str()); } -// FirebaseGet -FirebaseGet::FirebaseGet(const std::string& host, const std::string& auth, - const std::string& path, - const std::shared_ptr http) - : FirebaseCall(host, auth, "GET", path, "", http) { +// FirebaseRequest +int FirebaseRequest::sendRequest( + const std::string& host, const std::string& auth, + char* method, const std::string& path, const std::string& data) { + std::string path_with_auth = makeFirebaseURL(path, auth); + http_->setReuseConnection(true); + http_->begin(host, path_with_auth); + int status = http_->sendRequest(method, data); + analyzeError(method, status, path_with_auth); + response_ = http_->getString(); } -// FirebaseSet -FirebaseSet::FirebaseSet(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, - const std::shared_ptr http) - : FirebaseCall(host, auth, "PUT", path, value, http) { - if (!error()) { - // TODO: parse json - json_ = response(); - } -} +// FirebaseStream +void FirebaseStream::startStreaming(const std::string& host, const std::string& auth, const std::string& path) { + std::string path_with_auth = makeFirebaseURL(path, auth); + http_->setReuseConnection(true); + http_->begin(host, path_with_auth); -// FirebasePush -FirebasePush::FirebasePush(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, - const std::shared_ptr http) - : FirebaseCall(host, auth, "POST", path, value, http) { - if (!error()) { - name_ = json()["name"].as(); - } -} + http_->addHeader("Accept", "text/event-stream"); + const char* headers[] = {"Location"}; + http_->collectHeaders(headers, 1); -// FirebaseRemove -FirebaseRemove::FirebaseRemove(const std::string& host, const std::string& auth, - const std::string& path, - const std::shared_ptr http) - : FirebaseCall(host, auth, "DELETE", path, "", http) { -} + int status = http_->sendRequest("GET", ""); + analyzeError("STREAM", status, path_with_auth); -// FirebaseStream -FirebaseStream::FirebaseStream(const std::string& host, const std::string& auth, - const std::string& path, - const std::shared_ptr http) - : FirebaseCall(host, auth, "STREAM", path, "", http) { + while (status == HttpStatus::TEMPORARY_REDIRECT) { + std::string location = http_->header("Location"); + http_->setReuseConnection(false); + http_->end(); + http_->setReuseConnection(true); + http_->begin(location); + status = http_->sendRequest("GET", std::string()); + } } bool FirebaseStream::available() { diff --git a/src/Firebase.h b/src/Firebase.h index f0943f12..00bf084b 100644 --- a/src/Firebase.h +++ b/src/Firebase.h @@ -29,12 +29,6 @@ #include "FirebaseError.h" #include "FirebaseObject.h" -class FirebaseGet; -class FirebaseSet; -class FirebasePush; -class FirebaseRemove; -class FirebaseStream; - // Firebase REST API client. class Firebase { public: @@ -43,24 +37,19 @@ class Firebase { const std::string& auth() const; // Fetch json encoded `value` at `path`. - FirebaseGet get(const std::string& path); - virtual std::unique_ptr getPtr(const std::string& path); + void get(const std::string& path); // Set json encoded `value` at `path`. - FirebaseSet set(const std::string& path, const std::string& json); - virtual std::unique_ptr setPtr(const std::string& path, const std::string& json); + void set(const std::string& path, const std::string& json); // Add new json encoded `value` to list at `path`. - FirebasePush push(const std::string& path, const std::string& json); - virtual std::unique_ptr pushPtr(const std::string& path, const std::string& json); + void push(const std::string& path, const std::string& json); // Delete value at `path`. - FirebaseRemove remove(const std::string& path); - virtual std::unique_ptr removePtr(const std::string& path); + void remove(const std::string& path); // Start a stream of events that affect value at `path`. - FirebaseStream stream(const std::string& path); - virtual std::unique_ptr streamPtr(const std::string& path); + void stream(const std::string& path); protected: // Used for testing. @@ -72,20 +61,19 @@ class Firebase { std::string auth_; }; + class FirebaseCall { public: - FirebaseCall() {} - FirebaseCall(const std::string& host, const std::string& auth, - const char* method, const std::string& path, - const std::string& data = "", - const std::shared_ptr http = NULL); + FirebaseCall(const std::shared_ptr http = NULL) : http_(http) {} virtual ~FirebaseCall(); - virtual const FirebaseError& error() const { + const FirebaseError& error() const { return error_; } - virtual const std::string& response() const { + void analyzeError(char* method, int status, const std::string & path_with_auth); + + const std::string& response() const { return response_; } @@ -98,59 +86,22 @@ class FirebaseCall { std::shared_ptr> buffer_; }; -class FirebaseGet : public FirebaseCall { - public: - FirebaseGet() {} - FirebaseGet(const std::string& host, const std::string& auth, - const std::string& path, const std::shared_ptr http = NULL); - - private: - std::string json_; +class FirebaseRequest : public FirebaseCall { + public: + FirebaseRequest(const std::shared_ptr http = NULL) : FirebaseCall(http) { } + virtual ~FirebaseRequest() {} + int sendRequest(const std::string& host, const std::string& auth, + char* method, const std::string& path, const std::string& data = ""); }; -class FirebaseSet: public FirebaseCall { - public: - FirebaseSet() {} - FirebaseSet(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, const std::shared_ptr http = NULL); - - - private: - std::string json_; -}; - -class FirebasePush : public FirebaseCall { - public: - FirebasePush() {} - FirebasePush(const std::string& host, const std::string& auth, - const std::string& path, const std::string& value, const std::shared_ptr http = NULL); - virtual ~FirebasePush() {} - - virtual const std::string& name() const { - return name_; - } - - private: - std::string name_; -}; - -class FirebaseRemove : public FirebaseCall { - public: - FirebaseRemove() {} - FirebaseRemove(const std::string& host, const std::string& auth, - const std::string& path, const std::shared_ptr http = NULL); -}; - - class FirebaseStream : public FirebaseCall { public: - FirebaseStream() {} - FirebaseStream(const std::string& host, const std::string& auth, - const std::string& path, const std::shared_ptr http = NULL); + FirebaseStream(const std::shared_ptr http = NULL) : FirebaseCall(http) { } virtual ~FirebaseStream() {} // Return if there is any event available to read. - virtual bool available(); + bool available(); + void startStreaming(const std::string& host, const std::string& auth, const std::string& path); // Event type. enum Event { @@ -174,13 +125,6 @@ class FirebaseStream : public FirebaseCall { // Read next json encoded `event` from stream. virtual Event read(std::string& event); - - const FirebaseError& error() const { - return _error; - } - - private: - FirebaseError _error; }; #endif // firebase_h diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index d2c9ed8a..b0205f34 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -20,12 +20,22 @@ template class std::basic_string; void FirebaseArduino::begin(const String& host, const String& auth) { - http_.reset(FirebaseHttpClient::create()); - http_->setReuseConnection(true); host_ = host.c_str(); auth_ = auth.c_str(); } +void FirebaseArduino::initStream() { + stream_http_.reset(FirebaseHttpClient::create()); + stream_http_->setReuseConnection(true); + stream_.reset(new FirebaseStream(stream_http_)); +} + +void FirebaseArduino::initRequest() { + req_http_.reset(FirebaseHttpClient::create()); + req_http_->setReuseConnection(true); + req_.reset(new FirebaseRequest(req_http_)); +} + String FirebaseArduino::pushInt(const String& path, int value) { return push(path, value); } @@ -46,9 +56,11 @@ String FirebaseArduino::pushString(const String& path, const String& value) { String FirebaseArduino::push(const String& path, const JsonVariant& value) { String buf; value.printTo(buf); - auto push = FirebasePush(host_, auth_, path.c_str(), buf.c_str(), http_); - error_ = push.error(); - return push.name().c_str(); + initRequest(); + int status = req_.get()->sendRequest(host_, auth_, "POST", path.c_str(), buf.c_str()); + error_ = req_.get()->error(); + const char* name = req_.get()->json()["name"].as(); + return name; } void FirebaseArduino::setInt(const String& path, int value) { @@ -71,72 +83,82 @@ void FirebaseArduino::setString(const String& path, const String& value) { void FirebaseArduino::set(const String& path, const JsonVariant& value) { String buf; value.printTo(buf); - auto set = FirebaseSet(host_, auth_, path.c_str(), buf.c_str(), http_); - error_ = set.error(); + initRequest(); + req_.get()->sendRequest(host_, auth_, "PUT", path.c_str(), buf.c_str()); + error_ = req_.get()->error(); +} + +void FirebaseArduino::getRequest(const String& path) { + initRequest(); + req_.get()->sendRequest(host_, auth_, "GET", path.c_str()); + error_ = req_.get()->error(); } FirebaseObject FirebaseArduino::get(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_); - error_ = get.error(); + getRequest(path); if (failed()) { return FirebaseObject{""}; } - return FirebaseObject(get.response().c_str()); + return FirebaseObject(req_.get()->response().c_str()); } int FirebaseArduino::getInt(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_); - error_ = get.error(); + getRequest(path); if (failed()) { return 0; } - return FirebaseObject(get.response().c_str()).getInt(); + return FirebaseObject(req_.get()->response().c_str()).getInt(); } float FirebaseArduino::getFloat(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_); - error_ = get.error(); + getRequest(path); if (failed()) { return 0.0f; } - return FirebaseObject(get.response().c_str()).getFloat(); + return FirebaseObject(req_.get()->response().c_str()).getFloat(); } String FirebaseArduino::getString(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_); - error_ = get.error(); + getRequest(path); if (failed()) { return ""; } - return FirebaseObject(get.response().c_str()).getString(); + return FirebaseObject(req_.get()->response().c_str()).getString(); } bool FirebaseArduino::getBool(const String& path) { - auto get = FirebaseGet(host_, auth_, path.c_str(), http_); - error_ = get.error(); + getRequest(path); if (failed()) { return ""; } - return FirebaseObject(get.response().c_str()).getBool(); + return FirebaseObject(req_.get()->response().c_str()).getBool(); } void FirebaseArduino::remove(const String& path) { - auto remove = FirebaseRemove(host_, auth_, path.c_str(), http_); - error_ = remove.error(); + initRequest(); + req_.get()->sendRequest(host_, auth_, "DELETE", path.c_str()); + error_ = req_.get()->error(); } void FirebaseArduino::stream(const String& path) { - auto stream = FirebaseStream(host_, auth_, path.c_str(), http_); - error_ = stream.error(); + initStream(); + stream_.get()->startStreaming(host_, auth_, path.c_str()); + error_ = stream_.get()->error(); } bool FirebaseArduino::available() { - auto client = http_->getStreamPtr(); + if (stream_http_.get() == nullptr) { + return 0; + } + auto client = stream_http_.get()->getStreamPtr(); return (client == nullptr) ? false : client->available(); } FirebaseObject FirebaseArduino::readEvent() { - auto client = http_->getStreamPtr(); + if (stream_http_.get() == nullptr) { + return FirebaseObject(""); + } + auto client = stream_http_.get()->getStreamPtr(); if (client == nullptr) { return FirebaseObject(""); } diff --git a/src/FirebaseArduino.h b/src/FirebaseArduino.h index 4d962b1b..6b9ae9f7 100644 --- a/src/FirebaseArduino.h +++ b/src/FirebaseArduino.h @@ -226,7 +226,14 @@ class FirebaseArduino { std::string host_; std::string auth_; FirebaseError error_; - std::shared_ptr http_; + std::shared_ptr req_http_; + std::shared_ptr req_; + std::shared_ptr stream_http_; + std::shared_ptr stream_; + + void initStream(); + void initRequest(); + void getRequest(const String& path); }; extern FirebaseArduino Firebase; diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 1752ba2f..055699c7 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -33,18 +33,7 @@ class FirebaseHttpClient { virtual std::string errorToString(int error_code) = 0; - bool isStreaming() const { - return _streaming != ""; - } - std::string getStreamingPath() const { - return _streaming; - } - void setStreaming(const std::string& path) { - _streaming = path; - } protected: - std::string _streaming = ""; - static const uint16_t kFirebasePort = 443; }; From 55a2ec636bd07050597724a6f3fcdf4598c7880f Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 11 Apr 2018 00:20:11 -0400 Subject: [PATCH 25/68] Attempt to fix mocks --- contrib/test/mock-firebase.h | 23 +--------------------- contrib/test/modem/get-command_test.cpp | 4 ++-- contrib/test/modem/push-command_test.cpp | 4 ++-- contrib/test/modem/remove-command_test.cpp | 4 ++-- contrib/test/modem/set-command_test.cpp | 4 ++-- 5 files changed, 9 insertions(+), 30 deletions(-) diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 92f1e9fa..eef57251 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -10,36 +10,15 @@ namespace modem { class MockFirebase : public Firebase { public: - MOCK_METHOD1(getPtr, std::unique_ptr(const std::string&)); - MOCK_METHOD2(setPtr, std::unique_ptr(const std::string&, const std::string&)); - MOCK_METHOD2(pushPtr, std::unique_ptr(const std::string&, const std::string&)); - MOCK_METHOD1(removePtr, std::unique_ptr(const std::string&)); - MOCK_METHOD1(streamPtr, std::unique_ptr(const std::string&)); }; -class MockFirebaseGet : public FirebaseGet { - public: - MOCK_CONST_METHOD0(response, const std::string&()); - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; -class MockFirebaseSet : public FirebaseSet { - public: - MOCK_CONST_METHOD0(json, const std::string&()); - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - -class MockFirebasePush : public FirebasePush { +class MockFirebaseRequest : public FirebaseRequest { public: MOCK_CONST_METHOD0(name, const std::string&()); MOCK_CONST_METHOD0(error, const FirebaseError&()); }; -class MockFirebaseRemove : public FirebaseRemove { - public: - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - class MockFirebaseStream : public FirebaseStream { public: MOCK_METHOD0(available, bool()); diff --git a/contrib/test/modem/get-command_test.cpp b/contrib/test/modem/get-command_test.cpp index 7372c79e..8dbf10c4 100644 --- a/contrib/test/modem/get-command_test.cpp +++ b/contrib/test/modem/get-command_test.cpp @@ -16,7 +16,7 @@ using ::testing::_; class GetCommandTest : public ::testing::Test { protected: void SetUp() override { - get_.reset(new MockFirebaseGet()); + get_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path) { @@ -39,7 +39,7 @@ class GetCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr get_; + std::unique_ptr get_; }; TEST_F(GetCommandTest, gets) { diff --git a/contrib/test/modem/push-command_test.cpp b/contrib/test/modem/push-command_test.cpp index 0b2a1d63..0f98a345 100644 --- a/contrib/test/modem/push-command_test.cpp +++ b/contrib/test/modem/push-command_test.cpp @@ -17,7 +17,7 @@ using ::testing::_; class PushCommandTest : public ::testing::Test { protected: void SetUp() override { - push_.reset(new MockFirebasePush()); + push_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path, const String& data) { @@ -54,7 +54,7 @@ class PushCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr push_; + std::unique_ptr push_; }; TEST_F(PushCommandTest, sendsData) { diff --git a/contrib/test/modem/remove-command_test.cpp b/contrib/test/modem/remove-command_test.cpp index 8f71903b..06147278 100644 --- a/contrib/test/modem/remove-command_test.cpp +++ b/contrib/test/modem/remove-command_test.cpp @@ -16,7 +16,7 @@ using ::testing::_; class RemoveCommandTest : public ::testing::Test { protected: void SetUp() override { - remove_.reset(new MockFirebaseRemove()); + remove_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path) { @@ -39,7 +39,7 @@ class RemoveCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr remove_; + std::unique_ptr remove_; }; TEST_F(RemoveCommandTest, success) { diff --git a/contrib/test/modem/set-command_test.cpp b/contrib/test/modem/set-command_test.cpp index 3bbe4747..d15a63cd 100644 --- a/contrib/test/modem/set-command_test.cpp +++ b/contrib/test/modem/set-command_test.cpp @@ -17,7 +17,7 @@ using ::testing::_; class SetCommandTest : public ::testing::Test { protected: void SetUp() override { - set_.reset(new MockFirebaseSet()); + set_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path, const String& data) { @@ -54,7 +54,7 @@ class SetCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr set_; + std::unique_ptr set_; }; TEST_F(SetCommandTest, sendsData) { From 37e0c4338f482b4129b87c3f96aaae1b986f126b Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Thu, 12 Apr 2018 00:36:14 -0400 Subject: [PATCH 26/68] attempt to fix test 2 --- contrib/test/modem/get-command_test.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/contrib/test/modem/get-command_test.cpp b/contrib/test/modem/get-command_test.cpp index 8dbf10c4..7ba6427a 100644 --- a/contrib/test/modem/get-command_test.cpp +++ b/contrib/test/modem/get-command_test.cpp @@ -29,9 +29,6 @@ class GetCommandTest : public ::testing::Test { EXPECT_CALL(*get_, error()) .WillRepeatedly(ReturnRef(error)); - EXPECT_CALL(fbase_, getPtr(_)) - .WillOnce(Return(ByMove(std::move(get_)))); - GetCommand getCmd(&fbase_); return getCmd.execute("GET", &in_, &out_); } From b81f28605b825d8d7c95895b2ebd9e442bda81ca Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Thu, 12 Apr 2018 00:54:54 -0400 Subject: [PATCH 27/68] Add mock response --- contrib/test/mock-firebase.h | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index eef57251..f89a2b4b 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -16,6 +16,7 @@ class MockFirebase : public Firebase { class MockFirebaseRequest : public FirebaseRequest { public: MOCK_CONST_METHOD0(name, const std::string&()); + MOCK_CONST_METHOD0(reponse, const std::string&()); MOCK_CONST_METHOD0(error, const FirebaseError&()); }; From a3d0e36621ba72fda5a18bae0d6de3e6b81f9d92 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Thu, 12 Apr 2018 01:05:53 -0400 Subject: [PATCH 28/68] fixed typo --- contrib/test/mock-firebase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index f89a2b4b..28e3ceb0 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -16,7 +16,7 @@ class MockFirebase : public Firebase { class MockFirebaseRequest : public FirebaseRequest { public: MOCK_CONST_METHOD0(name, const std::string&()); - MOCK_CONST_METHOD0(reponse, const std::string&()); + MOCK_CONST_METHOD0(response, const std::string&()); MOCK_CONST_METHOD0(error, const FirebaseError&()); }; From 3558351e2647cf8bf73501f2c12fa5ee931479b8 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Tue, 17 Apr 2018 22:36:00 -0400 Subject: [PATCH 29/68] Fixing a problem with reusing same client. --- src/FirebaseArduino.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index b0205f34..57244afa 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -25,15 +25,19 @@ void FirebaseArduino::begin(const String& host, const String& auth) { } void FirebaseArduino::initStream() { - stream_http_.reset(FirebaseHttpClient::create()); - stream_http_->setReuseConnection(true); - stream_.reset(new FirebaseStream(stream_http_)); + if (stream_http_.get() == nullptr) { + stream_http_.reset(FirebaseHttpClient::create()); + stream_http_->setReuseConnection(true); + stream_.reset(new FirebaseStream(stream_http_)); + } } void FirebaseArduino::initRequest() { - req_http_.reset(FirebaseHttpClient::create()); - req_http_->setReuseConnection(true); - req_.reset(new FirebaseRequest(req_http_)); + if (req_http_.get() == nullptr) { + req_http_.reset(FirebaseHttpClient::create()); + req_http_->setReuseConnection(true); + req_.reset(new FirebaseRequest(req_http_)); + } } String FirebaseArduino::pushInt(const String& path, int value) { From 4fc8da2526d099da9e1861bf47762fadf03cce94 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 00:06:52 -0400 Subject: [PATCH 30/68] Fix modem contrib --- contrib/src/modem/command.h | 8 ++++---- contrib/src/modem/db/DatabaseProtocol.cpp | 2 +- contrib/src/modem/db/DatabaseProtocol.h | 4 ++-- contrib/src/modem/db/begin-command.cpp | 5 +++-- contrib/src/modem/db/commands.h | 16 ++++++++-------- contrib/src/modem/db/get-command.cpp | 9 ++++----- contrib/src/modem/db/push-command.cpp | 11 +++++------ contrib/src/modem/db/remove-command.cpp | 6 +++--- contrib/src/modem/db/set-command.cpp | 11 +++++------ contrib/src/modem/db/stream-command.cpp | 18 ++++++++---------- 10 files changed, 43 insertions(+), 47 deletions(-) diff --git a/contrib/src/modem/command.h b/contrib/src/modem/command.h index 89aaee1a..bc5bde8c 100644 --- a/contrib/src/modem/command.h +++ b/contrib/src/modem/command.h @@ -1,7 +1,7 @@ #ifndef MODEM_COMMAND_H #define MODEM_COMMAND_H -#include "Firebase.h" +#include "FirebaseArduino.h" #include "modem/output-stream.h" #include "modem/input-stream.h" @@ -10,19 +10,19 @@ namespace modem { class Command { public: - Command(Firebase* fbase) : fbase_(fbase) {} + Command(FirebaseArduino* fbase) : fbase_(fbase) {} // Execute command, reading any additional data needed from stream. // Return false if execution failed. virtual bool execute(const String& command, InputStream* in, OutputStream* out) = 0; protected: - Firebase& fbase() { + FirebaseArduino& fbase() { return *fbase_; } private: - Firebase* fbase_; + FirebaseArduino* fbase_; }; } // modem diff --git a/contrib/src/modem/db/DatabaseProtocol.cpp b/contrib/src/modem/db/DatabaseProtocol.cpp index 338daf82..8a053ebb 100644 --- a/contrib/src/modem/db/DatabaseProtocol.cpp +++ b/contrib/src/modem/db/DatabaseProtocol.cpp @@ -42,7 +42,7 @@ void DatabaseProtocol::Execute(const String& command_name, InputStream* in, } std::unique_ptr DatabaseProtocol::CreateCommand(const String& text, - Firebase* fbase) { + FirebaseArduino* fbase) { std::unique_ptr command; if (text == "GET") { command.reset(new GetCommand(fbase)); diff --git a/contrib/src/modem/db/DatabaseProtocol.h b/contrib/src/modem/db/DatabaseProtocol.h index dec7fad5..8da8ed62 100644 --- a/contrib/src/modem/db/DatabaseProtocol.h +++ b/contrib/src/modem/db/DatabaseProtocol.h @@ -13,9 +13,9 @@ class DatabaseProtocol : public SerialProtocol { const std::vector& commands() const override; void Execute(const String& command, InputStream* in, OutputStream* out) override; private: - std::unique_ptr CreateCommand(const String& text, Firebase* fbase); + std::unique_ptr CreateCommand(const String& text, FirebaseArduino* fbase); - std::unique_ptr fbase_; + std::unique_ptr fbase_; }; diff --git a/contrib/src/modem/db/begin-command.cpp b/contrib/src/modem/db/begin-command.cpp index 9658815d..9950f8e7 100644 --- a/contrib/src/modem/db/begin-command.cpp +++ b/contrib/src/modem/db/begin-command.cpp @@ -33,13 +33,14 @@ bool BeginCommand::execute(const String& command, return false; } - new_firebase_.reset(new Firebase(host.c_str(), auth.c_str())); + new_firebase_.reset(new FirebaseArduino()); + new_firebase_.get()->begin(host.c_str(), auth.c_str()); out->println("+OK"); return true; } -std::unique_ptr BeginCommand::firebase() { +std::unique_ptr BeginCommand::firebase() { return std::move(new_firebase_); } diff --git a/contrib/src/modem/db/commands.h b/contrib/src/modem/db/commands.h index f6808024..2bb6bb71 100644 --- a/contrib/src/modem/db/commands.h +++ b/contrib/src/modem/db/commands.h @@ -1,7 +1,7 @@ #ifndef MODEM_DB_COMMANDS_H #define MODEM_DB_COMMANDS_H -#include "Firebase.h" +#include "FirebaseArduino.h" #include "modem/command.h" #include "modem/output-stream.h" #include "modem/input-stream.h" @@ -11,28 +11,28 @@ namespace modem { class GetCommand : public Command { public: - GetCommand(Firebase* fbase) : Command(fbase) {} + GetCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; class SetCommand : public Command { public: - SetCommand(Firebase* fbase) : Command(fbase) {} + SetCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; class RemoveCommand : public Command { public: - RemoveCommand(Firebase* fbase) : Command(fbase) {} + RemoveCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; class PushCommand : public Command { public: - PushCommand(Firebase* fbase) : Command(fbase) {} + PushCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; @@ -44,15 +44,15 @@ class BeginCommand : public Command { bool execute(const String& command, InputStream* in, OutputStream* out); // This can only be called once. - std::unique_ptr firebase(); + std::unique_ptr firebase(); private: - std::unique_ptr new_firebase_; + std::unique_ptr new_firebase_; }; class StreamCommand : public Command { public: - StreamCommand(Firebase* fbase) : Command(fbase) {} + StreamCommand(FirebaseArduino* fbase) : Command(fbase) {} bool execute(const String& command, InputStream* in, OutputStream* out); }; diff --git a/contrib/src/modem/db/get-command.cpp b/contrib/src/modem/db/get-command.cpp index f7c7c7ef..0b367915 100644 --- a/contrib/src/modem/db/get-command.cpp +++ b/contrib/src/modem/db/get-command.cpp @@ -13,16 +13,15 @@ bool GetCommand::execute(const String& command, return false; } - std::string path = in->readLine().c_str(); - std::unique_ptr get(fbase().getPtr(path)); + String path = in->readLine(); + String value = fbase().getString(path); - if (get->error()) { + if (fbase().error()) { out->print("-FAIL "); - out->println(get->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } - String value(get->response().c_str()); // TODO implement json parsing to pull and process value. out->print("+"); out->println(value); diff --git a/contrib/src/modem/db/push-command.cpp b/contrib/src/modem/db/push-command.cpp index 8ceb33b7..b1a06b19 100644 --- a/contrib/src/modem/db/push-command.cpp +++ b/contrib/src/modem/db/push-command.cpp @@ -14,15 +14,14 @@ bool PushCommand::execute(const String& command, return false; } - std::string path(in->readStringUntil(' ').c_str()); - std::string data(in->readLine().c_str()); + String path = in->readStringUntil(' '); + String data = in->readLine(); - std::unique_ptr push( - fbase().pushPtr(path, EncodeForJson(data))); + fbase().pushString(path, data); - if (push->error()) { + if (fbase().error()) { out->print("-FAIL "); - out->println(push->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } else { out->println("+OK"); diff --git a/contrib/src/modem/db/remove-command.cpp b/contrib/src/modem/db/remove-command.cpp index a144de23..1804618f 100644 --- a/contrib/src/modem/db/remove-command.cpp +++ b/contrib/src/modem/db/remove-command.cpp @@ -14,11 +14,11 @@ bool RemoveCommand::execute(const String& command, } String path = in->readLine(); - std::unique_ptr get(fbase().removePtr(path.c_str())); + fbase().remove(path); - if (get->error()) { + if (fbase().error()) { out->print("-FAIL "); - out->println(get->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } diff --git a/contrib/src/modem/db/set-command.cpp b/contrib/src/modem/db/set-command.cpp index 71530539..7dbfe0fc 100644 --- a/contrib/src/modem/db/set-command.cpp +++ b/contrib/src/modem/db/set-command.cpp @@ -14,15 +14,14 @@ bool SetCommand::execute(const String& command, return false; } - std::string path(in->readStringUntil(' ').c_str()); - std::string data(in->readLine().c_str()); + String path = in->readStringUntil(' '); + String data = in->readLine(); - std::unique_ptr set(fbase().setPtr(path, - EncodeForJson(data))); + fbase().setString(path, data); - if (set->error()) { + if (fbase().error()) { out->print("-FAIL "); - out->println(set->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } else { out->println("+OK"); diff --git a/contrib/src/modem/db/stream-command.cpp b/contrib/src/modem/db/stream-command.cpp index f8259bc6..4b9a9197 100644 --- a/contrib/src/modem/db/stream-command.cpp +++ b/contrib/src/modem/db/stream-command.cpp @@ -14,26 +14,24 @@ bool StreamCommand::execute(const String& command, } std::string path = in->readLine().c_str(); - std::unique_ptr stream(fbase().streamPtr(path)); + fbase().stream(path); - if (stream->error()) { + if (fbase().error()) { out->print("-FAIL "); - out->println(stream->error().message().c_str()); + out->println(fbase().error().c_str()); return false; } bool running = true; DynamicJsonBuffer buffer; while(running) { - if (stream->available()) { - std::string json; - FirebaseStream::Event event = stream->read(json); + if (fbase().available()) { + FirebaseObject event = fbase().readEvent(); out->print("+"); - out->print(FirebaseStream::EventToName(event).c_str()); + out->print(event.getString("event").c_str()); out->print(" "); - const auto& object = buffer.parseObject(json.c_str()); - String data = object["data"].asString(); - out->println(object["path"].asString()); + String data = event.getString("data"); + out->println(event.getString("path")); out->println(data.length()); out->println(data); } else if (in->available()) { From 353a6d7a759649823770cde3b04a5b254a15bc34 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 00:17:08 -0400 Subject: [PATCH 31/68] Remove dead code. --- src/Firebase.cpp | 24 ------------------------ src/Firebase.h | 25 ------------------------- 2 files changed, 49 deletions(-) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index 8cdf72f8..b6c10043 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -97,27 +97,3 @@ void FirebaseStream::startStreaming(const std::string& host, const std::string& status = http_->sendRequest("GET", std::string()); } } - -bool FirebaseStream::available() { - auto client = http_->getStreamPtr(); - return (client == nullptr) ? false : client->available(); -} - -FirebaseStream::Event FirebaseStream::read(std::string& event) { - auto client = http_->getStreamPtr(); - if (client == nullptr) { - return Event(); - } - Event type; - std::string typeStr = client->readStringUntil('\n').substring(7).c_str(); - if (typeStr == "put") { - type = Event::PUT; - } else if (typeStr == "patch") { - type = Event::PATCH; - } else { - type = Event::UNKNOWN; - } - event = client->readStringUntil('\n').substring(6).c_str(); - client->readStringUntil('\n'); // consume separator - return type; -} diff --git a/src/Firebase.h b/src/Firebase.h index 00bf084b..44450557 100644 --- a/src/Firebase.h +++ b/src/Firebase.h @@ -99,32 +99,7 @@ class FirebaseStream : public FirebaseCall { FirebaseStream(const std::shared_ptr http = NULL) : FirebaseCall(http) { } virtual ~FirebaseStream() {} - // Return if there is any event available to read. - bool available(); void startStreaming(const std::string& host, const std::string& auth, const std::string& path); - - // Event type. - enum Event { - UNKNOWN, - PUT, - PATCH - }; - - static inline std::string EventToName(Event event) { - switch(event) { - case UNKNOWN: - return "UNKNOWN"; - case PUT: - return "PUT"; - case PATCH: - return "PATCH"; - default: - return "INVALID_EVENT_" + event; - } - } - - // Read next json encoded `event` from stream. - virtual Event read(std::string& event); }; #endif // firebase_h From 8bce695b15e35ec9be6495d00406169790df23b3 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 00:27:05 -0400 Subject: [PATCH 32/68] Added proper mock object and method for modem tests --- contrib/test/mock-firebase.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 28e3ceb0..188ab777 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -3,13 +3,21 @@ #include #include "gtest/gtest.h" -#include "Firebase.h" +#include "FirebaseArduino.h" namespace firebase { namespace modem { -class MockFirebase : public Firebase { +class MockFirebase : public FirebaseArduino { public: + MOCK_CONST_METHOD0(error, const FirebaseError&()); + MOCK_CONST_METHOD1(getString, String ()); + MOCK_CONST_METHOD2(pushString, void()); + MOCK_CONST_METHOD1(remove, void()); + MOCK_CONST_METHOD2(setString, void()); + MOCK_CONST_METHOD0(available, bool ()); + MOCK_CONST_METHOD0(readEvent, FirebaseObject ()); + MOCK_CONST_METHOD2(begin, void ()); }; From 82cd290b5092a8f34ae0f0266c052c45ad82c7e7 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 00:35:40 -0400 Subject: [PATCH 33/68] fix param definition in mock-firebase.h --- contrib/test/mock-firebase.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 188ab777..17fd9b85 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -11,13 +11,13 @@ namespace modem { class MockFirebase : public FirebaseArduino { public: MOCK_CONST_METHOD0(error, const FirebaseError&()); - MOCK_CONST_METHOD1(getString, String ()); - MOCK_CONST_METHOD2(pushString, void()); - MOCK_CONST_METHOD1(remove, void()); - MOCK_CONST_METHOD2(setString, void()); + MOCK_CONST_METHOD1(getString, String (const String& path)); + MOCK_CONST_METHOD2(pushString, void(const String& path, const String& data)); + MOCK_CONST_METHOD1(remove, void(const String& path)); + MOCK_CONST_METHOD2(setString, void(const String& path, const String& data)); MOCK_CONST_METHOD0(available, bool ()); MOCK_CONST_METHOD0(readEvent, FirebaseObject ()); - MOCK_CONST_METHOD2(begin, void ()); + MOCK_CONST_METHOD2(begin, void (const String& host, const String& auth)); }; From 95ce5ec2b50e6688be5644fa022dce3630020fe4 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 00:44:56 -0400 Subject: [PATCH 34/68] remove test / mock dead code --- contrib/test/mock-firebase.h | 15 --------------- contrib/test/modem/get-command_test.cpp | 7 ------- contrib/test/modem/push-command_test.cpp | 8 -------- contrib/test/modem/remove-command_test.cpp | 7 ------- contrib/test/modem/set-command_test.cpp | 7 ------- 5 files changed, 44 deletions(-) diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 17fd9b85..94c31b5f 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -20,21 +20,6 @@ class MockFirebase : public FirebaseArduino { MOCK_CONST_METHOD2(begin, void (const String& host, const String& auth)); }; - -class MockFirebaseRequest : public FirebaseRequest { - public: - MOCK_CONST_METHOD0(name, const std::string&()); - MOCK_CONST_METHOD0(response, const std::string&()); - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - -class MockFirebaseStream : public FirebaseStream { - public: - MOCK_METHOD0(available, bool()); - MOCK_METHOD1(read, Event(std::string& event)); - MOCK_CONST_METHOD0(error, const FirebaseError&()); -}; - } // modem } // firebase #endif // TEST_MOCK_FIREBASE_H diff --git a/contrib/test/modem/get-command_test.cpp b/contrib/test/modem/get-command_test.cpp index 7ba6427a..5ff5cf16 100644 --- a/contrib/test/modem/get-command_test.cpp +++ b/contrib/test/modem/get-command_test.cpp @@ -16,7 +16,6 @@ using ::testing::_; class GetCommandTest : public ::testing::Test { protected: void SetUp() override { - get_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path) { @@ -26,9 +25,6 @@ class GetCommandTest : public ::testing::Test { } bool RunCommand(const FirebaseError& error) { - EXPECT_CALL(*get_, error()) - .WillRepeatedly(ReturnRef(error)); - GetCommand getCmd(&fbase_); return getCmd.execute("GET", &in_, &out_); } @@ -36,7 +32,6 @@ class GetCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr get_; }; TEST_F(GetCommandTest, gets) { @@ -44,8 +39,6 @@ TEST_F(GetCommandTest, gets) { FeedCommand(path); const String value("Test value"); - EXPECT_CALL(*get_, response()) - .WillOnce(ReturnRef(value)); EXPECT_CALL(out_, print(String("+"))) .WillOnce(Return(1)); diff --git a/contrib/test/modem/push-command_test.cpp b/contrib/test/modem/push-command_test.cpp index 0f98a345..1823dd0d 100644 --- a/contrib/test/modem/push-command_test.cpp +++ b/contrib/test/modem/push-command_test.cpp @@ -17,7 +17,6 @@ using ::testing::_; class PushCommandTest : public ::testing::Test { protected: void SetUp() override { - push_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path, const String& data) { @@ -41,12 +40,6 @@ class PushCommandTest : public ::testing::Test { } bool RunExpectingData(const String& data, const FirebaseError& error) { - EXPECT_CALL(*push_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, pushPtr(_, EncodeForJson(data))) - .WillOnce(Return(ByMove(std::move(push_)))); - PushCommand pushCmd(&fbase_); return pushCmd.execute("PUSH", &in_, &out_); } @@ -54,7 +47,6 @@ class PushCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr push_; }; TEST_F(PushCommandTest, sendsData) { diff --git a/contrib/test/modem/remove-command_test.cpp b/contrib/test/modem/remove-command_test.cpp index 06147278..9405869a 100644 --- a/contrib/test/modem/remove-command_test.cpp +++ b/contrib/test/modem/remove-command_test.cpp @@ -16,7 +16,6 @@ using ::testing::_; class RemoveCommandTest : public ::testing::Test { protected: void SetUp() override { - remove_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path) { @@ -26,11 +25,6 @@ class RemoveCommandTest : public ::testing::Test { } bool RunCommand(const FirebaseError& error) { - EXPECT_CALL(*remove_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, removePtr(_)) - .WillOnce(Return(ByMove(std::move(remove_)))); RemoveCommand command(&fbase_); return command.execute("REMOVE", &in_, &out_); @@ -39,7 +33,6 @@ class RemoveCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr remove_; }; TEST_F(RemoveCommandTest, success) { diff --git a/contrib/test/modem/set-command_test.cpp b/contrib/test/modem/set-command_test.cpp index d15a63cd..826e1254 100644 --- a/contrib/test/modem/set-command_test.cpp +++ b/contrib/test/modem/set-command_test.cpp @@ -17,7 +17,6 @@ using ::testing::_; class SetCommandTest : public ::testing::Test { protected: void SetUp() override { - set_.reset(new MockFirebaseRequest()); } void FeedCommand(const String& path, const String& data) { @@ -41,11 +40,6 @@ class SetCommandTest : public ::testing::Test { } bool RunExpectingData(const String& data, const FirebaseError& error) { - EXPECT_CALL(*set_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, setPtr(_, EncodeForJson(data))) - .WillOnce(Return(ByMove(std::move(set_)))); SetCommand setCmd(&fbase_); return setCmd.execute("SET", &in_, &out_); @@ -54,7 +48,6 @@ class SetCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr set_; }; TEST_F(SetCommandTest, sendsData) { From 38575e30d91910f7efaf8618ce5d6a179402a34e Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 00:53:15 -0400 Subject: [PATCH 35/68] Fix error() mock definition --- contrib/test/mock-firebase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 94c31b5f..1ca77d51 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -10,7 +10,7 @@ namespace modem { class MockFirebase : public FirebaseArduino { public: - MOCK_CONST_METHOD0(error, const FirebaseError&()); + MOCK_CONST_METHOD0(error, const String &()); MOCK_CONST_METHOD1(getString, String (const String& path)); MOCK_CONST_METHOD2(pushString, void(const String& path, const String& data)); MOCK_CONST_METHOD1(remove, void(const String& path)); From 905c4bcf6d0fa60b95f2c1410da9285fbba8d4e3 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 08:34:24 -0400 Subject: [PATCH 36/68] use explicit string comparison --- contrib/src/modem/db/get-command.cpp | 2 +- contrib/src/modem/db/push-command.cpp | 2 +- contrib/src/modem/db/remove-command.cpp | 2 +- contrib/src/modem/db/set-command.cpp | 2 +- contrib/src/modem/db/stream-command.cpp | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/contrib/src/modem/db/get-command.cpp b/contrib/src/modem/db/get-command.cpp index 0b367915..ec8fbad4 100644 --- a/contrib/src/modem/db/get-command.cpp +++ b/contrib/src/modem/db/get-command.cpp @@ -16,7 +16,7 @@ bool GetCommand::execute(const String& command, String path = in->readLine(); String value = fbase().getString(path); - if (fbase().error()) { + if (fbase().error() != "") { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/push-command.cpp b/contrib/src/modem/db/push-command.cpp index b1a06b19..b4975717 100644 --- a/contrib/src/modem/db/push-command.cpp +++ b/contrib/src/modem/db/push-command.cpp @@ -19,7 +19,7 @@ bool PushCommand::execute(const String& command, fbase().pushString(path, data); - if (fbase().error()) { + if (fbase().error() != "") { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/remove-command.cpp b/contrib/src/modem/db/remove-command.cpp index 1804618f..0c9f66f3 100644 --- a/contrib/src/modem/db/remove-command.cpp +++ b/contrib/src/modem/db/remove-command.cpp @@ -16,7 +16,7 @@ bool RemoveCommand::execute(const String& command, String path = in->readLine(); fbase().remove(path); - if (fbase().error()) { + if (fbase().error() != "") { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/set-command.cpp b/contrib/src/modem/db/set-command.cpp index 7dbfe0fc..e4902779 100644 --- a/contrib/src/modem/db/set-command.cpp +++ b/contrib/src/modem/db/set-command.cpp @@ -19,7 +19,7 @@ bool SetCommand::execute(const String& command, fbase().setString(path, data); - if (fbase().error()) { + if (fbase().error() != "") { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/stream-command.cpp b/contrib/src/modem/db/stream-command.cpp index 4b9a9197..36af4049 100644 --- a/contrib/src/modem/db/stream-command.cpp +++ b/contrib/src/modem/db/stream-command.cpp @@ -13,10 +13,10 @@ bool StreamCommand::execute(const String& command, return false; } - std::string path = in->readLine().c_str(); + String path = in->readLine().c_str(); fbase().stream(path); - if (fbase().error()) { + if (fbase().error() != "") { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; From 721a3c4f3b1bdb714329069846412819030e1ad0 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 18 Apr 2018 19:57:48 -0400 Subject: [PATCH 37/68] fix error empty checks, header files and makefile for modem test --- contrib/src/modem/db/get-command.cpp | 2 +- contrib/src/modem/db/push-command.cpp | 2 +- contrib/src/modem/db/remove-command.cpp | 2 +- contrib/src/modem/db/set-command.cpp | 2 +- contrib/src/modem/db/stream-command.cpp | 2 +- contrib/test/modem/Makefile | 4 ++-- contrib/test/modem/begin-command_test.cpp | 2 +- contrib/test/modem/get-command_test.cpp | 2 +- contrib/test/modem/push-command_test.cpp | 2 +- contrib/test/modem/remove-command_test.cpp | 2 +- contrib/test/modem/serial-transceiver_test.cpp | 2 +- contrib/test/modem/set-command_test.cpp | 2 +- contrib/test/modem/stream-command_test.cpp | 2 +- 13 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/src/modem/db/get-command.cpp b/contrib/src/modem/db/get-command.cpp index ec8fbad4..a92c4efc 100644 --- a/contrib/src/modem/db/get-command.cpp +++ b/contrib/src/modem/db/get-command.cpp @@ -16,7 +16,7 @@ bool GetCommand::execute(const String& command, String path = in->readLine(); String value = fbase().getString(path); - if (fbase().error() != "") { + if (fbase().error().length() == 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/push-command.cpp b/contrib/src/modem/db/push-command.cpp index b4975717..052649e7 100644 --- a/contrib/src/modem/db/push-command.cpp +++ b/contrib/src/modem/db/push-command.cpp @@ -19,7 +19,7 @@ bool PushCommand::execute(const String& command, fbase().pushString(path, data); - if (fbase().error() != "") { + if (fbase().error().length() == 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/remove-command.cpp b/contrib/src/modem/db/remove-command.cpp index 0c9f66f3..43120dc1 100644 --- a/contrib/src/modem/db/remove-command.cpp +++ b/contrib/src/modem/db/remove-command.cpp @@ -16,7 +16,7 @@ bool RemoveCommand::execute(const String& command, String path = in->readLine(); fbase().remove(path); - if (fbase().error() != "") { + if (fbase().error().length() == 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/set-command.cpp b/contrib/src/modem/db/set-command.cpp index e4902779..5874bff1 100644 --- a/contrib/src/modem/db/set-command.cpp +++ b/contrib/src/modem/db/set-command.cpp @@ -19,7 +19,7 @@ bool SetCommand::execute(const String& command, fbase().setString(path, data); - if (fbase().error() != "") { + if (fbase().error().length() == 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/stream-command.cpp b/contrib/src/modem/db/stream-command.cpp index 36af4049..92d88dd7 100644 --- a/contrib/src/modem/db/stream-command.cpp +++ b/contrib/src/modem/db/stream-command.cpp @@ -16,7 +16,7 @@ bool StreamCommand::execute(const String& command, String path = in->readLine().c_str(); fbase().stream(path); - if (fbase().error() != "") { + if (fbase().error().length() == 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/test/modem/Makefile b/contrib/test/modem/Makefile index 06b07175..39cbee53 100644 --- a/contrib/test/modem/Makefile +++ b/contrib/test/modem/Makefile @@ -130,8 +130,8 @@ arduino_mock_all.a : ArduinoMockAll.o # Builds shared objects. -Firebase.o : $(FIREBASE_SRC_ROOT)/Firebase.cpp - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/Firebase.cpp +Firebase.o : $(FIREBASE_SRC_ROOT)/FirebaseArduino.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/FirebaseArduino.cpp FirebaseHttpClient_dummy.o : $(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp diff --git a/contrib/test/modem/begin-command_test.cpp b/contrib/test/modem/begin-command_test.cpp index e8682cfe..d8f5a86d 100644 --- a/contrib/test/modem/begin-command_test.cpp +++ b/contrib/test/modem/begin-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "test/modem/mock-input-stream.h" diff --git a/contrib/test/modem/get-command_test.cpp b/contrib/test/modem/get-command_test.cpp index 5ff5cf16..ccaf3e98 100644 --- a/contrib/test/modem/get-command_test.cpp +++ b/contrib/test/modem/get-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "test/modem/mock-input-stream.h" diff --git a/contrib/test/modem/push-command_test.cpp b/contrib/test/modem/push-command_test.cpp index 1823dd0d..8edc18ef 100644 --- a/contrib/test/modem/push-command_test.cpp +++ b/contrib/test/modem/push-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "modem/json_util.h" diff --git a/contrib/test/modem/remove-command_test.cpp b/contrib/test/modem/remove-command_test.cpp index 9405869a..41efe347 100644 --- a/contrib/test/modem/remove-command_test.cpp +++ b/contrib/test/modem/remove-command_test.cpp @@ -2,7 +2,7 @@ #include "test/modem/mock-output-stream.h" #include "test/modem/mock-input-stream.h" #include "test/mock-firebase.h" -#include "Firebase.h" +#include "FirebaseArduino.h" #include "modem/db/commands.h" namespace firebase { diff --git a/contrib/test/modem/serial-transceiver_test.cpp b/contrib/test/modem/serial-transceiver_test.cpp index bcbed2a1..c5328612 100644 --- a/contrib/test/modem/serial-transceiver_test.cpp +++ b/contrib/test/modem/serial-transceiver_test.cpp @@ -1,6 +1,6 @@ #include -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/SerialTransceiver.h" diff --git a/contrib/test/modem/set-command_test.cpp b/contrib/test/modem/set-command_test.cpp index 826e1254..e573fb65 100644 --- a/contrib/test/modem/set-command_test.cpp +++ b/contrib/test/modem/set-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "modem/json_util.h" diff --git a/contrib/test/modem/stream-command_test.cpp b/contrib/test/modem/stream-command_test.cpp index 752a01a4..9bc27111 100644 --- a/contrib/test/modem/stream-command_test.cpp +++ b/contrib/test/modem/stream-command_test.cpp @@ -1,4 +1,4 @@ -#include "Firebase.h" +#include "FirebaseArduino.h" #include "gtest/gtest.h" #include "modem/db/commands.h" #include "test/modem/mock-input-stream.h" From 7dc2feab81a5ac753a03cad3d0159aaa3b31dcc9 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sun, 6 May 2018 19:30:40 -0400 Subject: [PATCH 38/68] fixing compilation and some of the tests. disabled stream test for now --- contrib/src/modem/db/get-command.cpp | 3 +- contrib/src/modem/db/push-command.cpp | 2 +- contrib/src/modem/db/remove-command.cpp | 2 +- contrib/src/modem/db/set-command.cpp | 2 +- contrib/src/modem/db/stream-command.cpp | 2 +- contrib/test/mock-firebase.h | 16 +++++----- contrib/test/modem/Makefile | 37 +++++++++++++--------- contrib/test/modem/begin-command_test.cpp | 8 ++--- contrib/test/modem/get-command_test.cpp | 13 ++++++-- contrib/test/modem/stream-command_test.cpp | 17 ++++------ src/FirebaseArduino.cpp | 22 +++++++------ src/FirebaseArduino.h | 16 +++++----- 12 files changed, 76 insertions(+), 64 deletions(-) diff --git a/contrib/src/modem/db/get-command.cpp b/contrib/src/modem/db/get-command.cpp index a92c4efc..0fb2c478 100644 --- a/contrib/src/modem/db/get-command.cpp +++ b/contrib/src/modem/db/get-command.cpp @@ -15,8 +15,7 @@ bool GetCommand::execute(const String& command, String path = in->readLine(); String value = fbase().getString(path); - - if (fbase().error().length() == 0) { + if (fbase().error().length() != 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/push-command.cpp b/contrib/src/modem/db/push-command.cpp index 052649e7..0ed420e5 100644 --- a/contrib/src/modem/db/push-command.cpp +++ b/contrib/src/modem/db/push-command.cpp @@ -19,7 +19,7 @@ bool PushCommand::execute(const String& command, fbase().pushString(path, data); - if (fbase().error().length() == 0) { + if (fbase().error().length() != 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/remove-command.cpp b/contrib/src/modem/db/remove-command.cpp index 43120dc1..3e17ce56 100644 --- a/contrib/src/modem/db/remove-command.cpp +++ b/contrib/src/modem/db/remove-command.cpp @@ -16,7 +16,7 @@ bool RemoveCommand::execute(const String& command, String path = in->readLine(); fbase().remove(path); - if (fbase().error().length() == 0) { + if (fbase().error().length() != 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/set-command.cpp b/contrib/src/modem/db/set-command.cpp index 5874bff1..c91821e1 100644 --- a/contrib/src/modem/db/set-command.cpp +++ b/contrib/src/modem/db/set-command.cpp @@ -19,7 +19,7 @@ bool SetCommand::execute(const String& command, fbase().setString(path, data); - if (fbase().error().length() == 0) { + if (fbase().error().length() != 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/src/modem/db/stream-command.cpp b/contrib/src/modem/db/stream-command.cpp index 92d88dd7..e9dd3959 100644 --- a/contrib/src/modem/db/stream-command.cpp +++ b/contrib/src/modem/db/stream-command.cpp @@ -16,7 +16,7 @@ bool StreamCommand::execute(const String& command, String path = in->readLine().c_str(); fbase().stream(path); - if (fbase().error().length() == 0) { + if (fbase().error().length() != 0) { out->print("-FAIL "); out->println(fbase().error().c_str()); return false; diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 1ca77d51..4bf04a42 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -10,14 +10,14 @@ namespace modem { class MockFirebase : public FirebaseArduino { public: - MOCK_CONST_METHOD0(error, const String &()); - MOCK_CONST_METHOD1(getString, String (const String& path)); - MOCK_CONST_METHOD2(pushString, void(const String& path, const String& data)); - MOCK_CONST_METHOD1(remove, void(const String& path)); - MOCK_CONST_METHOD2(setString, void(const String& path, const String& data)); - MOCK_CONST_METHOD0(available, bool ()); - MOCK_CONST_METHOD0(readEvent, FirebaseObject ()); - MOCK_CONST_METHOD2(begin, void (const String& host, const String& auth)); + MOCK_METHOD0(error, const String &()); + MOCK_METHOD1(getString, String (const String& path)); + MOCK_METHOD2(pushString, String (const String& path, const String& data)); + MOCK_METHOD1(remove, void(const String& path)); + MOCK_METHOD2(setString, void(const String& path, const String& data)); + MOCK_METHOD0(available, bool ()); + MOCK_METHOD0(readEvent, FirebaseObject ()); + MOCK_METHOD2(begin, void (const String& host, const String& auth)); }; } // modem diff --git a/contrib/test/modem/Makefile b/contrib/test/modem/Makefile index 39cbee53..387542eb 100644 --- a/contrib/test/modem/Makefile +++ b/contrib/test/modem/Makefile @@ -55,8 +55,9 @@ CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11 # All tests produced by this Makefile. Remember to add new tests you # created to the list. TESTS = get-command_test set-command_test remove-command_test \ - push-command_test begin-command_test stream-command_test \ + push-command_test begin-command_test \ serial-transceiver_test +# stream-command_test # All Google Test headers. Usually you shouldn't change this # definition. @@ -130,9 +131,15 @@ arduino_mock_all.a : ArduinoMockAll.o # Builds shared objects. -Firebase.o : $(FIREBASE_SRC_ROOT)/FirebaseArduino.cpp +FirebaseArduino.o : $(FIREBASE_SRC_ROOT)/FirebaseArduino.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/FirebaseArduino.cpp +FirebaseObject.o : $(FIREBASE_SRC_ROOT)/FirebaseObject.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/FirebaseObject.cpp + +Firebase.o : $(FIREBASE_SRC_ROOT)/Firebase.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(FIREBASE_SRC_ROOT)/Firebase.cpp + FirebaseHttpClient_dummy.o : $(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(PROJECT_ROOT)/test/dummies/FirebaseHttpClient_dummy.cpp @@ -144,7 +151,7 @@ get-command.o : $(SRC_ROOT)/modem/db/get-command.cpp get-command_test.o : $(TEST_DIR)/get-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/get-command_test.cpp -get-command_test : get-command_test.o Firebase.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a \ +get-command_test : get-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o get-command.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -155,7 +162,7 @@ set-command.o : $(SRC_ROOT)/modem/db/set-command.cpp set-command_test.o : $(TEST_DIR)/set-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/set-command_test.cpp -set-command_test : set-command.o set-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +set-command_test : set-command.o set-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -166,7 +173,7 @@ remove-command.o : $(SRC_ROOT)/modem/db/remove-command.cpp remove-command_test.o : $(TEST_DIR)/remove-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/remove-command_test.cpp -remove-command_test : remove-command.o remove-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +remove-command_test : remove-command.o remove-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -177,7 +184,7 @@ push-command.o : $(SRC_ROOT)/modem/db/push-command.cpp push-command_test.o : $(TEST_DIR)/push-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/push-command_test.cpp -push-command_test : push-command.o push-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +push-command_test : push-command.o push-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ @@ -188,20 +195,20 @@ begin-command.o : $(SRC_ROOT)/modem/db/begin-command.cpp begin-command_test.o : $(TEST_DIR)/begin-command_test.cpp $(GMOCK_HEADERS) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/begin-command_test.cpp -begin-command_test : begin-command.o begin-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +begin-command_test : begin-command.o begin-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ -stream-command.o : $(SRC_ROOT)/modem/db/stream-command.cpp - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/db/stream-command.cpp - -stream-command_test.o : $(TEST_DIR)/stream-command_test.cpp $(GMOCK_HEADERS) - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/stream-command_test.cpp - -stream-command_test : stream-command.o stream-command_test.o Firebase.o FirebaseHttpClient_dummy.o gmock_main.a \ +#stream-command.o : $(SRC_ROOT)/modem/db/stream-command.cpp +# $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/db/stream-command.cpp +# +#stream-command_test.o : $(TEST_DIR)/stream-command_test.cpp $(GMOCK_HEADERS) +# $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/stream-command_test.cpp +# +#stream-command_test : stream-command.o stream-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ +# $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ SerialTransceiver.o : $(SRC_ROOT)/modem/SerialTransceiver.cpp diff --git a/contrib/test/modem/begin-command_test.cpp b/contrib/test/modem/begin-command_test.cpp index d8f5a86d..c5700d4f 100644 --- a/contrib/test/modem/begin-command_test.cpp +++ b/contrib/test/modem/begin-command_test.cpp @@ -52,8 +52,7 @@ TEST_F(BeginCommandTest, hostOnly) { BeginCommand command; ASSERT_TRUE(command.execute("BEGIN_DB", &in_, &out_)); - std::unique_ptr firebase(command.firebase()); - EXPECT_EQ("", firebase->auth()); + std::unique_ptr firebase(command.firebase()); } TEST_F(BeginCommandTest, hostAndAuth) { @@ -66,8 +65,7 @@ TEST_F(BeginCommandTest, hostAndAuth) { BeginCommand command; ASSERT_TRUE(command.execute("BEGIN_DB", &in_, &out_)); - std::unique_ptr firebase(command.firebase()); - EXPECT_EQ(auth, firebase->auth()); + std::unique_ptr firebase(command.firebase()); } TEST_F(BeginCommandTest, neitherHostNorAuth) { @@ -77,7 +75,7 @@ TEST_F(BeginCommandTest, neitherHostNorAuth) { BeginCommand command; ASSERT_FALSE(command.execute("BEGIN_DB", &in_, &out_)); - std::unique_ptr firebase(command.firebase()); + std::unique_ptr firebase(command.firebase()); EXPECT_FALSE(firebase); } } // modem diff --git a/contrib/test/modem/get-command_test.cpp b/contrib/test/modem/get-command_test.cpp index ccaf3e98..4d378ca5 100644 --- a/contrib/test/modem/get-command_test.cpp +++ b/contrib/test/modem/get-command_test.cpp @@ -20,7 +20,7 @@ class GetCommandTest : public ::testing::Test { void FeedCommand(const String& path) { const String command_fragment(String(" ") + path); - EXPECT_CALL(in_, readLine()) + EXPECT_CALL(in_, readLine()) .WillOnce(Return(command_fragment)); } @@ -36,9 +36,13 @@ class GetCommandTest : public ::testing::Test { TEST_F(GetCommandTest, gets) { const String path("/test/path"); + const String command_fragment(" /test/path"); + const String no_error = ""; FeedCommand(path); const String value("Test value"); + EXPECT_CALL(fbase_, getString(command_fragment)).WillOnce(Return("Test value")); + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); EXPECT_CALL(out_, print(String("+"))) .WillOnce(Return(1)); @@ -51,13 +55,18 @@ TEST_F(GetCommandTest, gets) { TEST_F(GetCommandTest, handlesError) { FirebaseError error(-200, "Test Error."); + const String command_fragment(" /test/path"); const String path("/test/path"); + const String error_value = "Test Error."; FeedCommand(path); + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error_value)); + EXPECT_CALL(fbase_, getString(command_fragment)).WillOnce(Return("")); + EXPECT_CALL(out_, print(String("-FAIL "))) .WillOnce(Return(1)); - EXPECT_CALL(out_, println(String(error.message().c_str()))) + EXPECT_CALL(out_, println(error_value)) .WillOnce(Return(1)); ASSERT_FALSE(RunCommand(error)); diff --git a/contrib/test/modem/stream-command_test.cpp b/contrib/test/modem/stream-command_test.cpp index 9bc27111..52dccbb2 100644 --- a/contrib/test/modem/stream-command_test.cpp +++ b/contrib/test/modem/stream-command_test.cpp @@ -17,16 +17,10 @@ using ::testing::_; class StreamCommandTest : public ::testing::Test { protected: void SetUp() override { - stream_.reset(new MockFirebaseStream()); + stream_.reset(new FirebaseStream()); } bool RunCommand(const FirebaseError& error) { - EXPECT_CALL(*stream_, error()) - .WillRepeatedly(ReturnRef(error)); - - EXPECT_CALL(fbase_, streamPtr(_)) - .WillOnce(Return(ByMove(std::move(stream_)))); - StreamCommand cmd(&fbase_); return cmd.execute("BEGIN_STREAM", &in_, &out_); } @@ -34,7 +28,7 @@ class StreamCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr stream_; + std::unique_ptr stream_; }; TEST_F(StreamCommandTest, streams) { @@ -48,10 +42,11 @@ TEST_F(StreamCommandTest, streams) { const String data = "Test Value"; const String value(String("{\"path\" : \"/test/path\", \"data\" : \"") + data + "\"}"); - EXPECT_CALL(*stream_, available()) - .WillOnce(Return(true)) - .WillRepeatedly(Return(false)); + EXPECT_CALL(fbase_, available()) + .WillOnce(Return(true)) + .WillRepeatedly(Return(false)); + EXPECT_CALL(fbase_, startStreaming()); EXPECT_CALL(*stream_, read(_)) .WillOnce(Invoke([&value](std::string& json) { json = value.c_str(); diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 57244afa..4ab93f0e 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -58,12 +58,14 @@ String FirebaseArduino::pushString(const String& path, const String& value) { } String FirebaseArduino::push(const String& path, const JsonVariant& value) { - String buf; - value.printTo(buf); + int size = value.measureLength()+1; + char * buf = new char[size]; + value.printTo(buf, size); initRequest(); - int status = req_.get()->sendRequest(host_, auth_, "POST", path.c_str(), buf.c_str()); + int status = req_.get()->sendRequest(host_, auth_, "POST", path.c_str(), buf); error_ = req_.get()->error(); const char* name = req_.get()->json()["name"].as(); + delete buf; return name; } @@ -85,11 +87,13 @@ void FirebaseArduino::setString(const String& path, const String& value) { } void FirebaseArduino::set(const String& path, const JsonVariant& value) { - String buf; - value.printTo(buf); + int size = value.measureLength()+1; + char* buf= new char[size]; + value.printTo(buf, size); initRequest(); - req_.get()->sendRequest(host_, auth_, "PUT", path.c_str(), buf.c_str()); + req_.get()->sendRequest(host_, auth_, "PUT", path.c_str(), buf); error_ = req_.get()->error(); + delete buf; } void FirebaseArduino::getRequest(const String& path) { @@ -163,14 +167,14 @@ FirebaseObject FirebaseArduino::readEvent() { return FirebaseObject(""); } auto client = stream_http_.get()->getStreamPtr(); - if (client == nullptr) { + if (client == nullptr) { return FirebaseObject(""); - } + } String type = client->readStringUntil('\n').substring(7);; String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().asObject()["type"] = type; + obj.getJsonVariant().asObject()["type"] = type.c_str(); return obj; } diff --git a/src/FirebaseArduino.h b/src/FirebaseArduino.h index 6b9ae9f7..292d4c37 100644 --- a/src/FirebaseArduino.h +++ b/src/FirebaseArduino.h @@ -37,7 +37,7 @@ class FirebaseArduino { * \param host Your firebase db host, usually X.firebaseio.com. * \param auth Optional credentials for the db, a secret or token. */ - void begin(const String& host, const String& auth = ""); + virtual void begin(const String& host, const String& auth = ""); /** * Appends the integer value to the node at path. @@ -77,7 +77,7 @@ class FirebaseArduino { * \param value String value that you wish to append to the node. * \return The unique key of the new child node. */ - String pushString(const String& path, const String& value); + virtual String pushString(const String& path, const String& value); /** * Appends the JSON data to the node at path. @@ -123,7 +123,7 @@ class FirebaseArduino { * \param path The path inside of your db to the node you wish to update. * \param value String value that you wish to write. */ - void setString(const String& path, const String& value); + virtual void setString(const String& path, const String& value); /** * Writes the JSON data to the node located at path. @@ -157,7 +157,7 @@ class FirebaseArduino { * \param path The path to the node you wish to retrieve. * \return The string value located at that path. Will only be populated if success() is true. */ - String getString(const String& path); + virtual String getString(const String& path); /** * Gets the boolean value located at path. @@ -181,7 +181,7 @@ class FirebaseArduino { * \param path The path to the node you wish to remove, * including all of its children. */ - void remove(const String& path); + virtual void remove(const String& path); /** * Starts streaming any changes made to the node located at path, including @@ -198,7 +198,7 @@ class FirebaseArduino { * stream() has been called. * \return If a new event is ready. */ - bool available(); + virtual bool available(); /** * Reads the next event in a stream. This is only meaningful once stream() has @@ -206,7 +206,7 @@ class FirebaseArduino { * \return FirebaseObject will have ["type"] that describes the event type, ["path"] * that describes the effected path and ["data"] that was updated. */ - FirebaseObject readEvent(); + virtual FirebaseObject readEvent(); /** * \return Whether the last command was successful. @@ -221,7 +221,7 @@ class FirebaseArduino { /** * \return Error message from last command if failed() is true. */ - const String& error(); + virtual const String& error(); private: std::string host_; std::string auth_; From 4c5a98cc116081c135cda0d0b153d11f92d0fc06 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sun, 6 May 2018 20:32:51 -0400 Subject: [PATCH 39/68] remaining unit tests for push/set/remove for modem --- contrib/test/modem/get-command_test.cpp | 6 ++++-- contrib/test/modem/push-command_test.cpp | 16 ++++++++++------ contrib/test/modem/remove-command_test.cpp | 16 ++++++++++------ contrib/test/modem/set-command_test.cpp | 14 ++++++++------ 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/contrib/test/modem/get-command_test.cpp b/contrib/test/modem/get-command_test.cpp index 4d378ca5..813fad2f 100644 --- a/contrib/test/modem/get-command_test.cpp +++ b/contrib/test/modem/get-command_test.cpp @@ -37,11 +37,12 @@ class GetCommandTest : public ::testing::Test { TEST_F(GetCommandTest, gets) { const String path("/test/path"); const String command_fragment(" /test/path"); - const String no_error = ""; FeedCommand(path); const String value("Test value"); EXPECT_CALL(fbase_, getString(command_fragment)).WillOnce(Return("Test value")); + + const String no_error = ""; EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); EXPECT_CALL(out_, print(String("+"))) @@ -57,10 +58,11 @@ TEST_F(GetCommandTest, handlesError) { FirebaseError error(-200, "Test Error."); const String command_fragment(" /test/path"); const String path("/test/path"); - const String error_value = "Test Error."; FeedCommand(path); + const String error_value = "Test Error."; EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error_value)); + EXPECT_CALL(fbase_, getString(command_fragment)).WillOnce(Return("")); EXPECT_CALL(out_, print(String("-FAIL "))) diff --git a/contrib/test/modem/push-command_test.cpp b/contrib/test/modem/push-command_test.cpp index 8edc18ef..2f2ff82e 100644 --- a/contrib/test/modem/push-command_test.cpp +++ b/contrib/test/modem/push-command_test.cpp @@ -39,7 +39,7 @@ class PushCommandTest : public ::testing::Test { .WillOnce(Return(error_message.length())); } - bool RunExpectingData(const String& data, const FirebaseError& error) { + bool RunCommand() { PushCommand pushCmd(&fbase_); return pushCmd.execute("PUSH", &in_, &out_); } @@ -54,22 +54,26 @@ TEST_F(PushCommandTest, sendsData) { const String data("This is a test payload."); FeedCommand(path, data); + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); + ExpectOutput("+OK"); - ASSERT_TRUE(RunExpectingData(data, FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(PushCommandTest, HandlesError) { const String path("/test/path"); const String data("This is a test payload."); - FirebaseError error(-200, "Test error."); FeedCommand(path, data); - ExpectErrorOutput(error.message()); + const String error = "Test Error."; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); + + ExpectErrorOutput(error); - ASSERT_FALSE(RunExpectingData(data, error)); + ASSERT_FALSE(RunCommand()); } } // modem } // firebase - diff --git a/contrib/test/modem/remove-command_test.cpp b/contrib/test/modem/remove-command_test.cpp index 41efe347..e60f0524 100644 --- a/contrib/test/modem/remove-command_test.cpp +++ b/contrib/test/modem/remove-command_test.cpp @@ -24,8 +24,7 @@ class RemoveCommandTest : public ::testing::Test { .WillOnce(Return(command_fragment)); } - bool RunCommand(const FirebaseError& error) { - + bool RunCommand() { RemoveCommand command(&fbase_); return command.execute("REMOVE", &in_, &out_); } @@ -39,23 +38,28 @@ TEST_F(RemoveCommandTest, success) { const String path("/test/path"); FeedCommand(path); + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); + EXPECT_CALL(out_, println(String("+OK"))) .WillOnce(Return(3)); - ASSERT_TRUE(RunCommand(FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(RemoveCommandTest, handlesError) { - FirebaseError error(-200, "Test Error."); const String path("/test/path"); FeedCommand(path); EXPECT_CALL(out_, print(String("-FAIL "))) .WillOnce(Return(1)); - EXPECT_CALL(out_, println(String(error.message().c_str()))) + const String error = "Test Error."; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); + + EXPECT_CALL(out_, println(String(error.c_str()))) .WillOnce(Return(1)); - ASSERT_FALSE(RunCommand(error)); + ASSERT_FALSE(RunCommand()); } } // modem diff --git a/contrib/test/modem/set-command_test.cpp b/contrib/test/modem/set-command_test.cpp index e573fb65..99004581 100644 --- a/contrib/test/modem/set-command_test.cpp +++ b/contrib/test/modem/set-command_test.cpp @@ -39,8 +39,7 @@ class SetCommandTest : public ::testing::Test { .WillOnce(Return(error_message.length())); } - bool RunExpectingData(const String& data, const FirebaseError& error) { - + bool RunCommand() { SetCommand setCmd(&fbase_); return setCmd.execute("SET", &in_, &out_); } @@ -53,22 +52,25 @@ class SetCommandTest : public ::testing::Test { TEST_F(SetCommandTest, sendsData) { const String path("/test/path"); const String data("This is a test payload."); + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillOnce(ReturnRef(no_error)); FeedCommand(path, data); ExpectOutput("+OK"); - ASSERT_TRUE(RunExpectingData(data, FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(SetCommandTest, HandlesError) { const String path("/test/path"); const String data("This is a test payload."); - FirebaseError error(-200, "Test error."); + const String error = "TestError"; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); FeedCommand(path, data); - ExpectErrorOutput(error.message()); + ExpectErrorOutput(error); - ASSERT_FALSE(RunExpectingData(data, error)); + ASSERT_FALSE(RunCommand()); } } // modem } // firebase From a7bf1601d27ade1315951cbc292a57bb5813b4af Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Sun, 6 May 2018 22:09:54 -0400 Subject: [PATCH 40/68] Enabling and fix stream unit test for modem code --- contrib/src/modem/db/stream-command.cpp | 3 +- contrib/test/mock-firebase.h | 1 + contrib/test/modem/Makefile | 19 ++++++------ contrib/test/modem/stream-command_test.cpp | 36 ++++++++++++---------- src/FirebaseArduino.h | 2 +- 5 files changed, 31 insertions(+), 30 deletions(-) diff --git a/contrib/src/modem/db/stream-command.cpp b/contrib/src/modem/db/stream-command.cpp index e9dd3959..69e5bd33 100644 --- a/contrib/src/modem/db/stream-command.cpp +++ b/contrib/src/modem/db/stream-command.cpp @@ -21,14 +21,13 @@ bool StreamCommand::execute(const String& command, out->println(fbase().error().c_str()); return false; } - bool running = true; DynamicJsonBuffer buffer; while(running) { if (fbase().available()) { FirebaseObject event = fbase().readEvent(); out->print("+"); - out->print(event.getString("event").c_str()); + out->print(event.getString("type").c_str()); out->print(" "); String data = event.getString("data"); out->println(event.getString("path")); diff --git a/contrib/test/mock-firebase.h b/contrib/test/mock-firebase.h index 4bf04a42..916f4d00 100644 --- a/contrib/test/mock-firebase.h +++ b/contrib/test/mock-firebase.h @@ -18,6 +18,7 @@ class MockFirebase : public FirebaseArduino { MOCK_METHOD0(available, bool ()); MOCK_METHOD0(readEvent, FirebaseObject ()); MOCK_METHOD2(begin, void (const String& host, const String& auth)); + MOCK_METHOD1(stream, void (const String& path)); }; } // modem diff --git a/contrib/test/modem/Makefile b/contrib/test/modem/Makefile index 387542eb..bda22d32 100644 --- a/contrib/test/modem/Makefile +++ b/contrib/test/modem/Makefile @@ -56,8 +56,7 @@ CXXFLAGS += -g -Wall -Wextra -pthread -std=c++11 # created to the list. TESTS = get-command_test set-command_test remove-command_test \ push-command_test begin-command_test \ - serial-transceiver_test -# stream-command_test + serial-transceiver_test stream-command_test # All Google Test headers. Usually you shouldn't change this # definition. @@ -200,15 +199,15 @@ begin-command_test : begin-command.o begin-command_test.o FirebaseArduino.o Fire $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ -#stream-command.o : $(SRC_ROOT)/modem/db/stream-command.cpp -# $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/db/stream-command.cpp -# -#stream-command_test.o : $(TEST_DIR)/stream-command_test.cpp $(GMOCK_HEADERS) -# $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/stream-command_test.cpp -# -#stream-command_test : stream-command.o stream-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ +stream-command.o : $(SRC_ROOT)/modem/db/stream-command.cpp + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(SRC_ROOT)/modem/db/stream-command.cpp + +stream-command_test.o : $(TEST_DIR)/stream-command_test.cpp $(GMOCK_HEADERS) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(TEST_DIR)/stream-command_test.cpp + +stream-command_test : stream-command.o stream-command_test.o FirebaseArduino.o Firebase.o FirebaseObject.o FirebaseHttpClient_dummy.o gmock_main.a \ arduino_mock_all.a -# $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ + $(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ SerialTransceiver.o : $(SRC_ROOT)/modem/SerialTransceiver.cpp diff --git a/contrib/test/modem/stream-command_test.cpp b/contrib/test/modem/stream-command_test.cpp index 52dccbb2..783a24f7 100644 --- a/contrib/test/modem/stream-command_test.cpp +++ b/contrib/test/modem/stream-command_test.cpp @@ -17,10 +17,9 @@ using ::testing::_; class StreamCommandTest : public ::testing::Test { protected: void SetUp() override { - stream_.reset(new FirebaseStream()); } - bool RunCommand(const FirebaseError& error) { + bool RunCommand() { StreamCommand cmd(&fbase_); return cmd.execute("BEGIN_STREAM", &in_, &out_); } @@ -28,11 +27,20 @@ class StreamCommandTest : public ::testing::Test { MockInputStream in_; MockOutputStream out_; MockFirebase fbase_; - std::unique_ptr stream_; }; TEST_F(StreamCommandTest, streams) { const String path("/test/path"); + + const String no_error = ""; + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(no_error)); + + const String data = "TestValue"; + const String value(String("{\"path\":\"/test/path\",\"data\":\"") + data + "\",\"type\":\"PUT\"}"); + + const FirebaseObject fo = FirebaseObject(value.c_str()); + EXPECT_CALL(fbase_, readEvent()).WillRepeatedly(Return(fo)); + EXPECT_CALL(in_, available()) .WillRepeatedly(Return(true)); @@ -40,18 +48,10 @@ TEST_F(StreamCommandTest, streams) { .WillOnce(Return(path)) .WillOnce(Return("END_STREAM")); - const String data = "Test Value"; - const String value(String("{\"path\" : \"/test/path\", \"data\" : \"") + data + "\"}"); - EXPECT_CALL(fbase_, available()) + EXPECT_CALL(fbase_, available()) .WillOnce(Return(true)) .WillRepeatedly(Return(false)); - - EXPECT_CALL(fbase_, startStreaming()); - EXPECT_CALL(*stream_, read(_)) - .WillOnce(Invoke([&value](std::string& json) { - json = value.c_str(); - return FirebaseStream::PUT; - })); + EXPECT_CALL(fbase_, stream(path)); EXPECT_CALL(out_, print(String("+"))) .WillOnce(Return(1)); @@ -70,21 +70,23 @@ TEST_F(StreamCommandTest, streams) { EXPECT_CALL(out_, println(String("+OK"))) .WillOnce(Return(1)); - ASSERT_TRUE(RunCommand(FirebaseError())); + ASSERT_TRUE(RunCommand()); } TEST_F(StreamCommandTest, handlesError) { - FirebaseError error(-200, "Test Error."); + const String error("Test Error."); const String path("/test/path"); EXPECT_CALL(in_, readLine()) .WillOnce(Return(path)); + EXPECT_CALL(fbase_, error()).WillRepeatedly(ReturnRef(error)); + EXPECT_CALL(out_, print(String("-FAIL "))) .WillOnce(Return(1)); - EXPECT_CALL(out_, println(String(error.message().c_str()))) + EXPECT_CALL(out_, println(String(error.c_str()))) .WillOnce(Return(1)); - ASSERT_FALSE(RunCommand(error)); + ASSERT_FALSE(RunCommand()); } } // modem diff --git a/src/FirebaseArduino.h b/src/FirebaseArduino.h index 292d4c37..e2f264e1 100644 --- a/src/FirebaseArduino.h +++ b/src/FirebaseArduino.h @@ -191,7 +191,7 @@ class FirebaseArduino { * monitoring available() and calling readEvent() to get new events. * \param path The path inside of your db to the node you wish to monitor. */ - void stream(const String& path); + virtual void stream(const String& path); /** * Checks if there are new events available. This is only meaningful once From 30ca7786e79bec9fb2969a811f50ee4411d2abbc Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 20 Jun 2018 21:12:16 -0400 Subject: [PATCH 41/68] remove duplicates (#2) --- examples/FirebaseRoom_ESP8266/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/FirebaseRoom_ESP8266/README.md b/examples/FirebaseRoom_ESP8266/README.md index 7f1620db..37a38512 100644 --- a/examples/FirebaseRoom_ESP8266/README.md +++ b/examples/FirebaseRoom_ESP8266/README.md @@ -58,7 +58,7 @@ sensor data to Firebase, and trigger actuators from Firebase. - Add Grove modules to modules interactions. - Connect other Grove modules to the room and submit new [PRs](https://github.com/googlesamples/firebase-arduino/pulls) - Reduce the number of Firebase API calls using `FirebaseObject` or `FirebaseStream`. -- Watch or star the [GitHub repo repo](https://github.com/googlesamples/firebase-arduino) +- Watch or star the [GitHub repo](https://github.com/googlesamples/firebase-arduino) - Give [feedback](https://gitter.im/googlesamples/firebase-arduino) - Report [bugs](https://github.com/googlesamples/firebase-arduino/issues/new) - [Fork](https://github.com/googlesamples/firebase-arduino#fork-destination-box) and [contribute](https://github.com/googlesamples/firebase-arduino/blob/master/CONTRIBUTING.md) From 2347c48eddae069df4b43612c94dfdc17d736cbe Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 20 Jun 2018 21:18:31 -0400 Subject: [PATCH 42/68] Update README.md --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc9420f8..b1d537ce 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,10 @@ The Arduino library is [under heavy development](https://github.com/googlesample - [FirebaseArduino API Reference](http://firebase-arduino.readthedocs.io/) ## Dependencies -- FirebaseArduino now depends on [ArduinoJson library](https://github.com/bblanchon/ArduinoJson) instead of containing it's own version of it. Please either use Library Manager or download specific version of the library from github. +- FirebaseArduino now depends on [ArduinoJson library](https://github.com/bblanchon/ArduinoJson) instead of containing it's own version of it. Please either use Library Manager or download specific version of the library from github. We recommend that ArduinoJson is at least version [5.13.1](https://github.com/bblanchon/ArduinoJson/tree/v5.13.1) + +- ESP8266 Core SDK. We recommend using officially tagged releases and it should be at least [2.4.1] +(https://github.com/esp8266/Arduino/tree/2.4.1) ## Disclaimer From 2f76fae7baf9b088fd931637ef604282c341ea43 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 20 Jun 2018 21:19:13 -0400 Subject: [PATCH 43/68] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index b1d537ce..827cf7ec 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,7 @@ The Arduino library is [under heavy development](https://github.com/googlesample ## Dependencies - FirebaseArduino now depends on [ArduinoJson library](https://github.com/bblanchon/ArduinoJson) instead of containing it's own version of it. Please either use Library Manager or download specific version of the library from github. We recommend that ArduinoJson is at least version [5.13.1](https://github.com/bblanchon/ArduinoJson/tree/v5.13.1) -- ESP8266 Core SDK. We recommend using officially tagged releases and it should be at least [2.4.1] -(https://github.com/esp8266/Arduino/tree/2.4.1) +- ESP8266 Core SDK. We recommend using officially tagged releases and it should be at least [2.4.1](https://github.com/esp8266/Arduino/tree/2.4.1) ## Disclaimer From 88170c8110c02ff4d12128ba09ec6351c19b93d1 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 20 Jun 2018 21:49:33 -0400 Subject: [PATCH 44/68] Manually merge: "Report error when streaming loses connection. #179" --- .../test/dummies/FirebaseHttpClient_dummy.cpp | 4 + src/FirebaseArduino.cpp | 5 + src/FirebaseError.h | 8 ++ src/FirebaseHttpClient.h | 2 + src/FirebaseHttpClient.h~ | 45 +++++++++ src/FirebaseHttpClient_Esp8266.cpp | 4 + src/FirebaseHttpClient_Esp8266.cpp~ | 97 +++++++++++++++++++ 7 files changed, 165 insertions(+) create mode 100644 src/FirebaseHttpClient.h~ create mode 100644 src/FirebaseHttpClient_Esp8266.cpp~ diff --git a/contrib/test/dummies/FirebaseHttpClient_dummy.cpp b/contrib/test/dummies/FirebaseHttpClient_dummy.cpp index 571fa842..2a89ff90 100644 --- a/contrib/test/dummies/FirebaseHttpClient_dummy.cpp +++ b/contrib/test/dummies/FirebaseHttpClient_dummy.cpp @@ -23,6 +23,10 @@ class FirebaseHttpClientDummy : public FirebaseHttpClient { void addHeader(const std::string& UNUSED_ARG(name), const std::string& UNUSED_ARG(value)) override { } + bool connected() override { + return true; + } + void collectHeaders(const char* UNUSED_ARG(header_keys[]), const int UNUSED_ARG(count)) override { } diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 4ab93f0e..0e7ae87d 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -156,6 +156,11 @@ void FirebaseArduino::stream(const String& path) { bool FirebaseArduino::available() { if (stream_http_.get() == nullptr) { + error_ = FirebaseError(FIREBASE_ERROR_CODES::STREAM_NOT_INITIALIZED, "HTTP stream is not initialized"); + return 0; + } + if (!stream_http_.get()->connected()) { + error_ = FirebaseError(FIREBASE_ERROR_CODES::HTTP_CONNECTION_LOST, "Connection Lost"); return 0; } auto client = stream_http_.get()->getStreamPtr(); diff --git a/src/FirebaseError.h b/src/FirebaseError.h index 2a088aa9..422f9193 100644 --- a/src/FirebaseError.h +++ b/src/FirebaseError.h @@ -1,6 +1,14 @@ #ifndef firebase_error_h #define firebase_error_h + +// These error codes are used in addition to regular HTTP error codes. +// Same error space is shared between HTTP errors and these values. +enum FIREBASE_ERROR_CODES { + HTTP_CONNECTION_LOST = -5, + STREAM_NOT_INITIALIZED = -6 +}; + class FirebaseError { public: // Make it explicit that the empty constructor mean no error. diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 055699c7..300c3d28 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -33,6 +33,8 @@ class FirebaseHttpClient { virtual std::string errorToString(int error_code) = 0; + virtual bool connected() = 0; + protected: static const uint16_t kFirebasePort = 443; }; diff --git a/src/FirebaseHttpClient.h~ b/src/FirebaseHttpClient.h~ new file mode 100644 index 00000000..1b8aed1f --- /dev/null +++ b/src/FirebaseHttpClient.h~ @@ -0,0 +1,45 @@ +#ifndef FIREBASE_HTTP_CLIENT_H +#define FIREBASE_HTTP_CLIENT_H + +#include + +#include "Arduino.h" +#include "Stream.h" + +struct HttpStatus { + static const int TEMPORARY_REDIRECT = 307; +}; + +class FirebaseHttpClient { + public: + static FirebaseHttpClient* create(); + + virtual void setReuseConnection(bool reuse) = 0; + virtual void begin(const std::string& url) = 0; + virtual void begin(const std::string& host, const std::string& path) = 0; + + virtual void end() = 0; + + virtual void addHeader(const std::string& name, const std::string& value) = 0; + virtual void collectHeaders(const char* header_keys[], + const int header_key_count) = 0; + virtual std::string header(const std::string& name) = 0; + + virtual int sendRequest(const std::string& method, const std::string& data) = 0; + + virtual std::string getString() = 0; + + virtual Stream* getStreamPtr() = 0; + + virtual std::string errorToString(int error_code) = 0; + + virtual bool connected() = 0; + + protected: + static const uint16_t kFirebasePort = 443; +}; + +static const char kFirebaseFingerprint[] = + "B8 4F 40 70 0C 63 90 E0 07 E8 7D BD B4 11 D0 4A EA 9C 90 F6"; + +#endif // FIREBASE_HTTP_CLIENT_H diff --git a/src/FirebaseHttpClient_Esp8266.cpp b/src/FirebaseHttpClient_Esp8266.cpp index 92dbe92d..c78590dc 100644 --- a/src/FirebaseHttpClient_Esp8266.cpp +++ b/src/FirebaseHttpClient_Esp8266.cpp @@ -83,6 +83,10 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { return HTTPClient::errorToString(error_code).c_str(); } + bool connected() override { + return http_.connected(); + } + private: ForceReuseHTTPClient http_; }; diff --git a/src/FirebaseHttpClient_Esp8266.cpp~ b/src/FirebaseHttpClient_Esp8266.cpp~ new file mode 100644 index 00000000..b2e2362a --- /dev/null +++ b/src/FirebaseHttpClient_Esp8266.cpp~ @@ -0,0 +1,97 @@ + +#include "FirebaseHttpClient.h" + +#include + +// The ordering of these includes matters greatly. +#include +#include +#include + +// Detect whether stable version of HTTP library is installed instead of +// master branch and patch in missing status and methods. +#ifndef HTTP_CODE_TEMPORARY_REDIRECT +#define HTTP_CODE_TEMPORARY_REDIRECT 307 +#define USE_ESP_ARDUINO_CORE_2_0_0 +#endif + +// Firebase now returns `Connection: close` after REST streaming redirection. +// +// Override the built-in ESP8266HTTPClient to *not* close the +// connection if forceReuse it set to `true`. +class ForceReuseHTTPClient : public HTTPClient { +public: + void end() { + if (_forceReuse) { + _canReuse = true; + } + HTTPClient::end(); + } + void forceReuse(bool forceReuse) { + _forceReuse = forceReuse; + } +protected: + bool _forceReuse = false; +}; + +class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { + public: + FirebaseHttpClientEsp8266() {} + + void setReuseConnection(bool reuse) override { + http_.setReuse(reuse); + http_.forceReuse(reuse); + } + + void begin(const std::string& url) override { + http_.begin(url.c_str(), kFirebaseFingerprint); + } + + void begin(const std::string& host, const std::string& path) override { + http_.begin(host.c_str(), kFirebasePort, path.c_str(), kFirebaseFingerprint); + } + + void end() override { + http_.end(); + } + + void addHeader(const std::string& name, const std::string& value) override { + http_.addHeader(name.c_str(), value.c_str()); + } + + void collectHeaders(const char* header_keys[], const int count) override { + http_.collectHeaders(header_keys, count); + } + + std::string header(const std::string& name) override { + return http_.header(name.c_str()).c_str(); + } + + int sendRequest(const std::string& method, const std::string& data) override { + return http_.sendRequest(method.c_str(), (uint8_t*)data.c_str(), data.length()); + } + + std::string getString() override { + return http_.getString().c_str(); + } + + Stream* getStreamPtr() override { + return http_.getStreamPtr(); + } + + std::string errorToString(int error_code) override { + return HTTPClient::errorToString(error_code).c_str(); + } + + bool connected() override { + return http_.connected(); + } + + private: + ForceReuseHTTPClient http_; +}; + +FirebaseHttpClient* FirebaseHttpClient::create() { + return new FirebaseHttpClientEsp8266(); +} + From 9dcf20586b00d44332bbbd59ff8cbf20826fb939 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Wed, 20 Jun 2018 21:50:22 -0400 Subject: [PATCH 45/68] Removed temp files --- src/FirebaseHttpClient.h~ | 45 ------------- src/FirebaseHttpClient_Esp8266.cpp~ | 97 ----------------------------- 2 files changed, 142 deletions(-) delete mode 100644 src/FirebaseHttpClient.h~ delete mode 100644 src/FirebaseHttpClient_Esp8266.cpp~ diff --git a/src/FirebaseHttpClient.h~ b/src/FirebaseHttpClient.h~ deleted file mode 100644 index 1b8aed1f..00000000 --- a/src/FirebaseHttpClient.h~ +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef FIREBASE_HTTP_CLIENT_H -#define FIREBASE_HTTP_CLIENT_H - -#include - -#include "Arduino.h" -#include "Stream.h" - -struct HttpStatus { - static const int TEMPORARY_REDIRECT = 307; -}; - -class FirebaseHttpClient { - public: - static FirebaseHttpClient* create(); - - virtual void setReuseConnection(bool reuse) = 0; - virtual void begin(const std::string& url) = 0; - virtual void begin(const std::string& host, const std::string& path) = 0; - - virtual void end() = 0; - - virtual void addHeader(const std::string& name, const std::string& value) = 0; - virtual void collectHeaders(const char* header_keys[], - const int header_key_count) = 0; - virtual std::string header(const std::string& name) = 0; - - virtual int sendRequest(const std::string& method, const std::string& data) = 0; - - virtual std::string getString() = 0; - - virtual Stream* getStreamPtr() = 0; - - virtual std::string errorToString(int error_code) = 0; - - virtual bool connected() = 0; - - protected: - static const uint16_t kFirebasePort = 443; -}; - -static const char kFirebaseFingerprint[] = - "B8 4F 40 70 0C 63 90 E0 07 E8 7D BD B4 11 D0 4A EA 9C 90 F6"; - -#endif // FIREBASE_HTTP_CLIENT_H diff --git a/src/FirebaseHttpClient_Esp8266.cpp~ b/src/FirebaseHttpClient_Esp8266.cpp~ deleted file mode 100644 index b2e2362a..00000000 --- a/src/FirebaseHttpClient_Esp8266.cpp~ +++ /dev/null @@ -1,97 +0,0 @@ - -#include "FirebaseHttpClient.h" - -#include - -// The ordering of these includes matters greatly. -#include -#include -#include - -// Detect whether stable version of HTTP library is installed instead of -// master branch and patch in missing status and methods. -#ifndef HTTP_CODE_TEMPORARY_REDIRECT -#define HTTP_CODE_TEMPORARY_REDIRECT 307 -#define USE_ESP_ARDUINO_CORE_2_0_0 -#endif - -// Firebase now returns `Connection: close` after REST streaming redirection. -// -// Override the built-in ESP8266HTTPClient to *not* close the -// connection if forceReuse it set to `true`. -class ForceReuseHTTPClient : public HTTPClient { -public: - void end() { - if (_forceReuse) { - _canReuse = true; - } - HTTPClient::end(); - } - void forceReuse(bool forceReuse) { - _forceReuse = forceReuse; - } -protected: - bool _forceReuse = false; -}; - -class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { - public: - FirebaseHttpClientEsp8266() {} - - void setReuseConnection(bool reuse) override { - http_.setReuse(reuse); - http_.forceReuse(reuse); - } - - void begin(const std::string& url) override { - http_.begin(url.c_str(), kFirebaseFingerprint); - } - - void begin(const std::string& host, const std::string& path) override { - http_.begin(host.c_str(), kFirebasePort, path.c_str(), kFirebaseFingerprint); - } - - void end() override { - http_.end(); - } - - void addHeader(const std::string& name, const std::string& value) override { - http_.addHeader(name.c_str(), value.c_str()); - } - - void collectHeaders(const char* header_keys[], const int count) override { - http_.collectHeaders(header_keys, count); - } - - std::string header(const std::string& name) override { - return http_.header(name.c_str()).c_str(); - } - - int sendRequest(const std::string& method, const std::string& data) override { - return http_.sendRequest(method.c_str(), (uint8_t*)data.c_str(), data.length()); - } - - std::string getString() override { - return http_.getString().c_str(); - } - - Stream* getStreamPtr() override { - return http_.getStreamPtr(); - } - - std::string errorToString(int error_code) override { - return HTTPClient::errorToString(error_code).c_str(); - } - - bool connected() override { - return http_.connected(); - } - - private: - ForceReuseHTTPClient http_; -}; - -FirebaseHttpClient* FirebaseHttpClient::create() { - return new FirebaseHttpClientEsp8266(); -} - From 1bc2263e7795778f3227702583e760a440c7c1eb Mon Sep 17 00:00:00 2001 From: yehiyam Date: Thu, 2 Aug 2018 22:20:43 +0300 Subject: [PATCH 46/68] Updating firebase fingerprint The fingerprint changed on 2 Aug 2018. This is the new fingerprint --- src/FirebaseHttpClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 300c3d28..01d59f42 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -40,6 +40,6 @@ class FirebaseHttpClient { }; static const char kFirebaseFingerprint[] = - "B8 4F 40 70 0C 63 90 E0 07 E8 7D BD B4 11 D0 4A EA 9C 90 F6"; + "6F D0 9A 52 C0 E9 E4 CD A0 D3 02 A4 B7 A1 92 38 2D CA 2F 26"; #endif // FIREBASE_HTTP_CLIENT_H From e62c2177aadb891d7ef30d320ebcb9a32db6aba6 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 8 Aug 2018 15:11:52 +0200 Subject: [PATCH 47/68] Firebase.readEvent() returns "type" instead "put" while getting data from Firebase --- src/FirebaseArduino.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 0e7ae87d..b82de146 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,7 +179,7 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().asObject()["type"] = type.c_str(); + obj.getJsonVariant().asObject()["type"] = type; return obj; } From b14884ad1e0540bae3f37623cb012bf3fc604769 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 10:10:54 +0200 Subject: [PATCH 48/68] Use proper API --- src/FirebaseArduino.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index b82de146..5d72a446 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,7 +179,7 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().asObject()["type"] = type; + obj.getJsonVariant().asObject().set("type", type); return obj; } From 50a58656f4548b4eef3822f8053f02719df034c9 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 10:40:02 +0200 Subject: [PATCH 49/68] Use correct syntax and api --- src/FirebaseArduino.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 5d72a446..c957e6a0 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,7 +179,7 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().asObject().set("type", type); + obj.getJsonVariant().as().set("type", type); return obj; } From 434df1c47eafb70f427ca37a8162e24a8d58e289 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 10:58:42 +0200 Subject: [PATCH 50/68] Try with explicit objects --- src/FirebaseArduino.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index c957e6a0..3168ed85 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,7 +179,9 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().as().set("type", type); + JsonVariant v = obj.getJsonVariant(); + JsonObject& jsonObj = v.as(); + jsonObj.set("type", type); return obj; } From a2a9896b01953d9f0de1faa0953f493a6481ee01 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 11:11:11 +0200 Subject: [PATCH 51/68] Issue comes from the set during the tests... --- src/FirebaseArduino.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 3168ed85..5d72a446 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,9 +179,7 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - JsonVariant v = obj.getJsonVariant(); - JsonObject& jsonObj = v.as(); - jsonObj.set("type", type); + obj.getJsonVariant().asObject().set("type", type); return obj; } From 5746cb5ef610d1426fa3ac4d4924385dd70bde6f Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 11:14:11 +0200 Subject: [PATCH 52/68] Checking tests with latest ArduinoJson lib version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c9131df..3346864e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.13.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino - ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi From d330ced03cc4c59eeac5bf03a05750db6d0e64cb Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 11:31:06 +0200 Subject: [PATCH 53/68] Maybe... --- src/FirebaseArduino.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 5d72a446..9c917f24 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,7 +179,9 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().asObject().set("type", type); + if (NULL != type) { + obj.getJsonVariant().as().set("type", type); + } return obj; } From e4713f7cc967a188095a3a1b9e8126145a8e32a9 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 11:56:23 +0200 Subject: [PATCH 54/68] Another test --- .travis.yml | 2 +- src/FirebaseArduino.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3346864e..7c9131df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.13.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino - ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 9c917f24..5e7a58c0 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,7 +179,7 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - if (NULL != type) { + if (type.length() > 0) { obj.getJsonVariant().as().set("type", type); } return obj; From 2b475344c765b6c6f27fd6037cf5efcf1985d214 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 12:15:30 +0200 Subject: [PATCH 55/68] Another test... --- src/FirebaseArduino.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 5e7a58c0..b8fd6416 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,9 +179,9 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - if (type.length() > 0) { - obj.getJsonVariant().as().set("type", type); - } + JsonObject& jsonObject = obj.getJsonVariant().as(); + jsonObject.set("type", ""); + jsonObject.set("type", type); return obj; } From f1c940d97ffdeded6c749b539a0c90af34d635ee Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 12:20:46 +0200 Subject: [PATCH 56/68] Give up... --- src/FirebaseArduino.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index b8fd6416..c957e6a0 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,9 +179,7 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - JsonObject& jsonObject = obj.getJsonVariant().as(); - jsonObject.set("type", ""); - jsonObject.set("type", type); + obj.getJsonVariant().as().set("type", type); return obj; } From 728dd9d57ae6e714b36c5b0e015ac0879c7e4a84 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 12:32:13 +0200 Subject: [PATCH 57/68] Test with ESP8266 2.4.1 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c9131df..71d0c968 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.4.1 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino - ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi From 74f63e29064139f2c6d8d26199ff1fb02704795d Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 12:38:43 +0200 Subject: [PATCH 58/68] Revert "Test with ESP8266 2.4.1" This reverts commit 728dd9d57ae6e714b36c5b0e015ac0879c7e4a84. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 71d0c968..7c9131df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.4.1 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino - ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi From db8456913a645b8f8ca37dcf6be9ab141d207ebd Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 14:49:54 +0200 Subject: [PATCH 59/68] Quick final test --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c9131df..96b1f854 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.8.5 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino - ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi From f08825d525c7bc5a0ce2fb764f482081dee017b0 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 14:58:13 +0200 Subject: [PATCH 60/68] Revert "Quick final test" This reverts commit db8456913a645b8f8ca37dcf6be9ab141d207ebd. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 96b1f854..7c9131df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ addons: packages: - g++-4.8 env: -- ARDUINO_VERSION=1.8.5 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino +- ARDUINO_VERSION=1.6.9 ARDUINO_ESP8266_VERSION=2.3.0 LIB_NEOPIXEL_VERSION=v1.0.5 LIB_GFX_VERSION=v1.1.5 LIB_SSD1306_VERSION=1.1.0 LIB_JSON_VERSION=v5.11.2 ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino - ARDUINO_VERSION=nightly ARDUINO_ESP8266_VERSION=master LIB_NEOPIXEL_VERSION=master LIB_GFX_VERSION=master LIB_SSD1306_VERSION=master LIB_JSON_VERSION=master ARDUINO_ROOT=${HOME}/arduino-${ARDUINO_VERSION} ARDUINO_ESP8266_ROOT=${ARDUINO_ROOT}/hardware/esp8266com/esp8266 ARDUINO_HOME=${HOME}/Arduino install: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi From 3af3a1a9b3357cf2ce8d0ed93365ca01d138044d Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 16:07:49 +0200 Subject: [PATCH 61/68] Fixed! --- src/FirebaseArduino.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index c957e6a0..2cc631ef 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -179,7 +179,12 @@ FirebaseObject FirebaseArduino::readEvent() { String event = client->readStringUntil('\n').substring(6); client->readStringUntil('\n'); // consume separator FirebaseObject obj = FirebaseObject(event.c_str()); - obj.getJsonVariant().as().set("type", type); + + // required to have a copy of the string but use a char[] format which is + // the only supported format for JsonObject#set (it does not like the std::string of the test env) + char *cstr = new char[type.length() + 1]; + strcpy(cstr, type.c_str()); + obj.getJsonVariant().as().set("type", cstr); return obj; } From 3195d232e685522565f23edc429db481eb9ce773 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Wed, 15 Aug 2018 18:21:13 +0200 Subject: [PATCH 62/68] Integrated feedback --- src/FirebaseArduino.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FirebaseArduino.cpp b/src/FirebaseArduino.cpp index 2cc631ef..bae29595 100644 --- a/src/FirebaseArduino.cpp +++ b/src/FirebaseArduino.cpp @@ -183,8 +183,9 @@ FirebaseObject FirebaseArduino::readEvent() { // required to have a copy of the string but use a char[] format which is // the only supported format for JsonObject#set (it does not like the std::string of the test env) char *cstr = new char[type.length() + 1]; - strcpy(cstr, type.c_str()); + strncpy(cstr, type.c_str(), type.length() + 1); obj.getJsonVariant().as().set("type", cstr); + delete[] cstr; return obj; } From fb31f8e9e74c165c3d06ddd9dac660575d5425c0 Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Tue, 20 Nov 2018 16:08:04 +0100 Subject: [PATCH 63/68] [FirebaseObject] Error message is never reset #390 (#391) --- contrib/test/FirebaseArduino_test.cpp | 59 +++++++++++++++++++++++++-- src/FirebaseObject.cpp | 4 ++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/contrib/test/FirebaseArduino_test.cpp b/contrib/test/FirebaseArduino_test.cpp index 9f18865e..186acbc6 100644 --- a/contrib/test/FirebaseArduino_test.cpp +++ b/contrib/test/FirebaseArduino_test.cpp @@ -45,15 +45,15 @@ TEST(FirebaseObjectTest, GetInt) { TEST(FirebaseObjectTest, GetFloat) { { - FirebaseObject obj("43.0"); - EXPECT_EQ(43, obj.getFloat()); + FirebaseObject obj("43.1"); + EXPECT_FLOAT_EQ(43.1, obj.getFloat()); EXPECT_TRUE(obj.success()); EXPECT_FALSE(obj.failed()); EXPECT_EQ(obj.error(), ""); } { FirebaseObject obj("43"); - EXPECT_EQ(43, obj.getFloat()); + EXPECT_FLOAT_EQ(43, obj.getFloat()); EXPECT_TRUE(obj.success()); EXPECT_FALSE(obj.failed()); EXPECT_EQ(obj.error(), ""); @@ -112,6 +112,59 @@ TEST(FirebaseObjectTest, GetStringFailure) { EXPECT_EQ(obj.error(), "failed to convert to string"); } +TEST(FirebaseObjectTest, GetTwice) { + { + FirebaseObject obj("{\"foo\":\"bar\"}"); + EXPECT_EQ(obj.getString("hop"), ""); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to string"); + + EXPECT_EQ(obj.getString("foo"), "bar"); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } + { + FirebaseObject obj("{\"foo\": 42}"); + EXPECT_EQ(obj.getInt("hop"), 0); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to number"); + + EXPECT_EQ(obj.getInt("foo"), 42); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } + { + FirebaseObject obj("{\"foo\": true}"); + EXPECT_EQ(obj.getBool("hop"), 0); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to bool"); + + EXPECT_EQ(obj.getBool("foo"), true); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } + { + FirebaseObject obj("{\"foo\": 43.1}"); + EXPECT_FLOAT_EQ(obj.getFloat("hop"), 0); + EXPECT_FALSE(obj.success()); + EXPECT_TRUE(obj.failed()); + EXPECT_EQ(obj.error(), "failed to convert to number"); + + EXPECT_FLOAT_EQ(obj.getFloat("foo"), 43.1); + EXPECT_TRUE(obj.success()); + EXPECT_FALSE(obj.failed()); + EXPECT_EQ(obj.error(), ""); + } +} + + + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); diff --git a/src/FirebaseObject.cpp b/src/FirebaseObject.cpp index 44fa5c37..6cd9443f 100644 --- a/src/FirebaseObject.cpp +++ b/src/FirebaseObject.cpp @@ -32,6 +32,7 @@ bool FirebaseObject::getBool(const String& path) const { error_ = "failed to convert to bool"; return 0; } + error_ = ""; return static_cast(variant); } @@ -41,6 +42,7 @@ int FirebaseObject::getInt(const String& path) const { error_ = "failed to convert to number"; return 0; } + error_ = ""; return static_cast(variant); } @@ -50,6 +52,7 @@ float FirebaseObject::getFloat(const String& path) const { error_ = "failed to convert to number"; return 0; } + error_ = ""; return static_cast(variant); } @@ -59,6 +62,7 @@ String FirebaseObject::getString(const String& path) const { error_ = "failed to convert to string"; return ""; } + error_ = ""; return static_cast(variant); } From 3530f7de36740a85dffe6f85333fbc91cbfacbfc Mon Sep 17 00:00:00 2001 From: Lip Date: Fri, 25 Jan 2019 13:59:01 +0700 Subject: [PATCH 64/68] Fix issue #388 ESP8266 fails to reconnect to FIREBASE #388 https://github.com/FirebaseExtended/firebase-arduino/issues/388 --- src/Firebase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Firebase.cpp b/src/Firebase.cpp index b6c10043..fcf32993 100644 --- a/src/Firebase.cpp +++ b/src/Firebase.cpp @@ -47,6 +47,8 @@ void FirebaseCall::analyzeError(char* method, int status, const std::string& pat error_ = FirebaseError(status, std::string(method) + " " + path_with_auth + ": " + http_->errorToString(status)); + } else { + error_ = FirebaseError(); } } From cd5681f59cabdb31c2c50c55a5abc53af78a3280 Mon Sep 17 00:00:00 2001 From: Sergei Kotlyachkov Date: Fri, 1 Mar 2019 19:16:34 -0500 Subject: [PATCH 65/68] New fingerprint update --- src/FirebaseHttpClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 01d59f42..76d5ff66 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -40,6 +40,6 @@ class FirebaseHttpClient { }; static const char kFirebaseFingerprint[] = - "6F D0 9A 52 C0 E9 E4 CD A0 D3 02 A4 B7 A1 92 38 2D CA 2F 26"; + "E2 34 53 7A 1E D9 7D B8 C5 02 36 0D B2 77 9E 5E 0F 32 71 17"; // 2019 #endif // FIREBASE_HTTP_CLIENT_H From f152bd035388afe4f50a91a6268bb3637a85b378 Mon Sep 17 00:00:00 2001 From: Alex Volkovitsky Date: Fri, 19 Apr 2019 06:17:13 -0700 Subject: [PATCH 66/68] Update to latest RTDB SSL fingerprint (#438) --- src/FirebaseHttpClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 76d5ff66..4b585aa6 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -40,6 +40,6 @@ class FirebaseHttpClient { }; static const char kFirebaseFingerprint[] = - "E2 34 53 7A 1E D9 7D B8 C5 02 36 0D B2 77 9E 5E 0F 32 71 17"; // 2019 + "B6 F5 80 C8 B1 DA 61 C1 07 9D 80 42 D8 A9 1F AF 9F C8 96 7D"; // 2019-04 #endif // FIREBASE_HTTP_CLIENT_H From f02bf47ca5a923dbb7fab5fbfc2e1c62a99b460f Mon Sep 17 00:00:00 2001 From: TrickSumo Date: Mon, 2 Mar 2020 18:25:06 +0530 Subject: [PATCH 67/68] SSL Fingerprint Update --- src/FirebaseHttpClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FirebaseHttpClient.h b/src/FirebaseHttpClient.h index 4b585aa6..3fc66eb4 100644 --- a/src/FirebaseHttpClient.h +++ b/src/FirebaseHttpClient.h @@ -40,6 +40,6 @@ class FirebaseHttpClient { }; static const char kFirebaseFingerprint[] = - "B6 F5 80 C8 B1 DA 61 C1 07 9D 80 42 D8 A9 1F AF 9F C8 96 7D"; // 2019-04 + "03:D6:42:23:03:D1:0C:06:73:F7:E2:BD:29:47:13:C3:22:71:37:1B"; // 2020-02 #endif // FIREBASE_HTTP_CLIENT_H From c2b39a3afd55af27e0c39318b89bab71148517b2 Mon Sep 17 00:00:00 2001 From: Sam Stern Date: Fri, 7 Aug 2020 08:51:29 -0400 Subject: [PATCH 68/68] Update README.md (#498) --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 827cf7ec..62836a1f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,15 @@ This repo contains a collection of samples and an Arduino library that show how to call the [Firebase](https://www.firebase.com/) API from the [ESP8266 Arduino core](https://github.com/esp8266/Arduino). -The Arduino library is [under heavy development](https://github.com/googlesamples/firebase-arduino/issues), **experimental**, **unversioned** and its API is **not stable**. + +## Status + +![Status: Frozen](https://img.shields.io/badge/Status-Frozen-yellow) + +This repository is no longer under active development. No new features will be added and issues are not actively triaged. Pull Requests which fix bugs are welcome and will be reviewed on a best-effort basis. + +If you maintain a fork of this repository that you believe is healthier than the official version, we may consider recommending your fork. Please open a Pull Request if you believe that is the case. + ## Samples