forked from Arduino-CI/arduino_ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.h
46 lines (43 loc) · 1.29 KB
/
Client.h
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
#pragma once
#include <IPAddress.h>
#include <Stream.h>
class Client : public Stream {
public:
Client() {
// The Stream mock defines a String buffer but never puts anyting in it!
if (!mGodmodeDataIn) {
mGodmodeDataIn = new String;
}
}
Client(const Client &client) { // copy constructor
if (this != &client) { // not a self-assignment
if (mGodmodeDataIn &&
client.mGodmodeDataIn) { // replace what we previously had
delete mGodmodeDataIn; // get rid of previous value
mGodmodeDataIn = new String(client.mGodmodeDataIn->c_str());
}
}
}
Client &operator=(const Client &client) { // copy assignment operator
if (this != &client) { // not a self-assignment
if (mGodmodeDataIn &&
client.mGodmodeDataIn) { // replace what we previously had
delete mGodmodeDataIn; // get rid of previous value
mGodmodeDataIn = new String(client.mGodmodeDataIn->c_str());
}
}
return *this;
}
~Client() {
if (mGodmodeDataIn) {
delete mGodmodeDataIn;
mGodmodeDataIn = nullptr;
}
}
virtual size_t write(uint8_t value) {
mGodmodeDataIn->concat(value);
return 1;
}
protected:
uint8_t *rawIPAddress(IPAddress &addr) { return addr.raw_address(); }
};