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() {
38 for (std::list<BaseHook*>::iterator hook = m_listofPlugins.begin(); hook != m_listofPlugins.end(); hook++) {
39 (*hook)->DeinitHook();
43 void BaseHook::registerAudioManagerCore(AudioManagerCore* core) {
47 genError_t BaseHook::registerHookEngine(HookHandler* engine) {
48 m_hookhandler = engine;
52 genError_t HookHandler::registerHook(hookprio_t prio, genHook_t hookType, BaseHook* hookClass) {
54 std::list<prioList>* list;
56 if (prio < 0 || prio > 100) {
57 DLT_LOG( AudioManager, DLT_LOG_WARN, DLT_STRING("Register Hook: Priority out of range: "), DLT_INT(prio));
58 return GEN_OUTOFRANGE;
62 newEntry.hook = hookClass;
65 case HOOK_DOMAIN_REGISTER:
66 list = &m_domainRegisterList;
68 case HOOK_DOMAIN_DEREGISTER:
69 list = &m_domainDeregisterList;
71 case HOOK_SINK_REGISTER:
72 list = &m_sinkRegisterList;
74 case HOOK_SINK_DEREGISTER:
75 list = &m_sinkDeregisterList;
77 case HOOK_SOURCE_REGISTER:
78 list = &m_sourceRegisterList;
80 case HOOK_SOURCE_DEREGISTER:
81 list = &m_sourceDeregisterList;
83 case HOOK_GATEWAY_REGISTER:
84 list = &m_gatewayRegisterList;
86 case HOOK_GATEWAY_DERGISTER:
87 list = &m_gatewayDeregisterList;
89 case HOOK_ROUTING_REQUEST:
90 list = &m_routingRequestList;
92 case HOOK_ROUTING_COMPLETE:
93 list = &m_routingCompleteList;
95 case HOOK_SYSTEM_READY:
96 list = &m_systemReadyList;
98 case HOOK_SYSTEM_DOWN:
99 list = &m_systemDownList;
101 case HOOK_VOLUME_CHANGE:
102 list = &m_volumeChangeList;
104 case HOOK_MUTE_SOURCE:
105 list = &m_muteSourceList;
107 case HOOK_UNMUTE_SOURCE:
108 list = &m_unmuteSourceList;
111 list = &m_muteSinkList;
113 case HOOK_UNMUTE_SINK:
114 list = &m_unmuteSinkList;
116 case HOOK_USER_CONNECTION_REQUEST:
117 list = &m_userConnectionRequestList;
119 case HOOK_USER_DISCONNECTION_REQUEST:
120 list = &m_userDisconnectionReuestList;
122 case HOOK_CONNECTION_REQUEST:
123 list = &m_connectionRequestList;
125 case HOOK_DISCONNECTION_REQUEST:
126 list = &m_disconnectionReuestList;
128 case HOOK_INTERRUPT_REQUEST:
129 list = &m_interruptRequestList;
132 DLT_LOG(AudioManager, DLT_LOG_WARN, DLT_STRING("Trying to register unknown Hook "));
133 return GEN_OUTOFRANGE;
137 std::list<prioList>::iterator l;
138 for (l = list->begin(); l != list->end(); l++) {
139 if (l->prio > prio) {
143 std::advance(l, index);
144 list->insert(l, newEntry);
145 //TODO test the sorting of the hooks with more than one plugin
150 genError_t HookHandler::fireHookDomainRegister(char* Name, domain_t ID) {
151 for (std::list<prioList>::iterator hook = m_domainRegisterList.begin(); hook != m_domainDeregisterList.end(); hook++) {
152 if (hook->hook->hookDomainRegister(Name, ID) == HOOK_STOP)
158 genError_t HookHandler::fireHookDomainDeregister(domain_t ID) {
159 for (std::list<prioList>::iterator hook = m_domainDeregisterList.begin(); hook != m_domainDeregisterList.end(); hook++) {
160 if (hook->hook->hookDomainDeregister(ID) == HOOK_STOP)
166 genError_t HookHandler::fireHookSinkRegister(char* Name, sink_t ID) {
167 for (std::list<prioList>::iterator hook = m_sinkRegisterList.begin(); hook != m_sinkRegisterList.end(); hook++) {
168 if (hook->hook->hookSinkRegister(Name, ID) == HOOK_STOP)
174 genError_t HookHandler::fireHookSinkDeregister(sink_t ID) {
175 for (std::list<prioList>::iterator hook = m_sinkDeregisterList.begin(); hook != m_sinkDeregisterList.end(); hook++) {
176 if (hook->hook->hookSinkDeregister(ID) == HOOK_STOP)
182 genError_t HookHandler::fireHookSourceRegister(char* Name, source_t ID) {
183 for (std::list<prioList>::iterator hook = m_sourceRegisterList.begin(); hook != m_sourceRegisterList.end(); hook++) {
184 if (hook->hook->hookSourceRegister(Name, ID) == HOOK_STOP)
190 genError_t HookHandler::fireHookSourceDeregister(source_t ID) {
191 for (std::list<prioList>::iterator hook = m_sourceDeregisterList.begin(); hook != m_sourceDeregisterList.end(); hook++) {
192 if (hook->hook->hookSourceDeregister(ID) == HOOK_STOP)
198 genError_t HookHandler::fireHookGatewayRegister(char* Name, gateway_t ID) {
199 for (std::list<prioList>::iterator hook = m_gatewayRegisterList.begin(); hook != m_gatewayRegisterList.end(); hook++) {
200 if (hook->hook->hookGatewayRegister(Name, ID) == HOOK_STOP)
206 genError_t HookHandler::fireHookGatewayDeregister(gateway_t ID) {
207 for (std::list<prioList>::iterator hook = m_gatewayDeregisterList.begin(); hook != m_gatewayDeregisterList.end(); hook++) {
208 if (hook->hook->hookGatewayDeregister(ID) == HOOK_STOP)
214 genError_t HookHandler::fireHookSystemReady(void) {
215 for (std::list<prioList>::iterator hook = m_systemReadyList.begin(); hook != m_systemReadyList.end(); hook++) {
216 if (hook->hook->hookSystemReady() == HOOK_STOP)
222 genError_t HookHandler::fireHookSystemDown(void) {
223 for (std::list<prioList>::iterator hook = m_systemDownList.begin(); hook != m_systemDownList.end(); hook++) {
224 if (hook->hook->hookSystemDown() == HOOK_STOP)
230 genError_t HookHandler::fireHookConnectionRequest(source_t SourceID, sink_t SinkID) {
231 for (std::list<prioList>::iterator hook = m_connectionRequestList.begin(); hook != m_connectionRequestList.end(); hook++) {
232 if (hook->hook->hookConnectionRequest(SourceID, SinkID) == HOOK_STOP)
238 genError_t HookHandler::fireHookDisconnectionRequest(connection_t ID) {
239 for (std::list<prioList>::iterator hook = m_disconnectionReuestList.begin(); hook != m_disconnectionReuestList.end(); hook++) {
240 if (hook->hook->hookDisconnectionRequest(ID) == HOOK_STOP)
246 genError_t HookHandler::fireHookUserConnectionRequest(Queue* queue, source_t SourceID, sink_t SinkID) {
247 for (std::list<prioList>::iterator hook = m_userConnectionRequestList.begin(); hook != m_userConnectionRequestList.end(); hook++) {
248 if (hook->hook->hookUserConnectionRequest(queue, SourceID, SinkID) == HOOK_STOP)
254 genError_t HookHandler::fireHookUserDisconnectionRequest(Queue* queue, connection_t connID) {
255 for (std::list<prioList>::iterator hook = m_userDisconnectionReuestList.begin(); hook != m_userDisconnectionReuestList.end(); hook++) {
256 if (hook->hook->hookUserDisconnectionRequest(queue, connID) == HOOK_STOP)
262 genError_t HookHandler::fireHookRoutingRequest(bool onlyfree, source_t source, sink_t sink, std::list<genRoute_t>* ReturnList) {
263 for (std::list<prioList>::iterator hook = m_routingRequestList.begin(); hook != m_routingRequestList.end(); hook++) {
264 if (hook->hook->hookRoutingRequest(onlyfree, source, sink, ReturnList) == HOOK_STOP)
271 genError_t HookHandler::fireHookRoutingComplete(genRoute_t route) {
272 for (std::list<prioList>::iterator hook = m_routingCompleteList.begin(); hook != m_routingCompleteList.end(); hook++) {
273 if (hook->hook->hookRoutingComplete(route) == HOOK_STOP)
279 genError_t HookHandler::fireHookVolumeChange(volume_t newVolume, sink_t SinkID) {
280 for (std::list<prioList>::iterator hook = m_volumeChangeList.begin(); hook != m_volumeChangeList.end(); hook++) {
281 if (hook->hook->hookVolumeChange(newVolume, SinkID) == HOOK_STOP)
287 genError_t HookHandler::fireHookMuteSource(source_t ID) {
288 for (std::list<prioList>::iterator hook = m_muteSourceList.begin(); hook != m_muteSourceList.end(); hook++) {
289 if (hook->hook->hookMuteSource(ID) == HOOK_STOP)
295 genError_t HookHandler::fireHookUnmuteSource(source_t ID) {
296 for (std::list<prioList>::iterator hook = m_unmuteSourceList.begin(); hook != m_unmuteSourceList.end(); hook++) {
297 if (hook->hook->hookUnmuteSource(ID) == HOOK_STOP)
303 genError_t HookHandler::fireHookMuteSink(sink_t ID) {
304 for (std::list<prioList>::iterator hook = m_muteSinkList.begin(); hook != m_muteSinkList.end(); hook++) {
305 if (hook->hook->hookMuteSink(ID) == HOOK_STOP)
311 genError_t HookHandler::fireHookUnmuteSink(sink_t ID) {
312 for (std::list<prioList>::iterator hook = m_unmuteSinkList.begin(); hook != m_unmuteSinkList.end(); hook++) {
313 if (hook->hook->hookUnmuteSink(ID) == HOOK_STOP)
319 genError_t HookHandler::fireHookInterruptRequest(Queue* queue, source_t interruptSource, sink_t sink, genInt_t* interruptID) {
320 for (std::list<prioList>::iterator hook = m_interruptRequestList.begin(); hook != m_interruptRequestList.end(); hook++) {
321 if (hook->hook->hookInterruptRequest(queue, interruptSource, sink, interruptID) == HOOK_STOP)
327 void HookHandler::registerAudioManagerCore(AudioManagerCore* core) {
331 void HookHandler::loadHookPlugins() {
333 // foreach(QObject * plugin, QPluginLoader::staticInstances())
335 // HookPluginFactory* HookPluginFactory_ = qobject_cast<HookPluginFactory *>(plugin);
336 // if (HookPluginFactory_) {
337 // b = HookPluginFactory_->returnInstance();
338 // b->registerHookEngine(this);
339 // b->registerAudioManagerCore(m_core);
342 // if (b->returnPluginName(pName) == GEN_OK) {
343 // DLT_LOG( AudioManager, DLT_LOG_INFO, DLT_STRING("Registered Hook Plugin:"), DLT_STRING(pName));
344 // m_listofPlugins.append(b);