summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities/include
diff options
context:
space:
mode:
authorGENIVI Audio Manager Maintainer <genivi-maint-audiomanager@smtp1.genivi.org>2018-03-13 11:28:45 +0100
committerGitHub <noreply@github.com>2018-03-13 11:28:45 +0100
commitf32875117e54fd4887f3256d19518d3f62db6225 (patch)
tree0b387aae10734f32918c7ccc218c782230449104 /AudioManagerUtilities/include
parentcfded6ea1a53e5387e1f24c0a9132f363247669b (diff)
parentc0d9501bcfa14ea7d851e5dd1cdc89e03a651342 (diff)
downloadaudiomanager-f32875117e54fd4887f3256d19518d3f62db6225.tar.gz
Merge pull request #26 from GENIVI/utilityUpdates_CAPI_fixes
Utility updates capi fixes
Diffstat (limited to 'AudioManagerUtilities/include')
-rw-r--r--AudioManagerUtilities/include/CAmCommonAPIWrapper.h246
-rw-r--r--AudioManagerUtilities/include/CAmSocketHandler.h32
2 files changed, 145 insertions, 133 deletions
diff --git a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
index 82328d6..7d64a04 100644
--- a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
+++ b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
@@ -22,6 +22,7 @@
#include <string>
#include <list>
#include <map>
+#include <unordered_map>
#include <queue>
#include <memory>
#include <cassert>
@@ -48,29 +49,37 @@ class CAmSocketHandler;
class CAmCommonAPIWrapper
{
- void commonPrepareCallback(const sh_pollHandle_t handle, void* userData);
+ void commonPrepareCallback ( const sh_pollHandle_t, void* );
TAmShPollPrepare<CAmCommonAPIWrapper> pCommonPrepareCallback;
- bool commonDispatchCallback(const sh_pollHandle_t handle, void* userData);
- TAmShPollDispatch<CAmCommonAPIWrapper> pCommonDispatchCallback;
-
void commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void*);
TAmShPollFired<CAmCommonAPIWrapper> pCommonFireCallback;
bool commonCheckCallback(const sh_pollHandle_t handle, void*);
TAmShPollCheck<CAmCommonAPIWrapper> pCommonCheckCallback;
+
+ bool commonDispatchCallback(const sh_pollHandle_t handle, void* userData);
+ TAmShPollDispatch<CAmCommonAPIWrapper> pCommonDispatchCallback;
void commonTimerCallback(sh_timerHandle_t handle, void* userData);
TAmShTimerCallBack<CAmCommonAPIWrapper> pCommonTimerCallback;
- struct timerHandles
- {
- sh_timerHandle_t handle;
- CommonAPI::Timeout* timeout;
- };
-
CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler
+ typedef std::vector<CommonAPI::DispatchSource*> ArrayDispatchSources;
+ typedef ArrayDispatchSources::iterator IteratorArrayDispatchSources;
+ typedef std::unordered_map<am::sh_pollHandle_t, CommonAPI::Watch*> MapWatches;
+ typedef MapWatches::iterator IteratorMapWatches;
+ typedef std::unordered_map<am::sh_pollHandle_t,std::list<CommonAPI::DispatchSource*>> MapDispatchSources;
+ typedef MapDispatchSources::iterator IteratorDispatchSources;
+ typedef std::unordered_map<am::sh_pollHandle_t, CommonAPI::Timeout*> MapTimeouts;
+ typedef MapTimeouts::iterator IteratorMapTimeouts;
+
+ ArrayDispatchSources mRegisteredDispatchSources;
+ MapWatches mMapWatches;
+ MapDispatchSources mSourcesToDispatch;
+ MapTimeouts mListTimerhandles;
+
std::shared_ptr<CommonAPI::Runtime> mRuntime;
std::shared_ptr<CommonAPI::MainLoopContext> mContext;
@@ -78,22 +87,23 @@ class CAmCommonAPIWrapper
CommonAPI::WatchListenerSubscription mWatchListenerSubscription;
CommonAPI::TimeoutSourceListenerSubscription mTimeoutSourceListenerSubscription;
CommonAPI::WakeupListenerSubscription mWakeupListenerSubscription;
- std::multimap<CommonAPI::DispatchPriority, CommonAPI::DispatchSource*> mRegisteredDispatchSources;
- std::map<int,CommonAPI::Watch*> mMapWatches;
- CommonAPI::Watch* mWatchToCheck;
- std::list<CommonAPI::DispatchSource*> mSourcesToDispatch;
- std::vector<timerHandles> mpListTimerhandles;
+
void registerDispatchSource(CommonAPI::DispatchSource* dispatchSource, const CommonAPI::DispatchPriority dispatchPriority);
void deregisterDispatchSource(CommonAPI::DispatchSource* dispatchSource);
+ void deregisterAllDispatchSource();
void registerWatch(CommonAPI::Watch* watch, const CommonAPI::DispatchPriority dispatchPriority);
void deregisterWatch(CommonAPI::Watch* watch);
+ void deregisterAllWatches();
void registerTimeout(CommonAPI::Timeout* timeout, const CommonAPI::DispatchPriority dispatchPriority);
void deregisterTimeout(CommonAPI::Timeout* timeout);
- void wakeup();
+ void deregisterAllTimeouts();
+
+ 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:
@@ -133,24 +143,25 @@ public:
* @return Pointer to the socket handler.
*/
CAmSocketHandler *getSocketHandler() const { return mpSocketHandler; }
-#if COMMONAPI_VERSION_NUMBER >= 300
- /**
- * \brief Register stub objects.
- *
- * Example: std::shared_ptr<ConcreteStubClass> aStub;
- * registerService( aStub, "local", "com.your_company.instance_name", "service-name");
- *
- * @param shStub: Shared pointer to a stub instance
- * @param domain: A string with the domain name, usually "local"
- * @param instance: Common-api instance string as example "com.your_company.instance_name"
- * @param connectionId: A string connection id, which is used by CommonAPI to group applications
- *
- */
- template <class TStubImp> bool registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance, const CommonAPI::ConnectionId_t & connectionId)
- {
- return mRuntime->registerService(domain, instance, shStub, connectionId);
- }
-#endif
+
+ /**
+ * \brief Deprecated method. This class is used only in single connection applications and no connectionId is needed. Instead you should use bool registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance).
+ *
+ *
+ * Example: std::shared_ptr<ConcreteStubClass> aStub;
+ * registerService( aStub, "local", "com.your_company.instance_name", "service-name");
+ *
+ * @param shStub: Shared pointer to a stub instance
+ * @param domain: A string with the domain name, usually "local"
+ * @param instance: Common-api instance string as example "com.your_company.instance_name"
+ * @param connectionId: A string connection id, which is used by CommonAPI to group applications
+ *
+ */
+ template <class TStubImp> bool __attribute__((deprecated)) registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance, const CommonAPI::ConnectionId_t __attribute__((__unused__)) & /*connectionId*/)
+ {
+ return mRuntime->registerService(domain, instance, shStub, mContext);
+ }
+
/**
* \brief Register stub objects.
*
@@ -180,96 +191,93 @@ 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]);
- }
-
-#if COMMONAPI_VERSION_NUMBER >= 300
- /**
- * \brief Build proxy objects.
- *
- * Example: std::shared_ptr<AProxyClass<>> aProxy = buildProxy<AProxyClass>("local", "com.your_company.instance_name", "client-name");
- *
- * @param domain: A string with the domain name, usually "local"
- * @param instance: Common-api instance string as example "com.your_company.instance_name"
- * @param connectionId: A string connection id, which is used by CommonAPI to group applications
- *
- * @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, const CommonAPI::ConnectionId_t & connectionId)
- {
- return mRuntime->buildProxy<ProxyClass>(domain, instance, connectionId);
- }
-#endif
-
- /**
- * \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 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]);
+ }
+
+ /**
+ * \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).
+ *
+ * Example: std::shared_ptr<AProxyClass<>> aProxy = buildProxy<AProxyClass>("local", "com.your_company.instance_name", "client-name");
+ *
+ * @param domain: A string with the domain name, usually "local"
+ * @param instance: Common-api instance string as example "com.your_company.instance_name"
+ * @param connectionId: A string connection id, which is used by CommonAPI to group applications
+ *
+ * @return A proxy object.
+ */
+ 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);
+ }
+
+ /**
+ * \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).
- *
- * Build proxy objects.
- * Example: std::shared_ptr<AProxyClass<>> aProxy = buildProxy<AProxyClass>("local:com.your_company.interface_name:com.your_company.instance_name");
- *
- * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name"
- *
- * @return A proxy object.
- */
- template<template<typename ...> class ProxyClass, typename ... AttributeExtensions>
- std::shared_ptr<ProxyClass<AttributeExtensions...>> __attribute__((deprecated)) buildProxy(const std::string & address)
- {
- std::vector<std::string> parts=CommonAPI::split(address, ':');
- assert(parts.size()==3);
-
- return buildProxy<ProxyClass>(parts[0], parts[2]);
- }
+ /**
+ * \brief Deprecated method. Instead you should use buildProxy(const std::string &domain, const std::string &instance).
+ *
+ * Build proxy objects.
+ * Example: std::shared_ptr<AProxyClass<>> aProxy = buildProxy<AProxyClass>("local:com.your_company.interface_name:com.your_company.instance_name");
+ *
+ * @param address: Complete common-api address as example "local:com.your_company.interface_name:com.your_company.instance_name"
+ *
+ * @return A proxy object.
+ */
+ template<template<typename ...> class ProxyClass, typename ... AttributeExtensions>
+ std::shared_ptr<ProxyClass<AttributeExtensions...>> __attribute__((deprecated)) buildProxy(const std::string & address)
+ {
+ std::vector<std::string> parts=CommonAPI::split(address, ':');
+ assert(parts.size()==3);
+
+ return buildProxy<ProxyClass>(parts[0], parts[2]);
+ }
};
diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h
index 717f792..53010ba 100644
--- a/AudioManagerUtilities/include/CAmSocketHandler.h
+++ b/AudioManagerUtilities/include/CAmSocketHandler.h
@@ -27,6 +27,7 @@
#include <signal.h>
#include <vector>
#include <functional>
+#include <thread>
#include <sys/signalfd.h>
#include <audiomanagerconfig.h>
#include "audiomanagertypes.h"
@@ -217,6 +218,7 @@ class CAmSocketHandler
{
struct sh_poll_s //!<struct that holds information about polls
{
+ bool isValid;
sh_pollHandle_t handle; //!<handle to uniquely adress a filedesriptor
pollfd pollfdValue; //!<the array for polling the filedescriptors
std::function<void(const sh_pollHandle_t handle, void* userData)> prepareCB; //preperation callback
@@ -226,7 +228,7 @@ class CAmSocketHandler
void* userData;
sh_poll_s() :
- handle(0), pollfdValue(), prepareCB(), firedCB(), checkCB(), dispatchCB(), userData(0)
+ isValid(true), handle(0), pollfdValue(), prepareCB(), firedCB(), checkCB(), dispatchCB(), userData(0)
{}
};
@@ -244,10 +246,11 @@ class CAmSocketHandler
sh_timer_s() :
handle(0)
#ifdef WITH_TIMERFD
- , fd(0)
+ , fd(-1)
#endif
, countdown(), callback(), userData(0)
{}
+
};
struct sh_signal_s
@@ -291,22 +294,30 @@ class CAmSocketHandler
VectorListPoll_t mListPoll; //!<list that holds all information for the ppoll
sh_identifier_s mSetTimerKeys; //!A set of all used timer keys
std::list<sh_timer_s> mListTimer; //!<list of all timers
+#ifndef WITH_TIMERFD
std::list<sh_timer_s> mListActiveTimer; //!<list of all currently active timers
+#else
+ std::list<sh_timer_s> mListRemovedTimers;
+#endif
sh_identifier_s mSetSignalhandlerKeys; //!A set of all used signal handler keys
VectorSignalHandlers_t mSignalHandlers;
bool mRecreatePollfds; //!<when this is true, the poll list needs to be recreated
internal_codes_t mInternalCodes;
sh_pollHandle_t mSignalFdHandle;
+ VectorListPoll_t mListActivePolls;
+ const std::thread::id mThreadID; //!< Socket handler thread id used to check if the calls come from the same thread
#ifndef WITH_TIMERFD
timespec mStartTime; //!<here the actual time is saved for timecorrection
#endif
+
private:
+
bool fdIsValid(const int fd) const;
timespec* insertTime(timespec& buffertime);
#ifdef WITH_TIMERFD
am_Error_e createTimeFD(const itimerspec & timeouts, int & fd);
-
+ void closeRemovedTimers();
#else
void timerUp();
void timerCorrection();
@@ -408,28 +419,21 @@ private:
* @param a
* @return
*/
- inline static void fire(sh_poll_s& a);
-
- /**
- * functor to return all fired events
- * @param a
- * @return
- */
- inline static bool eventFired(const pollfd& a);
+ inline static void fire(const sh_poll_s* a);
/**
* functor to help find the items that do not need dispatching
* @param a
* @return
*/
- inline static bool noDispatching(const sh_poll_s& a);
+ inline static bool noDispatching(const sh_poll_s* a);
/**
* checks if dispatching is already finished
* @param a
* @return
*/
- inline static bool dispatchingFinished(const sh_poll_s& a);
+ inline static bool dispatchingFinished(const sh_poll_s* a);
/**
* timer fire callback
@@ -446,7 +450,7 @@ private:
bool nextHandle(sh_identifier_s & handle);
am_Error_e getFDPollData(const sh_pollHandle_t handle, sh_poll_s & outPollData);
-
+
public:
CAmSocketHandler();