2 * Copyright (C) 2011, BMW AG
9 * \author Christian Müller (christian.ei.mueller@bmw.de)
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
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.
26 #include "HookEngine.h"
28 BaseHook::BaseHook() {
31 BaseHook::~BaseHook() {
34 HookHandler::HookHandler() {
37 HookHandler::~HookHandler() {
40 void BaseHook::registerAudioManagerCore(AudioManagerCore* core) {
44 genError_t BaseHook::registerHookEngine(HookHandler* engine) {
45 m_hookhandler = engine;
49 genError_t HookHandler::registerHook(hookprio_t prio, genHook_t hookType,
50 BaseHook* hookClass) {
52 QList<prioList>* list;
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;
60 newEntry.hook = hookClass;
63 case HOOK_DOMAIN_REGISTER:
64 list = &m_domainRegisterList;
66 case HOOK_DOMAIN_DEREGISTER:
67 list = &m_domainDeregisterList;
69 case HOOK_SINK_REGISTER:
70 list = &m_sinkRegisterList;
72 case HOOK_SINK_DEREGISTER:
73 list = &m_sinkDeregisterList;
75 case HOOK_SOURCE_REGISTER:
76 list = &m_sourceRegisterList;
78 case HOOK_SOURCE_DEREGISTER:
79 list = &m_sourceDeregisterList;
81 case HOOK_GATEWAY_REGISTER:
82 list = &m_gatewayRegisterList;
84 case HOOK_GATEWAY_DERGISTER:
85 list = &m_gatewayDeregisterList;
87 case HOOK_ROUTING_REQUEST:
88 list = &m_routingRequestList;
90 case HOOK_ROUTING_COMPLETE:
91 list = &m_routingCompleteList;
93 case HOOK_SYSTEM_READY:
94 list = &m_systemReadyList;
96 case HOOK_SYSTEM_DOWN:
97 list = &m_systemDownList;
99 case HOOK_VOLUME_CHANGE:
100 list = &m_volumeChangeList;
102 case HOOK_MUTE_SOURCE:
103 list = &m_muteSourceList;
105 case HOOK_UNMUTE_SOURCE:
106 list = &m_unmuteSourceList;
109 list = &m_muteSinkList;
111 case HOOK_UNMUTE_SINK:
112 list = &m_unmuteSinkList;
114 case HOOK_USER_CONNECTION_REQUEST:
115 list = &m_userConnectionRequestList;
117 case HOOK_USER_DISCONNECTION_REQUEST:
118 list = &m_userDisconnectionReuestList;
120 case HOOK_CONNECTION_REQUEST:
121 list = &m_connectionRequestList;
123 case HOOK_DISCONNECTION_REQUEST:
124 list = &m_disconnectionReuestList;
126 case HOOK_INTERRUPT_REQUEST:
127 list = &m_interruptRequestList;
130 DLT_LOG(AudioManager,DLT_LOG_WARN, DLT_STRING("Trying to register unknown Hook "))
132 return GEN_OUTOFRANGE;
136 foreach(prioList l,*list)
142 list->insert(index, newEntry);
143 //TODO test the sorting of the hooks with more than one plugin
148 genError_t HookHandler::fireHookDomainRegister(char* Name, domain_t ID) {
149 foreach (prioList hook,m_domainRegisterList)
151 if (hook.hook->hookDomainRegister(Name, ID) == HOOK_STOP)
157 genError_t HookHandler::fireHookDomainDeregister(domain_t ID) {
158 foreach (prioList hook,m_domainDeregisterList)
160 if (hook.hook->hookDomainDeregister(ID) == HOOK_STOP)
166 genError_t HookHandler::fireHookSinkRegister(char* Name, sink_t ID) {
167 foreach (prioList hook,m_sinkRegisterList)
169 if (hook.hook->hookSinkRegister(Name, ID) == HOOK_STOP)
175 genError_t HookHandler::fireHookSinkDeregister(sink_t ID) {
176 foreach (prioList hook,m_sinkDeregisterList)
178 if (hook.hook->hookSinkDeregister(ID) == HOOK_STOP)
184 genError_t HookHandler::fireHookSourceRegister(char* Name, source_t ID) {
185 foreach (prioList hook,m_sourceRegisterList)
187 if (hook.hook->hookSinkRegister(Name, ID) == HOOK_STOP)
193 genError_t HookHandler::fireHookSourceDeregister(source_t ID) {
194 foreach (prioList hook,m_sourceDeregisterList)
196 if (hook.hook->hookSourceDeregister(ID) == HOOK_STOP)
202 genError_t HookHandler::fireHookGatewayRegister(char* Name, gateway_t ID) {
203 foreach (prioList hook,m_gatewayRegisterList)
205 if (hook.hook->hookGatewayRegister(Name, ID) == HOOK_STOP)
211 genError_t HookHandler::fireHookGatewayDeregister(gateway_t ID) {
212 foreach (prioList hook,m_gatewayDeregisterList)
214 if (hook.hook->hookGatewayDeregister(ID) == HOOK_STOP)
220 genError_t HookHandler::fireHookSystemReady(void) {
221 foreach (prioList hook,m_systemReadyList)
223 if (hook.hook->hookSystemReady() == HOOK_STOP)
229 genError_t HookHandler::fireHookSystemDown(void) {
230 foreach (prioList hook,m_systemDownList)
232 if (hook.hook->hookSystemDown() == HOOK_STOP)
238 genError_t HookHandler::fireHookConnectionRequest(source_t SourceID,
240 foreach (prioList hook,m_connectionRequestList)
242 if (hook.hook->hookConnectionRequest(SourceID, SinkID) == HOOK_STOP)
248 genError_t HookHandler::fireHookDisconnectionRequest(connection_t ID) {
249 foreach (prioList hook,m_disconnectionReuestList)
251 if (hook.hook->hookDisconnectionRequest(ID) == HOOK_STOP)
257 genError_t HookHandler::fireHookUserConnectionRequest(Queue* queue,
258 source_t SourceID, sink_t SinkID) {
259 foreach (prioList hook,m_userConnectionRequestList)
261 if (hook.hook->hookUserConnectionRequest(queue, SourceID, SinkID)
268 genError_t HookHandler::fireHookUserDisconnectionRequest(Queue* queue,
269 connection_t connID) {
270 foreach (prioList hook,m_userDisconnectionReuestList)
272 if (hook.hook->hookUserDisconnectionRequest(queue, connID)
279 genError_t HookHandler::fireHookRoutingRequest(bool onlyfree, source_t source,
280 sink_t sink, QList<genRoute_t>* ReturnList) {
281 foreach (prioList hook,m_routingRequestList)
283 if (hook.hook->hookRoutingRequest(onlyfree, source, sink,
284 ReturnList) == HOOK_STOP)
291 genError_t HookHandler::fireHookRoutingComplete(genRoute_t route) {
292 foreach (prioList hook,m_routingCompleteList)
294 if (hook.hook->hookRoutingComplete(route) == HOOK_STOP)
300 genError_t HookHandler::fireHookVolumeChange(volume_t newVolume, sink_t SinkID) {
301 foreach (prioList hook,m_volumeChangeList)
303 if (hook.hook->hookVolumeChange(newVolume, SinkID) == HOOK_STOP)
309 genError_t HookHandler::fireHookMuteSource(source_t ID) {
310 foreach (prioList hook,m_muteSourceList)
312 if (hook.hook->hookMuteSource(ID) == HOOK_STOP)
318 genError_t HookHandler::fireHookUnmuteSource(source_t ID) {
319 foreach (prioList hook,m_unmuteSourceList)
321 if (hook.hook->hookUnmuteSource(ID) == HOOK_STOP)
327 genError_t HookHandler::fireHookMuteSink(sink_t ID) {
328 foreach (prioList hook,m_muteSinkList)
330 if (hook.hook->hookMuteSink(ID) == HOOK_STOP)
336 genError_t HookHandler::fireHookUnmuteSink(sink_t ID) {
337 foreach (prioList hook,m_unmuteSinkList)
339 if (hook.hook->hookUnmuteSink(ID) == HOOK_STOP)
345 genError_t HookHandler::fireHookInterruptRequest(Queue* queue,
346 source_t interruptSource, sink_t sink, genInt_t* interruptID) {
347 foreach (prioList hook,m_interruptRequestList)
349 if (hook.hook->hookInterruptRequest(queue, interruptSource, sink,
350 interruptID) == HOOK_STOP)
356 void HookHandler::registerAudioManagerCore(AudioManagerCore* core) {
360 void HookHandler::loadHookPlugins() {
362 foreach (QObject *plugin, QPluginLoader::staticInstances())
364 HookPluginFactory* HookPluginFactory_ = qobject_cast<
365 HookPluginFactory *> (plugin);
366 if (HookPluginFactory_) {
367 b = HookPluginFactory_->returnInstance();
368 b->registerHookEngine(this);
369 b->registerAudioManagerCore(m_core);
372 if (b->returnPluginName(pName) == GEN_OK) {
373 DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Registered Hook Plugin:"), DLT_STRING(pName));