2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file RoutingSender.h
8 * \date 20-Oct-2011 3:42:04 PM
9 * \author Christian Mueller (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 Mueller 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.
25 #include "RoutingSender.h"
26 #include "PluginTemplate.h"
32 #define CALL_ALL_INTERFACES(...) \
33 std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin(); \
34 std::vector<InterfaceNamePairs>::iterator iterEnd = mListInterfaces.end(); \
35 for (; iter<iterEnd;++iter) \
37 (*iter).routingInterface->__VA_ARGS__; \
40 RoutingSender::RoutingSender(const std::vector<std::string>& listOfPluginDirectories)
45 mMapConnectionInterface(),
46 mMapCrossfaderInterface(),
47 mMapDomainInterface(),
49 mMapSourceInterface(),
52 std::vector<std::string> sharedLibraryNameList;
53 std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin();
54 std::vector<std::string>::const_iterator dirIterEnd = listOfPluginDirectories.end();
56 // search communicator plugins in configured directories
57 for (; dirIter < dirIterEnd; ++dirIter)
59 const char* directoryName = dirIter->c_str();
60 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Searching for HookPlugins in"),DLT_STRING(directoryName));
61 DIR *directory = opendir(directoryName);
65 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Error opening directory "),DLT_STRING(dirName.c_str()));
68 // iterate content of directory
69 struct dirent *itemInDirectory = 0;
70 while ((itemInDirectory = readdir(directory)))
72 unsigned char entryType = itemInDirectory->d_type;
73 std::string entryName = itemInDirectory->d_name;
75 bool regularFile = (entryType == DT_REG);
76 bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1));
78 if (regularFile && sharedLibExtension)
80 // DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("PluginSearch adding file "),DLT_STRING(entryName.c_str()));
81 std::string name(directoryName);
82 sharedLibraryNameList.push_back(name + "/" + entryName);
86 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("PluginSearch ignoring file "),DLT_STRING(entryName.c_str()));
93 // iterate all communicator plugins and start them
94 std::vector<std::string>::iterator iter = sharedLibraryNameList.begin();
95 std::vector<std::string>::iterator iterEnd = sharedLibraryNameList.end();
97 for (; iter != iterEnd; ++iter)
99 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Loading Hook plugin"),DLT_STRING(iter->c_str()));
101 RoutingSendInterface* (*createFunc)();
102 void* tempLibHandle=NULL;
103 createFunc = getCreateFunction<RoutingSendInterface*()>(*iter,tempLibHandle);
107 // DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Entry point of Communicator not found"));
111 RoutingSendInterface* router = createFunc();
115 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("HookPlugin initialization failed. Entry Function not callable"));
119 InterfaceNamePairs routerInterface;
120 routerInterface.routingInterface = router;
121 router->returnBusName(routerInterface.busName);
122 mListInterfaces.push_back(routerInterface);
123 mListLibraryHandles.push_back(tempLibHandle);
127 RoutingSender::~RoutingSender()
132 void RoutingSender::routingInterfacesReady()
134 CALL_ALL_INTERFACES(routingInterfacesReady())
137 void RoutingSender::routingInterfacesRundown()
139 CALL_ALL_INTERFACES(routingInterfacesRundown())
142 void RoutingSender::startupRoutingInterface(RoutingReceiveInterface *routingreceiveinterface)
144 CALL_ALL_INTERFACES(startupRoutingInterface(routingreceiveinterface))
147 am_Error_e RoutingSender::asyncAbort(const am_Handle_s& handle)
149 HandleInterfaceMap::iterator iter = mMapHandleInterface.begin();
150 iter=mMapHandleInterface.find(handle.handle);
151 if (iter != mMapHandleInterface.end())
153 return iter->second->asyncAbort(handle);
156 return E_NON_EXISTENT;
161 am_Error_e RoutingSender::asyncConnect(am_Handle_s& handle, const am_connectionID_t connectionID, const am_sourceID_t sourceID, const am_sinkID_t sinkID, const am_ConnectionFormat_e connectionFormat)
163 am_handleData_c handleData;
164 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
165 iter=mMapSinkInterface.find(sinkID);
166 if (iter != mMapSinkInterface.end())
168 handleData.connectionID=connectionID;
169 handle=createHandle(handleData,H_CONNECT);
170 mMapConnectionInterface.insert(std::make_pair(connectionID,iter->second));
171 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
172 return iter->second->asyncConnect(handle,connectionID,sourceID,sinkID,connectionFormat);
175 return E_NON_EXISTENT;
180 am_Error_e RoutingSender::asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID)
182 am_handleData_c handleData;
183 ConnectionInterfaceMap::iterator iter = mMapConnectionInterface.begin();
184 mMapConnectionInterface.find(connectionID);
185 if (iter != mMapConnectionInterface.end())
187 handleData.connectionID=connectionID;
188 handle=createHandle(handleData,H_DISCONNECT);
189 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
190 am_Error_e returnVal=iter->second->asyncDisconnect(handle,connectionID);
191 mMapConnectionInterface.erase(iter);
195 return E_NON_EXISTENT;
200 am_Error_e RoutingSender::asyncSetSinkVolume(am_Handle_s& handle, const am_sinkID_t sinkID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)
202 am_handleData_c handleData;
203 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
204 iter=mMapSinkInterface.find(sinkID);
205 if (iter != mMapSinkInterface.end())
206 handleData.sinkID=sinkID;
207 handleData.volume=volume;
208 handle=createHandle(handleData,H_SETSINKVOLUME);
209 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
210 return iter->second->asyncSetSinkVolume(handle,sinkID,volume,ramp,time);
211 return E_NON_EXISTENT;
216 am_Error_e RoutingSender::asyncSetSourceVolume(am_Handle_s& handle, const am_sourceID_t sourceID, const am_volume_t volume, const am_RampType_e ramp, const am_time_t time)
218 am_handleData_c handleData;
219 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
220 iter=mMapSourceInterface.find(sourceID);
221 if (iter != mMapSourceInterface.end())
222 handleData.sourceID=sourceID;
223 handleData.volume=volume;
224 handle=createHandle(handleData,H_SETSOURCEVOLUME);
225 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
226 return iter->second->asyncSetSourceVolume(handle,sourceID,volume,ramp,time);
227 return E_NON_EXISTENT;
232 am_Error_e RoutingSender::asyncSetSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state)
234 am_handleData_c handleData;
235 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
236 iter=mMapSourceInterface.find(sourceID);
237 if (iter != mMapSourceInterface.end())
238 handleData.sourceID=sourceID;
239 handleData.sourceState=state;
240 handle=createHandle(handleData,H_SETSOURCESTATE);
241 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
242 return iter->second->asyncSetSourceState(handle,sourceID,state);
243 return E_NON_EXISTENT;
248 am_Error_e RoutingSender::asyncSetSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty)
250 am_handleData_c handleData;
251 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
252 iter=mMapSinkInterface.find(sinkID);
253 if (iter != mMapSinkInterface.end())
254 handleData.sinkID=sinkID;
255 handleData.soundPropery=soundProperty;
256 handle=createHandle(handleData,H_SETSINKSOUNDPROPERTY);
257 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
258 return iter->second->asyncSetSinkSoundProperty(handle,soundProperty,sinkID);
259 return E_NON_EXISTENT;
264 am_Error_e RoutingSender::asyncSetSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty)
266 am_handleData_c handleData;
267 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
268 iter=mMapSourceInterface.find(sourceID);
269 if (iter != mMapSourceInterface.end())
270 handleData.sourceID=sourceID;
271 handleData.soundPropery=soundProperty;
272 handle=createHandle(handleData,H_SETSOURCESOUNDPROPERTY);
273 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
274 return iter->second->asyncSetSourceSoundProperty(handle,soundProperty,sourceID);
275 return E_NON_EXISTENT;
280 am_Error_e RoutingSender::asyncCrossFade(am_Handle_s& handle, const am_crossfaderID_t crossfaderID, const am_HotSink_e hotSink, const am_RampType_e rampType, const am_time_t time)
282 am_handleData_c handleData;
283 CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin();
284 iter=mMapCrossfaderInterface.find(crossfaderID);
285 if (iter != mMapCrossfaderInterface.end())
286 handleData.crossfaderID=crossfaderID;
287 handleData.hotSink=hotSink;
288 handle=createHandle(handleData,H_CROSSFADE);
289 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
290 return iter->second->asyncCrossFade(handle,crossfaderID,hotSink,rampType,time);
291 return E_NON_EXISTENT;
296 am_Error_e RoutingSender::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
298 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
299 iter=mMapDomainInterface.find(domainID);
300 if (iter != mMapDomainInterface.end())
301 return iter->second->setDomainState(domainID,domainState);
302 return E_NON_EXISTENT;
305 am_Error_e RoutingSender::addDomainLookup(const am_Domain_s& domainData)
307 std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin();
308 std::vector<InterfaceNamePairs>::iterator iterEnd = mListInterfaces.end();
309 for (; iter<iterEnd;++iter)
311 if((*iter).busName.compare(domainData.busname) == 0)
313 mMapDomainInterface.insert(std::make_pair(domainData.domainID,(*iter).routingInterface));
323 am_Error_e RoutingSender::addSourceLookup(const am_Source_s& sourceData)
325 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
326 iter=mMapDomainInterface.find(sourceData.domainID);
327 if (iter != mMapDomainInterface.end())
329 mMapSourceInterface.insert(std::make_pair(sourceData.sourceID,iter->second));
338 am_Error_e RoutingSender::addSinkLookup(const am_Sink_s& sinkData)
340 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
341 iter=mMapDomainInterface.find(sinkData.domainID);
342 if (iter != mMapDomainInterface.end())
344 mMapSinkInterface.insert(std::make_pair(sinkData.sinkID,iter->second));
353 am_Error_e RoutingSender::addCrossfaderLookup(const am_Crossfader_s& crossfaderData)
355 DomainInterfaceMap::iterator iter = mMapSourceInterface.begin();
356 iter=mMapSourceInterface.find(crossfaderData.sourceID);
357 if (iter != mMapSourceInterface.end())
359 mMapSourceInterface.insert(std::make_pair(crossfaderData.crossfaderID,iter->second));
366 am_Error_e RoutingSender::removeDomainLookup(const am_domainID_t domainID)
368 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
369 iter=mMapDomainInterface.find(domainID);
370 if (iter != mMapDomainInterface.end())
372 mMapDomainInterface.erase(iter);
376 return E_NON_EXISTENT;
381 am_Error_e RoutingSender::removeSourceLookup(const am_sourceID_t sourceID)
383 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
384 iter=mMapSourceInterface.find(sourceID);
385 if (iter != mMapSourceInterface.end())
387 mMapSourceInterface.erase(iter);
391 return E_NON_EXISTENT;
396 am_Error_e RoutingSender::removeSinkLookup(const am_sinkID_t sinkID)
398 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
399 iter=mMapSinkInterface.find(sinkID);
400 if (iter != mMapSinkInterface.end())
402 mMapSinkInterface.erase(iter);
406 return E_NON_EXISTENT;
411 am_Error_e RoutingSender::removeCrossfaderLookup(const am_crossfaderID_t crossfaderID)
413 CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin();
414 iter=mMapCrossfaderInterface.find(crossfaderID);
415 if (iter != mMapCrossfaderInterface.end())
417 mMapCrossfaderInterface.erase(iter);
421 return E_NON_EXISTENT;
425 am_Error_e RoutingSender::removeHandle(const am_Handle_s& handle)
427 if(mlistActiveHandles.erase(handle)) return E_OK;
431 am_Error_e RoutingSender::getListHandles(std::vector<am_Handle_s> & listHandles) const
434 HandlesMap::const_iterator it=mlistActiveHandles.begin();
435 for(;it!=mlistActiveHandles.end();++it)
437 listHandles.push_back(it->first);
442 am_Handle_s RoutingSender::createHandle(const am_handleData_c& handleData, const am_Handle_e type)
445 handle.handle=++mHandleCount; //todo: handle overflows here...
446 handle.handleType=type;
447 mlistActiveHandles.insert(std::make_pair(handle,handleData));
451 RoutingSender::am_handleData_c RoutingSender::returnHandleData(am_Handle_s handle)
453 HandlesMap::iterator it=mlistActiveHandles.begin();
454 it=mlistActiveHandles.find(handle);
458 void RoutingSender::unloadLibraries(void)
460 std::vector<void*>::iterator iterator=mListLibraryHandles.begin();
461 for(;iterator<mListLibraryHandles.end();++iterator)
465 mListLibraryHandles.clear();