Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
WSServer.h
1 /***** WSServer.h *****/
2 #include <string>
3 #include <memory>
4 #include <set>
5 #include <map>
6 #include <vector>
7 
8 #define WSSERVER_STREAM_BUFFERSIZE 1024
9 
10 // forward declarations for faster render.cpp compiles
11 namespace seasocks{
12  class Server;
13  class WebSocket;
14 }
15 class AuxTaskNonRT;
16 struct WSServerDataHandler;
17 
18 class WSServer{
19  friend struct WSServerDataHandler;
20  public:
21  WSServer();
22  WSServer(int _port);
23  ~WSServer();
24 
25  void setup(int port);
26 
27  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);
28 
29  int send(const char* address, const char* str);
30  int send(const char* address, void* buf, int num_bytes);
31 
32  private:
33  void cleanup();
34 
35  int port;
36  std::string address;
37  std::shared_ptr<seasocks::Server> server;
38 
39  std::map<std::string, std::unique_ptr<AuxTaskNonRT>> address_book;
40  std::unique_ptr<AuxTaskNonRT> server_task;
41 
42  void client_task_func(std::shared_ptr<WSServerDataHandler> handler, void* buf, int size);
43 };
void cleanup(BelaContext *context, void *userData)
User-defined cleanup function which runs when the program finishes.
Definition: render.cpp:82
Definition: WSServer.h:18
bool setup(BelaContext *context, void *userData)
User-defined initialisation function which runs before audio rendering begins.
Definition: render.cpp:36
Definition: AuxTaskNonRT.h:20