#pragma once #include #include #include #include #include #include "i2c_smbus.h" #include "RGBController.h" typedef std::function&)> I2CBusDetectorFunction; typedef std::function&)> DeviceDetectorFunction; typedef std::function&, std::vector&)> I2CDeviceDetectorFunction; typedef void (*ResourceManagerCallback)(void *); class ResourceManager { public: static ResourceManager *get(); ResourceManager(); ~ResourceManager(); void RegisterI2CBus(i2c_smbus_interface *); std::vector & GetI2CBusses(); void RegisterRGBController(RGBController *); std::vector & GetRGBControllers(); void RegisterI2CBusDetector (I2CBusDetectorFunction detector); void RegisterDeviceDetector (std::string name, DeviceDetectorFunction detector); void RegisterI2CDeviceDetector (std::string name, I2CDeviceDetectorFunction detector); void RegisterDeviceListChangeCallback(ResourceManagerCallback new_callback, void * new_callback_arg); unsigned int GetDetectionPercent(); const char* GetDetectionString(); void DeviceListChanged(); void Cleanup(); void DetectDevices(); void DetectDevicesThreadFunction(); void StopDeviceDetection(); void WaitForDeviceDetection(); private: static std::unique_ptr instance; std::atomic detection_is_required; std::atomic detection_percent; const char* detection_string; std::vector busses; std::vector rgb_controllers; std::vector device_detectors; std::vector device_detector_strings; std::vector i2c_bus_detectors; std::vector i2c_device_detectors; std::vector i2c_device_detector_strings; std::thread * DetectDevicesThread; std::mutex DetectDeviceMutex; std::mutex DeviceListChangeMutex; std::vector DeviceListChangeCallbacks; std::vector DeviceListChangeCallbackArgs; };