summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AudioManagerUtilities/include/CAmCommonAPIWrapper.h105
-rw-r--r--AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp2
-rw-r--r--AudioManagerUtilities/src/CAmSocketHandler.cpp111
3 files changed, 104 insertions, 114 deletions
diff --git a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
index 7d64a04..0f770c4 100644
--- a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
+++ b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
@@ -98,12 +98,12 @@ class CAmCommonAPIWrapper
void registerTimeout(CommonAPI::Timeout* timeout, const CommonAPI::DispatchPriority dispatchPriority);
void deregisterTimeout(CommonAPI::Timeout* timeout);
void deregisterAllTimeouts();
-
- CommonAPI::Watch* watchWithHandle(const sh_pollHandle_t handle);
+
+ CommonAPI::Watch* watchWithHandle(const sh_pollHandle_t handle);
CommonAPI::Timeout* timeoutWithHandle(const sh_pollHandle_t handle);
-
+
protected:
- CAmCommonAPIWrapper(CAmSocketHandler* socketHandler, const std::string& applicationName = "") ;
+ CAmCommonAPIWrapper ( CAmSocketHandler* socketHandler, const std::string& applicationName = "" ) ;
public:
@@ -191,42 +191,42 @@ public:
return mRuntime->unregisterService(domain, interface, instance);
}
- /**
+ /**
* \brief Deprecated method. Instead you should use bool registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance).
- *
- * Register stub objects.
- *
- * Example: std::shared_ptr<ConcreteStubClass> aStub;
- * registerService( aStub, "local:com.your_company.interface_name:com.your_company.instance_name");
- *
- * @param shStub: Shared pointer to a stub instance
- * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name"
- *
- */
- template <class TStubImp> bool __attribute__((deprecated)) registerStub(const std::shared_ptr<TStubImp> & shStub, const std::string & address)
- {
- std::vector<std::string> parts = CommonAPI::split(address, ':');
- assert(parts.size()==3);
-
- return registerService(shStub, parts[0], parts[2]);
- }
-
- /**
- * \brief Deprecated method. Instead you should use bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance).
- *
- * Unregister stub objects.
- *
- * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name"
- *
- */
- bool __attribute__((deprecated)) unregisterStub(const std::string & address)
- {
- std::vector<std::string> parts = CommonAPI::split(address, ':');
- assert(parts.size()==3);
-
- return unregisterService(parts[0], parts[1], parts[2]);
- }
-
+ *
+ * Register stub objects.
+ *
+ * Example: std::shared_ptr<ConcreteStubClass> aStub;
+ * registerService( aStub, "local:com.your_company.interface_name:com.your_company.instance_name");
+ *
+ * @param shStub: Shared pointer to a stub instance
+ * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name"
+ *
+ */
+ template <class TStubImp> bool __attribute__((deprecated)) registerStub(const std::shared_ptr<TStubImp> & shStub, const std::string & address)
+ {
+ std::vector<std::string> parts = CommonAPI::split(address, ':');
+ assert(parts.size()==3);
+
+ return registerService(shStub, parts[0], parts[2]);
+ }
+
+ /**
+ * \brief Deprecated method. Instead you should use bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance).
+ *
+ * Unregister stub objects.
+ *
+ * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name"
+ *
+ */
+ bool __attribute__((deprecated)) unregisterStub(const std::string & address)
+ {
+ std::vector<std::string> parts = CommonAPI::split(address, ':');
+ assert(parts.size()==3);
+
+ return unregisterService(parts[0], parts[1], parts[2]);
+ }
+
/**
* \brief Deprecated method. This class is used only in single connection applications and no connectionId is needed. Instead you should use buildProxy(const std::string &domain, const std::string &instance).
*
@@ -241,25 +241,26 @@ public:
template<template<typename ...> class ProxyClass, typename ... AttributeExtensions>
std::shared_ptr<ProxyClass<AttributeExtensions...>> __attribute__((deprecated)) buildProxy(const std::string &domain, const std::string &instance, const CommonAPI::ConnectionId_t __attribute__((__unused__)) & /*connectionId*/)
{
- return mRuntime->buildProxy<ProxyClass>(domain, instance, mContext);
+ return mRuntime->buildProxy<ProxyClass>(domain, instance, mContext);
}
- /**
- * \brief Build proxy objects.
- *
- * Example: std::shared_ptr<AProxyClass<>> aProxy = buildProxy<AProxyClass>("local", "com.your_company.instance_name");
- *
- * @param domain: A string with the domain name, usually "local"
- * @param instance: Common-api instance string as example "com.your_company.instance_name"
- *
- * @return A proxy object.
- */
+ /**
+ * \brief Build proxy objects.
+ *
+ * Example: std::shared_ptr<AProxyClass<>> aProxy = buildProxy<AProxyClass>("local", "com.your_company.instance_name");
+ *
+ * @param domain: A string with the domain name, usually "local"
+ * @param instance: Common-api instance string as example "com.your_company.instance_name"
+ *
+ * @return A proxy object.
+ */
template<template<typename ...> class ProxyClass, typename ... AttributeExtensions>
std::shared_ptr<ProxyClass<AttributeExtensions...>> buildProxy(const std::string &domain, const std::string &instance)
{
return mRuntime->buildProxy<ProxyClass>(domain, instance, mContext);
}
-
+
+
/**
* \brief Deprecated method. Instead you should use buildProxy(const std::string &domain, const std::string &instance).
*
@@ -277,7 +278,7 @@ public:
assert(parts.size()==3);
return buildProxy<ProxyClass>(parts[0], parts[2]);
- }
+ }
};
diff --git a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
index 4a6accf..702d384 100644
--- a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
+++ b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp
@@ -52,7 +52,7 @@ bool timeoutToTimespec(const int64_t & localTimeout, timespec & pollTimeout)
else
{
pollTimeout.tv_sec = localTimeout / 1000;
- pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000;
+ pollTimeout.tv_nsec = (localTimeout % 1000) * 1000000;
}
return true;
}
diff --git a/AudioManagerUtilities/src/CAmSocketHandler.cpp b/AudioManagerUtilities/src/CAmSocketHandler.cpp
index 7cf5594..4c46dd1 100644
--- a/AudioManagerUtilities/src/CAmSocketHandler.cpp
+++ b/AudioManagerUtilities/src/CAmSocketHandler.cpp
@@ -138,9 +138,9 @@ void CAmSocketHandler::start_listenting()
{
if (mRecreatePollfds)
{
-#ifdef WITH_TIMERFD
+ #ifdef WITH_TIMERFD
closeRemovedTimers();
-#endif
+ #endif
fdPollingArray.clear();
//freeze mListPoll by copying it - otherwise we get problems when we want to manipulate it during the next lines
mListActivePolls = mListPoll;
@@ -178,16 +178,16 @@ void CAmSocketHandler::start_listenting()
//todo: here could be a timer that makes sure naughty plugins return!
listPoll.clear();
//stage 0+1, call firedCB
- for (itMfdPollingArray = fdPollingArray.begin(); itMfdPollingArray != fdPollingArray.end(); ++itMfdPollingArray)
+ for (itMfdPollingArray = fdPollingArray.begin(); itMfdPollingArray != fdPollingArray.end(); itMfdPollingArray++)
{
itMfdPollingArray->revents &= itMfdPollingArray->events | POLLERR | POLLHUP;
if ( itMfdPollingArray->revents!=0 )
- {
+ {
listmPollIt = mListActivePolls.begin();
std::advance(listmPollIt, std::distance(fdPollingArray.begin(), itMfdPollingArray));
-
+
sh_poll_s & pollObj = *listmPollIt;
-
+
listPoll.push_back(&pollObj);
CAmSocketHandler::fire(&pollObj);
itMfdPollingArray->revents = 0;
@@ -333,31 +333,26 @@ am_Error_e CAmSocketHandler::listenToSignals(const std::vector<uint8_t> & listSi
auto actionPoll = [this](const pollfd pollfd, const sh_pollHandle_t, void*)
{
- const VectorSignalHandlers_t & signalHandlers = mSignalHandlers;
- /* We have a valid signal, read the info from the fd */
- struct signalfd_siginfo info;
- ssize_t bytes = read(pollfd.fd, &info, sizeof(info));
- if(bytes == -1)
- {
- if (errno == EAGAIN) //Something wrong, check for EAGAIN
- bytes = read(pollfd.fd, &info, sizeof(info));
- }
- if(bytes != sizeof(info))
- {
- //Failed to read from fd...
- logError("Failed to read from signal fd");
- throw std::runtime_error(std::string("Failed to read from signal fd."));
- }
-
- /* Notify all listeners */
- for(auto it: signalHandlers)
- it.callback(it.handle, info, it.userData);
+ const VectorSignalHandlers_t & signalHandlers = mSignalHandlers;
+ /* We have a valid signal, read the info from the fd */
+ struct signalfd_siginfo info;
+ ssize_t bytes = read(pollfd.fd, &info, sizeof(info));
+ if(bytes != sizeof(info))
+ {
+ //error received...
+ logError("Failed to read from signal fd");
+ throw std::runtime_error(std::string("Failed to read from signal fd."));
+ }
+
+ /* Notify all listeners */
+ for(auto it: signalHandlers)
+ it.callback(it.handle, info, it.userData);
};
/* We're going to add the signal fd through addFDPoll. At this point we don't have any signal listeners. */
return addFDPoll(signalHandlerFd, POLLIN | POLLERR | POLLHUP, NULL, actionPoll, [](const sh_pollHandle_t, void*)
{ return (false);}, NULL, NULL, mSignalFdHandle);
}
- else
+ else
{
int signalHandlerFd = signalfd(sgPollData.pollfdValue.fd, &sigset, 0);
if (signalHandlerFd == -1)
@@ -463,34 +458,33 @@ am::am_Error_e CAmSocketHandler::addFDPoll(const int fd, const short event, IAmS
am_Error_e CAmSocketHandler::removeFDPoll(const sh_pollHandle_t handle)
{
CHECK_CALLER_THREAD_ID()
-
- bool handleRemoved = false;
-
- for (auto it = mListPoll.begin(); it != mListPoll.end(); ++it)
+
+ VectorListPoll_t::iterator iterator = mListPoll.begin();
+
+ for (; iterator != mListPoll.end(); ++iterator)
{
- if (it->handle == handle)
+ if (iterator->handle == handle)
{
- it = mListPoll.erase(it);
+ iterator = mListPoll.erase(iterator);
mSetPollKeys.pollHandles.erase(handle);
- handleRemoved = true;
+ mRecreatePollfds = true;
break;
}
}
-
- if ( false == handleRemoved )
+
+ if (iterator == mListPoll.end())
return (E_UNKNOWN);
-
- mRecreatePollfds = true;
-
- for (auto it = mListActivePolls.begin(); it != mListActivePolls.end(); ++it)
+
+ VectorListPoll_t::iterator iteratorActivePolls = mListActivePolls.begin();
+ for (; iteratorActivePolls != mListActivePolls.end(); ++iteratorActivePolls)
{
- if (it->handle == handle)
+ if (iteratorActivePolls->handle == handle)
{
- it->isValid = false;
+ iteratorActivePolls->isValid = false;
break;
}
}
-
+
return (E_OK);
}
@@ -622,16 +616,9 @@ am_Error_e CAmSocketHandler::addTimer(const timespec & timeouts, std::function<v
auto actionPoll = [this](const pollfd pollfd, const sh_pollHandle_t handle, void* userData)
{
uint64_t mExpirations;
- ssize_t bytes = read(pollfd.fd, &mExpirations, sizeof(mExpirations));
- if(bytes == -1)
- {
- if (errno == EAGAIN)//Something wrong, check for EAGAIN
- bytes = read(pollfd.fd, &mExpirations, sizeof(mExpirations));
- }
-
- if(bytes != sizeof(mExpirations))
+ if(read(pollfd.fd, &mExpirations, sizeof(uint64_t))!=sizeof(uint64_t))
{
- //Failed to read from fd...
+ //error received...
logError("Failed to read from timer fd");
throw std::runtime_error(std::string("Failed to read from timer fd."));
}
@@ -1067,7 +1054,7 @@ void CAmSocketHandler::fire(const sh_poll_s* a)
bool CAmSocketHandler::noDispatching(const sh_poll_s* a)
{
//remove from list of there is no checkCB
- if (nullptr == a->checkCB || false == a->isValid)
+ if (nullptr == a->checkCB || false==a->isValid )
return (true);
return (!a->checkCB(a->handle, a->userData));
}
@@ -1078,7 +1065,7 @@ bool CAmSocketHandler::noDispatching(const sh_poll_s* a)
bool CAmSocketHandler::dispatchingFinished(const sh_poll_s* a)
{
//remove from list of there is no dispatchCB
- if (nullptr == a->dispatchCB || false == a->isValid)
+ if (nullptr == a->dispatchCB || false==a->isValid )
return (true);
return (!a->dispatchCB(a->handle, a->userData));
}
@@ -1096,16 +1083,16 @@ inline timespec* CAmSocketHandler::insertTime(timespec& buffertime)
buffertime = mListActiveTimer.front().countdown;
return (&buffertime);
}
- else
-#endif
+ else
+#endif
{
return (NULL);
}
}
-#ifdef WITH_TIMERFD
+#ifdef WITH_TIMERFD
am_Error_e CAmSocketHandler::createTimeFD(const itimerspec & timeouts, int & fd)
-{
+{
fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
if (fd < 0)
{
@@ -1123,15 +1110,17 @@ am_Error_e CAmSocketHandler::createTimeFD(const itimerspec & timeouts, int & fd)
void CAmSocketHandler::closeRemovedTimers()
{
- for (auto it : mListRemovedTimers)
+ std::list<sh_timer_s>::iterator it(mListRemovedTimers.begin());
+ while (it != mListRemovedTimers.end())
{
- if( it.fd > -1 )
- close( it.fd );
+ if( it->fd > -1 )
+ close( it->fd );
+ ++it;
}
mListRemovedTimers.clear();
}
-#endif
+#endif
void CAmSocketHandler::callTimer(sh_timer_s& a)
{