forked from FirebaseExtended/firebase-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbegin-command.cpp
48 lines (37 loc) · 954 Bytes
/
begin-command.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "modem/db/commands.h"
namespace firebase {
namespace modem {
bool BeginCommand::execute(const String& command,
InputStream* in, OutputStream* out) {
if (in == nullptr || out == nullptr) {
return false;
}
if (command != "BEGIN_DB") {
return false;
}
String host;
String auth;
String data(in->readLine());
int space_index = data.indexOf(' ');
if (space_index == -1) {
// host only.
host = data;
} else {
// host and auth.
host = data.substring(0, space_index);
auth = data.substring(space_index + 1);
}
if (host.length() == 0) {
out->println("-FAIL Missing host");
return false;
}
new_firebase_.reset(new FirebaseArduino());
new_firebase_.get()->begin(host.c_str(), auth.c_str());
out->println("+OK");
return true;
}
std::unique_ptr<FirebaseArduino> BeginCommand::firebase() {
return std::move(new_firebase_);
}
} // modem
} // firebase