xbmc
PeripheralBusAndroid.h
1 /*
2  * Copyright (C) 2016-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "peripherals/PeripheralTypes.h"
12 #include "peripherals/bus/PeripheralBus.h"
13 #include "threads/CriticalSection.h"
14 
15 #include "platform/android/activity/IInputDeviceCallbacks.h"
16 #include "platform/android/activity/IInputDeviceEventHandler.h"
17 #include "platform/android/peripherals/AndroidJoystickState.h"
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 class CJNIViewInputDevice;
25 
26 namespace PERIPHERALS
27 {
29  public IInputDeviceCallbacks,
31  {
32  public:
33  explicit CPeripheralBusAndroid(CPeripherals& manager);
34  ~CPeripheralBusAndroid() override;
35 
36  // specialisation of CPeripheralBus
37  bool InitializeProperties(CPeripheral& peripheral) override;
38  void Initialise(void) override;
39  void ProcessEvents() override;
40 
41  // implementations of IInputDeviceCallbacks
42  void OnInputDeviceAdded(int deviceId) override;
43  void OnInputDeviceChanged(int deviceId) override;
44  void OnInputDeviceRemoved(int deviceId) override;
45 
46  // implementation of IInputDeviceEventHandler
47  bool OnInputDeviceEvent(const AInputEvent* event) override;
48 
49  protected:
50  // implementation of CPeripheralBus
51  bool PerformDeviceScan(PeripheralScanResults &results) override;
52 
53  private:
54  static PeripheralScanResults GetInputDevices();
55 
56  static std::string GetDeviceLocation(int deviceId);
57  static bool GetDeviceId(const std::string& deviceLocation, int& deviceId);
58 
59  static bool ConvertToPeripheralScanResult(const CJNIViewInputDevice& inputDevice, PeripheralScanResult& peripheralScanResult);
60 
61  static void LogInputDevice(const CJNIViewInputDevice &device);
62  static std::vector<std::pair<int, const char*>> GetInputSources();
63 
64  mutable std::map<int, CAndroidJoystickState> m_joystickStates;
65  PeripheralScanResults m_scanResults;
66  CCriticalSection m_critSectionStates;
67  CCriticalSection m_critSectionResults;
68  };
69  using PeripheralBusAndroidPtr = std::shared_ptr<CPeripheralBusAndroid>;
70 }
Definition: PeripheralTypes.h:348
Definition: PeripheralTypes.h:318
void Initialise(void) override
Initialise this bus and start a polling thread if this bus needs polling.
Definition: PeripheralBusAndroid.cpp:123
Definition: RetroPlayerInput.h:15
Definition: IInputDeviceCallbacks.h:11
bool InitializeProperties(CPeripheral &peripheral) override
Initialize the properties of a peripheral with a known location.
Definition: PeripheralBusAndroid.cpp:63
bool PerformDeviceScan(PeripheralScanResults &results) override
Scan for devices on this bus and add them to the results list. This will have to be implemented for e...
Definition: PeripheralBusAndroid.cpp:313
Definition: PeripheralBus.h:34
void ProcessEvents() override
Poll for events.
Definition: PeripheralBusAndroid.cpp:129
Definition: IInputDeviceEventHandler.h:13
Definition: PeripheralBusAndroid.h:28
Definition: Peripheral.h:62
Definition: Peripherals.h:49