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"
30 #include "PluginTemplate.h"
34 #define CALL_ALL_INTERFACES(...) \
35 std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin(); \
36 std::vector<InterfaceNamePairs>::iterator iterEnd = mListInterfaces.end(); \
37 for (; iter<iterEnd;++iter) \
39 (*iter).routingInterface->__VA_ARGS__; \
42 RoutingSender::RoutingSender(const std::vector<std::string>& listOfPluginDirectories)
47 mMapConnectionInterface(),
48 mMapCrossfaderInterface(),
49 mMapDomainInterface(),
51 mMapSourceInterface(),
54 std::vector<std::string> sharedLibraryNameList;
55 std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin();
56 std::vector<std::string>::const_iterator dirIterEnd = listOfPluginDirectories.end();
58 // search communicator plugins in configured directories
59 for (; dirIter < dirIterEnd; ++dirIter)
61 const char* directoryName = dirIter->c_str();
62 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Searching for HookPlugins in"),DLT_STRING(directoryName));
63 DIR *directory = opendir(directoryName);
67 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Error opening directory "),DLT_STRING(dirName.c_str()));
70 // iterate content of directory
71 struct dirent *itemInDirectory = 0;
72 while ((itemInDirectory = readdir(directory)))
74 unsigned char entryType = itemInDirectory->d_type;
75 std::string entryName = itemInDirectory->d_name;
77 bool regularFile = (entryType == DT_REG);
78 bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1));
80 if (regularFile && sharedLibExtension)
82 // DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("PluginSearch adding file "),DLT_STRING(entryName.c_str()));
83 std::string name(directoryName);
84 sharedLibraryNameList.push_back(name + "/" + entryName);
88 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("PluginSearch ignoring file "),DLT_STRING(entryName.c_str()));
95 // iterate all communicator plugins and start them
96 std::vector<std::string>::iterator iter = sharedLibraryNameList.begin();
97 std::vector<std::string>::iterator iterEnd = sharedLibraryNameList.end();
99 for (; iter != iterEnd; ++iter)
101 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Loading Hook plugin"),DLT_STRING(iter->c_str()));
103 RoutingSendInterface* (*createFunc)();
104 void* tempLibHandle=NULL;
105 createFunc = getCreateFunction<RoutingSendInterface*()>(*iter,tempLibHandle);
109 // DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("Entry point of Communicator not found"));
113 RoutingSendInterface* router = createFunc();
117 //DLT_LOG(AudioManager,DLT_LOG_INFO, DLT_STRING("HookPlugin initialization failed. Entry Function not callable"));
121 InterfaceNamePairs routerInterface;
122 routerInterface.routingInterface = router;
124 //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain....
125 router->returnBusName(routerInterface.busName);
126 mListInterfaces.push_back(routerInterface);
127 mListLibraryHandles.push_back(tempLibHandle);
129 //now all plugins are loaded, so the interface is ready
132 RoutingSender::~RoutingSender()
137 void RoutingSender::routingInterfacesReady()
139 CALL_ALL_INTERFACES(routingInterfacesReady())
142 void RoutingSender::routingInterfacesRundown()
144 CALL_ALL_INTERFACES(routingInterfacesRundown())
147 void RoutingSender::startupRoutingInterface(RoutingReceiveInterface *routingreceiveinterface)
149 CALL_ALL_INTERFACES(startupRoutingInterface(routingreceiveinterface))
152 am_Error_e RoutingSender::asyncAbort(const am_Handle_s& handle)
154 HandleInterfaceMap::iterator iter = mMapHandleInterface.begin();
155 iter=mMapHandleInterface.find(handle.handle);
156 if (iter != mMapHandleInterface.end())
158 return iter->second->asyncAbort(handle);
161 return E_NON_EXISTENT;
166 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)
168 am_handleData_c handleData;
169 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
170 iter=mMapSinkInterface.find(sinkID);
171 if (iter != mMapSinkInterface.end())
173 handleData.connectionID=connectionID;
174 handle=createHandle(handleData,H_CONNECT);
175 mMapConnectionInterface.insert(std::make_pair(connectionID,iter->second));
176 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
177 return iter->second->asyncConnect(handle,connectionID,sourceID,sinkID,connectionFormat);
180 return E_NON_EXISTENT;
185 am_Error_e RoutingSender::asyncDisconnect(am_Handle_s& handle, const am_connectionID_t connectionID)
187 am_handleData_c handleData;
188 ConnectionInterfaceMap::iterator iter = mMapConnectionInterface.begin();
189 mMapConnectionInterface.find(connectionID);
190 if (iter != mMapConnectionInterface.end())
192 handleData.connectionID=connectionID;
193 handle=createHandle(handleData,H_DISCONNECT);
194 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
195 am_Error_e returnVal=iter->second->asyncDisconnect(handle,connectionID);
196 mMapConnectionInterface.erase(iter);
200 return E_NON_EXISTENT;
205 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)
207 am_handleData_c handleData;
208 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
209 iter=mMapSinkInterface.find(sinkID);
210 if (iter != mMapSinkInterface.end())
211 handleData.sinkID=sinkID;
212 handleData.volume=volume;
213 handle=createHandle(handleData,H_SETSINKVOLUME);
214 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
215 return iter->second->asyncSetSinkVolume(handle,sinkID,volume,ramp,time);
216 return E_NON_EXISTENT;
221 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)
223 am_handleData_c handleData;
224 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
225 iter=mMapSourceInterface.find(sourceID);
226 if (iter != mMapSourceInterface.end())
227 handleData.sourceID=sourceID;
228 handleData.volume=volume;
229 handle=createHandle(handleData,H_SETSOURCEVOLUME);
230 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
231 return iter->second->asyncSetSourceVolume(handle,sourceID,volume,ramp,time);
232 return E_NON_EXISTENT;
237 am_Error_e RoutingSender::asyncSetSourceState(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SourceState_e state)
239 am_handleData_c handleData;
240 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
241 iter=mMapSourceInterface.find(sourceID);
242 if (iter != mMapSourceInterface.end())
243 handleData.sourceID=sourceID;
244 handleData.sourceState=state;
245 handle=createHandle(handleData,H_SETSOURCESTATE);
246 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
247 return iter->second->asyncSetSourceState(handle,sourceID,state);
248 return E_NON_EXISTENT;
253 am_Error_e RoutingSender::asyncSetSinkSoundProperty(am_Handle_s& handle, const am_sinkID_t sinkID, const am_SoundProperty_s & soundProperty)
255 am_handleData_c handleData;
256 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
257 iter=mMapSinkInterface.find(sinkID);
258 if (iter != mMapSinkInterface.end())
259 handleData.sinkID=sinkID;
260 handleData.soundPropery=soundProperty;
261 handle=createHandle(handleData,H_SETSINKSOUNDPROPERTY);
262 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
263 return iter->second->asyncSetSinkSoundProperty(handle,soundProperty,sinkID);
264 return E_NON_EXISTENT;
269 am_Error_e RoutingSender::asyncSetSourceSoundProperty(am_Handle_s& handle, const am_sourceID_t sourceID, const am_SoundProperty_s & soundProperty)
271 am_handleData_c handleData;
272 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
273 iter=mMapSourceInterface.find(sourceID);
274 if (iter != mMapSourceInterface.end())
275 handleData.sourceID=sourceID;
276 handleData.soundPropery=soundProperty;
277 handle=createHandle(handleData,H_SETSOURCESOUNDPROPERTY);
278 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
279 return iter->second->asyncSetSourceSoundProperty(handle,soundProperty,sourceID);
280 return E_NON_EXISTENT;
285 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)
287 am_handleData_c handleData;
288 CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin();
289 iter=mMapCrossfaderInterface.find(crossfaderID);
290 if (iter != mMapCrossfaderInterface.end())
291 handleData.crossfaderID=crossfaderID;
292 handleData.hotSink=hotSink;
293 handle=createHandle(handleData,H_CROSSFADE);
294 mMapHandleInterface.insert(std::make_pair(handle.handle,iter->second));
295 return iter->second->asyncCrossFade(handle,crossfaderID,hotSink,rampType,time);
296 return E_NON_EXISTENT;
301 am_Error_e RoutingSender::setDomainState(const am_domainID_t domainID, const am_DomainState_e domainState)
303 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
304 iter=mMapDomainInterface.find(domainID);
305 if (iter != mMapDomainInterface.end())
306 return iter->second->setDomainState(domainID,domainState);
307 return E_NON_EXISTENT;
310 am_Error_e RoutingSender::addDomainLookup(const am_Domain_s& domainData)
312 std::vector<InterfaceNamePairs>::iterator iter = mListInterfaces.begin();
313 std::vector<InterfaceNamePairs>::iterator iterEnd = mListInterfaces.end();
314 for (; iter<iterEnd;++iter)
316 if((*iter).busName.compare(domainData.busname) == 0)
318 mMapDomainInterface.insert(std::make_pair(domainData.domainID,(*iter).routingInterface));
328 am_Error_e RoutingSender::addSourceLookup(const am_Source_s& sourceData)
330 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
331 iter=mMapDomainInterface.find(sourceData.domainID);
332 if (iter != mMapDomainInterface.end())
334 mMapSourceInterface.insert(std::make_pair(sourceData.sourceID,iter->second));
343 am_Error_e RoutingSender::addSinkLookup(const am_Sink_s& sinkData)
345 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
346 iter=mMapDomainInterface.find(sinkData.domainID);
347 if (iter != mMapDomainInterface.end())
349 mMapSinkInterface.insert(std::make_pair(sinkData.sinkID,iter->second));
358 am_Error_e RoutingSender::addCrossfaderLookup(const am_Crossfader_s& crossfaderData)
360 DomainInterfaceMap::iterator iter = mMapSourceInterface.begin();
361 iter=mMapSourceInterface.find(crossfaderData.sourceID);
362 if (iter != mMapSourceInterface.end())
364 mMapSourceInterface.insert(std::make_pair(crossfaderData.crossfaderID,iter->second));
371 am_Error_e RoutingSender::removeDomainLookup(const am_domainID_t domainID)
373 DomainInterfaceMap::iterator iter = mMapDomainInterface.begin();
374 iter=mMapDomainInterface.find(domainID);
375 if (iter != mMapDomainInterface.end())
377 mMapDomainInterface.erase(iter);
381 return E_NON_EXISTENT;
386 am_Error_e RoutingSender::removeSourceLookup(const am_sourceID_t sourceID)
388 SourceInterfaceMap::iterator iter = mMapSourceInterface.begin();
389 iter=mMapSourceInterface.find(sourceID);
390 if (iter != mMapSourceInterface.end())
392 mMapSourceInterface.erase(iter);
396 return E_NON_EXISTENT;
401 am_Error_e RoutingSender::removeSinkLookup(const am_sinkID_t sinkID)
403 SinkInterfaceMap::iterator iter = mMapSinkInterface.begin();
404 iter=mMapSinkInterface.find(sinkID);
405 if (iter != mMapSinkInterface.end())
407 mMapSinkInterface.erase(iter);
411 return E_NON_EXISTENT;
416 am_Error_e RoutingSender::removeCrossfaderLookup(const am_crossfaderID_t crossfaderID)
418 CrossfaderInterfaceMap::iterator iter = mMapCrossfaderInterface.begin();
419 iter=mMapCrossfaderInterface.find(crossfaderID);
420 if (iter != mMapCrossfaderInterface.end())
422 mMapCrossfaderInterface.erase(iter);
426 return E_NON_EXISTENT;
430 am_Error_e RoutingSender::removeHandle(const am_Handle_s& handle)
432 if(mlistActiveHandles.erase(handle)) return E_OK;
436 am_Error_e RoutingSender::getListHandles(std::vector<am_Handle_s> & listHandles) const
439 HandlesMap::const_iterator it=mlistActiveHandles.begin();
440 for(;it!=mlistActiveHandles.end();++it)
442 listHandles.push_back(it->first);
447 am_Handle_s RoutingSender::createHandle(const am_handleData_c& handleData, const am_Handle_e type)
450 handle.handle=++mHandleCount; //todo: handle overflows here...
451 handle.handleType=type;
452 mlistActiveHandles.insert(std::make_pair(handle,handleData));
456 RoutingSender::am_handleData_c RoutingSender::returnHandleData(am_Handle_s handle)
458 HandlesMap::iterator it=mlistActiveHandles.begin();
459 it=mlistActiveHandles.find(handle);
463 void RoutingSender::unloadLibraries(void)
465 std::vector<void*>::iterator iterator=mListLibraryHandles.begin();
466 for(;iterator<mListLibraryHandles.end();++iterator)
470 mListLibraryHandles.clear();