aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xbmc/peripherals/addons/PeripheralAddon.cpp87
-rw-r--r--xbmc/peripherals/addons/PeripheralAddon.h8
-rw-r--r--xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp4
3 files changed, 91 insertions, 8 deletions
diff --git a/xbmc/peripherals/addons/PeripheralAddon.cpp b/xbmc/peripherals/addons/PeripheralAddon.cpp
index ab94ae1ca5..0f662b2b5b 100644
--- a/xbmc/peripherals/addons/PeripheralAddon.cpp
+++ b/xbmc/peripherals/addons/PeripheralAddon.cpp
@@ -79,12 +79,7 @@ CPeripheralAddon::CPeripheralAddon(ADDON::AddonProps props, bool bProvidesJoysti
CPeripheralAddon::~CPeripheralAddon(void)
{
- m_peripherals.clear();
-
- // only clear buttonMaps but don't delete them as they are owned by a CAddonJoystickInputHandling instance
- m_buttonMaps.clear();
-
- Destroy();
+ DestroyAddon();
}
void CPeripheralAddon::ResetProperties(void)
@@ -113,6 +108,8 @@ ADDON::AddonPtr CPeripheralAddon::GetRunningInstance(void) const
ADDON_STATUS CPeripheralAddon::CreateAddon(void)
{
+ CExclusiveLock lock(m_dllSection);
+
// Reset all properties to defaults
ResetProperties();
@@ -135,6 +132,25 @@ ADDON_STATUS CPeripheralAddon::CreateAddon(void)
return status;
}
+void CPeripheralAddon::DestroyAddon()
+{
+ {
+ CSingleLock lock(m_critSection);
+ m_peripherals.clear();
+ }
+
+ {
+ CSingleLock lock(m_buttonMapMutex);
+ // only clear buttonMaps but don't delete them as they are owned by a CAddonJoystickInputHandling instance
+ m_buttonMaps.clear();
+ }
+
+ {
+ CExclusiveLock lock(m_dllSection);
+ Destroy();
+ }
+}
+
bool CPeripheralAddon::GetAddonProperties(void)
{
PERIPHERAL_CAPABILITIES addonCapabilities = { };
@@ -367,7 +383,13 @@ bool CPeripheralAddon::PerformDeviceScan(PeripheralScanResults &results)
PERIPHERAL_INFO* pScanResults;
PERIPHERAL_ERROR retVal;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
LogError(retVal = m_struct.PerformDeviceScan(&peripheralCount, &pScanResults), "PerformDeviceScan()");
+
if (retVal == PERIPHERAL_NO_ERROR)
{
for (unsigned int i = 0; i < peripheralCount; i++)
@@ -409,6 +431,11 @@ bool CPeripheralAddon::ProcessEvents(void)
if (!m_bProvidesJoysticks)
return false;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
PERIPHERAL_ERROR retVal;
unsigned int eventCount = 0;
@@ -481,6 +508,14 @@ bool CPeripheralAddon::ProcessEvents(void)
bool CPeripheralAddon::SendRumbleEvent(unsigned int peripheralIndex, unsigned int driverIndex, float magnitude)
{
+ if (!m_bProvidesJoysticks)
+ return false;
+
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
PERIPHERAL_EVENT eventStruct = { };
eventStruct.peripheral_index = peripheralIndex;
@@ -496,6 +531,11 @@ bool CPeripheralAddon::GetJoystickProperties(unsigned int index, CPeripheralJoys
if (!m_bProvidesJoysticks)
return false;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
PERIPHERAL_ERROR retVal;
JOYSTICK_INFO joystickStruct;
@@ -521,6 +561,11 @@ bool CPeripheralAddon::GetFeatures(const CPeripheral* device,
if (!m_bProvidesButtonMaps)
return false;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
PERIPHERAL_ERROR retVal;
ADDON::Joystick joystickInfo;
@@ -561,6 +606,11 @@ bool CPeripheralAddon::MapFeature(const CPeripheral* device,
if (!m_bProvidesButtonMaps)
return false;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
PERIPHERAL_ERROR retVal;
ADDON::Joystick joystickInfo;
@@ -586,6 +636,11 @@ bool CPeripheralAddon::GetIgnoredPrimitives(const CPeripheral* device, Primitive
if (!m_bProvidesButtonMaps)
return false;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
PERIPHERAL_ERROR retVal;
ADDON::Joystick joystickInfo;
@@ -621,6 +676,11 @@ bool CPeripheralAddon::SetIgnoredPrimitives(const CPeripheral* device, const Pri
if (!m_bProvidesButtonMaps)
return false;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return false;
+
PERIPHERAL_ERROR retVal;
ADDON::Joystick joystickInfo;
@@ -646,6 +706,11 @@ void CPeripheralAddon::SaveButtonMap(const CPeripheral* device)
if (!m_bProvidesButtonMaps)
return;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return;
+
ADDON::Joystick joystickInfo;
GetJoystickInfo(device, joystickInfo);
@@ -665,6 +730,11 @@ void CPeripheralAddon::RevertButtonMap(const CPeripheral* device)
if (!m_bProvidesButtonMaps)
return;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return;
+
ADDON::Joystick joystickInfo;
GetJoystickInfo(device, joystickInfo);
@@ -703,6 +773,11 @@ void CPeripheralAddon::PowerOffJoystick(unsigned int index)
if (!SupportsFeature(FEATURE_POWER_OFF))
return;
+ CSharedLock lock(m_dllSection);
+
+ if (!DllLoaded())
+ return;
+
m_struct.PowerOffJoystick(index);
}
diff --git a/xbmc/peripherals/addons/PeripheralAddon.h b/xbmc/peripherals/addons/PeripheralAddon.h
index 267be3585d..c035ea6fba 100644
--- a/xbmc/peripherals/addons/PeripheralAddon.h
+++ b/xbmc/peripherals/addons/PeripheralAddon.h
@@ -25,6 +25,7 @@
#include "input/joysticks/JoystickTypes.h"
#include "peripherals/PeripheralTypes.h"
#include "threads/CriticalSection.h"
+#include "threads/SharedSection.h"
#include <map>
#include <memory>
@@ -64,6 +65,11 @@ namespace PERIPHERALS
*/
ADDON_STATUS CreateAddon(void);
+ /*!
+ * \brief Deinitialize the instance of this add-on
+ */
+ void DestroyAddon();
+
bool Register(unsigned int peripheralIndex, const PeripheralPtr& peripheral);
void UnregisterRemovedDevices(const PeripheralScanResults &results, PeripheralVector& removedPeripherals);
void GetFeatures(std::vector<PeripheralFeature> &features) const;
@@ -166,5 +172,7 @@ namespace PERIPHERALS
PERIPHERAL_PROPERTIES m_info;
KodiToAddonFuncTable_Peripheral m_struct;
+
+ CSharedSection m_dllSection;
};
}
diff --git a/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp b/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp
index 6e9526f435..303dd828de 100644
--- a/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp
+++ b/xbmc/peripherals/bus/virtual/PeripheralBusAddon.cpp
@@ -57,7 +57,7 @@ CPeripheralBusAddon::~CPeripheralBusAddon()
// destroy any (loaded) addons
for (const auto& addon : m_addons)
- addon->Destroy();
+ addon->DestroyAddon();
m_failedAddons.clear();
m_addons.clear();
@@ -509,7 +509,7 @@ void CPeripheralBusAddon::UpdateAddons(void)
if (erased)
{
CSingleExit exit(m_critSection);
- erased->Destroy();
+ erased->DestroyAddon();
}
}
}