-
-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathResourceManager.h
More file actions
234 lines (199 loc) · 10.7 KB
/
Copy pathResourceManager.h
File metadata and controls
234 lines (199 loc) · 10.7 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*---------------------------------------------------------*\
| ResourceManager.h |
| |
| OpenRGB Resource Manager controls access to application |
| components including RGBControllers, I2C interfaces, |
| and network SDK components |
| |
| Adam Honse (CalcProgrammer1) 27 Sep 2020 |
| |
| This file is part of the OpenRGB project |
| SPDX-License-Identifier: GPL-2.0-or-later |
\*---------------------------------------------------------*/
#pragma once
#include <memory>
#include <vector>
#include <functional>
#include <thread>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
#include "DetectionManager.h"
#include "hidapi_wrapper.h"
#include "i2c_smbus.h"
#include "ResourceManagerCallback.h"
#include "filesystem.h"
#include "find_usb_serial_port.h"
using json = nlohmann::json;
class LogManager;
class NetworkClient;
class NetworkServer;
class PluginManagerInterface;
class ProfileManager;
class RGBController;
class SettingsManager;
typedef struct
{
unsigned short vendor_id;
unsigned short product_id;
unsigned short release_number;
unsigned short usage_page;
unsigned short usage;
int interface_number;
std::string serial_number;
std::string manufacturer_string;
std::string product_string;
std::string path;
} HIDDeviceInfo;
typedef struct
{
unsigned short vendor_id;
unsigned short product_id;
std::string serial_number;
std::string manufacturer_string;
std::string product_string;
} USBDeviceInfo;
class ResourceManager
{
public:
ResourceManager();
~ResourceManager();
/*-----------------------------------------------------*\
| ResourceManager Global Instance Accessor |
\*-----------------------------------------------------*/
static ResourceManager* get();
/*-----------------------------------------------------*\
| Resource Accessors |
\*-----------------------------------------------------*/
std::vector<NetworkClient*>& GetClients();
filesystem::path GetConfigurationDirectory();
std::string GetDefaultServerHost();
unsigned short GetDefaultServerPort();
LogManager* GetLogManager();
std::vector<HIDDeviceInfo> GetHIDDeviceInfo();
std::vector<i2c_smbus_interface*>& GetI2CBuses();
std::vector<i2c_smbus_info> GetI2CBusInfo();
std::vector<std::string> GetSerialPorts();
std::vector<SerialDeviceInfo> GetUSBSerialPorts();
std::vector<USBDeviceInfo> GetUSBDeviceInfo();
PluginManagerInterface* GetPluginManager();
ProfileManager* GetProfileManager();
std::vector<RGBController*>& GetRGBControllers();
std::vector<RGBControllerInterface*>& GetRGBControllerInterfaces();
NetworkServer* GetServer();
SettingsManager* GetSettingsManager();
void SetConfigurationDirectory(const filesystem::path &directory);
void SetDefaultServerHost(std::string server_host);
void SetDefaultServerPort(unsigned short server_port);
void SetPluginManager(PluginManagerInterface* plugin_manager_ptr);
/*-----------------------------------------------------*\
| Network Client Registration |
\*-----------------------------------------------------*/
void RegisterNetworkClient(NetworkClient* new_client);
void UnregisterNetworkClient(NetworkClient* network_client);
/*-----------------------------------------------------*\
| Local Client Accessors |
\*-----------------------------------------------------*/
NetworkClient* GetLocalClient();
unsigned int GetLocalClientProtocolVersion();
bool IsLocalClient();
/*-----------------------------------------------------*\
| Callback Registration Functions |
\*-----------------------------------------------------*/
void RegisterResourceManagerCallback(ResourceManagerCallback new_callback, void * new_callback_arg);
void UnregisterResourceManagerCallback(ResourceManagerCallback new_callback, void * new_callback_arg);
/*-----------------------------------------------------*\
| Functions to manage detection |
\*-----------------------------------------------------*/
bool GetDetectionEnabled();
unsigned int GetDetectionPercent();
std::string GetDetectionString();
void StopDeviceDetection();
void RescanDevices();
void UpdateDeviceList();
void WaitForDetection();
/*-----------------------------------------------------*\
| Functions to signal update callbacks |
\*-----------------------------------------------------*/
void SignalResourceManagerUpdate(unsigned int update_reason);
void Initialize(bool tryConnect, bool detectDevices, bool startServer, bool applyPostOptions);
void InitializeServer();
void WaitForInitialization();
private:
bool AttemptLocalConnection();
void SetupConfigurationDirectory();
/*-----------------------------------------------------*\
| Static pointer to shared instance of ResourceManager |
\*-----------------------------------------------------*/
static ResourceManager* instance;
/*-----------------------------------------------------*\
| Auto connection permitting flag |
\*-----------------------------------------------------*/
bool tryAutoConnect;
/*-----------------------------------------------------*\
| Detection enabled flag |
\*-----------------------------------------------------*/
bool detection_enabled;
/*-----------------------------------------------------*\
| Auto connection active flag |
\*-----------------------------------------------------*/
bool auto_connection_active;
/*-----------------------------------------------------*\
| Auto connection client pointer |
\*-----------------------------------------------------*/
NetworkClient * auto_connection_client;
/*-----------------------------------------------------*\
| Auto connection permitting flag |
\*-----------------------------------------------------*/
bool start_server;
/*-----------------------------------------------------*\
| Auto connection permitting flag |
\*-----------------------------------------------------*/
bool apply_post_options;
/*-----------------------------------------------------*\
| Initialization completion flag |
\*-----------------------------------------------------*/
std::atomic<bool> init_finished;
/*-----------------------------------------------------*\
| Plugin Manager |
\*-----------------------------------------------------*/
PluginManagerInterface* plugin_manager;
/*-----------------------------------------------------*\
| Profile Manager |
\*-----------------------------------------------------*/
ProfileManager* profile_manager;
/*-----------------------------------------------------*\
| Settings Manager |
\*-----------------------------------------------------*/
SettingsManager* settings_manager;
/*-----------------------------------------------------*\
| RGBControllers |
\*-----------------------------------------------------*/
std::vector<RGBController*> rgb_controllers;
std::vector<RGBController*> rgb_controllers_hw;
std::vector<RGBControllerInterface*> rgb_controller_interfaces;
/*-----------------------------------------------------*\
| Network Server |
\*-----------------------------------------------------*/
NetworkServer* server;
std::string default_server_host;
unsigned short default_server_port;
/*-----------------------------------------------------*\
| Network Clients |
\*-----------------------------------------------------*/
std::vector<NetworkClient*> clients;
/*-----------------------------------------------------*\
| Device List Mutex |
\*-----------------------------------------------------*/
std::mutex DeviceListChangeMutex;
/*-----------------------------------------------------*\
| ResourceManager Callbacks |
\*-----------------------------------------------------*/
std::vector<ResourceManagerCallback> ResourceManagerCallbacks;
std::vector<void *> ResourceManagerCallbackArgs;
std::mutex ResourceManagerCallbackMutex;
/*-----------------------------------------------------*\
| OpenRGB configuration directory path |
\*-----------------------------------------------------*/
filesystem::path config_dir;
};