MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / HttpServer

Class HttpServer

Tactility/Include/Tactility/network/HttpServer.h:10–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8namespace tt::network {
9
10class HttpServer {
11
12public:
13
14 /**
15 * @brief Function for URI matching used by server.
16 *
17 * @param[in] referenceUri URI/template with respect to which the other URI is matched
18 * @param[in] uriToCheck URI/template being matched to the reference URI/template
19 * @param[in] matchUpTo For specifying the actual length of `uri_to_match` up to
20 * which the matching algorithm is to be applied (The maximum
21 * value is `strlen(uri_to_match)`, independent of the length
22 * of `reference_uri`)
23 * @return true on match
24 */
25 typedef bool (*UriMatchFunction)(const char* referenceUri, const char* uriToCheck, size_t matchUpTo);
26
27private:
28
29 const uint32_t port;
30 const std::string address;
31 const uint32_t stackSize;
32 const UriMatchFunction matchUri;
33
34 std::vector<httpd_uri_t> handlers;
35
36 RecursiveMutex mutex;
37 httpd_handle_t server = nullptr;
38
39 bool startInternal();
40 void stopInternal();
41
42public:
43
44 HttpServer(
45 uint32_t port,
46 const std::string& address,
47 std::vector<httpd_uri_t> handlers,
48 uint32_t stackSize = 5120,
49 UriMatchFunction matchUri = httpd_uri_match_wildcard
50 ) :
51 port(port),
52 address(address),
53 stackSize(stackSize),
54 matchUri(matchUri),
55 handlers(std::move(handlers))
56 {}
57
58 bool start();
59
60 void stop();
61
62 bool isStarted() const {
63 auto lock = mutex.asScopedLock();
64 lock.lock();
65 return server != nullptr;
66 }
67};

Callers 1

DevelopmentServiceClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected