-
Notifications
You must be signed in to change notification settings - Fork 7
/
API.h
78 lines (60 loc) · 1.96 KB
/
API.h
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
69
70
71
72
73
74
75
76
77
78
#pragma once
#include "VoiceTranscoderAPI.h"
#include <UtilTypes.h>
#include <cstring>
const size_t MAX_CALLBACK_COUNT = 64;
template <typename ...T_ARGS>
class Event : public IEvent<T_ARGS...> {
typedef void (* callback_t)(T_ARGS...);
callback_t m_callbacks[MAX_CALLBACK_COUNT];
size_t m_callbackCount;
public:
Event() {
m_callbackCount = 0;
}
virtual ~Event() {}
void operator()(T_ARGS... args) {
for (size_t i = 0; i < m_callbackCount; i++) {
m_callbacks[i](args...);
}
}
virtual void operator+=(callback_t callback) override final {
//for (size_t i = 0; i < m_callbackCount; i++) {
// if (m_callbacks[i] == callback) {
// return;
// }
//}
if (m_callbackCount == MAX_CALLBACK_COUNT) {
return;
}
m_callbacks[m_callbackCount++] = callback;
};
virtual void operator-=(callback_t callback) override final {
for (size_t i = 0; i < m_callbackCount; i++) {
if (m_callbacks[i] == callback) {
memmove(&m_callbacks[i], &m_callbacks[i+1], (m_callbackCount - i - 1) * sizeof(callback_t));
m_callbackCount--;
return;
}
}
};
};
class VoiceTranscoderAPI final : public IVoiceTranscoderAPI {
public:
virtual ~VoiceTranscoderAPI() {}
size_t MajorVersion() override;
size_t MinorVersion() override;
bool IsClientSpeaking(size_t clientIndex) override;
IEvent<size_t>& OnClientStartSpeak() override;
IEvent<size_t>& OnClientStopSpeak() override;
void MuteClient(size_t clientIndex) override;
void UnmuteClient(size_t clientIndex) override;
bool IsClientMuted(size_t clientIndex) override;
void PlaySound(size_t receiverClientIndex, const char *soundFilePath) override;
void BlockClient(size_t clientIndex) override;
void UnblockClient(size_t clientIndex) override;
bool IsClientBlocked(size_t clientIndex) override;
};
extern Event<size_t> g_OnClientStartSpeak;
extern Event<size_t> g_OnClientStopSpeak;
extern VoiceTranscoderAPI g_voiceTranscoderAPI;