1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
#pragma once
/*
* Copyright (C) 2005-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "system.h"
#include "bus/PeripheralBus.h"
#include "devices/Peripheral.h"
#include "settings/lib/ISettingCallback.h"
#include "threads/CriticalSection.h"
#include "threads/Thread.h"
#include "utils/Observer.h"
class CFileItemList;
class CSetting;
class CSettingsCategory;
class TiXmlElement;
class CAction;
class CKey;
namespace PERIPHERALS
{
#define g_peripherals CPeripherals::Get()
class CPeripherals : public ISettingCallback,
public Observable
{
public:
static CPeripherals &Get(void);
virtual ~CPeripherals(void);
/*!
* @brief Initialise the peripherals manager.
*/
virtual void Initialise(void);
/*!
* @brief Clear all data known by the peripherals manager.
*/
virtual void Clear(void);
/*!
* @brief Get the instance of the peripheral at the given location.
* @param strLocation The location.
* @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
* @return The peripheral or NULL if it wasn't found.
*/
virtual CPeripheral *GetPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
/*!
* @brief Check whether a peripheral is present at the given location.
* @param strLocation The location.
* @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
* @return True when a peripheral was found, false otherwise.
*/
virtual bool HasPeripheralAtLocation(const CStdString &strLocation, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
/*!
* @brief Get the bus that holds the device with the given location.
* @param strLocation The location.
* @return The bus or NULL if no device was found.
*/
virtual CPeripheralBus *GetBusWithDevice(const CStdString &strLocation) const;
/*!
* @brief Get all peripheral instances that have the given feature.
* @param results The list of results.
* @param feature The feature to search for.
* @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
* @return The number of devices that have been found.
*/
virtual int GetPeripheralsWithFeature(std::vector<CPeripheral *> &results, const PeripheralFeature feature, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
size_t GetNumberOfPeripherals() const;
/*!
* @brief Check whether there is at least one device present with the given feature.
* @param feature The feature to check for.
* @param busType The bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
* @return True when at least one device was found with this feature, false otherwise.
*/
virtual bool HasPeripheralWithFeature(const PeripheralFeature feature, PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN) const;
/*!
* @brief Called when a device has been added to a bus.
* @param bus The bus the device was added to.
* @param peripheral The peripheral that has been added.
*/
virtual void OnDeviceAdded(const CPeripheralBus &bus, const CPeripheral &peripheral);
/*!
* @brief Called when a device has been deleted from a bus.
* @param bus The bus from which the device removed.
* @param peripheral The peripheral that has been removed.
*/
virtual void OnDeviceDeleted(const CPeripheralBus &bus, const CPeripheral &peripheral);
/*!
* @brief Creates a new instance of a peripheral.
* @param bus The bus on which this peripheral is present.
* @param result The scan result from the device scanning code.
* @return The new peripheral or NULL if it could not be created.
*/
CPeripheral *CreatePeripheral(CPeripheralBus &bus, const PeripheralScanResult& result);
/*!
* @brief Add the settings that are defined in the mappings file to the peripheral (if there is anything defined).
* @param peripheral The peripheral to get the settings for.
*/
void GetSettingsFromMapping(CPeripheral &peripheral) const;
/*!
* @brief Trigger a device scan on all known busses
*/
virtual void TriggerDeviceScan(const PeripheralBusType type = PERIPHERAL_BUS_UNKNOWN);
/*!
* @brief Get the instance of a bus given it's type.
* @param type The bus type.
* @return The bus or NULL if it wasn't found.
*/
virtual CPeripheralBus *GetBusByType(const PeripheralBusType type) const;
/*!
* @brief Get all fileitems for a path.
* @param strPath The path to the directory to get the items from.
* @param items The item list.
*/
virtual void GetDirectory(const CStdString &strPath, CFileItemList &items) const;
/*!
* @brief Get the instance of a peripheral given it's path.
* @param strPath The path to the peripheral.
* @return The peripheral or NULL if it wasn't found.
*/
virtual CPeripheral *GetByPath(const CStdString &strPath) const;
/*!
* @brief Try to let one of the peripherals handle an action.
* @param action The change to handle.
* @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
*/
virtual bool OnAction(const CAction &action);
/*!
* @brief Check whether there's a peripheral that reports to be muted.
* @return True when at least one peripheral reports to be muted, false otherwise.
*/
virtual bool IsMuted(void);
/*!
* @brief Try to toggle the mute status via a peripheral.
* @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
*/
virtual bool ToggleMute(void);
/*!
* @brief Try to toggle the playing device state via a peripheral.
* @param mode Whether to activate, put on standby or toggle the source.
* @param iPeripheral Optional CPeripheralCecAdapter pointer to a specific device, instead of iterating through all of them.
* @return True when the playing device has been switched on, false otherwise.
*/
virtual bool ToggleDeviceState(const CecStateChange mode = STATE_SWITCH_TOGGLE, const unsigned int iPeripheral = 0);
/*!
* @brief Try to mute the audio via a peripheral.
* @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
*/
virtual bool Mute(void) { return ToggleMute(); } // TODO CEC only supports toggling the mute status at this time
/*!
* @brief Try to unmute the audio via a peripheral.
* @return True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.
*/
virtual bool UnMute(void) { return ToggleMute(); } // TODO CEC only supports toggling the mute status at this time
/*!
* @brief Try to get a keypress from a peripheral.
* @param frameTime The current frametime.
* @param key The fetched key.
* @return True when a keypress was fetched, false otherwise.
*/
virtual bool GetNextKeypress(float frameTime, CKey &key);
bool SupportsCEC(void) const
{
#if defined(HAVE_LIBCEC)
return true;
#else
return false;
#endif
}
virtual void OnSettingChanged(const CSetting *setting);
virtual void OnSettingAction(const CSetting *setting);
private:
CPeripherals(void);
bool LoadMappings(void);
bool GetMappingForDevice(const CPeripheralBus &bus, PeripheralScanResult& result) const;
static void GetSettingsFromMappingsFile(TiXmlElement *xmlNode, std::map<CStdString, PeripheralDeviceSetting> &m_settings);
bool m_bInitialised;
bool m_bIsStarted;
#if !defined(HAVE_LIBCEC)
bool m_bMissingLibCecWarningDisplayed;
#endif
std::vector<CPeripheralBus *> m_busses;
std::vector<PeripheralDeviceMapping> m_mappings;
CSettingsCategory * m_settings;
CCriticalSection m_critSection;
};
}
|