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

Commit7a7578b

Browse files
committed
Compiling examples and unit tests, still some linking issues
1 parent42c9ef2 commit7a7578b

15 files changed

+95
-75
lines changed

‎src/Firebase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ const JsonObject& FirebaseCall::json() {
137137
//TODO(edcoyne): This is not efficient, we should do something smarter with
138138
//the buffers.
139139
buffer_ =DynamicJsonBuffer();
140-
return buffer_.parseObject(response());
140+
return buffer_.parseObject(response().c_str());
141141
}
142142

143143
// FirebaseGet
@@ -188,15 +188,15 @@ bool FirebaseStream::available() {
188188
FirebaseStream::EventFirebaseStream::read(std::string& event) {
189189
auto client = http_->getStreamPtr();
190190
Event type;
191-
std::string typeStr = client->readStringUntil('\n').substring(7);
191+
std::string typeStr = client->readStringUntil('\n').substring(7).c_str();
192192
if (typeStr =="put") {
193193
type = Event::PUT;
194194
}elseif (typeStr =="patch") {
195195
type = Event::PATCH;
196196
}else {
197197
type = Event::UNKNOWN;
198198
}
199-
event = client->readStringUntil('\n').substring(6);
199+
event = client->readStringUntil('\n').substring(6).c_str();
200200
client->readStringUntil('\n');// consume separator
201201
return type;
202202
}

‎src/FirebaseArduino.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
voidFirebaseArduino::begin(const String& host,const String& auth) {
2020
http_.reset(FirebaseHttpClient::create());
2121
http_->setReuseConnection(true);
22-
host_ = host;
23-
auth_ = auth;
22+
host_ = host.c_str();
23+
auth_ = auth.c_str();
2424
}
2525

2626
StringFirebaseArduino::pushInt(const String& path,int value) {
@@ -43,9 +43,9 @@ String FirebaseArduino::pushString(const String& path, const String& value) {
4343
StringFirebaseArduino::push(const String& path,const JsonVariant& value) {
4444
String buf;
4545
value.printTo(buf);
46-
auto push =FirebasePush(host_, auth_, path, buf, http_.get());
46+
auto push =FirebasePush(host_, auth_, path.c_str(), buf.c_str(), http_.get());
4747
error_ = push.error();
48-
return push.name();
48+
return push.name().c_str();
4949
}
5050

5151
voidFirebaseArduino::setInt(const String& path,int value) {
@@ -68,62 +68,62 @@ void FirebaseArduino::setString(const String& path, const String& value) {
6868
voidFirebaseArduino::set(const String& path,const JsonVariant& value) {
6969
String buf;
7070
value.printTo(buf);
71-
auto set =FirebaseSet(host_, auth_, path, buf, http_.get());
71+
auto set =FirebaseSet(host_, auth_, path.c_str(), buf.c_str(), http_.get());
7272
error_ = set.error();
7373
}
7474

7575
FirebaseObjectFirebaseArduino::get(const String& path) {
76-
auto get =FirebaseGet(host_, auth_, path, http_.get());
76+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
7777
error_ = get.error();
7878
if (failed()) {
7979
return FirebaseObject{""};
8080
}
81-
returnFirebaseObject(get.response());
81+
returnFirebaseObject(get.response().c_str());
8282
}
8383

8484
intFirebaseArduino::getInt(const String& path) {
85-
auto get =FirebaseGet(host_, auth_, path, http_.get());
85+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
8686
error_ = get.error();
8787
if (failed()) {
8888
return0;
8989
}
90-
returnFirebaseObject(get.response()).getInt();
90+
returnFirebaseObject(get.response().c_str()).getInt();
9191
}
9292

9393

9494
floatFirebaseArduino::getFloat(const String& path) {
95-
auto get =FirebaseGet(host_, auth_, path, http_.get());
95+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
9696
error_ = get.error();
9797
if (failed()) {
9898
return0.0f;
9999
}
100-
returnFirebaseObject(get.response()).getFloat();
100+
returnFirebaseObject(get.response().c_str()).getFloat();
101101
}
102102

103103
StringFirebaseArduino::getString(const String& path) {
104-
auto get =FirebaseGet(host_, auth_, path, http_.get());
104+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
105105
error_ = get.error();
106106
if (failed()) {
107107
return"";
108108
}
109-
returnFirebaseObject(get.response()).getString();
109+
returnFirebaseObject(get.response().c_str()).getString();
110110
}
111111

112112
boolFirebaseArduino::getBool(const String& path) {
113-
auto get =FirebaseGet(host_, auth_, path, http_.get());
113+
auto get =FirebaseGet(host_, auth_, path.c_str(), http_.get());
114114
error_ = get.error();
115115
if (failed()) {
116116
return"";
117117
}
118-
returnFirebaseObject(get.response()).getBool();
118+
returnFirebaseObject(get.response().c_str()).getBool();
119119
}
120120
voidFirebaseArduino::remove(const String& path) {
121-
auto remove =FirebaseRemove(host_, auth_, path, http_.get());
121+
auto remove =FirebaseRemove(host_, auth_, path.c_str(), http_.get());
122122
error_ = remove.error();
123123
}
124124

125125
voidFirebaseArduino::stream(const String& path) {
126-
auto stream =FirebaseStream(host_, auth_, path, http_.get());
126+
auto stream =FirebaseStream(host_, auth_, path.c_str(), http_.get());
127127
error_ = stream.error();
128128
}
129129

@@ -136,7 +136,7 @@ FirebaseObject FirebaseArduino::readEvent() {
136136
String type = client->readStringUntil('\n').substring(7);;
137137
String event = client->readStringUntil('\n').substring(6);
138138
client->readStringUntil('\n');// consume separator
139-
FirebaseObject obj =FirebaseObject(event);
139+
FirebaseObject obj =FirebaseObject(event.c_str());
140140
obj.getJsonVariant().asObject()["type"] = type;
141141
return obj;
142142
}
@@ -150,7 +150,7 @@ bool FirebaseArduino::failed() {
150150
}
151151

152152
const String&FirebaseArduino::error() {
153-
return error_.message();
153+
return error_.message().c_str();
154154
}
155155

156156
FirebaseArduino Firebase;

‎src/FirebaseArduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ class FirebaseArduino {
221221
*/
222222
const String&error();
223223
private:
224-
String host_;
225-
String auth_;
224+
std::string host_;
225+
std::string auth_;
226226
FirebaseError error_;
227227
std::unique_ptr<FirebaseHttpClient> http_;
228228
};

‎src/FirebaseHttpClient.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef FIREBASE_HTTP_CLIENT_H
22
#defineFIREBASE_HTTP_CLIENT_H
33

4+
#include<string>
5+
46
#include"Arduino.h"
57
#include"Stream.h"
68

@@ -13,29 +15,29 @@ class FirebaseHttpClient {
1315
static FirebaseHttpClient*create();
1416

1517
virtualvoidsetReuseConnection(bool reuse) = 0;
16-
virtualvoidbegin(constString& url) = 0;
17-
virtualvoidbegin(constString& host,constString& path) = 0;
18+
virtualvoidbegin(conststd::string& url) = 0;
19+
virtualvoidbegin(conststd::string& host,conststd::string& path) = 0;
1820

1921
virtualvoidend() = 0;
2022

21-
virtualvoidaddHeader(constString& name,constString& value) = 0;
23+
virtualvoidaddHeader(conststd::string& name,conststd::string& value) = 0;
2224
virtualvoidcollectHeaders(constchar* header_keys[],
2325
constint header_key_count) = 0;
24-
virtualStringheader(constString& name) = 0;
26+
virtualstd::stringheader(conststd::string& name) = 0;
2527

26-
virtualintsendRequest(constString& method,constString& data) = 0;
28+
virtualintsendRequest(conststd::string& method,conststd::string& data) = 0;
2729

28-
virtualStringgetString() = 0;
30+
virtualstd::stringgetString() = 0;
2931

3032
virtual Stream*getStreamPtr() = 0;
3133

32-
virtualStringerrorToString(int error_code) = 0;
34+
virtualstd::stringerrorToString(int error_code) = 0;
3335

3436
protected:
3537
staticconstuint16_tkFirebasePort =443;
3638
};
3739

38-
staticconstStringkFirebaseFingerprint =
40+
staticconstcharkFirebaseFingerprint[] =
3941
"7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A";
4042

4143
#endif// FIREBASE_HTTP_CLIENT_H

‎src/FirebaseHttpClient_Esp8266.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include<sstream>
12

23
#include"FirebaseHttpClient.h"
34

@@ -21,47 +22,49 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient {
2122
http_.setReuse(reuse);
2223
}
2324

24-
voidbegin(constString& url)override {
25-
http_.begin(url,kFirebaseFingerprint);
25+
voidbegin(conststd::string& url)override {
26+
http_.begin(url.c_str(),kFirebaseFingerprint);
2627
}
2728

28-
voidbegin(constString& host,constString& path)override {
29-
http_.begin(host,kFirebasePort, path,true,kFirebaseFingerprint);
29+
voidbegin(conststd::string& host,conststd::string& path)override {
30+
http_.begin(host.c_str(),kFirebasePort, path.c_str(),true,kFirebaseFingerprint);
3031
}
3132

3233
voidend()override {
3334
http_.end();
3435
}
3536

36-
voidaddHeader(constString& name,constString& value)override {
37-
http_.addHeader(name, value);
37+
voidaddHeader(conststd::string& name,conststd::string& value)override {
38+
http_.addHeader(name.c_str(), value.c_str());
3839
}
3940

4041
voidcollectHeaders(constchar* header_keys[],constint count)override {
4142
http_.collectHeaders(header_keys, count);
4243
}
4344

44-
Stringheader(constString& name)override {
45-
return http_.header(name.c_str());
45+
std::stringheader(conststd::string& name)override {
46+
return http_.header(name.c_str()).c_str();
4647
}
4748

48-
intsendRequest(constString& method,constString& data)override {
49+
intsendRequest(conststd::string& method,conststd::string& data)override {
4950
return http_.sendRequest(method.c_str(), (uint8_t*)data.c_str(), data.length());
5051
}
5152

52-
StringgetString()override {
53-
return http_.getString();
53+
std::stringgetString()override {
54+
return http_.getString().c_str();
5455
}
5556

5657
Stream*getStreamPtr()override {
5758
return http_.getStreamPtr();
5859
}
5960

60-
StringerrorToString(int error_code)override {
61+
std::stringerrorToString(int error_code)override {
6162
#ifdef USE_ESP_ARDUINO_CORE_2_0_0
62-
returnString(error_code);
63+
std::ostringstream ss;
64+
ss << error_code;
65+
return ss.str();
6366
#else
64-
returnHTTPClient::errorToString(error_code);
67+
returnHTTPClient::errorToString(error_code).c_str();
6568
#endif
6669
}
6770

@@ -72,4 +75,4 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient {
7275
FirebaseHttpClient*FirebaseHttpClient::create() {
7376
returnnewFirebaseHttpClientEsp8266();
7477
}
75-
78+

‎src/FirebaseObject.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
#include"FirebaseObject.h"
1818

19-
FirebaseObject::FirebaseObject(const String& data) : data_{data} {
19+
// We need to make a copy of data here, even though it may be large.
20+
// It will need to be long lived.
21+
FirebaseObject::FirebaseObject(constchar* data) : data_{data} {
2022
json_ = buffer_.parse(&data_[0]);
2123
// TODO(proppy): find a way to check decoding error, tricky because
2224
// ArduinoJson doesn't surface error for variant parsing.

‎src/FirebaseObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FirebaseObject {
3333
* Construct from json.
3434
* \param data JSON formatted string.
3535
*/
36-
FirebaseObject(constString& data);
36+
FirebaseObject(constchar* data);
3737

3838
/**
3939
* Return the value as a boolean.

‎src/modem/get-command.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ bool GetCommand::execute(const String& command,
1313
returnfalse;
1414
}
1515

16-
String path = in->readLine();
16+
std::string path = in->readLine().c_str();
1717
std::unique_ptr<FirebaseGet>get(fbase().getPtr(path));
1818

1919
if (get->error()) {

‎src/modem/json_util.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33

44
namespacefirebase {
55
namespacemodem {
6+
namespace {
7+
std::stringReplaceAll(std::string str,const std::string& from,const std::string& to) {
8+
size_t start_pos =0;
9+
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
10+
str.replace(start_pos, from.length(), to);
11+
start_pos += to.length();// Handles case where 'to' is a substring of 'from'
12+
}
13+
return str;
14+
}
15+
}
616

717
// TODO(edcoyne): We should use a json library to escape.
8-
inlineStringEncodeForJson(String input) {
9-
input.replace("\\","\\\\");
10-
input.replace("\"","\\\"");
18+
inlinestd::stringEncodeForJson(std::string input) {
19+
ReplaceAll(input,"\\","\\\\");
20+
ReplaceAll(input,"\"","\\\"");
1121
return"\"" + input +"\"";
1222
}
1323

‎src/modem/push-command.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ bool PushCommand::execute(const String& command,
1414
returnfalse;
1515
}
1616

17-
Stringpath(in->readStringUntil(''));
18-
Stringdata(in->readLine());
17+
std::stringpath(in->readStringUntil('').c_str());
18+
std::stringdata(in->readLine().c_str());
1919

2020
std::unique_ptr<FirebasePush>push(
2121
fbase().pushPtr(path,EncodeForJson(data)));
2222

2323
if (push->error()) {
2424
out->print("-FAIL");
25-
out->println(push->error().message());
25+
out->println(push->error().message().c_str());
2626
returnfalse;
2727
}else {
2828
out->println("+OK");

‎src/modem/set-command.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ bool SetCommand::execute(const String& command,
1414
returnfalse;
1515
}
1616

17-
Stringpath(in->readStringUntil(''));
18-
Stringdata(in->readLine());
17+
std::stringpath(in->readStringUntil('').c_str());
18+
std::stringdata(in->readLine().c_str());
1919

20-
std::unique_ptr<FirebaseSet>set(fbase().setPtr(path.c_str(),
21-
EncodeForJson(data).c_str()));
20+
std::unique_ptr<FirebaseSet>set(fbase().setPtr(path,
21+
EncodeForJson(data)));
2222

2323
if (set->error()) {
2424
out->print("-FAIL");

‎src/modem/stream-command.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,27 @@ bool StreamCommand::execute(const String& command,
1313
returnfalse;
1414
}
1515

16-
String path = in->readLine();
16+
std::string path = in->readLine().c_str();
1717
std::unique_ptr<FirebaseStream>stream(fbase().streamPtr(path));
1818

1919
if (stream->error()) {
2020
out->print("-FAIL");
21-
out->println(stream->error().message());
21+
out->println(stream->error().message().c_str());
2222
returnfalse;
2323
}
2424

2525
bool running =true;
2626
while(running) {
2727
if (stream->available()) {
28-
String json;
28+
std::string json;
2929
FirebaseStream::Event event = stream->read(json);
3030
out->print("+");
31-
out->print(FirebaseStream::EventToName(event) +"");
31+
out->print(FirebaseStream::EventToName(event).c_str());
32+
out->print("");
3233
// TODO(edcoyne): add json parsing and get real path.
3334
out->println("/dummy/path");
3435
out->println(json.length());
35-
out->println(json);
36+
out->println(json.c_str());
3637
}elseif (in->available()) {
3738
String command = in->readLine();
3839
if (command =="END_STREAM") {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp