-
Notifications
You must be signed in to change notification settings - Fork 4
/
LocalServer.h
64 lines (49 loc) · 2.04 KB
/
LocalServer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef OTF_LOCALSERVER_H
#define OTF_LOCALSERVER_H
#include <stdint.h>
#include <stddef.h>
#if defined(ARDUINO)
#include <Arduino.h>
#endif
namespace OTF {
class LocalClient {
public:
/** Returns a boolean indicating if data is currently available from this client. */
virtual bool dataAvailable() = 0;
/**
* Reads up to `length` bytes from the request stream into `buffer`.
* @return The number of bytes read.
*/
virtual size_t readBytes(char *buffer, size_t length) = 0;
/**
* Reads up to `length` bytes from the request stream until `terminator` or the end of stream is reached.
* @return The number of bytes read.
*/
virtual size_t readBytesUntil(char terminator, char *buffer, size_t length) = 0;
/** Prints a null-terminated string to the response stream. This method may be called multiple times before the stream is closed. */
virtual void print(const char *data) = 0;
#if defined(ARDUINO)
/** Prints a null-terminated string to the response stream. This method may be called multiple times before the stream is closed. */
virtual void print(const __FlashStringHelper *data) = 0;
#endif
/** Writes `size` bytes from `buffer` to the response stream. */
virtual size_t write(const char *buffer, size_t size) = 0;
// /** Returns the next character in the request stream (without advancing the stream), or returns -1 if no character is available. */
// virtual int peek() = 0;
/** Sets the maximum number of milliseconds to wait for data to be available when readBytes() is called. */
virtual void setTimeout(int timeout) = 0;
virtual void flush() = 0;
virtual void stop() = 0;
};
class LocalServer {
public:
/**
* Closes the active client (if one is active) and accepts a new client (if one is available).
* @return The newly accepted client, or `nullptr` if none was available.
*/
virtual LocalClient *acceptClient() = 0;
/** Starts listening for connections. */
virtual void begin() = 0;
};
}// namespace OTF
#endif