3 * Copyright (C) 2005-2011 Team XBMC
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)
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.
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
24 #include "utils/StdString.h"
25 #include "peripherals/PeripheralTypes.h"
31 class CGUIDialogPeripheralSettings;
35 friend class CGUIDialogPeripheralSettings;
38 CPeripheral(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId);
40 virtual ~CPeripheral(void);
42 bool operator ==(const CPeripheral &right) const;
43 bool operator !=(const CPeripheral &right) const;
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; }
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.
62 bool HasFeature(const PeripheralFeature feature) const;
65 * @brief Get all features that are supported by this device.
66 * @param features The features.
68 void GetFeatures(std::vector<PeripheralFeature> &features) const;
71 * @brief Initialises the peripheral.
72 * @return True when the peripheral has been initialised succesfully, false otherwise.
74 bool Initialise(void);
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.
81 virtual bool InitialiseFeature(const PeripheralFeature feature) { return true; }
84 * @brief Called when a setting changed.
85 * @param strChangedSetting The changed setting.
87 virtual void OnSettingChanged(const CStdString &strChangedSetting) {};
90 * @brief Called when one or more settings changed. Calls OnSettingChanged for every setting.
92 virtual void OnSettingsChanged(void);
95 * @brief Get all subdevices if this device is multifunctional.
96 * @param subDevices The subdevices.
98 virtual void GetSubdevices(std::vector<CPeripheral *> &subDevices) const;
101 * @return True when this device is multifunctional, false otherwise.
103 virtual bool IsMultiFunctional(void) const;
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.
110 virtual void AddSetting(const CStdString &strKey, const CSetting *setting);
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.
117 virtual bool HasSetting(const CStdString &strKey) const;
120 * @return True when this device has any settings, false otherwise.
122 virtual bool HasSettings(void) const;
125 * @return True when this device has any configurable settings, false otherwise.
127 virtual bool HasConfigurableSettings(void) const;
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.
134 virtual const CStdString GetSettingString(const CStdString &strKey) const;
135 virtual void SetSetting(const CStdString &strKey, const CStdString &strValue);
137 virtual int GetSettingInt(const CStdString &strKey) const;
138 virtual void SetSetting(const CStdString &strKey, int iValue);
140 virtual bool GetSettingBool(const CStdString &strKey) const;
141 virtual void SetSetting(const CStdString &strKey, bool bValue);
143 virtual float GetSettingFloat(const CStdString &strKey) const;
144 virtual void SetSetting(const CStdString &strKey, float fValue);
146 virtual void PersistSettings(void) const;
147 virtual void LoadPersistedSettings(void);
148 virtual void ResetDefaultSettings(void);
150 virtual bool ErrorOccured(void) const { return m_bError; }
153 virtual void ClearSettings(void);
155 PeripheralType m_type;
156 PeripheralBusType m_busType;
157 CStdString m_strLocation;
158 CStdString m_strDeviceName;
159 CStdString m_strSettingsFile;
160 CStdString m_strFileLocation;
162 char * m_strVendorId;
164 char * m_strProductId;
168 std::vector<PeripheralFeature> m_features;
169 std::vector<CPeripheral *> m_subDevices;
170 std::map<CStdString, CSetting *> m_settings;