From 2c07942478f839f6082dbc87aecb94b4a34bf085 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 27 Oct 2018 16:52:28 -0500 Subject: [PATCH] Move the SMXManager from SMX to SMXManager. --- sdk/Windows/SMX.cpp | 28 +++++++++++++--------------- sdk/Windows/SMXManager.cpp | 2 ++ sdk/Windows/SMXManager.h | 3 +++ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/sdk/Windows/SMX.cpp b/sdk/Windows/SMX.cpp index a9f48f8..de7f29c 100644 --- a/sdk/Windows/SMX.cpp +++ b/sdk/Windows/SMX.cpp @@ -23,12 +23,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser return TRUE; } -static shared_ptr g_pSMX; - // DLL interface: SMX_API void SMX_Start(SMXUpdateCallback callback, void *pUser) { - if(g_pSMX != NULL) + if(SMXManager::g_pSMX != NULL) return; // The C++ interface takes a std::function, which doesn't need a user pointer. We add @@ -38,12 +36,12 @@ SMX_API void SMX_Start(SMXUpdateCallback callback, void *pUser) }; // Log(ssprintf("Struct sizes (native): %i %i %i\n", sizeof(SMXConfig), sizeof(SMXInfo), sizeof(SMXSensorTestModeData))); - g_pSMX = make_shared(UpdateCallback); + SMXManager::g_pSMX = make_shared(UpdateCallback); } SMX_API void SMX_Stop() { - g_pSMX.reset(); + SMXManager::g_pSMX.reset(); } SMX_API void SMX_SetLogCallback(SMXLogCallback callback) @@ -54,14 +52,14 @@ SMX_API void SMX_SetLogCallback(SMXLogCallback callback) }); } -SMX_API bool SMX_GetConfig(int pad, SMXConfig *config) { return g_pSMX->GetDevice(pad)->GetConfig(*config); } -SMX_API void SMX_SetConfig(int pad, const SMXConfig *config) { g_pSMX->GetDevice(pad)->SetConfig(*config); } -SMX_API void SMX_GetInfo(int pad, SMXInfo *info) { g_pSMX->GetDevice(pad)->GetInfo(*info); } -SMX_API uint16_t SMX_GetInputState(int pad) { return g_pSMX->GetDevice(pad)->GetInputState(); } -SMX_API void SMX_FactoryReset(int pad) { g_pSMX->GetDevice(pad)->FactoryReset(); } -SMX_API void SMX_ForceRecalibration(int pad) { g_pSMX->GetDevice(pad)->ForceRecalibration(); } -SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode) { g_pSMX->GetDevice(pad)->SetSensorTestMode((SensorTestMode) mode); } -SMX_API bool SMX_GetTestData(int pad, SMXSensorTestModeData *data) { return g_pSMX->GetDevice(pad)->GetTestData(*data); } -SMX_API void SMX_SetLights(const char lightsData[864]) { g_pSMX->SetLights(string(lightsData, 864)); } -SMX_API void SMX_ReenableAutoLights() { g_pSMX->ReenableAutoLights(); } +SMX_API bool SMX_GetConfig(int pad, SMXConfig *config) { return SMXManager::g_pSMX->GetDevice(pad)->GetConfig(*config); } +SMX_API void SMX_SetConfig(int pad, const SMXConfig *config) { SMXManager::g_pSMX->GetDevice(pad)->SetConfig(*config); } +SMX_API void SMX_GetInfo(int pad, SMXInfo *info) { SMXManager::g_pSMX->GetDevice(pad)->GetInfo(*info); } +SMX_API uint16_t SMX_GetInputState(int pad) { return SMXManager::g_pSMX->GetDevice(pad)->GetInputState(); } +SMX_API void SMX_FactoryReset(int pad) { SMXManager::g_pSMX->GetDevice(pad)->FactoryReset(); } +SMX_API void SMX_ForceRecalibration(int pad) { SMXManager::g_pSMX->GetDevice(pad)->ForceRecalibration(); } +SMX_API void SMX_SetTestMode(int pad, SensorTestMode mode) { SMXManager::g_pSMX->GetDevice(pad)->SetSensorTestMode((SensorTestMode) mode); } +SMX_API bool SMX_GetTestData(int pad, SMXSensorTestModeData *data) { return SMXManager::g_pSMX->GetDevice(pad)->GetTestData(*data); } +SMX_API void SMX_SetLights(const char lightsData[864]) { SMXManager::g_pSMX->SetLights(string(lightsData, 864)); } +SMX_API void SMX_ReenableAutoLights() { SMXManager::g_pSMX->ReenableAutoLights(); } SMX_API const char *SMX_Version() { return SMX_BUILD_VERSION; } diff --git a/sdk/Windows/SMXManager.cpp b/sdk/Windows/SMXManager.cpp index 10676ed..baa0593 100644 --- a/sdk/Windows/SMXManager.cpp +++ b/sdk/Windows/SMXManager.cpp @@ -13,6 +13,8 @@ namespace { Mutex g_Lock; } +shared_ptr SMXManager::g_pSMX; + SMX::SMXManager::SMXManager(function pCallback): m_UserCallbackThread("SMXUserCallbackThread") { diff --git a/sdk/Windows/SMXManager.h b/sdk/Windows/SMXManager.h index cf079f3..133977f 100644 --- a/sdk/Windows/SMXManager.h +++ b/sdk/Windows/SMXManager.h @@ -33,6 +33,9 @@ struct SMXControllerState class SMXManager { public: + // Our singleton: + static shared_ptr g_pSMX; + // pCallback is a function to be called when something changes on any device. This allows // efficiently detecting when a panel is pressed or other changes happen. SMXManager(function pCallback);