Formatted variable names to conform with snail case standard

This commit is contained in:
rockerbacon 2019-09-20 18:24:30 -03:00
parent 34509ad6d6
commit 21b6c2367f
2 changed files with 29 additions and 29 deletions

View File

@ -18,71 +18,71 @@
#define MAX_CONNECTION_TRIES 10 #define MAX_CONNECTION_TRIES 10
#define TIME_BETWEEN_CONNECTION_TRIES 1s #define TIME_BETWEEN_CONNECTION_TRIES 1s
void stopAndDeletePairedDevice (PairedDevice &pairedDevice) void stopAndDeletePairedDevice (ConnectedDevice &connected_device)
{ {
log_printf(INFO, "%s (Device %d on %s) disconnected", pairedDevice.device->name.c_str(), pairedDevice.device->index, pairedDevice.device->path.c_str()); log_printf(INFO, "%s (Device %d on %s) disconnected", connected_device.device->name.c_str(), connected_device.device->index, connected_device.device->path.c_str());
pairedDevice.device->stop(); connected_device.device->stop();
pairedDevice.associatedThread.join(); connected_device.associatedThread.join();
delete(pairedDevice.device); delete(connected_device.device);
} }
DeviceFinder::~DeviceFinder() DeviceFinder::~DeviceFinder()
{ {
this->devicesMutex.lock(); this->devices_mutex.lock();
for (auto it = this->devices.begin(); it != this->devices.end(); it++) { for (auto it = this->devices.begin(); it != this->devices.end(); it++) {
for (auto jt = it->second.begin(); jt != it->second.end(); jt++) { for (auto jt = it->second.begin(); jt != it->second.end(); jt++) {
stopAndDeletePairedDevice(jt->second); stopAndDeletePairedDevice(jt->second);
} }
} }
this->devicesMutex.unlock(); this->devices_mutex.unlock();
} }
void DeviceFinder::insertNewDevice(const std::string &path, HIDPP::DeviceIndex index) void DeviceFinder::insertNewDevice(const std::string &path, HIDPP::DeviceIndex index)
{ {
Device *device = new Device(path, index); Device *device = new Device(path, index);
this->devicesMutex.lock(); this->devices_mutex.lock();
log_printf(INFO, "%s detected: device %d on %s", device->name.c_str(), index, path.c_str()); log_printf(INFO, "%s detected: device %d on %s", device->name.c_str(), index, path.c_str());
auto pathBucket = this->devices.emplace(path, std::map<HIDPP::DeviceIndex, PairedDevice>()).first; auto path_bucket = this->devices.emplace(path, std::map<HIDPP::DeviceIndex, ConnectedDevice>()).first;
pathBucket->second.emplace(index, PairedDevice{ path_bucket->second.emplace(index, ConnectedDevice{
device, device,
std::thread([device]() { std::thread([device]() {
device->start(); device->start();
}) })
}); });
this->devicesMutex.unlock(); this->devices_mutex.unlock();
} }
void DeviceFinder::stopAndDeleteAllDevicesIn (const std::string &path) void DeviceFinder::stopAndDeleteAllDevicesIn (const std::string &path)
{ {
this->devicesMutex.lock(); this->devices_mutex.lock();
auto pathBucket = this->devices.find(path); auto path_bucket = this->devices.find(path);
if (pathBucket != this->devices.end()) if (path_bucket != this->devices.end())
{ {
for (auto& indexBucket : pathBucket->second) { for (auto& index_bucket : path_bucket->second) {
stopAndDeletePairedDevice(indexBucket.second); stopAndDeletePairedDevice(index_bucket.second);
} }
this->devices.erase(pathBucket); this->devices.erase(path_bucket);
} }
this->devicesMutex.unlock(); this->devices_mutex.unlock();
log_printf(WARN, "Attempted to disconnect not previously connected devices on %s", path.c_str()); log_printf(WARN, "Attempted to disconnect not previously connected devices on %s", path.c_str());
} }
void DeviceFinder::stopAndDeleteDevice (const std::string &path, HIDPP::DeviceIndex index) void DeviceFinder::stopAndDeleteDevice (const std::string &path, HIDPP::DeviceIndex index)
{ {
this->devicesMutex.lock(); this->devices_mutex.lock();
auto pathBucket = this->devices.find(path); auto path_bucket = this->devices.find(path);
if (pathBucket != this->devices.end()) if (path_bucket != this->devices.end())
{ {
auto indexBucket = pathBucket->second.find(index); auto index_bucket = path_bucket->second.find(index);
if (indexBucket != pathBucket->second.end()) if (index_bucket != path_bucket->second.end())
{ {
stopAndDeletePairedDevice(indexBucket->second); stopAndDeletePairedDevice(index_bucket->second);
pathBucket->second.erase(indexBucket); path_bucket->second.erase(index_bucket);
} }
} }
this->devicesMutex.unlock(); this->devices_mutex.unlock();
log_printf(WARN, "Attempted to disconnect not previously connected device %d on %s", index, path.c_str()); log_printf(WARN, "Attempted to disconnect not previously connected device %d on %s", index, path.c_str());
} }

View File

@ -14,7 +14,7 @@
class Device; class Device;
struct PairedDevice { struct ConnectedDevice {
Device *device; Device *device;
std::thread associatedThread; std::thread associatedThread;
}; };
@ -31,8 +31,8 @@ protected:
void addDevice(const char* path); void addDevice(const char* path);
void removeDevice(const char* path); void removeDevice(const char* path);
private: private:
std::mutex devicesMutex; std::mutex devices_mutex;
std::map<std::string, std::map<HIDPP::DeviceIndex, PairedDevice>> devices; std::map<std::string, std::map<HIDPP::DeviceIndex, ConnectedDevice>> devices;
}; };
extern DeviceFinder* finder; extern DeviceFinder* finder;