1616#include " Firebase.h"
1717
1818using std::unique_ptr;
19+ using std::shared_ptr;
1920
2021namespace {
2122std::string makeFirebaseURL (const std::string& path, const std::string& auth) {
@@ -42,55 +43,30 @@ const std::string& Firebase::auth() const {
4243}
4344
4445FirebaseGet Firebase::get (const std::string& path) {
45- return FirebaseGet (host_, auth_, path, http_.get ());
46- }
47-
48- unique_ptr<FirebaseGet> Firebase::getPtr (const std::string& path) {
49- return unique_ptr<FirebaseGet>(new FirebaseGet (host_, auth_, path, http_.get ()));
46+ return FirebaseGet (host_, auth_, path, http_);
5047}
5148
5249FirebaseSet Firebase::set (const std::string& path, const std::string& value) {
53- return FirebaseSet (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- new FirebaseSet (host_, auth_, path, value, http_.get ()));
50+ return FirebaseSet (host_, auth_, path, value, http_);
6051}
6152
6253FirebasePush Firebase::push (const std::string& path, const std::string& value) {
63- return FirebasePush (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- new FirebasePush (host_, auth_, path, value, http_.get ()));
54+ return FirebasePush (host_, auth_, path, value, http_);
6855}
6956
7057FirebaseRemove Firebase::remove (const std::string& path) {
71- return FirebaseRemove (host_, auth_, path, http_.get ());
72- }
73-
74- unique_ptr<FirebaseRemove> Firebase::removePtr (const std::string& path) {
75- return unique_ptr<FirebaseRemove>(
76- new FirebaseRemove (host_, auth_, path, http_.get ()));
58+ return FirebaseRemove (host_, auth_, path, http_);
7759}
7860
7961FirebaseStream Firebase::stream (const std::string& path) {
8062 // TODO: create new client dedicated to stream.
81- return FirebaseStream (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- new FirebaseStream (host_, auth_, path, http_.get ()));
63+ return FirebaseStream (host_, auth_, path, http_);
8864}
8965
9066// FirebaseCall
9167FirebaseCall::FirebaseCall (const std::string& host, const std::string& auth,
9268 const char * 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
142118const 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
150128FirebaseGet::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
157135FirebaseSet::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
168146FirebasePush::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 <const char *>();
@@ -177,14 +155,14 @@ FirebasePush::FirebasePush(const std::string& host, const std::string& auth,
177155// FirebaseRemove
178156FirebaseRemove::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
185163FirebaseStream::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
0 commit comments