forked from FirebaseExtended/firebase-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream-command.cpp
51 lines (44 loc) · 1.19 KB
/
stream-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
49
50
51
#include "modem/db/commands.h"
namespace firebase {
namespace modem {
bool StreamCommand::execute(const String& command,
InputStream* in, OutputStream* out) {
if (in == nullptr || out == nullptr) {
return false;
}
if (command != "BEGIN_STREAM") {
return false;
}
String path = in->readLine().c_str();
fbase().stream(path);
if (fbase().error().length() != 0) {
out->print("-FAIL ");
out->println(fbase().error().c_str());
return false;
}
bool running = true;
DynamicJsonBuffer buffer;
while(running) {
if (fbase().available()) {
FirebaseObject event = fbase().readEvent();
out->print("+");
out->print(event.getString("type").c_str());
out->print(" ");
String data = event.getString("data");
out->println(event.getString("path"));
out->println(data.length());
out->println(data);
} else if (in->available()) {
String command = in->readLine();
if (command == "END_STREAM") {
out->println("+OK");
running = false;
} else {
out->println("-FAIL Cannot call any command but END_STREAM.");
}
}
}
return true;
}
} // modem
} // firebase