From b616ca1e864f7530b9dfce4c38f9d24a9f0809c9 Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Fri, 10 Feb 2017 11:12:42 +0100 Subject: * many database observers can be registred now by the database handler. Signed-off-by: Christian Linke --- AudioManagerCore/src/CAmRoutingSender.cpp | 253 +++++++++++++++++------------- 1 file changed, 140 insertions(+), 113 deletions(-) (limited to 'AudioManagerCore/src/CAmRoutingSender.cpp') diff --git a/AudioManagerCore/src/CAmRoutingSender.cpp b/AudioManagerCore/src/CAmRoutingSender.cpp index fc0953f..0e25e68 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& listOfPluginDirectories, IAmDatabaseHandler* databaseHandler) : - mHandleCount(0), // - mlistActiveHandles(), // - mListInterfaces(), // - mMapConnectionInterface(), // - mMapCrossfaderInterface(), // - mMapDomainInterface(), // - mMapSinkInterface(), // - mMapSourceInterface(), // - mpRoutingReceiver(), // - mpDatabaseHandler(databaseHandler) -{ +CAmRoutingSender::CAmRoutingSender( + const std::vector& 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 sharedLibraryNameList; + std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); + std::vector::const_iterator dirIterEnd = listOfPluginDirectories.end(); - std::vector sharedLibraryNameList; - std::vector::const_iterator dirIter = listOfPluginDirectories.begin(); - std::vector::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::iterator iter = sharedLibraryNameList.begin(); + std::vector::iterator iterEnd = sharedLibraryNameList.end(); + + for (; iter != iterEnd; ++iter) + { + logInfo(__METHOD_NAME__,"try loading: ", *iter); - // iterate all communicator plugins and start them - std::vector::iterator iter = sharedLibraryNameList.begin(); - std::vector::iterator iterEnd = sharedLibraryNameList.end(); + IAmRoutingSend* (*createFunc)(); + void* tempLibHandle = NULL; + createFunc = getCreateFunction(*iter, tempLibHandle); - for (; iter != iterEnd; ++iter) - { - logInfo(__METHOD_NAME__,"try loading: ", *iter); + if (!createFunc) + { + logError(__METHOD_NAME__,"Entry point of RoutingPlugin not found"); + continue; + } - IAmRoutingSend* (*createFunc)(); - void* tempLibHandle = NULL; - createFunc = getCreateFunction(*iter, tempLibHandle); + IAmRoutingSend* router = createFunc(); - if (!createFunc) - { - logError(__METHOD_NAME__,"Entry point of RoutingPlugin not found"); - continue; - } + if (!router) + { + logError(__METHOD_NAME__,"initialization of plugin ",*iter,"failed. Entry Function not callable"); + dlclose(tempLibHandle); + continue; + } - IAmRoutingSend* router = createFunc(); + InterfaceNamePairs routerInterface; + routerInterface.routingInterface = router; - if (!router) - { - logError(__METHOD_NAME__,"initialization of plugin ",*iter,"failed. Entry Function not callable"); - 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; - 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; - } + 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); - } + //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() -- cgit v1.2.1 From 9ad6f67f6c39ec4ff49c382d5beaf9006f664fcb Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Wed, 15 Feb 2017 01:47:24 -0800 Subject: handle overflow of handles correctly Signed-off-by: Christian Linke --- AudioManagerCore/src/CAmRoutingSender.cpp | 33 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'AudioManagerCore/src/CAmRoutingSender.cpp') diff --git a/AudioManagerCore/src/CAmRoutingSender.cpp b/AudioManagerCore/src/CAmRoutingSender.cpp index 0e25e68..9cc013d 100644 --- a/AudioManagerCore/src/CAmRoutingSender.cpp +++ b/AudioManagerCore/src/CAmRoutingSender.cpp @@ -813,17 +813,32 @@ am_Error_e CAmRoutingSender::getListHandles(std::vector & listHandl am_Handle_s CAmRoutingSender::createHandle(std::shared_ptr 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() -- cgit v1.2.1