[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / peripherals / devices / Peripheral.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <set>
23 #include "utils/StdString.h"
24 #include "peripherals/PeripheralTypes.h"
25
26 class TiXmlDocument;
27
28 namespace PERIPHERALS
29 {
30   class CGUIDialogPeripheralSettings;
31
32   class CPeripheral
33   {
34     friend class CGUIDialogPeripheralSettings;
35
36   public:
37     CPeripheral(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId);
38     CPeripheral(void);
39     virtual ~CPeripheral(void);
40
41     bool operator ==(const CPeripheral &right) const;
42     bool operator !=(const CPeripheral &right) const;
43
44     const CStdString &FileLocation(void) const     { return m_strFileLocation; }
45     const CStdString &Location(void) const         { return m_strLocation; }
46     int VendorId(void) const                       { return m_iVendorId; }
47     const char *VendorIdAsString(void) const       { return m_strVendorId.c_str(); }
48     int ProductId(void) const                      { return m_iProductId; }
49     const char *ProductIdAsString(void) const      { return m_strProductId.c_str(); }
50     const PeripheralType Type(void) const          { return m_type; }
51     const PeripheralBusType GetBusType(void) const { return m_busType; };
52     const CStdString &DeviceName(void) const       { return m_strDeviceName; }
53     bool IsHidden(void) const                      { return m_bHidden; }
54     void SetHidden(bool bSetTo = true)             { m_bHidden = bSetTo; }
55     const CStdString &GetVersionInfo(void) const   { return m_strVersionInfo; }
56
57     /*!
58      * @brief Check whether this device has the given feature.
59      * @param feature The feature to check for.
60      * @return True when the device has the feature, false otherwise.
61      */
62     bool HasFeature(const PeripheralFeature feature) const;
63
64     /*!
65      * @brief Get all features that are supported by this device.
66      * @param features The features.
67      */
68     void GetFeatures(std::vector<PeripheralFeature> &features) const;
69
70     /*!
71      * @brief Initialises the peripheral.
72      * @return True when the peripheral has been initialised succesfully, false otherwise.
73      */
74     bool Initialise(void);
75
76     /*!
77      * @brief Initialise one of the features of this peripheral.
78      * @param feature The feature to initialise.
79      * @return True when the feature has been initialised succesfully, false otherwise.
80      */
81     virtual bool InitialiseFeature(const PeripheralFeature feature) { return true; }
82
83     /*!
84      * @brief Called when a setting changed.
85      * @param strChangedSetting The changed setting.
86      */
87     virtual void OnSettingChanged(const CStdString &strChangedSetting) {};
88
89     /*!
90      * @brief Called when this device is removed, before calling the destructor.
91      */
92     virtual void OnDeviceRemoved(void) {}
93
94     /*!
95      * @brief Get all subdevices if this device is multifunctional.
96      * @param subDevices The subdevices.
97      */
98     virtual void GetSubdevices(std::vector<CPeripheral *> &subDevices) const;
99
100     /*!
101      * @return True when this device is multifunctional, false otherwise.
102      */
103     virtual bool IsMultiFunctional(void) const;
104
105     /*!
106      * @brief Add a setting to this peripheral. This will overwrite a previous setting with the same key.
107      * @param strKey The key of the setting.
108      * @param setting The setting.
109      */
110     virtual void AddSetting(const CStdString &strKey, const CSetting *setting);
111
112     /*!
113      * @brief Check whether a setting is known with the given key.
114      * @param strKey The key to search.
115      * @return True when found, false otherwise.
116      */
117     virtual bool HasSetting(const CStdString &strKey) const;
118
119     /*!
120      * @return True when this device has any settings, false otherwise.
121      */
122     virtual bool HasSettings(void) const;
123
124     /*!
125      * @return True when this device has any configurable settings, false otherwise.
126      */
127     virtual bool HasConfigurableSettings(void) const;
128
129     /*!
130      * @brief Get the value of a setting.
131      * @param strKey The key to search.
132      * @return The value or an empty string if it wasn't found.
133      */
134     virtual const CStdString GetSettingString(const CStdString &strKey) const;
135     virtual bool SetSetting(const CStdString &strKey, const CStdString &strValue);
136     virtual void SetSettingVisible(const CStdString &strKey, bool bSetTo);
137     virtual bool IsSettingVisible(const CStdString &strKey) const;
138
139     virtual int GetSettingInt(const CStdString &strKey) const;
140     virtual bool SetSetting(const CStdString &strKey, int iValue);
141
142     virtual bool GetSettingBool(const CStdString &strKey) const;
143     virtual bool SetSetting(const CStdString &strKey, bool bValue);
144
145     virtual float GetSettingFloat(const CStdString &strKey) const;
146     virtual bool SetSetting(const CStdString &strKey, float fValue);
147
148     virtual void PersistSettings(bool bExiting = false);
149     virtual void LoadPersistedSettings(void);
150     virtual void ResetDefaultSettings(void);
151
152     virtual std::vector<CSetting *> GetSettings(void) const;
153
154     virtual bool ErrorOccured(void) const { return m_bError; }
155
156   protected:
157     virtual void ClearSettings(void);
158
159     PeripheralType                   m_type;
160     PeripheralBusType                m_busType;
161     CStdString                       m_strLocation;
162     CStdString                       m_strDeviceName;
163     CStdString                       m_strSettingsFile;
164     CStdString                       m_strFileLocation;
165     int                              m_iVendorId;
166     CStdString                       m_strVendorId;
167     int                              m_iProductId;
168     CStdString                       m_strProductId;
169     CStdString                       m_strVersionInfo;
170     bool                             m_bInitialised;
171     bool                             m_bHidden;
172     bool                             m_bError;
173     std::vector<PeripheralFeature>   m_features;
174     std::vector<CPeripheral *>       m_subDevices;
175     std::map<CStdString, CSetting *> m_settings;
176     std::set<CStdString>             m_changedSettings;
177   };
178 }