2 * Copyright (C) 2011, BMW AG
4 * GeniviAudioMananger AudioManagerDaemon
6 * \file CommandSender.cpp
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 "CommandSender.h"
26 #include "command/CommandReceiveInterface.h"
28 #include "PluginTemplate.h"
29 #include "DLTWrapper.h"
33 #define REQUIRED_INTERFACE_VERSION 1
35 //!< macro to call all interfaces
36 #define CALL_ALL_INTERFACES(...) \
37 std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin(); \
38 std::vector<CommandSendInterface*>::iterator iterEnd = mListInterfaces.end(); \
39 for (; iter<iterEnd;++iter) \
41 (*iter)->__VA_ARGS__; \
44 CommandSender::CommandSender(const std::vector<std::string>& listOfPluginDirectories) :
46 mListLibraryHandles(),
49 std::vector<std::string> sharedLibraryNameList;
50 std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin();
51 std::vector<std::string>::const_iterator dirIterEnd = listOfPluginDirectories.end();
53 // search communicator plugins in configured directories
54 for (; dirIter < dirIterEnd; ++dirIter)
56 const char* directoryName = dirIter->c_str();
57 logInfo("Searching for CommandPlugins in" , *dirIter);
58 DIR *directory = opendir(directoryName);
62 logError("Error opening directory ",*dirIter);
66 // iterate content of directory
67 struct dirent *itemInDirectory = 0;
68 while ((itemInDirectory = readdir(directory)))
70 unsigned char entryType = itemInDirectory->d_type;
71 std::string entryName = itemInDirectory->d_name;
73 bool regularFile = (entryType == DT_REG || entryType == DT_LNK);
74 bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1));
76 if (regularFile && sharedLibExtension)
78 std::string name(directoryName);
79 sharedLibraryNameList.push_back(name + "/" + entryName);
85 // iterate all communicator plugins and start them
86 std::vector<std::string>::iterator iter = sharedLibraryNameList.begin();
87 std::vector<std::string>::iterator iterEnd = sharedLibraryNameList.end();
89 for (; iter < iterEnd; ++iter)
91 logInfo("Loading CommandSender plugin", *iter);
92 CommandSendInterface* (*createFunc)();
93 void* tempLibHandle = NULL;
94 createFunc = getCreateFunction<CommandSendInterface*()>(*iter, tempLibHandle);
98 logInfo("Entry point of CommandPlugin not found", *iter);
102 CommandSendInterface* commander = createFunc();
106 logInfo("CommandPlugin initialization failed. Entry Function not callable");
111 if (commander->getInterfaceVersion() < REQUIRED_INTERFACE_VERSION)
113 logInfo("RoutingPlugin initialization failed. Version of Interface to old");
117 mListInterfaces.push_back(commander);
118 mListLibraryHandles.push_back(tempLibHandle);
119 mListLibraryNames.push_back(iter->c_str());
123 CommandSender::~CommandSender()
128 am_Error_e CommandSender::stopInterface()
130 am_Error_e returnError = E_OK;
132 std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin();
133 std::vector<CommandSendInterface*>::iterator iterEnd = mListInterfaces.end();
134 for (; iter < iterEnd; ++iter)
136 am_Error_e error = (*iter)->stopInterface();
145 am_Error_e CommandSender::startupInterface(CommandReceiveInterface *commandreceiveinterface)
147 am_Error_e returnError = E_OK;
149 std::vector<CommandSendInterface*>::iterator iter = mListInterfaces.begin();
150 std::vector<CommandSendInterface*>::iterator iterEnd = mListInterfaces.end();
151 for (; iter < iterEnd; ++iter)
153 am_Error_e error = (*iter)->startupInterface(commandreceiveinterface);
162 void CommandSender::cbCommunicationReady()
164 CALL_ALL_INTERFACES(cbCommunicationReady())
167 void CommandSender::cbCommunicationRundown()
169 CALL_ALL_INTERFACES(cbCommunicationRundown())
172 void CommandSender::cbNumberOfMainConnectionsChanged()
174 CALL_ALL_INTERFACES(cbNumberOfMainConnectionsChanged())
177 void CommandSender::cbNumberOfSinksChanged()
179 CALL_ALL_INTERFACES(cbNumberOfSinksChanged())
182 void CommandSender::cbNumberOfSourcesChanged()
184 CALL_ALL_INTERFACES(cbNumberOfSourcesChanged())
187 void CommandSender::cbNumberOfSinkClassesChanged()
189 CALL_ALL_INTERFACES(cbNumberOfSinkClassesChanged())
192 void CommandSender::cbNumberOfSourceClassesChanged()
194 CALL_ALL_INTERFACES(cbNumberOfSourceClassesChanged())
197 void CommandSender::cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)
199 CALL_ALL_INTERFACES(cbMainConnectionStateChanged(connectionID,connectionState))
202 void CommandSender::cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s SoundProperty)
204 CALL_ALL_INTERFACES(cbMainSinkSoundPropertyChanged(sinkID,SoundProperty))
207 void CommandSender::cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s & SoundProperty)
209 CALL_ALL_INTERFACES(cbMainSourceSoundPropertyChanged(sourceID,SoundProperty))
212 void CommandSender::cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s & availability)
214 CALL_ALL_INTERFACES(cbSinkAvailabilityChanged(sinkID,availability))
217 void CommandSender::cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s & availability)
219 CALL_ALL_INTERFACES(cbSourceAvailabilityChanged(sourceID,availability))
222 void CommandSender::cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume)
224 CALL_ALL_INTERFACES(cbVolumeChanged(sinkID,volume))
227 void CommandSender::cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState)
229 CALL_ALL_INTERFACES(cbSinkMuteStateChanged(sinkID,muteState))
232 void CommandSender::cbSystemPropertyChanged(const am_SystemProperty_s & SystemProperty)
234 CALL_ALL_INTERFACES(cbSystemPropertyChanged(SystemProperty))
237 void CommandSender::cbTimingInformationChanged(const am_mainConnectionID_t mainConnection, const am_timeSync_t time)
239 CALL_ALL_INTERFACES(cbTimingInformationChanged(mainConnection,time))
242 am_Error_e am::CommandSender::getListPlugins(std::vector<std::string> & interfaces) const
244 interfaces = mListLibraryNames;
248 void CommandSender::unloadLibraries(void)
250 std::vector<void*>::iterator iterator = mListLibraryHandles.begin();
251 for (; iterator < mListLibraryHandles.end(); ++iterator)
255 mListLibraryHandles.clear();
258 uint16_t CommandSender::getInterfaceVersion() const
260 return CommandSendVersion;