3 * Copyright (C) 2005-2013 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, see
18 * <http://www.gnu.org/licenses/>.
23 #include "utils/StdString.h"
24 #include "peripherals/PeripheralTypes.h"
30 class CGUIDialogPeripheralSettings;
34 friend class CGUIDialogPeripheralSettings;
37 CPeripheral(const PeripheralType type, const PeripheralBusType busType, const CStdString &strLocation, const CStdString &strDeviceName, int iVendorId, int iProductId);
39 virtual ~CPeripheral(void);
41 bool operator ==(const CPeripheral &right) const;
42 bool operator !=(const CPeripheral &right) const;
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; }
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 this device is removed, before calling the destructor.
92 virtual void OnDeviceRemoved(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 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;
139 virtual int GetSettingInt(const CStdString &strKey) const;
140 virtual bool SetSetting(const CStdString &strKey, int iValue);
142 virtual bool GetSettingBool(const CStdString &strKey) const;
143 virtual bool SetSetting(const CStdString &strKey, bool bValue);
145 virtual float GetSettingFloat(const CStdString &strKey) const;
146 virtual bool SetSetting(const CStdString &strKey, float fValue);
148 virtual void PersistSettings(bool bExiting = false);
149 virtual void LoadPersistedSettings(void);
150 virtual void ResetDefaultSettings(void);
152 virtual std::vector<CSetting *> GetSettings(void) const;
154 virtual bool ErrorOccured(void) const { return m_bError; }
157 virtual void ClearSettings(void);
159 PeripheralType m_type;
160 PeripheralBusType m_busType;
161 CStdString m_strLocation;
162 CStdString m_strDeviceName;
163 CStdString m_strSettingsFile;
164 CStdString m_strFileLocation;
166 CStdString m_strVendorId;
168 CStdString m_strProductId;
169 CStdString m_strVersionInfo;
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;