2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "peripherals/PeripheralTypes.h"
12 #include "peripherals/bus/PeripheralBus.h"
13 #include "threads/CriticalSection.h"
15 #include "platform/android/activity/IInputDeviceCallbacks.h"
16 #include "platform/android/activity/IInputDeviceEventHandler.h"
17 #include "platform/android/peripherals/AndroidJoystickState.h"
24 class CJNIViewInputDevice
;
28 class CPeripheralBusAndroid
: public CPeripheralBus
,
29 public IInputDeviceCallbacks
,
30 public IInputDeviceEventHandler
33 explicit CPeripheralBusAndroid(CPeripherals
& manager
);
34 ~CPeripheralBusAndroid() override
;
36 // specialisation of CPeripheralBus
37 bool InitializeProperties(CPeripheral
& peripheral
) override
;
38 bool InitializeButtonMap(const CPeripheral
& peripheral
,
39 KODI::JOYSTICK::IButtonMap
& buttonMap
) const override
;
40 void Initialise(void) override
;
41 void ProcessEvents() override
;
43 // implementations of IInputDeviceCallbacks
44 void OnInputDeviceAdded(int deviceId
) override
;
45 void OnInputDeviceChanged(int deviceId
) override
;
46 void OnInputDeviceRemoved(int deviceId
) override
;
48 // implementation of IInputDeviceEventHandler
49 bool OnInputDeviceEvent(const AInputEvent
* event
) override
;
52 // implementation of CPeripheralBus
53 bool PerformDeviceScan(PeripheralScanResults
& results
) override
;
56 static PeripheralScanResults
GetInputDevices();
58 static std::string
GetDeviceLocation(int deviceId
);
59 static bool GetDeviceId(const std::string
& deviceLocation
, int& deviceId
);
61 static bool ConvertToPeripheralScanResult(const CJNIViewInputDevice
& inputDevice
,
62 PeripheralScanResult
& peripheralScanResult
);
64 static void LogInputDevice(const CJNIViewInputDevice
& device
);
65 static std::vector
<std::pair
<int, const char*>> GetInputSources();
67 mutable std::map
<int, CAndroidJoystickState
> m_joystickStates
;
68 PeripheralScanResults m_scanResults
;
69 mutable CCriticalSection m_critSectionStates
;
70 CCriticalSection m_critSectionResults
;
72 using PeripheralBusAndroidPtr
= std::shared_ptr
<CPeripheralBusAndroid
>;
73 } // namespace PERIPHERALS