#include #include #include #include #include #include #include "lighthouse_driver_wrapper.h" #include "imu_data_provider.h" #include "sauna_device_driver.h" #if defined(_WIN32) #define HMD_DLL_EXPORT extern "C" __declspec(dllexport) #define HMD_DLL_IMPORT extern "C" __declspec(dllimport) #elif defined(__GNUC__) || defined(COMPILER_GCC) || defined(__APPLE__) #define HMD_DLL_EXPORT extern "C" __attribute__((visibility("default"))) #define HMD_DLL_IMPORT extern "C") #else #error "Unsupported Platform." #endif using namespace vr; using namespace sauna; /** * @brief Main driver provider class * * This class is the main entry point for our custom driver. * It wraps the lighthouse driver and adds our custom functionality. */ class SaunaDeviceProvider : public IServerTrackedDeviceProvider { public: SaunaDeviceProvider() : m_bInitialized(false) { } virtual ~SaunaDeviceProvider() { Cleanup(); } virtual EVRInitError Init(IVRDriverContext *pDriverContext) override { VR_INIT_SERVER_DRIVER_CONTEXT(pDriverContext); VRDriverLog()->Log("Initializing Sauna Driver"); m_pLighthouseDriver = std::make_unique(); if (!m_pLighthouseDriver->Initialize()) { VRDriverLog()->Log("Failed to initialize lighthouse driver"); return VRInitError_Driver_Failed; } m_pIMUDataProvider = std::make_unique(); if (!m_pIMUDataProvider->Initialize()) { VRDriverLog()->Log("Failed to initialize IMU data provider"); return VRInitError_Driver_Failed; } // Get the lighthouse driver provider IServerTrackedDeviceProvider* pLighthouseProvider = m_pLighthouseDriver->GetDriverProvider(); if (!pLighthouseProvider) { VRDriverLog()->Log("Failed to get lighthouse driver provider"); return VRInitError_Driver_Failed; } // Initialize our device wrappers // We'll create these on demand when devices are added m_bInitialized = true; VRDriverLog()->Log("Sauna Driver initialized successfully"); return VRInitError_None; } virtual void Cleanup() override { VRDriverLog()->Log("Cleaning up Sauna Driver"); if (m_pIMUDataProvider) { m_pIMUDataProvider->Shutdown(); m_pIMUDataProvider.reset(); } if (m_pLighthouseDriver) { m_pLighthouseDriver->Shutdown(); m_pLighthouseDriver.reset(); } m_bInitialized = false; VR_CLEANUP_SERVER_DRIVER_CONTEXT(); } virtual const char * const *GetInterfaceVersions() override { return vr::k_InterfaceVersions; } virtual void RunFrame() override { if (!m_bInitialized) return; // Forward the call to the lighthouse driver if (m_pLighthouseDriver) { m_pLighthouseDriver->RunFrame(); } // Process any pending IMU data // In a real implementation, we would collect IMU data here // from the devices and update the IMU data provider } virtual bool ShouldBlockStandbyMode() override { // Forward the call to the lighthouse driver if (m_pLighthouseDriver && m_pLighthouseDriver->GetDriverProvider()) { return m_pLighthouseDriver->GetDriverProvider()->ShouldBlockStandbyMode(); } return false; } virtual void EnterStandby() override { // Forward the call to the lighthouse driver if (m_pLighthouseDriver) { m_pLighthouseDriver->EnterStandby(); } } virtual void LeaveStandby() override { // Forward the call to the lighthouse driver if (m_pLighthouseDriver) { m_pLighthouseDriver->LeaveStandby(); } } private: bool m_bInitialized; std::unique_ptr m_pLighthouseDriver; std::unique_ptr m_pIMUDataProvider; std::vector> m_vDeviceDrivers; }; // Driver factory method HMD_DLL_EXPORT void *HmdDriverFactory(const char *pInterfaceName, int *pReturnCode) { if (0 == strcmp(IServerTrackedDeviceProvider_Version, pInterfaceName)) { return new SaunaDeviceProvider(); } if (pReturnCode) *pReturnCode = VRInitError_Init_InterfaceNotFound; return nullptr; }