adding feature in the compile script:
[profile/ivi/audiomanager.git] / AudioManagerDaemon / HookEngine.cpp
1 /**
2  * Copyright (C) 2011, BMW AG
3  *
4  * AudioManangerDeamon
5  *
6  * \file HookEngine.cpp
7  *
8  * \date 20.05.2011
9  * \author Christian Müller (christian.ei.mueller@bmw.de)
10  *
11  * \section License
12  * GNU Lesser General Public License, version 2.1, with special exception (GENIVI clause)
13  * Copyright (C) 2011, BMW AG – Christian Müller  Christian.ei.mueller@bmw.de
14  *
15  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
16  * 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 Lesser General Public License, version 2.1, for more details.
17  * You should have received a copy of the GNU Lesser General Public License, version 2.1, along with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
18  * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may also be applicable to programs even in cases in which the program is not a library in the technical sense.
19  * Linking AudioManager statically or dynamically with other modules is making a combined work based on AudioManager. You may license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to license your linked modules under the GNU Lesser General Public License, version 2.1, you may use the program under the following exception.
20  * As a special exception, the copyright holders of AudioManager give you permission to combine AudioManager with software programs or libraries that are released under any license unless such a combination is not permitted by the license of such a software program or library. You may copy and distribute such a system following the terms of the GNU Lesser General Public License, version 2.1, including this special exception, for AudioManager and the licenses of the other code concerned.
21  * Note that people who make modified versions of AudioManager are not obligated to grant this special exception for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, version 2.1, gives permission to release a modified version without this exception; this exception also makes it possible to release a modified version which carries forward this exception.
22  *
23  *
24  */
25
26 #include "HookEngine.h"
27
28 BaseHook::BaseHook() {
29 }
30
31 BaseHook::~BaseHook() {
32 }
33
34 HookHandler::HookHandler() {
35 }
36
37 HookHandler::~HookHandler() {
38 }
39
40 void BaseHook::registerAudioManagerCore(AudioManagerCore* core) {
41         m_core = core;
42 }
43
44 genError_t BaseHook::registerHookEngine(HookHandler* engine) {
45         m_hookhandler = engine;
46         return GEN_OK;
47 }
48
49 genError_t HookHandler::registerHook(hookprio_t prio, genHook_t hookType,
50                 BaseHook* hookClass) {
51         prioList newEntry;
52         QList<prioList>* list;
53
54         if (prio < 0 || prio > 100) {
55                 DLT_LOG(AudioManager,DLT_LOG_WARN, DLT_STRING("Register Hook: Priority out of range: "), DLT_INT(prio));
56                 return GEN_OUTOFRANGE;
57         }
58
59         newEntry.prio = prio;
60         newEntry.hook = hookClass;
61
62         switch (hookType) {
63         case HOOK_DOMAIN_REGISTER:
64                 list = &m_domainRegisterList;
65                 break;
66         case HOOK_DOMAIN_DEREGISTER:
67                 list = &m_domainDeregisterList;
68                 break;
69         case HOOK_SINK_REGISTER:
70                 list = &m_sinkRegisterList;
71                 break;
72         case HOOK_SINK_DEREGISTER:
73                 list = &m_sinkDeregisterList;
74                 break;
75         case HOOK_SOURCE_REGISTER:
76                 list = &m_sourceRegisterList;
77                 break;
78         case HOOK_SOURCE_DEREGISTER:
79                 list = &m_sourceDeregisterList;
80                 break;
81         case HOOK_GATEWAY_REGISTER:
82                 list = &m_gatewayRegisterList;
83                 break;
84         case HOOK_GATEWAY_DERGISTER:
85                 list = &m_gatewayDeregisterList;
86                 break;
87         case HOOK_ROUTING_REQUEST:
88                 list = &m_routingRequestList;
89                 break;
90         case HOOK_ROUTING_COMPLETE:
91                 list = &m_routingCompleteList;
92                 break;
93         case HOOK_SYSTEM_READY:
94                 list = &m_systemReadyList;
95                 break;
96         case HOOK_SYSTEM_DOWN:
97                 list = &m_systemDownList;
98                 break;
99         case HOOK_VOLUME_CHANGE:
100                 list = &m_volumeChangeList;
101                 break;
102         case HOOK_MUTE_SOURCE:
103                 list = &m_muteSourceList;
104                 break;
105         case HOOK_UNMUTE_SOURCE:
106                 list = &m_unmuteSourceList;
107                 break;
108         case HOOK_MUTE_SINK:
109                 list = &m_muteSinkList;
110                 break;
111         case HOOK_UNMUTE_SINK:
112                 list = &m_unmuteSinkList;
113                 break;
114         case HOOK_USER_CONNECTION_REQUEST:
115                 list = &m_userConnectionRequestList;
116                 break;
117         case HOOK_USER_DISCONNECTION_REQUEST:
118                 list = &m_userDisconnectionReuestList;
119                 break;
120         case HOOK_CONNECTION_REQUEST:
121                 list = &m_connectionRequestList;
122                 break;
123         case HOOK_DISCONNECTION_REQUEST:
124                 list = &m_disconnectionReuestList;
125                 break;
126         case HOOK_INTERRUPT_REQUEST:
127                 list = &m_interruptRequestList;
128                 break;
129         default:
130                 DLT_LOG(AudioManager,DLT_LOG_WARN, DLT_STRING("Trying to register unknown Hook "))
131                 ;
132                 return GEN_OUTOFRANGE;
133         }
134
135         int index = 0;
136         foreach(prioList l,*list)
137                 {
138                         if (l.prio > prio) {
139                                 index++;
140                         }
141                 }
142         list->insert(index, newEntry);
143         //TODO test the sorting of the hooks with more than one plugin
144
145         return GEN_OK;
146 }
147
148 genError_t HookHandler::fireHookDomainRegister(char* Name, domain_t ID) {
149         foreach (prioList hook,m_domainRegisterList)
150                 {
151                         if (hook.hook->hookDomainRegister(Name, ID) == HOOK_STOP)
152                                 break;
153                 }
154         return GEN_OK;
155 }
156
157 genError_t HookHandler::fireHookDomainDeregister(domain_t ID) {
158         foreach (prioList hook,m_domainDeregisterList)
159                 {
160                         if (hook.hook->hookDomainDeregister(ID) == HOOK_STOP)
161                                 break;
162                 }
163         return GEN_OK;
164 }
165
166 genError_t HookHandler::fireHookSinkRegister(char* Name, sink_t ID) {
167         foreach (prioList hook,m_sinkRegisterList)
168                 {
169                         if (hook.hook->hookSinkRegister(Name, ID) == HOOK_STOP)
170                                 break;
171                 }
172         return GEN_OK;
173 }
174
175 genError_t HookHandler::fireHookSinkDeregister(sink_t ID) {
176         foreach (prioList hook,m_sinkDeregisterList)
177                 {
178                         if (hook.hook->hookSinkDeregister(ID) == HOOK_STOP)
179                                 break;
180                 }
181         return GEN_OK;
182 }
183
184 genError_t HookHandler::fireHookSourceRegister(char* Name, source_t ID) {
185         foreach (prioList hook,m_sourceRegisterList)
186                 {
187                         if (hook.hook->hookSinkRegister(Name, ID) == HOOK_STOP)
188                                 break;
189                 }
190         return GEN_OK;
191 }
192
193 genError_t HookHandler::fireHookSourceDeregister(source_t ID) {
194         foreach (prioList hook,m_sourceDeregisterList)
195                 {
196                         if (hook.hook->hookSourceDeregister(ID) == HOOK_STOP)
197                                 break;
198                 }
199         return GEN_OK;
200 }
201
202 genError_t HookHandler::fireHookGatewayRegister(char* Name, gateway_t ID) {
203         foreach (prioList hook,m_gatewayRegisterList)
204                 {
205                         if (hook.hook->hookGatewayRegister(Name, ID) == HOOK_STOP)
206                                 break;
207                 }
208         return GEN_OK;
209 }
210
211 genError_t HookHandler::fireHookGatewayDeregister(gateway_t ID) {
212         foreach (prioList hook,m_gatewayDeregisterList)
213                 {
214                         if (hook.hook->hookGatewayDeregister(ID) == HOOK_STOP)
215                                 break;
216                 }
217         return GEN_OK;
218 }
219
220 genError_t HookHandler::fireHookSystemReady(void) {
221         foreach (prioList hook,m_systemReadyList)
222                 {
223                         if (hook.hook->hookSystemReady() == HOOK_STOP)
224                                 break;
225                 }
226         return GEN_OK;
227 }
228
229 genError_t HookHandler::fireHookSystemDown(void) {
230         foreach (prioList hook,m_systemDownList)
231                 {
232                         if (hook.hook->hookSystemDown() == HOOK_STOP)
233                                 break;
234                 }
235         return GEN_OK;
236 }
237
238 genError_t HookHandler::fireHookConnectionRequest(source_t SourceID,
239                 sink_t SinkID) {
240         foreach (prioList hook,m_connectionRequestList)
241                 {
242                         if (hook.hook->hookConnectionRequest(SourceID, SinkID) == HOOK_STOP)
243                                 break;
244                 }
245         return GEN_OK;
246 }
247
248 genError_t HookHandler::fireHookDisconnectionRequest(connection_t ID) {
249         foreach (prioList hook,m_disconnectionReuestList)
250                 {
251                         if (hook.hook->hookDisconnectionRequest(ID) == HOOK_STOP)
252                                 break;
253                 }
254         return GEN_OK;
255 }
256
257 genError_t HookHandler::fireHookUserConnectionRequest(Queue* queue,
258                 source_t SourceID, sink_t SinkID) {
259         foreach (prioList hook,m_userConnectionRequestList)
260                 {
261                         if (hook.hook->hookUserConnectionRequest(queue, SourceID, SinkID)
262                                         == HOOK_STOP)
263                                 break;
264                 }
265         return GEN_OK;
266 }
267
268 genError_t HookHandler::fireHookUserDisconnectionRequest(Queue* queue,
269                 connection_t connID) {
270         foreach (prioList hook,m_userDisconnectionReuestList)
271                 {
272                         if (hook.hook->hookUserDisconnectionRequest(queue, connID)
273                                         == HOOK_STOP)
274                                 break;
275                 }
276         return GEN_OK;
277 }
278
279 genError_t HookHandler::fireHookRoutingRequest(bool onlyfree, source_t source,
280                 sink_t sink, QList<genRoute_t>* ReturnList) {
281         foreach (prioList hook,m_routingRequestList)
282                 {
283                         if (hook.hook->hookRoutingRequest(onlyfree, source, sink,
284                                         ReturnList) == HOOK_STOP)
285                                 break;
286                 }
287         return GEN_OK;
288 }
289
290 //todo change type
291 genError_t HookHandler::fireHookRoutingComplete(genRoute_t route) {
292         foreach (prioList hook,m_routingCompleteList)
293                 {
294                         if (hook.hook->hookRoutingComplete(route) == HOOK_STOP)
295                                 break;
296                 }
297         return GEN_OK;
298 }
299
300 genError_t HookHandler::fireHookVolumeChange(volume_t newVolume, sink_t SinkID) {
301         foreach (prioList hook,m_volumeChangeList)
302                 {
303                         if (hook.hook->hookVolumeChange(newVolume, SinkID) == HOOK_STOP)
304                                 break;
305                 }
306         return GEN_OK;
307 }
308
309 genError_t HookHandler::fireHookMuteSource(source_t ID) {
310         foreach (prioList hook,m_muteSourceList)
311                 {
312                         if (hook.hook->hookMuteSource(ID) == HOOK_STOP)
313                                 break;
314                 }
315         return GEN_OK;
316 }
317
318 genError_t HookHandler::fireHookUnmuteSource(source_t ID) {
319         foreach (prioList hook,m_unmuteSourceList)
320                 {
321                         if (hook.hook->hookUnmuteSource(ID) == HOOK_STOP)
322                                 break;
323                 }
324         return GEN_OK;
325 }
326
327 genError_t HookHandler::fireHookMuteSink(sink_t ID) {
328         foreach (prioList hook,m_muteSinkList)
329                 {
330                         if (hook.hook->hookMuteSink(ID) == HOOK_STOP)
331                                 break;
332                 }
333         return GEN_OK;
334 }
335
336 genError_t HookHandler::fireHookUnmuteSink(sink_t ID) {
337         foreach (prioList hook,m_unmuteSinkList)
338                 {
339                         if (hook.hook->hookUnmuteSink(ID) == HOOK_STOP)
340                                 break;
341                 }
342         return GEN_OK;
343 }
344
345 genError_t HookHandler::fireHookInterruptRequest(Queue* queue,
346                 source_t interruptSource, sink_t sink, genInt_t* interruptID) {
347         foreach (prioList hook,m_interruptRequestList)
348                 {
349                         if (hook.hook->hookInterruptRequest(queue, interruptSource, sink,
350                                         interruptID) == HOOK_STOP)
351                                 break;
352                 }
353         return GEN_OK;
354 }
355
356 void HookHandler::registerAudioManagerCore(AudioManagerCore* core) {
357         m_core = core;
358 }
359
360 void HookHandler::loadHookPlugins() {
361         BaseHook *b = NULL;
362         foreach (QObject *plugin, QPluginLoader::staticInstances())
363                 {
364                         HookPluginFactory* HookPluginFactory_ = qobject_cast<
365                                         HookPluginFactory *> (plugin);
366                         if (HookPluginFactory_) {
367                                 b = HookPluginFactory_->returnInstance();
368                                 b->registerHookEngine(this);
369                                 b->registerAudioManagerCore(m_core);
370                                 b->InitHook();
371                                 char pName[40];
372                                 if (b->returnPluginName(pName) == GEN_OK) {
373                                         DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Registered Hook Plugin:"), DLT_STRING(pName));
374                                 }
375                         }
376                 }
377 }
378