-
Notifications
You must be signed in to change notification settings - Fork 0
/
srsinterfaceplugin.h
121 lines (95 loc) · 4.03 KB
/
srsinterfaceplugin.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//==============================================================================
/**
@file SRSInterfacePlugin.h
@brief CPU plugin
@copyright (c) 2018, Corsair Memory, Inc.
This source code is licensed under the MIT-style license found in the LICENSE file.
**/
//==============================================================================
#include "Common/ESDBasePlugin.h"
#include <mutex>
#include <thread>
#include <atomic>
class SRSInterfacePlugin : public ESDBasePlugin
{
public:
SRSInterfacePlugin();
virtual ~SRSInterfacePlugin();
void KeyDownForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) override;
void KeyUpForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) override;
void TitleParametersDidChange(const std::string& inAction, const std::string& inContext, const json& inPayload, const std::string& inDeviceID) override;
void SendToPlugin(const std::string& inAction, const std::string& inContext, const json& inPayload, const std::string& inDeviceID) override;
void WillAppearForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) override;
void WillDisappearForAction(const std::string& inAction, const std::string& inContext, const json &inPayload, const std::string& inDeviceID) override;
void DeviceDidConnect(const std::string& inDeviceID, const json &inDeviceInfo) override;
void DeviceDidDisconnect(const std::string& inDeviceID) override;
void UpdateSRSData(class SRSData* srsData);
private:
const int serverStopDelayTime = 60;
std::mutex mVisibleContextsMutex;
std::map < std::string, class SRSActionSettings > mVisibleContexts;
class SRSInterface* srs_server = nullptr;
json prevJsonData = 0;
bool radioChange = false; // Update radios if there is a settings change
void DrawContext(const std::string& context, unsigned int radio, class SRSData* srsData, const class SRSActionSettings& as);
};
/*
class SRSInterfacePlugin
{
private:
std::mutex mVisibleContextsMutex;
std::map<std::string, SRSActionSettings> visibleContexts;
std::thread tSenderNameShowTimer;
std::atomic<bool> stopSenderNameShowTimer;
std::condition_variable cvStopSenderNameShowTimer;
std::chrono::seconds timeToWait;
public:
void IsAppearing(const std::string& context)
{
std::scoped_lock lock(mVisibleContextsMutex);
SRSActionSettings newSetting;
visibleContexts.insert(std::make_pair(context, newSetting));
if (visibleContexts.size() == 1)
{
stopSenderNameShowTimer = false;
if (!tSenderNameShowTimer.joinable()) tSenderNameShowTimer = std::thread(&SRSInterfacePlugin::SenderNameShowTimer, this);
}
}
void IsDisappearing(const std::string& context)
{
std::cout << "Disappearing before lock\n";
std::scoped_lock lock(mVisibleContextsMutex);
visibleContexts.erase(context);
std::cout << "Disappering after lock\n";
if (visibleContexts.size() == 0)
{
stopSenderNameShowTimer = true;
cvStopSenderNameShowTimer.notify_all();
std::cout << "Notifying done in disappearing, joining.\n";
if (tSenderNameShowTimer.joinable()) tSenderNameShowTimer.join();
std::cout << "Joining done\n";
}
}
void SenderNameShowTimer()
{
std::mutex localMutex;
std::unique_lock<std::mutex> lock(localMutex);
while (!stopSenderNameShowTimer)
{
if (cvStopSenderNameShowTimer.wait_for(lock, timeToWait) == std::cv_status::timeout)
{
std::scoped_lock lock(mVisibleContextsMutex);
std::cout << "Timer\n";
for (auto& it : visibleContexts)
{
//Do something
}
}
}
}
SRSInterfacePlugin()
{
timeToWait = std::chrono::seconds(1);
}
};
*/