1 /*
2  *  Copyright (C) 2015-2020 Garrett Brown
3  *  Copyright (C) 2015-2020 Team Kodi
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSE.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "StorageTypes.h"
12 #include "buttonmapper/ButtonMapTypes.h"
13 
14 #include <chrono>
15 #include <set>
16 #include <stdint.h>
17 #include <string>
18 
19 namespace JOYSTICK
20 {
21   class IControllerHelper;
22 
23   class CButtonMap
24   {
25   public:
26     CButtonMap(const std::string& strResourcePath, IControllerHelper *controllerHelper);
27     CButtonMap(const std::string& strResourcePath, const DevicePtr& device, IControllerHelper *controllerHelper);
28 
~CButtonMap(void)29     virtual ~CButtonMap(void) { }
30 
Path(void)31     const std::string& Path(void) const { return m_strResourcePath; }
32 
Device(void)33     const DevicePtr& Device(void) const { return m_device; }
34 
35     bool IsValid(void) const;
36 
37     const ButtonMap& GetButtonMap();
38 
39     void MapFeatures(const std::string& controllerId, const FeatureVector& features);
40 
41     bool SaveButtonMap();
42 
43     bool RevertButtonMap();
44 
45     bool ResetButtonMap(const std::string& controllerId);
46 
47     bool Refresh(void);
48 
49   protected:
50     virtual bool Load(void) = 0;
51     virtual bool Save(void) const = 0;
52 
53     static void MergeFeature(const kodi::addon::JoystickFeature& feature, FeatureVector& features, const std::string& controllerId);
54 
55     static void Sanitize(FeatureVector& features, const std::string& controllerId);
56 
57     // Construction parameter
58     IControllerHelper *const m_controllerHelper;
59 
60     const std::string m_strResourcePath;
61     DevicePtr         m_device;
62     DevicePtr         m_originalDevice;
63     ButtonMap         m_buttonMap;
64     ButtonMap         m_originalButtonMap;
65 
66   private:
67     std::chrono::steady_clock::time_point m_timestamp;
68     bool    m_bModified;
69   };
70 }
71