Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Report error when streaming loses connection. #179

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Firebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Firebase {
class FirebaseError {
public:
FirebaseError() {}
FirebaseError(int code, const std::string& message) : code_(code), message_(message) {
FirebaseError(int code, const std::string& message) : code_(code), message_(message) {
}
operator bool() const { return code_ != 0; }
int code() const { return code_; }
Expand Down
4 changes: 4 additions & 0 deletions src/FirebaseArduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ void FirebaseArduino::stream(const String& path) {
}

bool FirebaseArduino::available() {
if (!http_->connected()) {
error_ = FirebaseError(HTTP_CONNECTION_LOST, "Connection Lost");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

return false;
}
return http_->getStreamPtr()->available();
}

Expand Down
4 changes: 4 additions & 0 deletions src/FirebaseArduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
*/
class FirebaseArduino {
public:
enum ERROR_CODES {
HTTP_CONNECTION_LOST = -5
};

/**
* Must be called first. This initialize the client with the given
* firebase host and credentials.
Expand Down
2 changes: 2 additions & 0 deletions src/FirebaseHttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class FirebaseHttpClient {

virtual void end() = 0;

virtual bool connected() = 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;
Expand Down
6 changes: 5 additions & 1 deletion src/FirebaseHttpClient_Esp8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient {
http_.end();
}

void addHeader(const std::string& name, const std::string& value) override {
bool connected() override {
return http_.connected();
}

void addHeader(const std::string& name, const std::string& value) override {
http_.addHeader(name.c_str(), value.c_str());
}

Expand Down
3 changes: 1 addition & 2 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ FIREBASE_DIR=..
GTEST_DIR=googletest/googletest
ARDUINOJSON_DIR=../src/third-party/arduino-json-5.3

FIREBASE_SRCS=${FIREBASE_DIR}/src/FirebaseObject.cpp\
${FIREBASE_DIR}/src/FirebaseObject.h
FIREBASE_SRCS=${FIREBASE_DIR}/src/FirebaseObject.cpp
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have the .h here when you run "make clean" it deletes it. We also don't need it.

Copy link
Contributor

@proppy proppy Jun 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, maybe we should just have a _DEPS

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are fine just leaving it out, it works this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, the only gotcha is that it won't force to recompile if the .h changes.

GTEST_SRCS=${GTEST_DIR}/src/gtest-all.cpp
ARDUINOJSON_SRCS=${ARDUINOJSON_DIR}/src/JsonBuffer.cpp\
${ARDUINOJSON_DIR}/src/JsonObject.cpp\
Expand Down
3 changes: 3 additions & 0 deletions test/dummies/FirebaseHttpClient_dummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class FirebaseHttpClientDummy : public FirebaseHttpClient {
void end() override {
}

bool connected() override {
return true;

void addHeader(const std::string& UNUSED_ARG(name), const std::string& UNUSED_ARG(value)) override {
}

Expand Down