Merge pull request #2948 from ace20022/blu_lang_fix
[vuplus_xbmc] / xbmc / peripherals / Peripherals.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 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, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "system.h"
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"
28
29 class CFileItemList;
30 class CSetting;
31 class CSettingsCategory;
32 class TiXmlElement;
33 class CAction;
34 class CKey;
35
36 namespace PERIPHERALS
37 {
38   #define g_peripherals CPeripherals::Get()
39
40   class CPeripherals : public ISettingCallback
41   {
42   public:
43     static CPeripherals &Get(void);
44     virtual ~CPeripherals(void);
45
46     /*!
47      * @brief Initialise the peripherals manager.
48      */
49     virtual void Initialise(void);
50
51     /*!
52      * @brief Clear all data known by the peripherals manager.
53      */
54     virtual void Clear(void);
55
56     /*!
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.
61      */
62     virtual CPeripheral *GetPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
63
64     /*!
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.
69      */
70     virtual bool HasPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
71
72     /*!
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.
76      */
77     virtual CPeripheralBus *GetBusWithDevice(const CStdString &strLocation) const;
78
79     /*!
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.
85      */
86     virtual int GetPeripheralsWithFeature(std::vector<CPeripheral *> &results, const PeripheralFeature feature, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
87
88     size_t GetNumberOfPeripherals() const;
89
90     /*!
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.
95      */
96     virtual bool HasPeripheralWithFeature(const PeripheralFeature feature, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
97
98     /*!
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.
102      */
103     virtual void OnDeviceAdded(const CPeripheralBus &bus, const CPeripheral &peripheral);
104
105     /*!
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.
109      */
110     virtual void OnDeviceDeleted(const CPeripheralBus &bus, const CPeripheral &peripheral);
111
112     /*!
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.
117      */
118     CPeripheral *CreatePeripheral(CPeripheralBus &bus, const PeripheralScanResult& result);
119
120     /*!
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.
123      */
124     void GetSettingsFromMapping(CPeripheral &peripheral) const;
125
126     /*!
127      * @brief Trigger a device scan on all known busses
128      */
129     virtual void TriggerDeviceScan(const PeripheralBusType type = PERIPHERAL_BUS_UNKNOWN);
130
131     /*!
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.
135      */
136     virtual CPeripheralBus *GetBusByType(const PeripheralBusType type) const;
137
138     /*!
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.
142      */
143     virtual void GetDirectory(const CStdString &strPath, CFileItemList &items) const;
144
145     /*!
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.
149      */
150     virtual CPeripheral *GetByPath(const CStdString &strPath) const;
151
152     /*!
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.
156      */
157     virtual bool OnAction(const CAction &action);
158
159     /*!
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.
162      */
163     virtual bool IsMuted(void);
164
165     /*!
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.
168      */
169     virtual bool ToggleMute(void);
170
171     /*!
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.
176      */
177     virtual bool ToggleDeviceState(const CecStateChange mode = STATE_SWITCH_TOGGLE, const unsigned int iPeripheral = 0);
178
179     /*!
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.
182      */
183     virtual bool Mute(void) { return ToggleMute(); } // TODO CEC only supports toggling the mute status at this time
184
185     /*!
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.
188      */
189     virtual bool UnMute(void) { return ToggleMute(); } // TODO CEC only supports toggling the mute status at this time
190
191     /*!
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.
196      */
197     virtual bool GetNextKeypress(float frameTime, CKey &key);
198
199     bool SupportsCEC(void) const
200     {
201 #if defined(HAVE_LIBCEC)
202       return true;
203 #else
204       return false;
205 #endif
206     }
207     
208     virtual void OnSettingChanged(const CSetting *setting);
209     virtual void OnSettingAction(const CSetting *setting);
210
211   private:
212     CPeripherals(void);
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);
216
217     bool                                 m_bInitialised;
218     bool                                 m_bIsStarted;
219 #if !defined(HAVE_LIBCEC)
220     bool                                 m_bMissingLibCecWarningDisplayed;
221 #endif
222     std::vector<CPeripheralBus *>        m_busses;
223     std::vector<PeripheralDeviceMapping> m_mappings;
224     CSettingsCategory *                  m_settings;
225     CCriticalSection                     m_critSection;
226   };
227 }