Use unique pointer for global device manager

Changed from raw pointer to a unique_ptr, also renamed from finder to
device_manager
This commit is contained in:
pixl 2020-06-24 22:27:19 -04:00
parent 5f76ccc4ac
commit 181be50f88
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
3 changed files with 8 additions and 8 deletions

View File

@ -44,7 +44,7 @@ namespace logid
std::map<std::string, std::shared_ptr<Receiver>> _receivers; std::map<std::string, std::shared_ptr<Receiver>> _receivers;
}; };
extern DeviceManager* finder; extern std::unique_ptr<DeviceManager> device_manager;
} }
#endif //LOGID_DEVICEMANAGER_H #endif //LOGID_DEVICEMANAGER_H

View File

@ -39,10 +39,10 @@ std::string config_file = DEFAULT_CONFIG_FILE;
LogLevel logid::global_loglevel = INFO; LogLevel logid::global_loglevel = INFO;
// Configuration* logid::global_config; // Configuration* logid::global_config;
DeviceManager* logid::finder; std::unique_ptr<DeviceManager> logid::device_manager;
bool logid::kill_logid = false; bool logid::kill_logid = false;
std::mutex logid::finder_reloading; std::mutex logid::device_manager_reload;
enum class Option enum class Option
{ {
@ -172,12 +172,12 @@ int main(int argc, char** argv)
*/ */
// Scan devices, create listeners, handlers, etc. // Scan devices, create listeners, handlers, etc.
finder = new DeviceManager(); device_manager = std::make_unique<DeviceManager>();
while(!kill_logid) { while(!kill_logid) {
finder_reloading.lock(); device_manager_reload.lock();
finder_reloading.unlock(); device_manager_reload.unlock();
finder->run(); device_manager->run();
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -26,7 +26,7 @@ namespace logid
// void reload(); // void reload();
extern bool kill_logid; extern bool kill_logid;
extern std::mutex finder_reloading; extern std::mutex device_manager_reload;
} }
#endif //LOGID_LOGID_H #endif //LOGID_LOGID_H