Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
SimpleWebServer.h
Go to the documentation of this file.
1
11#ifndef SIMPLEWEBSERVER_H
12#define SIMPLEWEBSERVER_H
13
15#include <atomic>
16#include <functional>
17#include <map>
18#include <mutex>
19#include <string>
20#include <thread>
21#include <vector>
22
24
25
32{
33 public:
34 using RequestCallback = std::function<std::vector<char>(const std::string&)>;
35
37 // Declare class methods.
39
40 SimpleWebServer(int nPort = 8080);
42 void SetHtmlContent(const std::string& szHtml);
43 void RegisterEndpoint(const std::string& szEndpoint, RequestCallback fnCallback);
44
45 private:
47 // Private Members
49
50 int m_nPort;
51 std::atomic<int> m_nSocketFD;
52 std::atomic<bool> m_bRunning;
53 std::string m_szHtmlContent;
54 std::map<std::string, RequestCallback> m_mGetCallbacks;
55 std::mutex m_muDataMutex;
56
57 // Thread Management.
58 std::thread m_thAcceptThread;
59 std::vector<std::thread> m_vWorkerThreads;
60 std::mutex m_muThreadMutex;
61
63 // Private Methods
65
66 void StartServer();
67 void StopServer();
68 void AcceptLoop();
69 void HandleClient(int nClientFD);
70};
71
72#endif
A lightweight, multi-threaded HTTP server.
Definition SimpleWebServer.h:32
void RegisterEndpoint(const std::string &szEndpoint, RequestCallback fnCallback)
Registers a GET endpoint with a callback function.
Definition SimpleWebServer.cpp:79
void StopServer()
Stops the web server.
Definition SimpleWebServer.cpp:152
void StartServer()
Starts the web server.
Definition SimpleWebServer.cpp:92
void HandleClient(int nClientFD)
Handles an individual client connection.
Definition SimpleWebServer.cpp:227
void AcceptLoop()
Main loop to accept incoming connections.
Definition SimpleWebServer.cpp:190
~SimpleWebServer()
Destroy the Simple Web Server object.
Definition SimpleWebServer.cpp:50
void SetHtmlContent(const std::string &szHtml)
Mutator for the Html Content private member.
Definition SimpleWebServer.cpp:64