Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
Loading...
Searching...
No Matches
WSServer.h
1/***** WSServer.h *****/
2#include <string>
3#include <memory>
4#include <set>
5#include <map>
6#include <vector>
7#include <functional>
8
9// forward declarations for faster render.cpp compiles
10namespace seasocks{
11 class Server;
12 class WebSocket;
13}
14class AuxTaskNonRT;
16
17class WSServer{
18 friend struct WSServerDataHandler;
19 public:
20 WSServer();
21 WSServer(int _port);
22 ~WSServer();
23
24 void setup(int port);
25
26 void addAddress(std::string address, std::function<void(std::string, void*, int)> on_receive = nullptr, std::function<void(std::string)> on_connect = nullptr, std::function<void(std::string)> on_disconnect = nullptr, bool binary = false);
27
28 int sendNonRt(const char* address, const char* str);
29 int sendNonRt(const char* address, const void* buf, unsigned int size);
30 int sendRt(const char* address, const char* str);
31 int sendRt(const char* address, const void* buf, unsigned int size);
32
33 private:
34 void cleanup();
35
36 int port;
37 std::string address;
38 std::shared_ptr<seasocks::Server> server;
39
40 struct AddressBookItem {
41 std::unique_ptr<AuxTaskNonRT> thread;
42 std::shared_ptr<WSServerDataHandler> handler;
43 };
44 std::map<std::string, AddressBookItem> address_book;
45 std::unique_ptr<AuxTaskNonRT> server_task;
46
47 void client_task_func(std::shared_ptr<WSServerDataHandler> handler, const void* buf, unsigned int size);
48};
Definition AuxTaskNonRT.h:20
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition render.cpp:51
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition render.cpp:96
Definition WSServer.cpp:17