Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2138bf

Browse files
committed
Crazy update to use shared_ptr and get rid of old ArduinoJson library and use latest one.
1 parentd7aebba commitd2138bf

File tree

81 files changed

+85
-5216
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+85
-5216
lines changed

‎src/Firebase.cpp

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include"Firebase.h"
1717

1818
using std::unique_ptr;
19+
using std::shared_ptr;
1920

2021
namespace {
2122
std::stringmakeFirebaseURL(const std::string& path,const std::string& auth) {
@@ -42,55 +43,30 @@ const std::string& Firebase::auth() const {
4243
}
4344

4445
FirebaseGetFirebase::get(const std::string& path) {
45-
returnFirebaseGet(host_, auth_, path, http_.get());
46-
}
47-
48-
unique_ptr<FirebaseGet>Firebase::getPtr(const std::string& path) {
49-
return unique_ptr<FirebaseGet>(newFirebaseGet(host_, auth_, path, http_.get()));
46+
returnFirebaseGet(host_, auth_, path, http_);
5047
}
5148

5249
FirebaseSetFirebase::set(const std::string& path,const std::string& value) {
53-
returnFirebaseSet(host_, auth_, path, value, http_.get());
54-
}
55-
56-
unique_ptr<FirebaseSet>Firebase::setPtr(const std::string& path,
57-
const std::string& value) {
58-
return unique_ptr<FirebaseSet>(
59-
newFirebaseSet(host_, auth_, path, value, http_.get()));
50+
returnFirebaseSet(host_, auth_, path, value, http_);
6051
}
6152

6253
FirebasePushFirebase::push(const std::string& path,const std::string& value) {
63-
returnFirebasePush(host_, auth_, path, value, http_.get());
64-
}
65-
unique_ptr<FirebasePush>Firebase::pushPtr(const std::string& path,const std::string& value) {
66-
return unique_ptr<FirebasePush>(
67-
newFirebasePush(host_, auth_, path, value, http_.get()));
54+
returnFirebasePush(host_, auth_, path, value, http_);
6855
}
6956

7057
FirebaseRemoveFirebase::remove(const std::string& path) {
71-
returnFirebaseRemove(host_, auth_, path, http_.get());
72-
}
73-
74-
unique_ptr<FirebaseRemove>Firebase::removePtr(const std::string& path) {
75-
return unique_ptr<FirebaseRemove>(
76-
newFirebaseRemove(host_, auth_, path, http_.get()));
58+
returnFirebaseRemove(host_, auth_, path, http_);
7759
}
7860

7961
FirebaseStreamFirebase::stream(const std::string& path) {
8062
// TODO: create new client dedicated to stream.
81-
returnFirebaseStream(host_, auth_, path, http_.get());
82-
}
83-
84-
unique_ptr<FirebaseStream>Firebase::streamPtr(const std::string& path) {
85-
// TODO: create new client dedicated to stream.
86-
return unique_ptr<FirebaseStream>(
87-
newFirebaseStream(host_, auth_, path, http_.get()));
63+
returnFirebaseStream(host_, auth_, path, http_);
8864
}
8965

9066
// FirebaseCall
9167
FirebaseCall::FirebaseCall(const std::string& host,const std::string& auth,
9268
constchar* method,const std::string& path,
93-
const std::string& data, FirebaseHttpClient* http) : http_(http) {
69+
const std::string& data,const std::shared_ptr<FirebaseHttpClient> http) : http_(http) {
9470
std::string path_with_auth =makeFirebaseURL(path, auth);
9571
http_->setReuseConnection(true);
9672
http_->begin(host, path_with_auth);
@@ -141,22 +117,24 @@ FirebaseCall::~FirebaseCall() {
141117

142118
const JsonObject&FirebaseCall::json() {
143119
//TODO(edcoyne): This is not efficient, we should do something smarter with
144-
//the buffers.
145-
buffer_ =DynamicJsonBuffer();
146-
return buffer_.parseObject(response().c_str());
120+
//the buffers. kotl: Is this still valid?
121+
if (buffer_.get() ==NULL) {
122+
buffer_.reset(new StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>());
123+
}
124+
return buffer_.get()->parseObject(response().c_str());
147125
}
148126

149127
// FirebaseGet
150128
FirebaseGet::FirebaseGet(const std::string& host,const std::string& auth,
151129
const std::string& path,
152-
FirebaseHttpClient* http)
130+
const std::shared_ptr<FirebaseHttpClient> http)
153131
: FirebaseCall(host, auth,"GET", path,"", http) {
154132
}
155133

156134
// FirebaseSet
157135
FirebaseSet::FirebaseSet(const std::string& host,const std::string& auth,
158136
const std::string& path,const std::string& value,
159-
FirebaseHttpClient* http)
137+
const std::shared_ptr<FirebaseHttpClient> http)
160138
: FirebaseCall(host, auth,"PUT", path, value, http) {
161139
if (!error()) {
162140
// TODO: parse json
@@ -167,7 +145,7 @@ FirebaseSet::FirebaseSet(const std::string& host, const std::string& auth,
167145
// FirebasePush
168146
FirebasePush::FirebasePush(const std::string& host,const std::string& auth,
169147
const std::string& path,const std::string& value,
170-
FirebaseHttpClient* http)
148+
const std::shared_ptr<FirebaseHttpClient> http)
171149
: FirebaseCall(host, auth,"POST", path, value, http) {
172150
if (!error()) {
173151
name_ =json()["name"].as<constchar*>();
@@ -177,14 +155,14 @@ FirebasePush::FirebasePush(const std::string& host, const std::string& auth,
177155
// FirebaseRemove
178156
FirebaseRemove::FirebaseRemove(const std::string& host,const std::string& auth,
179157
const std::string& path,
180-
FirebaseHttpClient* http)
158+
const std::shared_ptr<FirebaseHttpClient> http)
181159
: FirebaseCall(host, auth,"DELETE", path,"", http) {
182160
}
183161

184162
// FirebaseStream
185163
FirebaseStream::FirebaseStream(const std::string& host,const std::string& auth,
186164
const std::string& path,
187-
FirebaseHttpClient* http)
165+
const std::shared_ptr<FirebaseHttpClient> http)
188166
: FirebaseCall(host, auth,"STREAM", path,"", http) {
189167
}
190168

‎src/Firebase.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222

2323
#include<Arduino.h>
2424
#include<memory>
25+
#include<ArduinoJson.h>
26+
2527
#include"FirebaseHttpClient.h"
2628
#include"FirebaseError.h"
27-
#defineARDUINOJSON_USE_ARDUINO_STRING1
28-
#include"third-party/arduino-json-5.6.7/include/ArduinoJson.h"
29+
#include"FirebaseObject.h"
2930

3031
classFirebaseGet;
3132
classFirebaseSet;
@@ -42,30 +43,24 @@ class Firebase {
4243

4344
// Fetch json encoded `value` at `path`.
4445
FirebaseGetget(const std::string& path);
45-
virtual std::unique_ptr<FirebaseGet>getPtr(const std::string& path);
46-
4746
// Set json encoded `value` at `path`.
4847
FirebaseSetset(const std::string& path,const std::string& json);
49-
virtual std::unique_ptr<FirebaseSet>setPtr(const std::string& path,const std::string& json);
5048

5149
// Add new json encoded `value` to list at `path`.
5250
FirebasePushpush(const std::string& path,const std::string& json);
53-
virtual std::unique_ptr<FirebasePush>pushPtr(const std::string& path,const std::string& json);
5451

5552
// Delete value at `path`.
5653
FirebaseRemoveremove(const std::string& path);
57-
virtual std::unique_ptr<FirebaseRemove>removePtr(const std::string& path);
5854

5955
// Start a stream of events that affect value at `path`.
6056
FirebaseStreamstream(const std::string& path);
61-
virtual std::unique_ptr<FirebaseStream>streamPtr(const std::string& path);
6257

6358
protected:
6459
// Used for testing.
6560
Firebase() {}
6661

6762
private:
68-
std::unique_ptr<FirebaseHttpClient> http_;
63+
std::shared_ptr<FirebaseHttpClient> http_;
6964
std::string host_;
7065
std::string auth_;
7166
};
@@ -76,7 +71,7 @@ class FirebaseCall {
7671
FirebaseCall(const std::string& host,const std::string& auth,
7772
constchar* method,const std::string& path,
7873
const std::string& data ="",
79-
FirebaseHttpClient* http =NULL);
74+
const std::shared_ptr<FirebaseHttpClient> http =NULL);
8075
virtual~FirebaseCall();
8176

8277
virtualconst FirebaseError&error()const {
@@ -90,17 +85,17 @@ class FirebaseCall {
9085
const JsonObject&json();
9186

9287
protected:
93-
FirebaseHttpClient* http_;
88+
const std::shared_ptr<FirebaseHttpClient> http_;
9489
FirebaseError error_;
9590
std::string response_;
96-
DynamicJsonBuffer buffer_;
91+
std::shared_ptr<StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>> buffer_;
9792
};
9893

9994
classFirebaseGet :publicFirebaseCall {
10095
public:
10196
FirebaseGet() {}
10297
FirebaseGet(const std::string& host,const std::string& auth,
103-
const std::string& path, FirebaseHttpClient* http =NULL);
98+
const std::string& path,const std::shared_ptr<FirebaseHttpClient> http =NULL);
10499

105100
private:
106101
std::string json_;
@@ -110,7 +105,7 @@ class FirebaseSet: public FirebaseCall {
110105
public:
111106
FirebaseSet() {}
112107
FirebaseSet(const std::string& host,const std::string& auth,
113-
const std::string& path,const std::string& value, FirebaseHttpClient* http =NULL);
108+
const std::string& path,const std::string& value,const std::shared_ptr<FirebaseHttpClient> http =NULL);
114109

115110

116111
private:
@@ -121,7 +116,7 @@ class FirebasePush : public FirebaseCall {
121116
public:
122117
FirebasePush() {}
123118
FirebasePush(const std::string& host,const std::string& auth,
124-
const std::string& path,const std::string& value, FirebaseHttpClient* http =NULL);
119+
const std::string& path,const std::string& value,const std::shared_ptr<FirebaseHttpClient> http =NULL);
125120
virtual~FirebasePush() {}
126121

127122
virtualconst std::string&name()const {
@@ -136,15 +131,15 @@ class FirebaseRemove : public FirebaseCall {
136131
public:
137132
FirebaseRemove() {}
138133
FirebaseRemove(const std::string& host,const std::string& auth,
139-
const std::string& path, FirebaseHttpClient* http =NULL);
134+
const std::string& path,const std::shared_ptr<FirebaseHttpClient> http =NULL);
140135
};
141136

142137

143138
classFirebaseStream :publicFirebaseCall {
144139
public:
145140
FirebaseStream() {}
146141
FirebaseStream(const std::string& host,const std::string& auth,
147-
const std::string& path, FirebaseHttpClient* http =NULL);
142+
const std::string& path,const std::shared_ptr<FirebaseHttpClient> http =NULL);
148143
virtual~FirebaseStream() {}
149144

150145
// Return if there is any event available to read.

‎src/FirebaseArduino.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ String FirebaseArduino::pushString(const String& path, const String& value) {
4646
StringFirebaseArduino::push(const String& path,const JsonVariant& value) {
4747
String buf;
4848
value.printTo(buf);
49-
auto push =FirebasePush(host_, auth_, path.c_str(), buf.c_str(), http_.get());
49+
auto push =FirebasePush(host_, auth_, path.c_str(), buf.c_str(), http_);
5050
error_ = push.error();
5151
return push.name().c_str();
5252
}
@@ -71,12 +71,12 @@ void FirebaseArduino::setString(const String& path, const String& value) {
7171
voidFirebaseArduino::set(const String& path,const JsonVariant& value) {
7272
String buf;
7373
value.printTo(buf);
74-
auto set =FirebaseSet(host_, auth_, path.c_str(), buf.c_str(), http_.get());
74+
auto set =FirebaseSet(host_, auth_, path.c_str(), buf.c_str(), http_);
7575
error_ = set.error();
7676
}
7777

7878
FirebaseObjectFirebaseArduino::get(const String& path) {
79-
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
79+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_);
8080
error_ = get.error();
8181
if (failed()) {
8282
return FirebaseObject{""};
@@ -85,7 +85,7 @@ FirebaseObject FirebaseArduino::get(const String& path) {
8585
}
8686

8787
intFirebaseArduino::getInt(const String& path) {
88-
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
88+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_);
8989
error_ = get.error();
9090
if (failed()) {
9191
return0;
@@ -95,7 +95,7 @@ int FirebaseArduino::getInt(const String& path) {
9595

9696

9797
floatFirebaseArduino::getFloat(const String& path) {
98-
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
98+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_);
9999
error_ = get.error();
100100
if (failed()) {
101101
return0.0f;
@@ -104,7 +104,7 @@ float FirebaseArduino::getFloat(const String& path) {
104104
}
105105

106106
StringFirebaseArduino::getString(const String& path) {
107-
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
107+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_);
108108
error_ = get.error();
109109
if (failed()) {
110110
return"";
@@ -113,20 +113,20 @@ String FirebaseArduino::getString(const String& path) {
113113
}
114114

115115
boolFirebaseArduino::getBool(const String& path) {
116-
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
116+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_);
117117
error_ = get.error();
118118
if (failed()) {
119119
return"";
120120
}
121121
returnFirebaseObject(get.response().c_str()).getBool();
122122
}
123123
voidFirebaseArduino::remove(const String& path) {
124-
auto remove =FirebaseRemove(host_, auth_, path.c_str(), http_.get());
124+
auto remove =FirebaseRemove(host_, auth_, path.c_str(), http_);
125125
error_ = remove.error();
126126
}
127127

128128
voidFirebaseArduino::stream(const String& path) {
129-
auto stream =FirebaseStream(host_, auth_, path.c_str(), http_.get());
129+
auto stream =FirebaseStream(host_, auth_, path.c_str(), http_);
130130
error_ = stream.error();
131131
}
132132

‎src/FirebaseArduino.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class FirebaseArduino {
229229
std::string host_;
230230
std::string auth_;
231231
FirebaseError error_;
232-
std::unique_ptr<FirebaseHttpClient> http_;
232+
std::shared_ptr<FirebaseHttpClient> http_;
233233
};
234234

235235
extern FirebaseArduino Firebase;

‎src/FirebaseCloudMessaging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const FirebaseError FirebaseCloudMessaging::SendMessageToTopic(
6363

6464
const FirebaseErrorFirebaseCloudMessaging::SendPayload(
6565
constchar* payload) {
66-
std::unique_ptr<FirebaseHttpClient>client(FirebaseHttpClient::create());
66+
std::shared_ptr<FirebaseHttpClient>client(FirebaseHttpClient::create());
6767
client->begin("http://fcm.googleapis.com/fcm/send");
6868
client->addHeader("Authorization", auth_header_.c_str());
6969
client->addHeader("Content-Type","application/json");

‎src/FirebaseCloudMessaging.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#include<vector>
2727
#include"FirebaseHttpClient.h"
2828
#include"FirebaseError.h"
29-
#defineARDUINOJSON_USE_ARDUINO_STRING1
30-
#include"third-party/arduino-json-5.6.7/include/ArduinoJson.h"
29+
#include<ArduinoJson.h>
3130

3231
// Defines the actual message to the client, for more detail on
3332
// options and settings see:

‎src/FirebaseObject.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
// We need to make a copy of data here, even though it may be large.
2020
// It will need to be long lived.
2121
FirebaseObject::FirebaseObject(constchar* data) : data_{data} {
22-
json_ = buffer_.parse(&data_[0]);
22+
buffer_.reset(new StaticJsonBuffer<FIREBASE_JSONBUFFER_SIZE>);
23+
json_ = buffer_.get()->parse(&data_[0]);
2324
// TODO(proppy): find a way to check decoding error, tricky because
2425
// ArduinoJson doesn't surface error for variant parsing.
2526
// See: https://github.com/bblanchon/ArduinoJson/issues/279
@@ -83,7 +84,7 @@ JsonVariant FirebaseObject::getJsonVariant(const String& path) const {
8384
// make `start` a C string.
8485
*p =0;
8586
// return json variant at `start`.
86-
json = json.asObject().get(start);
87+
json = json.asObject().get<JsonVariant>(start);
8788
// advance to next path element.
8889
start = p +1;
8990
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp