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 "bus/PeripheralBus.h"
24 #include "devices/Peripheral.h"
25 #include "settings/ISettingCallback.h"
26 #include "threads/CriticalSection.h"
27 #include "threads/Thread.h"
31 class CSettingsCategory;
38 #define g_peripherals CPeripherals::Get()
40 class CPeripherals : public ISettingCallback
43 static CPeripherals &Get(void);
44 virtual ~CPeripherals(void);
47 * @brief Initialise the peripherals manager.
49 virtual void Initialise(void);
52 * @brief Clear all data known by the peripherals manager.
54 virtual void Clear(void);
57 * @brief Get the instance of the peripheral at the given location.
58 * @param strLocation The location.
59 * @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
60 * @return The peripheral or NULL if it wasn't found.
62 virtual CPeripheral *GetPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
65 * @brief Check whether a peripheral is present at the given location.
66 * @param strLocation The location.
67 * @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
68 * @return True when a peripheral was found, false otherwise.
70 virtual bool HasPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
73 * @brief Get the bus that holds the device with the given location.
74 * @param strLocation The location.
75 * @return The bus or NULL if no device was found.
77 virtual CPeripheralBus *GetBusWithDevice(const CStdString &strLocation) const;
80 * @brief Get all peripheral instances that have the given feature.
81 * @param results The list of results.
82 * @param feature The feature to search for.
83 * @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
84 * @return The number of devices that have been found.
86 virtual int GetPeripheralsWithFeature(std::vector<CPeripheral *> &results, const PeripheralFeature feature, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
88 size_t GetNumberOfPeripherals() const;
91 * @brief Check whether there is at least one device present with the given feature.
92 * @param feature The feature to check for.
93 * @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
94 * @return True when at least one device was found with this feature, false otherwise.
96 virtual bool HasPeripheralWithFeature(const PeripheralFeature feature, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
99 * @brief Called when a device has been added to a bus.
100 * @param bus The bus the device was added to.
101 * @param peripheral The peripheral that has been added.
103 virtual void OnDeviceAdded(const CPeripheralBus &bus, const CPeripheral &peripheral);
106 * @brief Called when a device has been deleted from a bus.
107 * @param bus The bus from which the device removed.
108 * @param peripheral The peripheral that has been removed.
110 virtual void OnDeviceDeleted(const CPeripheralBus &bus, const CPeripheral &peripheral);
113 * @brief Creates a new instance of a peripheral.
114 * @param bus The bus on which this peripheral is present.
115 * @param result The scan result from the device scanning code.
116 * @return The new peripheral or NULL if it could not be created.
118 CPeripheral *CreatePeripheral(CPeripheralBus &bus, const PeripheralScanResult& result);
121 * @brief Add the settings that are defined in the mappings file to the peripheral (if there is anything defined).
122 * @param peripheral The peripheral to get the settings for.
124 void GetSettingsFromMapping(CPeripheral &peripheral) const;
127 * @brief Trigger a device scan on all known busses
129 virtual void TriggerDeviceScan(const PeripheralBusType type = PERIPHERAL_BUS_UNKNOWN);
132 * @brief Get the instance of a bus given it's type.
133 * @param type The bus type.
134 * @return The bus or NULL if it wasn't found.
136 virtual CPeripheralBus *GetBusByType(const PeripheralBusType type) const;
139 * @brief Get all fileitems for a path.
140 * @param strPath The path to the directory to get the items from.
141 * @param items The item list.
143 virtual void GetDirectory(const CStdString &strPath, CFileItemList &items) const;
146 * @brief Get the instance of a peripheral given it's path.
147 * @param strPath The path to the peripheral.
148 * @return The peripheral or NULL if it wasn't found.
150 virtual CPeripheral *GetByPath(const CStdString &strPath) const;
153 * @brief Try to let one of the peripherals handle an action.
154 * @param action The change to handle.
155 * @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
157 virtual bool OnAction(const CAction &action);
160 * @brief Check whether there's a peripheral that reports to be muted.
161 * @return True when at least one peripheral reports to be muted, false otherwise.
163 virtual bool IsMuted(void);
166 * @brief Try to toggle the mute status via a peripheral.
167 * @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
169 virtual bool ToggleMute(void);
172 * @brief Try to toggle the playing device state via a peripheral.
173 * @param mode Whether to activate, put on standby or toggle the source.
174 * @param iPeripheral Optional CPeripheralCecAdapter pointer to a specific device, instead of iterating through all of them.
175 * @return True when the playing device has been switched on, false otherwise.
177 virtual bool ToggleDeviceState(const CecStateChange mode = STATE_SWITCH_TOGGLE, const unsigned int iPeripheral = 0);
180 * @brief Try to mute the audio via a peripheral.
181 * @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
183 virtual bool Mute(void) { return ToggleMute(); } // TODO CEC only supports toggling the mute status at this time
186 * @brief Try to unmute the audio via a peripheral.
187 * @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
189 virtual bool UnMute(void) { return ToggleMute(); } // TODO CEC only supports toggling the mute status at this time
192 * @brief Try to get a keypress from a peripheral.
193 * @param frameTime The current frametime.
194 * @param key The fetched key.
195 * @return True when a keypress was fetched, false otherwise.
197 virtual bool GetNextKeypress(float frameTime, CKey &key);
199 bool SupportsCEC(void) const
201 #if defined(HAVE_LIBCEC)
208 virtual void OnSettingChanged(const CSetting *setting);
209 virtual void OnSettingAction(const CSetting *setting);
213 bool LoadMappings(void);
214 bool GetMappingForDevice(const CPeripheralBus &bus, PeripheralScanResult& result) const;
215 static void GetSettingsFromMappingsFile(TiXmlElement *xmlNode, std::map<CStdString, CSetting *> &m_settings);
219 #if !defined(HAVE_LIBCEC)
220 bool m_bMissingLibCecWarningDisplayed;
222 std::vector<CPeripheralBus *> m_busses;
223 std::vector<PeripheralDeviceMapping> m_mappings;
224 CSettingsCategory * m_settings;
225 CCriticalSection m_critSection;