summaryrefslogtreecommitdiff
path: root/AudioManagerCore/src/CAmRoutingSender.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerCore/src/CAmRoutingSender.cpp')
-rw-r--r--AudioManagerCore/src/CAmRoutingSender.cpp286
1 files changed, 164 insertions, 122 deletions
diff --git a/AudioManagerCore/src/CAmRoutingSender.cpp b/AudioManagerCore/src/CAmRoutingSender.cpp
index fc0953f..9cc013d 100644
--- a/AudioManagerCore/src/CAmRoutingSender.cpp
+++ b/AudioManagerCore/src/CAmRoutingSender.cpp
@@ -45,133 +45,160 @@ namespace am
#define __METHOD_NAME__ std::string (std::string("CAmRoutingSender::") + __func__)
-CAmRoutingSender::CAmRoutingSender(const std::vector<std::string>& listOfPluginDirectories, IAmDatabaseHandler* databaseHandler) :
- mHandleCount(0), //
- mlistActiveHandles(), //
- mListInterfaces(), //
- mMapConnectionInterface(), //
- mMapCrossfaderInterface(), //
- mMapDomainInterface(), //
- mMapSinkInterface(), //
- mMapSourceInterface(), //
- mpRoutingReceiver(), //
- mpDatabaseHandler(databaseHandler)
-{
+CAmRoutingSender::CAmRoutingSender(
+ const std::vector<std::string>& listOfPluginDirectories,
+ IAmDatabaseHandler* databaseHandler) :
+ mHandleCount(0), //
+ mlistActiveHandles(), //
+ mListInterfaces(), //
+ mMapConnectionInterface(), //
+ mMapCrossfaderInterface(), //
+ mMapDomainInterface(), //
+ mMapSinkInterface(), //
+ mMapSourceInterface(), //
+ mpRoutingReceiver(), //
+ mpDatabaseHandler(databaseHandler) {
+
+ if (listOfPluginDirectories.empty()) {
+ logError(__METHOD_NAME__,"List of routingplugins is empty");
+ }
- if (listOfPluginDirectories.empty())
- {
- logError(__METHOD_NAME__,"List of routingplugins is empty");
- }
+ std::vector<std::string> sharedLibraryNameList;
+ std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin();
+ std::vector<std::string>::const_iterator dirIterEnd = listOfPluginDirectories.end();
- std::vector<std::string> sharedLibraryNameList;
- std::vector<std::string>::const_iterator dirIter = listOfPluginDirectories.begin();
- std::vector<std::string>::const_iterator dirIterEnd = listOfPluginDirectories.end();
+ // search communicator plugins in configured directories
+ for (; dirIter < dirIterEnd; ++dirIter)
+ {
+ const char* directoryName = dirIter->c_str();
+ logInfo(__METHOD_NAME__,"Searching for HookPlugins in", directoryName);
+ DIR *directory = opendir(directoryName);
- // search communicator plugins in configured directories
- for (; dirIter < dirIterEnd; ++dirIter)
- {
- const char* directoryName = dirIter->c_str();
- logInfo(__METHOD_NAME__,"Searching for HookPlugins in", directoryName);
- DIR *directory = opendir(directoryName);
+ if (!directory)
+ {
+ logError(__METHOD_NAME__,"Error opening directory: ", directoryName);
+ continue;
+ }
- if (!directory)
- {
- logError(__METHOD_NAME__,"Error opening directory: ", directoryName);
- continue;
- }
+ // iterate content of directory
+ struct dirent *itemInDirectory = 0;
+ while ((itemInDirectory = readdir(directory)))
+ {
+ unsigned char entryType = itemInDirectory->d_type;
+ std::string entryName = itemInDirectory->d_name;
+ std::string fullName = *dirIter + "/" + entryName;
+
+ bool regularFile = (entryType == DT_REG || entryType == DT_LNK);
+ bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1));
+
+ // Handle cases where readdir() could not determine the file type
+ if (entryType == DT_UNKNOWN) {
+ struct stat buf;
+
+ if (stat(fullName.c_str(), &buf)) {
+ logInfo(__METHOD_NAME__,"Failed to stat file: ", entryName, errno);
+ continue;
+ }
+
+ regularFile = S_ISREG(buf.st_mode);
+ }
+
+ if (regularFile && sharedLibExtension)
+ {
+ logInfo(__METHOD_NAME__,"adding file: ", entryName);
+ std::string name(directoryName);
+ sharedLibraryNameList.push_back(name + "/" + entryName);
+ }
+ else
+ {
+ logInfo(__METHOD_NAME__, "plugin search ignoring file :", entryName);
+ }
+ }
- // iterate content of directory
- struct dirent *itemInDirectory = 0;
- while ((itemInDirectory = readdir(directory)))
- {
- unsigned char entryType = itemInDirectory->d_type;
- std::string entryName = itemInDirectory->d_name;
- std::string fullName = *dirIter + "/" + entryName;
-
- bool regularFile = (entryType == DT_REG || entryType == DT_LNK);
- bool sharedLibExtension = ("so" == entryName.substr(entryName.find_last_of(".") + 1));
-
- // Handle cases where readdir() could not determine the file type
- if (entryType == DT_UNKNOWN) {
- struct stat buf;
-
- if (stat(fullName.c_str(), &buf)) {
- logInfo(__METHOD_NAME__,"Failed to stat file: ", entryName, errno);
- continue;
- }
-
- regularFile = S_ISREG(buf.st_mode);
- }
-
- if (regularFile && sharedLibExtension)
- {
- logInfo(__METHOD_NAME__,"adding file: ", entryName);
- std::string name(directoryName);
- sharedLibraryNameList.push_back(name + "/" + entryName);
- }
- else
- {
- logInfo(__METHOD_NAME__, "plugin search ignoring file :", entryName);
- }
- }
+ closedir(directory);
+ }
- closedir(directory);
- }
+ // iterate all communicator plugins and start them
+ std::vector<std::string>::iterator iter = sharedLibraryNameList.begin();
+ std::vector<std::string>::iterator iterEnd = sharedLibraryNameList.end();
- // iterate all communicator plugins and start them
- std::vector<std::string>::iterator iter = sharedLibraryNameList.begin();
- std::vector<std::string>::iterator iterEnd = sharedLibraryNameList.end();
+ for (; iter != iterEnd; ++iter)
+ {
+ logInfo(__METHOD_NAME__,"try loading: ", *iter);
- for (; iter != iterEnd; ++iter)
- {
- logInfo(__METHOD_NAME__,"try loading: ", *iter);
+ IAmRoutingSend* (*createFunc)();
+ void* tempLibHandle = NULL;
+ createFunc = getCreateFunction<IAmRoutingSend*()>(*iter, tempLibHandle);
- IAmRoutingSend* (*createFunc)();
- void* tempLibHandle = NULL;
- createFunc = getCreateFunction<IAmRoutingSend*()>(*iter, tempLibHandle);
+ if (!createFunc)
+ {
+ logError(__METHOD_NAME__,"Entry point of RoutingPlugin not found");
+ continue;
+ }
- if (!createFunc)
- {
- logError(__METHOD_NAME__,"Entry point of RoutingPlugin not found");
- continue;
- }
+ IAmRoutingSend* router = createFunc();
- IAmRoutingSend* router = createFunc();
+ if (!router)
+ {
+ logError(__METHOD_NAME__,"initialization of plugin ",*iter,"failed. Entry Function not callable");
+ dlclose(tempLibHandle);
+ continue;
+ }
- if (!router)
- {
- logError(__METHOD_NAME__,"initialization of plugin ",*iter,"failed. Entry Function not callable");
- dlclose(tempLibHandle);
- continue;
- }
+ InterfaceNamePairs routerInterface;
+ routerInterface.routingInterface = router;
- InterfaceNamePairs routerInterface;
- routerInterface.routingInterface = router;
-
- //check libversion
- std::string version, cVersion(RoutingVersion);
- router->getInterfaceVersion(version);
- uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion;
- std::istringstream(version.substr(0, 1)) >> majorVersion;
- std::istringstream(version.substr(2, 1)) >> minorVersion;
- std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion;
- std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion;
-
-
-
- if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion)))
- {
- logError(__METHOD_NAME__,"Routing initialization failed. Version of Interface to old");
- dlclose(tempLibHandle);
- continue;
- }
+ //check libversion
+ std::string version, cVersion(RoutingVersion);
+ router->getInterfaceVersion(version);
+ uint16_t minorVersion, majorVersion, cMinorVersion, cMajorVersion;
+ std::istringstream(version.substr(0, 1)) >> majorVersion;
+ std::istringstream(version.substr(2, 1)) >> minorVersion;
+ std::istringstream(cVersion.substr(0, 1)) >> cMajorVersion;
+ std::istringstream(cVersion.substr(2, 1)) >> cMinorVersion;
- //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain....
- router->returnBusName(routerInterface.busName);
- assert(!routerInterface.busName.empty());
- mListInterfaces.push_back(routerInterface);
- mListLibraryHandles.push_back(tempLibHandle);
- }
+ if (majorVersion < cMajorVersion || ((majorVersion == cMajorVersion) && (minorVersion > cMinorVersion)))
+ {
+ logError(__METHOD_NAME__,"Routing initialization failed. Version of Interface to old");
+ dlclose(tempLibHandle);
+ continue;
+ }
+
+ //here, the busname is saved together with the interface. Later The domains will register with the name and sinks, sources etc with the domain....
+ router->returnBusName(routerInterface.busName);
+ assert(!routerInterface.busName.empty());
+ mListInterfaces.push_back(routerInterface);
+ mListLibraryHandles.push_back(tempLibHandle);
+ }
+
+ dboNewSink = [&](const am_Sink_s& sink) {
+ addSinkLookup(sink);
+ };
+ dboNewSource = [&](const am_Source_s& source) {
+ addSourceLookup(source);
+ };
+ dboNewDomain = [&](const am_Domain_s& domain) {
+ addDomainLookup(domain);
+ };
+ //todo: newGateway implement something
+ //todo: newConverter implement something
+ dboNewCrossfader = [&](const am_Crossfader_s& crossfader) {
+ addCrossfaderLookup(crossfader);
+ };
+ dboRemovedSink = [&](const am_sinkID_t sinkID, const bool visible) {
+ removeSinkLookup(sinkID);
+ };
+ dboRemovedSource = [&](const am_sourceID_t sourceID, const bool visible) {
+ removeSourceLookup(sourceID);
+ };
+ dboRemoveDomain = [&](const am_domainID_t domainID) {
+ removeDomainLookup(domainID);
+ };
+ //todo: removeGateway implement something
+ //todo: removeConverter implement something
+ dboRemoveCrossfader = [&](const am_crossfaderID_t crossfaderID) {
+ removeCrossfaderLookup(crossfaderID);
+ };
}
CAmRoutingSender::~CAmRoutingSender()
@@ -786,17 +813,32 @@ am_Error_e CAmRoutingSender::getListHandles(std::vector<am_Handle_s> & listHandl
am_Handle_s CAmRoutingSender::createHandle(std::shared_ptr<handleDataBase> handleData, const am_Handle_e type)
{
am_Handle_s handle;
- if (++mHandleCount>=1024) //defined by 10 bit (out if structure!)
- mHandleCount=1;
- handle.handle = mHandleCount;
handle.handleType = type;
- mlistActiveHandles.insert(std::make_pair(handle, handleData));
- if ((mlistActiveHandles.size()%100) == 0)
- {
- logInfo("CAmRoutingSender::createHandle warning: too many open handles, number of handles: ", mlistActiveHandles.size());
+
+ for (int checkOverflow=0;checkOverflow<1024;checkOverflow++)
+ {
+ if (++mHandleCount>=1024) //defined by 10 bit (out if structure!)
+ {
+ mHandleCount=1;
+ }
+ handle.handle = mHandleCount;
+
+ if ( mlistActiveHandles.find(handle) == mlistActiveHandles.end() )
+ {
+ mlistActiveHandles.insert(std::make_pair(handle, handleData));
+ if (mlistActiveHandles.size()>100)
+ {
+ logWarning(__METHOD_NAME__,"too many open handles, number of handles: ", mlistActiveHandles.size());
+ }
+ logInfo(__METHOD_NAME__,handle.handle, handle.handleType);
+ return (handle);
+ }
}
- logInfo(__METHOD_NAME__,handle.handle, handle.handleType);
- return (handle);
+
+ logError(__METHOD_NAME__,"could not create new handle, all handles in use!");
+ handle.handle=0;
+
+ return(handle);
}
void CAmRoutingSender::setRoutingReady()