Merge pull request #473 from Montellese/onplaybackspeedchanged
[vuplus_xbmc] / xbmc / peripherals / devices / Peripheral.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2011 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, write to
18  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19  *  http://www.gnu.org/copyleft/gpl.html
20  *
21  */
22
23 #include <vector>
24 #include "utils/StdString.h"
25 #include "peripherals/PeripheralTypes.h"
26
27 class TiXmlDocument;
28
29 namespace PERIPHERALS
30 {
31   class CGUIDialogPeripheralSettings;
32
33   class CPeripheral
34   {
35     friend class CGUIDialogPeripheralSettings;
36
37   public:
38     CPeripheral(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId);
39     CPeripheral(void);
40     virtual ~CPeripheral(void);
41
42     bool operator ==(const CPeripheral &right) const;
43     bool operator !=(const CPeripheral &right) const;
44
45     const CStdString &FileLocation(void) const     { return m_strFileLocation; }
46     const CStdString &Location(void) const         { return m_strLocation; }
47     int VendorId(void) const                       { return m_iVendorId; }
48     const char *VendorIdAsString(void) const       { return m_strVendorId; }
49     int ProductId(void) const                      { return m_iProductId; }
50     const char *ProductIdAsString(void) const      { return m_strProductId; }
51     const PeripheralType Type(void) const          { return m_type; }
52     const PeripheralBusType GetBusType(void) const { return m_busType; };
53     const CStdString &DeviceName(void) const       { return m_strDeviceName; }
54     bool IsHidden(void) const                      { return m_bHidden; }
55     void SetHidden(bool bSetTo = true)             { m_bHidden = bSetTo; }
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 one or more settings changed. Calls OnSettingChanged for every setting.
91      */
92     virtual void OnSettingsChanged(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 void SetSetting(const CStdString &strKey, const CStdString &strValue);
136
137     virtual int GetSettingInt(const CStdString &strKey) const;
138     virtual void SetSetting(const CStdString &strKey, int iValue);
139
140     virtual bool GetSettingBool(const CStdString &strKey) const;
141     virtual void SetSetting(const CStdString &strKey, bool bValue);
142
143     virtual float GetSettingFloat(const CStdString &strKey) const;
144     virtual void SetSetting(const CStdString &strKey, float fValue);
145
146     virtual void PersistSettings(void) const;
147     virtual void LoadPersistedSettings(void);
148     virtual void ResetDefaultSettings(void);
149
150     virtual bool ErrorOccured(void) const { return m_bError; }
151
152   protected:
153     virtual void ClearSettings(void);
154
155     PeripheralType                   m_type;
156     PeripheralBusType                m_busType;
157     CStdString                       m_strLocation;
158     CStdString                       m_strDeviceName;
159     CStdString                       m_strSettingsFile;
160     CStdString                       m_strFileLocation;
161     int                              m_iVendorId;
162     char *                           m_strVendorId;
163     int                              m_iProductId;
164     char *                           m_strProductId;
165     bool                             m_bInitialised;
166     bool                             m_bHidden;
167     bool                             m_bError;
168     std::vector<PeripheralFeature>   m_features;
169     std::vector<CPeripheral *>       m_subDevices;
170     std::map<CStdString, CSetting *> m_settings;
171   };
172 }