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

Commit6f65250

Browse files
committed
Revert "Add call ids"
This reverts commit077e060.
1 parent077e060 commit6f65250

File tree

2 files changed

+30
-114
lines changed

2 files changed

+30
-114
lines changed

‎Firebase.cpp

Lines changed: 19 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -33,101 +33,48 @@ String makeUrl(const String& path, const String& auth) {
3333

3434
}// namespace
3535

36-
Firebase::Firebase(const String& host) {
37-
connection_.reset(newFirebaseConnection(host));
36+
Firebase::Firebase(const String& host): host_(host){
37+
http_.setReuse(true);
3838
}
3939

4040
Firebase&Firebase::auth(const String& auth) {
41-
connection_->auth(auth);
41+
auth_ =auth;
4242
return *this;
4343
}
4444

4545
FirebaseCallFirebase::get(const String& path) {
46-
returnFirebaseCall("GET", path,++current_call_id_, connection_.get());
46+
returnFirebaseCall(host_, auth_,"GET", path,&http_);
4747
}
4848

4949
FirebaseCallFirebase::push(const String& path,const String& value) {
50-
returnFirebaseCall("POST", path, value,++current_call_id_, connection_.get());
50+
returnFirebaseCall(host_, auth_,"POST", path, value,&http_);
5151
}
5252

5353
FirebaseCallFirebase::remove(const String& path) {
54-
returnFirebaseCall("DELETE", path,++current_call_id_, connection_.get());
54+
returnFirebaseCall(host_, auth_,"DELETE", path,&http_);
5555
}
56-
/*
56+
5757
FirebaseEventStreamFirebase::stream(const String& path) {
5858
returnFirebaseEventStream(host_, auth_, path);
59-
}*/
60-
61-
/* FirebaseConnection*/
62-
FirebaseConnection::FirebaseConnection(const String& host) : host_(host) {
63-
http_.setReuse(true);
64-
}
65-
66-
FirebaseConnection&FirebaseConnection::auth(const String& auth) {
67-
auth_ = auth;
68-
return *this;
69-
}
70-
71-
intFirebaseConnection::sendRequest(constchar* method,const String& path,const String& value) {
72-
const String url =makeUrl(path, auth_);
73-
http_.begin(host_.c_str(),kFirebasePort, url.c_str(),true,kFirebaseFingerprint);
74-
int status = http_.sendRequest(method, (uint8_t*)value.c_str(), value.length());
75-
if (status == HTTP_CODE_OK) {
76-
remaining_call_buffer_ = http_.getSize();
77-
}
78-
return status;
79-
}
80-
81-
StringFirebaseConnection::getString() {
82-
remaining_call_buffer_ =0;
83-
return http_.getString();
84-
}
85-
86-
boolFirebaseConnection::isOwner(int call_id) {
87-
return owning_call_id_ == call_id;
88-
}
89-
90-
voidFirebaseConnection::setOwner(int call_id) {
91-
owning_call_id_ = call_id;
92-
drainResponseBuffer();
93-
}
94-
95-
voidFirebaseConnection::drainResponseBuffer() {
96-
auto* stream = http_.getStreamPtr();
97-
Serial.println("Available");
98-
Serial.println(stream->available());
99-
100-
101-
constint buffer_size =128;
102-
uint8_t buffer[buffer_size];
103-
int read =0;
104-
int to_read = (buffer_size < remaining_call_buffer_) ? buffer_size : remaining_call_buffer_;
105-
//TODO(edcoyne) This only reads what is available. Is this sufficient or should we wait?
106-
while (remaining_call_buffer_ >0 && (read = stream->read(buffer, to_read) >0)) {
107-
Serial.println("Draining");
108-
Serial.println(remaining_call_buffer_);
109-
remaining_call_buffer_ -= read;
110-
to_read = (buffer_size < remaining_call_buffer_) ? buffer_size : remaining_call_buffer_;
111-
}
112-
Serial.println("Done draining");
113-
Serial.println(remaining_call_buffer_);
11459
}
11560

11661
/* FirebaseCall*/
11762

118-
FirebaseCall::FirebaseCall(constchar* method,const String& path,const String& value,
119-
int call_id, FirebaseConnection* connection)
120-
: connection_(connection), call_id_(call_id) {
121-
connection_->setOwner(call_id);
122-
status_ = connection_->sendRequest(method, path, value);
63+
FirebaseCall::FirebaseCall(const String& host,const String& auth,
64+
constchar* method,const String& path,const String& value,
65+
HTTPClient* http) : http_(http) {
66+
const String url =makeUrl(path, auth);
67+
http_->begin(host.c_str(),kFirebasePort, url.c_str(),true,kFirebaseFingerprint);
68+
status_ = http_->sendRequest(method, (uint8_t*)value.c_str(), value.length());
12369
if (isError()) {
124-
error_message_ =String(method) +"" +path +":" +HTTPClient::errorToString(status_);
70+
error_message_ =String(method) +"" +url +":" +HTTPClient::errorToString(status_);
12571
}
12672
}
12773

128-
FirebaseCall::FirebaseCall(constchar* method,const String& path,int call_id,
129-
FirebaseConnection* connection)
130-
: FirebaseCall(method, path,"", call_id, connection) {}
74+
FirebaseCall::FirebaseCall(const String& host,const String& auth,
75+
constchar* method,const String& path,
76+
HTTPClient* http) : FirebaseCall(host, auth, method, path,"", http) {
77+
}
13178

13279
boolFirebaseCall::isOk()const {
13380
return status_ == HTTP_CODE_OK;
@@ -142,16 +89,7 @@ String FirebaseCall::errorMessage() const {
14289
}
14390

14491
StringFirebaseCall::rawResponse() {
145-
if (!connection_->isOwner(call_id_)) {
146-
setErrorNotOwner();
147-
return"";
148-
}
149-
return connection_->getString();
150-
}
151-
152-
voidFirebaseCall::setErrorNotOwner() {
153-
status_ =kStatusNotConnectionOwner;
154-
error_message_ ="Connection no longer owns connection";
92+
return http_->getString();
15593
}
15694

15795
/* FirebaseEventStream*/

‎Firebase.h

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,6 @@
3030
classFirebaseCall;
3131
classFirebaseEventStream;
3232

33-
classFirebaseConnection {
34-
public:
35-
FirebaseConnection(const String& host);
36-
FirebaseConnection&auth(const String& auth);
37-
38-
// Returns true if call with call_id owns the connection.
39-
boolisOwner(int call_id);
40-
voidsetOwner(int call_id);
41-
42-
intsendRequest(constchar* method,const String& path,const String& value);
43-
StringgetString();
44-
private:
45-
voiddrainResponseBuffer();
46-
47-
int owning_call_id_ =0;
48-
int remaining_call_buffer_ =0;
49-
HTTPClient http_;
50-
String host_;
51-
String auth_;
52-
};
53-
5433
// Primary client to the Firebase backend.
5534
classFirebase {
5635
public:
@@ -70,21 +49,21 @@ class Firebase {
7049
// Starts a stream of events that effect object at "path".
7150
FirebaseEventStreamstream(const String& path);
7251

73-
Firebase(const Firebase&) =delete;
74-
Firebase&operator=(const Firebase&) =delete;
7552
private:
76-
int current_call_id_ =0;
77-
std::unique_ptr<FirebaseConnection> connection_;
53+
HTTPClient http_;
54+
String host_;
55+
String auth_;
7856
};
7957

8058
classFirebaseCall {
8159
public:
82-
staticconstintkStatusNotConnectionOwner = -1000;
60+
FirebaseCall(const String& host,const String& auth,
61+
constchar* method,const String& path,const String& value,
62+
HTTPClient* http);
63+
FirebaseCall(const String& host,const String& auth,
64+
constchar* method,const String& path,
65+
HTTPClient* http);
8366

84-
FirebaseCall(constchar* method,const String& path,const String& value,int call_id,
85-
FirebaseConnection* connection);
86-
FirebaseCall(constchar* method,const String& path,int call_id,
87-
FirebaseConnection* connection);
8867

8968
// True if there was an error completing call.
9069
boolisError()const;
@@ -102,11 +81,10 @@ class FirebaseCall {
10281
}
10382

10483
private:
105-
voidsetErrorNotOwner();
84+
FirebaseCall(HTTPClient* http);
10685

107-
FirebaseConnection* connection_;
86+
HTTPClient* http_;
10887

109-
int call_id_;
11088
int status_;
11189
String error_message_;
11290
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp