-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClientManager.h
More file actions
68 lines (49 loc) · 2.23 KB
/
Copy pathClientManager.h
File metadata and controls
68 lines (49 loc) · 2.23 KB
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
65
66
67
68
#ifndef CLIENTMANAGER_H
#define CLIENTMANAGER_H
#include <boost/lockfree/spsc_queue.hpp>
#include <unordered_map>
#include <thread>
#include <atomic>
#include "global.h"
#include "ClientObject.h"
class ClientManager {
public:
// Singleton instance of the ClientManager
static ClientManager& getInstance();
// Starts the ClientManager's processing loop
void startProcessing();
// Stops the processing loop (optional, not necessary for detached thread)
void stopProcessing();
// Function to allow WebSocketServer to push data into the queue
bool enqueueClientInfo(const ClientInfo& clientInfo);
// Function to push SampleData into rawSamplesQueue
bool enqueueRawSamples(const SampleData& sampleData);
// Function to push big FFT data into the queue
bool enqueueFFTData(const std::array<float, 1025>& fftData);
// get number of active clients
int getNumberOfLoggedInClients();
private:
ClientManager() = default;
~ClientManager() = default;
// Deleted copy constructor and assignment operator to prevent copying
ClientManager(const ClientManager&) = delete;
ClientManager& operator=(const ClientManager&) = delete;
// Internal method to process messages
void processMessages();
// handles user and password of the clients
void checkUserPW();
// The SPSC queue for client events
boost::lockfree::spsc_queue<ClientInfo, boost::lockfree::capacity<100>> clientQueue;
// Queue for raw sample data
boost::lockfree::spsc_queue<SampleData, boost::lockfree::capacity<1024>> rawSamplesQueue;
// Queue for FFT bins (full scale FFT)
boost::lockfree::spsc_queue<std::array<float, 1025>, boost::lockfree::capacity<100>> bigFFTqueue;
// Queue for FFT bins (narrowband FFT)
boost::lockfree::spsc_queue<std::array<float, 1025>, boost::lockfree::capacity<100>> smallFFTqueue;
// Queue for audio samples from the SignalDecoder
// queue for about 2 seconds (8kHz sample rate and 1024 sample packets)
boost::lockfree::spsc_queue<std::array<float, 1025>, boost::lockfree::capacity<20>> audioQueue;
// Map to store the active ClientObjects by clientId
std::unordered_map<int, std::unique_ptr<ClientObject>> clientMap;
};
#endif // CLIENTMANAGER_H