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"
32 class CGUIDialogPeripheralSettings;
37 STATE_ACTIVATE_SOURCE,
43 friend class CGUIDialogPeripheralSettings;
46 CPeripheral(const PeripheralScanResult& scanResult);
47 virtual ~CPeripheral(void);
49 bool operator ==(const CPeripheral &right) const;
50 bool operator !=(const CPeripheral &right) const;
51 bool operator ==(const PeripheralScanResult& right) const;
52 bool operator !=(const PeripheralScanResult& right) const;
54 const CStdString &FileLocation(void) const { return m_strFileLocation; }
55 const CStdString &Location(void) const { return m_strLocation; }
56 int VendorId(void) const { return m_iVendorId; }
57 const char *VendorIdAsString(void) const { return m_strVendorId.c_str(); }
58 int ProductId(void) const { return m_iProductId; }
59 const char *ProductIdAsString(void) const { return m_strProductId.c_str(); }
60 const PeripheralType Type(void) const { return m_type; }
61 const PeripheralBusType GetBusType(void) const { return m_busType; };
62 const CStdString &DeviceName(void) const { return m_strDeviceName; }
63 bool IsHidden(void) const { return m_bHidden; }
64 void SetHidden(bool bSetTo = true) { m_bHidden = bSetTo; }
65 const CStdString &GetVersionInfo(void) const { return m_strVersionInfo; }
68 * @brief Check whether this device has the given feature.
69 * @param feature The feature to check for.
70 * @return True when the device has the feature, false otherwise.
72 bool HasFeature(const PeripheralFeature feature) const;
75 * @brief Get all features that are supported by this device.
76 * @param features The features.
78 void GetFeatures(std::vector<PeripheralFeature> &features) const;
81 * @brief Initialises the peripheral.
82 * @return True when the peripheral has been initialised succesfully, false otherwise.
84 bool Initialise(void);
87 * @brief Initialise one of the features of this peripheral.
88 * @param feature The feature to initialise.
89 * @return True when the feature has been initialised succesfully, false otherwise.
91 virtual bool InitialiseFeature(const PeripheralFeature feature) { return true; }
94 * @brief Called when a setting changed.
95 * @param strChangedSetting The changed setting.
97 virtual void OnSettingChanged(const CStdString &strChangedSetting) {};
100 * @brief Called when this device is removed, before calling the destructor.
102 virtual void OnDeviceRemoved(void) {}
105 * @brief Get all subdevices if this device is multifunctional.
106 * @param subDevices The subdevices.
108 virtual void GetSubdevices(std::vector<CPeripheral *> &subDevices) const;
111 * @return True when this device is multifunctional, false otherwise.
113 virtual bool IsMultiFunctional(void) const;
116 * @brief Add a setting to this peripheral. This will overwrite a previous setting with the same key.
117 * @param strKey The key of the setting.
118 * @param setting The setting.
120 virtual void AddSetting(const CStdString &strKey, const CSetting *setting);
123 * @brief Check whether a setting is known with the given key.
124 * @param strKey The key to search.
125 * @return True when found, false otherwise.
127 virtual bool HasSetting(const CStdString &strKey) const;
130 * @return True when this device has any settings, false otherwise.
132 virtual bool HasSettings(void) const;
135 * @return True when this device has any configurable settings, false otherwise.
137 virtual bool HasConfigurableSettings(void) const;
140 * @brief Get the value of a setting.
141 * @param strKey The key to search.
142 * @return The value or an empty string if it wasn't found.
144 virtual const CStdString GetSettingString(const CStdString &strKey) const;
145 virtual bool SetSetting(const CStdString &strKey, const CStdString &strValue);
146 virtual void SetSettingVisible(const CStdString &strKey, bool bSetTo);
147 virtual bool IsSettingVisible(const CStdString &strKey) const;
149 virtual int GetSettingInt(const CStdString &strKey) const;
150 virtual bool SetSetting(const CStdString &strKey, int iValue);
152 virtual bool GetSettingBool(const CStdString &strKey) const;
153 virtual bool SetSetting(const CStdString &strKey, bool bValue);
155 virtual float GetSettingFloat(const CStdString &strKey) const;
156 virtual bool SetSetting(const CStdString &strKey, float fValue);
158 virtual void PersistSettings(bool bExiting = false);
159 virtual void LoadPersistedSettings(void);
160 virtual void ResetDefaultSettings(void);
162 virtual std::vector<CSetting *> GetSettings(void) const;
164 virtual bool ErrorOccured(void) const { return m_bError; }
167 virtual void ClearSettings(void);
169 PeripheralType m_type;
170 PeripheralBusType m_busType;
171 PeripheralBusType m_mappedBusType;
172 CStdString m_strLocation;
173 CStdString m_strDeviceName;
174 CStdString m_strSettingsFile;
175 CStdString m_strFileLocation;
177 CStdString m_strVendorId;
179 CStdString m_strProductId;
180 CStdString m_strVersionInfo;
184 std::vector<PeripheralFeature> m_features;
185 std::vector<CPeripheral *> m_subDevices;
186 std::map<CStdString, CSetting *> m_settings;
187 std::set<CStdString> m_changedSettings;