28 #include <sys/types.h>
34 #include "TAmPluginTemplate.h"
36 #include "audiomanagerconfig.h"
44 #define CALL_ALL_INTERFACES(...) \
45 std::vector<IAmCommandSend*>::iterator iter = mListInterfaces.begin(); \
46 std::vector<IAmCommandSend*>::iterator iterEnd = mListInterfaces.end(); \
47 for (; iter<iterEnd;++iter) \
49 (*iter)->__VA_ARGS__; \
54 mListLibraryHandles(),
58 if (listOfPluginDirectories.empty())
60 logError(
"CAmCommandSender::CAmCommandSender: List of commandplugins is empty");
63 std::vector<std::string> sharedLibraryNameList;
64 std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin();
65 std::vector<std::string>::const_iterator dirIterEnd = listOfPluginDirectories.end();
68 for (; dirIter < dirIterEnd; ++dirIter)
70 const char* directoryName = dirIter->c_str();
71 logInfo(
"Searching for CommandPlugins in", *dirIter);
72 DIR *directory = opendir(directoryName);
76 logError(
"Error opening directory ", *dirIter);
81 struct dirent *itemInDirectory = 0;
82 while ((itemInDirectory = readdir(directory)))
84 unsigned char entryType = itemInDirectory->d_type;
85 std::string entryName = itemInDirectory->d_name;
86 std::string fullName = *dirIter +
"/" + entryName;
88 bool regularFile = (entryType == DT_REG || entryType == DT_LNK);
89 bool sharedLibExtension = (
"so" == entryName.substr(entryName.find_last_of(
".") + 1));
92 if (entryType == DT_UNKNOWN) {
95 if (stat(fullName.c_str(), &buf)) {
96 logInfo(__PRETTY_FUNCTION__,
"Failed to stat file: ", entryName, errno);
100 regularFile = S_ISREG(buf.st_mode);
103 if (regularFile && sharedLibExtension)
105 std::string name(directoryName);
106 sharedLibraryNameList.push_back(name +
"/" + entryName);
113 std::vector<std::string>::iterator iter = sharedLibraryNameList.begin();
114 std::vector<std::string>::iterator iterEnd = sharedLibraryNameList.end();
116 for (; iter < iterEnd; ++iter)
118 logInfo(
"Loading CommandSender plugin", *iter);
120 void* tempLibHandle = NULL;
121 createFunc = getCreateFunction<IAmCommandSend*()>(*iter, tempLibHandle);
125 logInfo(
"Entry point of CommandPlugin not found", *iter);
133 logInfo(
"CommandPlugin initialization failed. Entry Function not callable");
134 dlclose(tempLibHandle);
141 uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion;
142 std::istringstream(version.substr(0, 1)) >> majorVersion;
143 std::istringstream(version.substr(2, 1)) >> minorVersion;
144 std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion;
145 std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion;
149 if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion)))
151 logError(
"CommandInterface initialization failed. Version of Interface to old");
152 dlclose(tempLibHandle);
156 mListInterfaces.push_back(commander);
157 mListLibraryHandles.push_back(tempLibHandle);
158 mListLibraryNames.push_back(iter->c_str());
169 mCommandReceiver = iCommandReceiver;
172 std::vector<IAmCommandSend*>::iterator iter = mListInterfaces.begin();
173 std::vector<IAmCommandSend*>::iterator iterEnd = mListInterfaces.end();
174 for (; iter < iterEnd; ++iter)
176 am_Error_e error = (*iter)->startupInterface(iCommandReceiver);
182 return (returnError);
275 std::vector<uint16_t> listStartupHandles;
276 for (
size_t i = 0; i < mListInterfaces.size(); i++)
285 std::vector<IAmCommandSend*>::iterator iter = mListInterfaces.begin();
286 std::vector<IAmCommandSend*>::iterator iterEnd = mListInterfaces.end();
287 std::vector<uint16_t>::const_iterator handleIter(listStartupHandles.begin());
288 for (; iter < iterEnd; ++iter)
290 (*iter)->setCommandReady(*(handleIter++));
298 std::vector<uint16_t> listStartupHandles;
299 for (
size_t i = 0; i < mListInterfaces.size(); i++)
308 std::vector<IAmCommandSend*>::iterator iter = mListInterfaces.begin();
309 std::vector<IAmCommandSend*>::iterator iterEnd = mListInterfaces.end();
310 std::vector<uint16_t>::const_iterator handleIter(listStartupHandles.begin());
311 for (; iter < iterEnd; ++iter)
313 (*iter)->setCommandRundown(*(handleIter++));
324 interfaces = mListLibraryNames;
350 CALL_ALL_INTERFACES(cbMainSinkNotificationConfigurationChanged(sinkID,mainNotificationConfiguration));
355 CALL_ALL_INTERFACES(cbMainSourceNotificationConfigurationChanged(sourceID,mainNotificationConfiguration));
358 void CAmCommandSender::unloadLibraries(
void)
360 std::vector<void*>::iterator iterator = mListLibraryHandles.begin();
361 for (; iterator < mListLibraryHandles.end(); ++iterator)
365 mListLibraryHandles.clear();
am_Error_e getListPlugins(std::vector< std::string > &interfaces) const
void cbNumberOfSourceClassesChanged()
void cbNewSink(am_SinkType_s sink)
This class realizes the command Interface.
uint16_t getRundownHandle()
returns a rundown handle
am_Error_e startupInterfaces(CAmCommandReceiver *iCommandReceiver)
am_Error_e
the errors of the audiomanager.
This struct holds information about the configuration for notifications.
void logInfo(T value, TArgs...args)
logs given values with infolevel with the default context
void cbSystemPropertyChanged(const am_SystemProperty_s &systemProperty)
void cbSinkUpdated(const am_sinkID_t sinkID, const am_sinkClass_t sinkClassID, const std::vector< am_MainSoundProperty_s > &listMainSoundProperties)
void cbNewMainConnection(const am_MainConnectionType_s mainConnection)
This struct holds the payload of a notification.
virtual void getInterfaceVersion(std::string &version) const =0
returns the interface version as string.
#define CALL_ALL_INTERFACES(...)
macro to call all interfaces
void cbSourceNotification(const am_sourceID_t sourceID, const am_NotificationPayload_s ¬ification)
this type holds all information of sinks relevant to the HMI
int16_t am_timeSync_t
offset time that is introduced in milli seconds.
void cbMainSinkSoundPropertyChanged(const am_sinkID_t sinkID, const am_MainSoundProperty_s &soundProperty)
SPDX license identifier: MPL-2.0.
void cbMainSourceSoundPropertyChanged(const am_sourceID_t sourceID, const am_MainSoundProperty_s &soundProperty)
void cbRemovedSource(const am_sourceID_t source)
void cbTimingInformationChanged(const am_mainConnectionID_t mainConnectionID, const am_timeSync_t time)
void cbNewSource(const am_SourceType_s source)
struct describing system properties
void waitOnRundown(bool rundown)
tells the ComandReceiver to start waiting for all handles to be confirmed
SPDX license identifier: MPL-2.0.
CAmCommandSender(const std::vector< std::string > &listOfPluginDirectories)
struct describung mainsound property
void getInterfaceVersion(std::string &version) const
void cbNumberOfSinkClassesChanged()
uint16_t am_sourceID_t
a source ID
void cbSinkNotification(const am_sinkID_t sinkID, const am_NotificationPayload_s ¬ification)
am_ConnectionState_e
represents the connection state
void cbSourceMainNotificationConfigurationChanged(const am_sourceID_t sourceID, const am_NotificationConfiguration_s &mainNotificationConfiguration)
this type holds all information of connections relevant to the HMI
void cbSourceUpdated(const am_sourceID_t sourceID, const am_sourceClass_t sourceClassID, const std::vector< am_MainSoundProperty_s > &listMainSoundProperties)
void cbSinkMuteStateChanged(const am_sinkID_t sinkID, const am_MuteState_e muteState)
uint16_t am_sourceClass_t
void cbRemovedMainConnection(const am_mainConnectionID_t mainConnection)
this describes the availability of a sink or a source together with the latest change ...
void logError(T value, TArgs...args)
logs given values with errorlevel with the default context
void cbSinkAvailabilityChanged(const am_sinkID_t sinkID, const am_Availability_s &availability)
void waitOnStartup(bool startup)
tells the ComandReceiver to start waiting for all handles to be confirmed
void cbVolumeChanged(const am_sinkID_t sinkID, const am_mainVolume_t volume)
void cbSinkMainNotificationConfigurationChanged(const am_sinkID_t sinkID, const am_NotificationConfiguration_s &mainNotificationConfiguration)
void cbMainConnectionStateChanged(const am_mainConnectionID_t connectionID, const am_ConnectionState_e connectionState)
SPDX license identifier: MPL-2.0.
int16_t am_mainVolume_t
This is the volume presented on the command interface.
no error - positive reply
void cbSourceAvailabilityChanged(const am_sourceID_t sourceID, const am_Availability_s &availability)
uint16_t getStartupHandle()
returns a startup handle
this type holds all information of sources relevant to the HMI
uint16_t am_sinkID_t
a sink ID
uint16_t am_mainConnectionID_t
a mainConnection ID
This interface handles all communication from the AudioManagerDaemon towards the system.
void cbRemovedSink(const am_sinkID_t sink)