summaryrefslogtreecommitdiff
path: root/AudioManagerUtilities/include
diff options
context:
space:
mode:
Diffstat (limited to 'AudioManagerUtilities/include')
-rw-r--r--AudioManagerUtilities/include/CAmCommandLineSingleton.h26
-rw-r--r--AudioManagerUtilities/include/CAmCommonAPIWrapper.h421
-rw-r--r--AudioManagerUtilities/include/CAmDbusWrapper.h58
-rw-r--r--AudioManagerUtilities/include/CAmDltWrapper.h299
-rw-r--r--AudioManagerUtilities/include/CAmSerializer.h2201
-rw-r--r--AudioManagerUtilities/include/CAmSocketHandler.h468
-rw-r--r--[-rwxr-xr-x]AudioManagerUtilities/include/CAmWatchdog.h11
-rw-r--r--AudioManagerUtilities/include/TAmPluginTemplate.h46
8 files changed, 1830 insertions, 1700 deletions
diff --git a/AudioManagerUtilities/include/CAmCommandLineSingleton.h b/AudioManagerUtilities/include/CAmCommandLineSingleton.h
index 10d92d4..4a1f081 100644
--- a/AudioManagerUtilities/include/CAmCommandLineSingleton.h
+++ b/AudioManagerUtilities/include/CAmCommandLineSingleton.h
@@ -21,7 +21,6 @@
*
*/
-
#ifndef AUDIOMANAGERUTILITIES_INCLUDE_CAMCOMMANDLINESINGLETON_H_
#define AUDIOMANAGERUTILITIES_INCLUDE_CAMCOMMANDLINESINGLETON_H_
@@ -29,21 +28,22 @@
namespace am {
-class CAmCommandLineSingleton {
+class CAmCommandLineSingleton
+{
public:
- static TCLAP::CmdLine* instanciateOnce(const std::string& message,
- const char delimiter = ' ',
- const std::string& version = "none",
- bool helpAndVersion = true);
-
- static TCLAP::CmdLine* instance();
-
- static void deleteInstance();
-
+ static TCLAP::CmdLine *instanciateOnce(const std::string &message,
+ const char delimiter = ' ',
+ const std::string &version = "none",
+ bool helpAndVersion = true);
+
+ static TCLAP::CmdLine *instance();
+
+ static void deleteInstance();
+
private:
- CAmCommandLineSingleton();
- virtual ~CAmCommandLineSingleton();
+ CAmCommandLineSingleton();
+ virtual ~CAmCommandLineSingleton();
};
} /* namespace am */
diff --git a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
index a83b5b3..a384f33 100644
--- a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
+++ b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h
@@ -15,7 +15,6 @@
* For further information see http://www.genivi.org/.
*/
-
#ifndef COMMONAPIWRAPPER_H_
#define COMMONAPIWRAPPER_H_
@@ -27,9 +26,9 @@
#include <cassert>
#include <CommonAPI/CommonAPI.hpp>
#ifndef COMMONAPI_INTERNAL_COMPILATION
-#define COMMONAPI_INTERNAL_COMPILATION
-#include <CommonAPI/MainLoopContext.hpp>
-#undef COMMONAPI_INTERNAL_COMPILATION
+# define COMMONAPI_INTERNAL_COMPILATION
+# include <CommonAPI/MainLoopContext.hpp>
+# undef COMMONAPI_INTERNAL_COMPILATION
#endif
#include <CommonAPI/Utils.hpp>
#include "audiomanagerconfig.h"
@@ -48,247 +47,251 @@ class CAmSocketHandler;
class CAmCommonAPIWrapper
{
- void commonPrepareCallback(const sh_pollHandle_t handle, void* userData);
- TAmShPollPrepare<CAmCommonAPIWrapper> pCommonPrepareCallback;
+ void commonPrepareCallback(const sh_pollHandle_t handle, void *userData);
+
+ TAmShPollPrepare<CAmCommonAPIWrapper> pCommonPrepareCallback;
+
+ bool commonDispatchCallback(const sh_pollHandle_t handle, void *userData);
- bool commonDispatchCallback(const sh_pollHandle_t handle, void* userData);
TAmShPollDispatch<CAmCommonAPIWrapper> pCommonDispatchCallback;
- void commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void*);
+ void commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void *);
+
TAmShPollFired<CAmCommonAPIWrapper> pCommonFireCallback;
- bool commonCheckCallback(const sh_pollHandle_t handle, void*);
+ bool commonCheckCallback(const sh_pollHandle_t handle, void *);
+
TAmShPollCheck<CAmCommonAPIWrapper> pCommonCheckCallback;
- void commonTimerCallback(sh_timerHandle_t handle, void* userData);
+ void commonTimerCallback(sh_timerHandle_t handle, void *userData);
+
TAmShTimerCallBack<CAmCommonAPIWrapper> pCommonTimerCallback;
- struct timerHandles
+ struct timerHandles
{
sh_timerHandle_t handle;
- CommonAPI::Timeout* timeout;
+ CommonAPI::Timeout *timeout;
};
- CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler
+ CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler
- std::shared_ptr<CommonAPI::Runtime> mRuntime;
- std::shared_ptr<CommonAPI::MainLoopContext> mContext;
+ std::shared_ptr<CommonAPI::Runtime> mRuntime;
+ std::shared_ptr<CommonAPI::MainLoopContext> mContext;
CommonAPI::DispatchSourceListenerSubscription mDispatchSourceListenerSubscription;
- 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 registerWatch(CommonAPI::Watch* watch, const CommonAPI::DispatchPriority dispatchPriority);
- void deregisterWatch(CommonAPI::Watch* watch);
- void registerTimeout(CommonAPI::Timeout* timeout, const CommonAPI::DispatchPriority dispatchPriority);
- void deregisterTimeout(CommonAPI::Timeout* timeout);
- void wakeup();
+ 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 registerWatch(CommonAPI::Watch *watch, const CommonAPI::DispatchPriority dispatchPriority);
+ void deregisterWatch(CommonAPI::Watch *watch);
+ void registerTimeout(CommonAPI::Timeout *timeout, const CommonAPI::DispatchPriority dispatchPriority);
+ void deregisterTimeout(CommonAPI::Timeout *timeout);
+ void wakeup();
protected:
- CAmCommonAPIWrapper(CAmSocketHandler* socketHandler, const std::string & applicationName = "") ;
+ CAmCommonAPIWrapper(CAmSocketHandler *socketHandler, const std::string &applicationName = "");
public:
virtual ~CAmCommonAPIWrapper();
- /**
- * \brief Returns an already instantiated object.
- *
- * This method should be called after the instantiateOnce(...) has been called with non null socket handler parameter.
- *
- * @return The common-api wrapper object.
- */
- static CAmCommonAPIWrapper* getInstance();
-
- /**
- * \brief Deletes the instanciated object
- */
- static void deleteInstance();
-
- /**
- * \brief Creates a singleton instance attached to the provided socket handler object.
- *
- * This method should be called only once because it instantiates a single object.
- * Otherwise it will throw an exception.
- * The first call of this method with non null parameter loads the common-api and attaches it to the main loop.
- *
- * @param socketHandler: A pointer to socket handler or NULL
- *
- * @return The common-api wrapper object.
- */
- static CAmCommonAPIWrapper* instantiateOnce(CAmSocketHandler* socketHandler, const std::string & applicationName = "");
-
-
- /**
- * \brief Getter for the socket handler.
- *
- * @return Pointer to the socket handler.
- */
- CAmSocketHandler *getSocketHandler() const { return mpSocketHandler; }
-
- /**
- * \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.
- *
- * Example: std::shared_ptr<ConcreteStubClass> aStub;
- * registerService( aStub, "local", "com.your_company.instance_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"
- *
- */
- template <class TStubImp> bool registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance)
- {
- return mRuntime->registerService(domain, instance, shStub, mContext);
- }
-
- /**
- * \brief Unregister stub objects.
- *
- * @param domain: A string with the domain name, usually "local"
- * @param interface: Common-api interface string as example "com.your_company.interface_name"
- * @param instance: Common-api instance string as example "com.your_company.instance_name"
- *
- */
- bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance)
- {
- 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]);
- }
-
- /**
- * \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 Returns an already instantiated object.
+ *
+ * This method should be called after the instantiateOnce(...) has been called with non null socket handler parameter.
+ *
+ * @return The common-api wrapper object.
+ */
+ static CAmCommonAPIWrapper *getInstance();
+
+ /**
+ * \brief Deletes the instanciated object
+ */
+ static void deleteInstance();
+
+ /**
+ * \brief Creates a singleton instance attached to the provided socket handler object.
+ *
+ * This method should be called only once because it instantiates a single object.
+ * Otherwise it will throw an exception.
+ * The first call of this method with non null parameter loads the common-api and attaches it to the main loop.
+ *
+ * @param socketHandler: A pointer to socket handler or NULL
+ *
+ * @return The common-api wrapper object.
+ */
+ static CAmCommonAPIWrapper *instantiateOnce(CAmSocketHandler *socketHandler, const std::string &applicationName = "");
+
+ /**
+ * \brief Getter for the socket handler.
+ *
+ * @return Pointer to the socket handler.
+ */
+ CAmSocketHandler *getSocketHandler() const { return mpSocketHandler; }
+
+ /**
+ * \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.
+ *
+ * Example: std::shared_ptr<ConcreteStubClass> aStub;
+ * registerService( aStub, "local", "com.your_company.instance_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"
+ *
+ */
+ template <class TStubImp>
+ bool registerService(const std::shared_ptr<TStubImp> &shStub, const std::string &domain, const std::string &instance)
+ {
+ return mRuntime->registerService(domain, instance, shStub, mContext);
+ }
+
+ /**
+ * \brief Unregister stub objects.
+ *
+ * @param domain: A string with the domain name, usually "local"
+ * @param interface: Common-api interface string as example "com.your_company.interface_name"
+ * @param instance: Common-api instance string as example "com.your_company.instance_name"
+ *
+ */
+ bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance)
+ {
+ 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]);
+ }
+
+ /**
+ * \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]);
+ }
+};
-//Alias
-extern CAmCommonAPIWrapper* (*getCAPI)();
+// Alias
+extern CAmCommonAPIWrapper *(*getCAPI)();
#ifndef AMCAPI
- #define AMCAPI getCAPI()
+# define AMCAPI getCAPI()
#endif
#ifndef AM_CAPI
- #define AM_CAPI getCAPI()
+# define AM_CAPI getCAPI()
#endif
#ifndef CAPI
- #define CAPI getCAPI()
+# define CAPI getCAPI()
#endif
-
}
#endif /* COMMONAPIWRAPPER_H_ */
diff --git a/AudioManagerUtilities/include/CAmDbusWrapper.h b/AudioManagerUtilities/include/CAmDbusWrapper.h
index 0352c35..37ecf6b 100644
--- a/AudioManagerUtilities/include/CAmDbusWrapper.h
+++ b/AudioManagerUtilities/include/CAmDbusWrapper.h
@@ -37,54 +37,60 @@ namespace am
class CAmDbusWrapper
{
public:
- CAmDbusWrapper(CAmSocketHandler* socketHandler,DBusBusType type=DBUS_BUS_SESSION,
- const std::string& prefix = DBUS_SERVICE_PREFIX, const std::string& objectPath = DBUS_SERVICE_OBJECT_PATH);
+ CAmDbusWrapper(CAmSocketHandler *socketHandler, DBusBusType type = DBUS_BUS_SESSION,
+ const std::string &prefix = DBUS_SERVICE_PREFIX, const std::string &objectPath = DBUS_SERVICE_OBJECT_PATH);
virtual ~CAmDbusWrapper();
- void registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, void* userdata, const std::string& prefix = DBUS_SERVICE_OBJECT_PATH);
- void registerSignalWatch(DBusHandleMessageFunction handler, const std::string& rule, void* userdata);
- void getDBusConnection(DBusConnection*& connection) const;
+ void registerCallback(const DBusObjectPathVTable *vtable, const std::string &path, void *userdata, const std::string &prefix = DBUS_SERVICE_OBJECT_PATH);
+ void registerSignalWatch(DBusHandleMessageFunction handler, const std::string &rule, void *userdata);
+ void getDBusConnection(DBusConnection * &connection) const;
static dbus_bool_t addWatch(DBusWatch *watch, void *userData);
static void removeWatch(DBusWatch *watch, void *userData);
static void toogleWatch(DBusWatch *watch, void *userData);
- static dbus_bool_t addTimeout(DBusTimeout *timeout, void* userData);
- static void removeTimeout(DBusTimeout *timeout, void* userData);
- static void toggleTimeout(DBusTimeout *timeout, void* userData);
+ static dbus_bool_t addTimeout(DBusTimeout *timeout, void *userData);
+ static void removeTimeout(DBusTimeout *timeout, void *userData);
+ static void toggleTimeout(DBusTimeout *timeout, void *userData);
+
+ void dbusPrepareCallback(const sh_pollHandle_t handle, void *userData);
- void dbusPrepareCallback(const sh_pollHandle_t handle, void* userData);
TAmShPollPrepare<CAmDbusWrapper> pDbusPrepareCallback;
- bool dbusDispatchCallback(const sh_pollHandle_t handle, void* userData);
+ bool dbusDispatchCallback(const sh_pollHandle_t handle, void *userData);
+
TAmShPollDispatch<CAmDbusWrapper> pDbusDispatchCallback;
- void dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData);
+ void dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void *userData);
+
TAmShPollFired<CAmDbusWrapper> pDbusFireCallback;
- bool dbusCheckCallback(const sh_pollHandle_t handle, void* userData);
+ bool dbusCheckCallback(const sh_pollHandle_t handle, void *userData);
+
TAmShPollCheck<CAmDbusWrapper> pDbusCheckCallback;
- void dbusTimerCallback(sh_timerHandle_t handle, void* userData);
+ void dbusTimerCallback(sh_timerHandle_t handle, void *userData);
+
TAmShTimerCallBack<CAmDbusWrapper> pDbusTimerCallback;
private:
- static CAmDbusWrapper* mpReference; //!< reference to the dbus instance
+ static CAmDbusWrapper *mpReference; //!< reference to the dbus instance
static DBusHandlerResult cbRootIntrospection(DBusConnection *conn, DBusMessage *msg, void *reference);
- dbus_bool_t addWatchDelegate(DBusWatch * watch, void* userData);
+ dbus_bool_t addWatchDelegate(DBusWatch *watch, void *userData);
void removeWatchDelegate(DBusWatch *watch, void *userData);
void toogleWatchDelegate(DBusWatch *watch, void *userData);
- dbus_bool_t addTimeoutDelegate(DBusTimeout *timeout, void* userData);
- void removeTimeoutDelegate(DBusTimeout *timeout, void* userData);
- void toggleTimeoutDelegate(DBusTimeout *timeout, void* userData);
- DBusObjectPathVTable mObjectPathVTable; //!< the vpathtable
- DBusConnection* mpDbusConnection; //!< pointer to the dbus connection used
- DBusError mDBusError; //!< dbuserror
- std::vector<std::string> mListNodes; //!< holds a list of all nodes of the dbus
- std::vector<sh_timerHandle_t*> mpListTimerhandles; //!< pointer to the timer handles
- CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler
- std::map<DBusWatch*, sh_pollHandle_t> mMapHandleWatch; //!< map to the handle watches
- DBusBusType mDbusType;
+ dbus_bool_t addTimeoutDelegate(DBusTimeout *timeout, void *userData);
+ void removeTimeoutDelegate(DBusTimeout *timeout, void *userData);
+ void toggleTimeoutDelegate(DBusTimeout *timeout, void *userData);
+
+ DBusObjectPathVTable mObjectPathVTable; //!< the vpathtable
+ DBusConnection *mpDbusConnection; //!< pointer to the dbus connection used
+ DBusError mDBusError; //!< dbuserror
+ std::vector<std::string> mListNodes; //!< holds a list of all nodes of the dbus
+ std::vector<sh_timerHandle_t *> mpListTimerhandles; //!< pointer to the timer handles
+ CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler
+ std::map<DBusWatch *, sh_pollHandle_t> mMapHandleWatch; //!< map to the handle watches
+ DBusBusType mDbusType;
};
}
diff --git a/AudioManagerUtilities/include/CAmDltWrapper.h b/AudioManagerUtilities/include/CAmDltWrapper.h
index 4d725d8..b6772d9 100644
--- a/AudioManagerUtilities/include/CAmDltWrapper.h
+++ b/AudioManagerUtilities/include/CAmDltWrapper.h
@@ -29,67 +29,67 @@
#include "audiomanagertypes.h"
#ifdef WITH_DLT
- #include <dlt.h>
+# include <dlt.h>
#else
- #include <stdint.h>
- #include <sstream>
+# include <stdint.h>
+# include <sstream>
- #define DLT_USER_BUF_MAX_SIZE 2048
+# define DLT_USER_BUF_MAX_SIZE 2048
- /**
- * This structure is used for every context used in an application.
- */
- typedef struct
- {
- char contextID[4]; /**< context id */
- int32_t log_level_pos; /**< offset in user-application context field */
- int32_t log_level_user; /** any message above this log level is not logged */
- } DltContext;
+/**
+ * This structure is used for every context used in an application.
+ */
+typedef struct
+{
+ char contextID[4]; /**< context id */
+ int32_t log_level_pos; /**< offset in user-application context field */
+ int32_t log_level_user; /** any message above this log level is not logged */
+} DltContext;
- /**
- * Definition of DLT trace status
- */
- typedef enum
- {
- DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */
- DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */
- DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */
- } DltTraceStatusType;
+/**
+ * Definition of DLT trace status
+ */
+typedef enum
+{
+ DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */
+ DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */
+ DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */
+} DltTraceStatusType;
- /**
- * This structure is used for context data used in an application.
- */
- typedef struct
- {
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char* context_description; /**< description of context */
- } DltContextData;
+/**
+ * This structure is used for context data used in an application.
+ */
+typedef struct
+{
+ DltContext *handle; /**< pointer to DltContext */
+ std::stringstream buffer; /**< buffer for building log message*/
+ int32_t log_level; /**< log level */
+ int32_t trace_status; /**< trace status */
+ int32_t args_num; /**< number of arguments for extended header*/
+ uint8_t mcnt; /**< message counter */
+ char *context_description; /**< description of context */
+} DltContextData;
- /**
- * Definitions of DLT log level
- */
- typedef enum
- {
- DLT_LOG_DEFAULT = -1, /**< Default log level */
- DLT_LOG_OFF = 0x00, /**< Log level off */
- DLT_LOG_FATAL = 0x01, /**< fatal system error */
- DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */
- DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */
- DLT_LOG_INFO = 0x04, /**< informational */
- DLT_LOG_DEBUG = 0x05, /**< debug */
- DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */
- } DltLogLevelType;
-
- #define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO
- #define DLT_DECLARE_CONTEXT(CONTEXT) \
+/**
+ * Definitions of DLT log level
+ */
+typedef enum
+{
+ DLT_LOG_DEFAULT = -1, /**< Default log level */
+ DLT_LOG_OFF = 0x00, /**< Log level off */
+ DLT_LOG_FATAL = 0x01, /**< fatal system error */
+ DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */
+ DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */
+ DLT_LOG_INFO = 0x04, /**< informational */
+ DLT_LOG_DEBUG = 0x05, /**< debug */
+ DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */
+} DltLogLevelType;
+
+# define DLT_DEFAULT_LOG_LEVEL DLT_LOG_INFO
+# define DLT_DECLARE_CONTEXT(CONTEXT) \
DltContext CONTEXT;
- #define DLT_IMPORT_CONTEXT(CONTEXT) \
+# define DLT_IMPORT_CONTEXT(CONTEXT) \
extern DltContext CONTEXT;
#endif // WITH_DLT
@@ -112,13 +112,13 @@ public:
*/
typedef struct
{
- DltContext *handle; /**< pointer to DltContext */
- std::stringstream buffer; /**< buffer for building log message*/
- int32_t log_level; /**< log level */
- int32_t trace_status; /**< trace status */
- int32_t args_num; /**< number of arguments for extended header*/
- uint8_t mcnt; /**< message counter */
- char* context_description; /**< description of context */
+ DltContext *handle; /**< pointer to DltContext */
+ std::stringstream buffer; /**< buffer for building log message*/
+ int32_t log_level; /**< log level */
+ int32_t trace_status; /**< trace status */
+ int32_t args_num; /**< number of arguments for extended header*/
+ uint8_t mcnt; /**< message counter */
+ char *context_description; /**< description of context */
} NoDltContextData;
/*
@@ -126,9 +126,9 @@ public:
*/
enum logDestination
{
- DAEMON=0, //!< logging with the DLT daemon
- COMMAND_LINE=1, //!< logging with commandline
- FILE_OUT =2 //!< logging into a file
+ DAEMON = 0, //!< logging with the DLT daemon
+ COMMAND_LINE = 1, //!< logging with commandline
+ FILE_OUT = 2 //!< logging into a file
};
/**
@@ -140,39 +140,42 @@ public:
* @param Filename the filename with absolute path where the log shall be written. only needed if logDest==FILE_OUT
* @param onlyError if set to true, only errors will be logged. just valid for commandline and file logs, default value = false
*/
- static CAmDltWrapper* instanctiateOnce(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false);
-
+ static CAmDltWrapper *instanctiateOnce(const char *appid, const char *description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename = "", bool onlyError = false);
+
/**
* get the Wrapper Instance
*/
- static CAmDltWrapper* instance();
+ static CAmDltWrapper *instance();
/**
* register a context
*/
- void registerContext(DltContext& handle, const char *contextid, const char * description);
- void registerContext(DltContext& handle, const char *contextid, const char * description, const DltLogLevelType level, const DltTraceStatusType status);
- void unregisterContext(DltContext& handle);
+ void registerContext(DltContext &handle, const char *contextid, const char *description);
+ void registerContext(DltContext &handle, const char *contextid, const char *description, const DltLogLevelType level, const DltTraceStatusType status);
+ void unregisterContext(DltContext &handle);
bool getEnabled();
+
~CAmDltWrapper();
- bool init(DltLogLevelType loglevel, DltContext* context = NULL);
+ bool init(DltLogLevelType loglevel, DltContext *context = NULL);
+
bool checkLogLevel(DltLogLevelType logLevel)
{
#ifdef WITH_DLT
- #ifdef DLT_IS_LOG_LEVEL_ENABLED
+# ifdef DLT_IS_LOG_LEVEL_ENABLED
if (mlogDestination == logDestination::DAEMON)
{
return (dlt_user_is_logLevel_enabled(&mDltContext, logLevel) == DLT_RETURN_TRUE);
}
- #else
+# else
(void)logLevel;
- #endif
+# endif // ifdef DLT_IS_LOG_LEVEL_ENABLED
return true;
-#else
+#else // ifdef WITH_DLT
return (logLevel <= mDltContext.log_level_user);
-#endif
+#endif // ifdef WITH_DLT
}
+
void deinit();
void send();
void append(const int8_t value);
@@ -183,48 +186,51 @@ public:
void append(const uint32_t value);
void append(const uint64_t value);
void append(const int64_t value);
- void append(const std::string& value);
+ void append(const std::string &value);
void append(const bool value);
- void append(const std::vector<uint8_t> & data);
-
- template<class T> void appendNoDLT(T value)
+ void append(const std::vector<uint8_t> &data);
+
+ template<class T>
+ void appendNoDLT(T value)
{
- mNoDltContextData.buffer << value <<" ";
+ mNoDltContextData.buffer << value << " ";
}
// specialization for const char*
- template<typename T = const char*> void append(const char* value)
+ template<typename T = const char *>
+ void append(const char *value)
{
- #ifdef WITH_DLT
- if (mlogDestination == logDestination::DAEMON)
- {
- dlt_user_log_write_string(&mDltContextData, value);
- }
- else
- {
- mNoDltContextData.buffer << std::string(value);
- }
- #else
+#ifdef WITH_DLT
+ if (mlogDestination == logDestination::DAEMON)
+ {
+ dlt_user_log_write_string(&mDltContextData, value);
+ }
+ else
+ {
mNoDltContextData.buffer << std::string(value);
- #endif //WITH_DLT
+ }
+#else // ifdef WITH_DLT
+ mNoDltContextData.buffer << std::string(value);
+#endif // WITH_DLT
}
private:
- static const std::vector<const char*> mStr_error;
- static const std::vector<const char*> mStr_sourceState;
- static const std::vector<const char*> mStr_MuteState;
- static const std::vector<const char*> mStr_DomainState;
- static const std::vector<const char*> mStr_ConnectionState;
- static const std::vector<const char*> mStr_Availability;
- static const std::vector<const char*> mStr_Interrupt;
- static const std::vector<const char*> mStr_Handle;
- static const std::vector<const char*> mStr_NotificationStatus;
+ static const std::vector<const char *> mStr_error;
+ static const std::vector<const char *> mStr_sourceState;
+ static const std::vector<const char *> mStr_MuteState;
+ static const std::vector<const char *> mStr_DomainState;
+ static const std::vector<const char *> mStr_ConnectionState;
+ static const std::vector<const char *> mStr_Availability;
+ static const std::vector<const char *> mStr_Interrupt;
+ static const std::vector<const char *> mStr_Handle;
+ static const std::vector<const char *> mStr_NotificationStatus;
public:
// specialization for const am_Error_e
- template<typename T = const am_Error_e> void append(const am_Error_e value)
+ template<typename T = const am_Error_e>
+ void append(const am_Error_e value)
{
if (static_cast<std::size_t>(value) >= mStr_error.size())
{
@@ -232,11 +238,13 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_error[value]);
}
// specialization for const am_Error_e
- template<typename T = const am_SourceState_e> void append(const am_SourceState_e value)
+ template<typename T = const am_SourceState_e>
+ void append(const am_SourceState_e value)
{
if (static_cast<std::size_t>(value) >= mStr_sourceState.size())
{
@@ -244,11 +252,12 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_sourceState[value]);
}
-
- template<typename T = const am_MuteState_e> void append(const am_MuteState_e value)
+ template<typename T = const am_MuteState_e>
+ void append(const am_MuteState_e value)
{
if (static_cast<std::size_t>(value) >= mStr_MuteState.size())
{
@@ -256,10 +265,12 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_MuteState[value]);
}
- template<typename T = const am_DomainState_e> void append(const am_DomainState_e value)
+ template<typename T = const am_DomainState_e>
+ void append(const am_DomainState_e value)
{
if (static_cast<std::size_t>(value) >= mStr_DomainState.size())
{
@@ -267,10 +278,12 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_DomainState[value]);
}
- template<typename T = const am_ConnectionState_e> void append(const am_ConnectionState_e value)
+ template<typename T = const am_ConnectionState_e>
+ void append(const am_ConnectionState_e value)
{
if (static_cast<std::size_t>(value) >= mStr_ConnectionState.size())
{
@@ -278,10 +291,12 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_ConnectionState[value]);
}
- template<typename T = const am_Availability_e> void append(const am_Availability_e value)
+ template<typename T = const am_Availability_e>
+ void append(const am_Availability_e value)
{
if (static_cast<std::size_t>(value) >= mStr_Availability.size())
{
@@ -289,10 +304,12 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_Availability[value]);
}
- template<typename T = const am_InterruptState_e> void append(const am_InterruptState_e value)
+ template<typename T = const am_InterruptState_e>
+ void append(const am_InterruptState_e value)
{
if (static_cast<std::size_t>(value) >= mStr_Interrupt.size())
{
@@ -300,10 +317,12 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_Interrupt[value]);
}
- template<typename T = const am_Handle_e> void append(const am_Handle_e value)
+ template<typename T = const am_Handle_e>
+ void append(const am_Handle_e value)
{
if (static_cast<std::size_t>(value) >= mStr_Handle.size())
{
@@ -311,16 +330,19 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_Handle[value]);
}
-
- template<typename T = const am_Handle_s> void append(const am_Handle_s value)
+
+ template<typename T = const am_Handle_s>
+ void append(const am_Handle_s value)
{
- append (value.handleType);
- append (value.handle);
+ append(value.handleType);
+ append(value.handle);
}
- template<typename T = const am_NotificationStatus_e> void append(const am_NotificationStatus_e value)
+ template<typename T = const am_NotificationStatus_e>
+ void append(const am_NotificationStatus_e value)
{
if (static_cast<std::size_t>(value) >= mStr_NotificationStatus.size())
{
@@ -328,11 +350,13 @@ public:
append(static_cast<uint16_t>(value));
return;
}
+
append(mStr_NotificationStatus[value]);
}
// Template to print unknown pointer types with their address
- template<typename T> void append(T* value)
+ template<typename T>
+ void append(T *value)
{
std::ostringstream ss;
ss << "0x" << std::hex << (uint64_t)value;
@@ -340,7 +364,8 @@ public:
}
// Template to print unknown types
- template<typename T> void append(T value)
+ template<typename T>
+ void append(T value)
{
std::ostringstream ss;
ss << std::dec << value;
@@ -349,7 +374,8 @@ public:
// Template parameter pack to generate recursive code
void append(void) {}
- template<typename T, typename... TArgs> void append(T value, TArgs... args)
+ template<typename T, typename... TArgs>
+ void append(T value, TArgs... args)
{
this->append(value);
this->append(args...);
@@ -359,19 +385,20 @@ private:
/**
* private contructor
*/
- CAmDltWrapper(const char *appid, const char * description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename="",bool onlyError=false); //is private because of singleton pattern
- bool initNoDlt(DltLogLevelType loglevel, DltContext* context);
+ CAmDltWrapper(const char *appid, const char *description, const bool debugEnabled = true, const logDestination logDest = logDestination::DAEMON, const std::string Filename = "", bool onlyError = false); // is private because of singleton pattern
+ bool initNoDlt(DltLogLevelType loglevel, DltContext *context);
std::string now();
- DltContext mDltContext; //!< the default context
- DltContextData mDltContextData; //!< contextdata
- NoDltContextData mNoDltContextData; //!<contextdata for std out logging
- std::map<DltContext*,std::string> mMapContext; //!< a Map for all registered context
- bool mDebugEnabled; //!< debug Enabled or not
- logDestination mlogDestination; //!< The log destination
- std::ofstream mFilename; //!< Filename for logging
- bool mOnlyError; //!< Only if Log Level is above Error
- bool mLogOn; //!< Used to keep track if currently logging is on
- static CAmDltWrapper* mpDLTWrapper; //!< pointer to the wrapper instance
+
+ DltContext mDltContext; //!< the default context
+ DltContextData mDltContextData; //!< contextdata
+ NoDltContextData mNoDltContextData; //!< contextdata for std out logging
+ std::map<DltContext *, std::string> mMapContext; //!< a Map for all registered context
+ bool mDebugEnabled; //!< debug Enabled or not
+ logDestination mlogDestination; //!< The log destination
+ std::ofstream mFilename; //!< Filename for logging
+ bool mOnlyError; //!< Only if Log Level is above Error
+ bool mLogOn; //!< Used to keep track if currently logging is on
+ static CAmDltWrapper *mpDLTWrapper; //!< pointer to the wrapper instance
static pthread_mutex_t mMutex;
};
@@ -384,17 +411,19 @@ private:
* @param ...
*/
template<typename T, typename... TArgs>
-void log(DltContext* const context, DltLogLevelType loglevel, T value, TArgs... args)
+void log(DltContext *const context, DltLogLevelType loglevel, T value, TArgs... args)
{
- CAmDltWrapper* inst(CAmDltWrapper::instance());
+ CAmDltWrapper *inst(CAmDltWrapper::instance());
if (!inst->getEnabled())
{
return;
}
+
if (!inst->init(loglevel, context))
{
return;
}
+
inst->append(value);
inst->append(args...);
inst->send();
@@ -430,7 +459,7 @@ void logInfo(T value, TArgs... args)
template<typename T, typename... TArgs>
void logError(T value, TArgs... args)
{
- log(NULL, DLT_LOG_ERROR,value,args...);
+ log(NULL, DLT_LOG_ERROR, value, args...);
}
/**
@@ -441,7 +470,7 @@ void logError(T value, TArgs... args)
template<typename T, typename... TArgs>
void logWarning(T value, TArgs... args)
{
- log(NULL, DLT_LOG_WARN,value,args...);
+ log(NULL, DLT_LOG_WARN, value, args...);
}
/**
@@ -452,7 +481,7 @@ void logWarning(T value, TArgs... args)
template<typename T, typename... TArgs>
void logVerbose(T value, TArgs... args)
{
- log(NULL, DLT_LOG_VERBOSE,value,args...);
+ log(NULL, DLT_LOG_VERBOSE, value, args...);
}
}
diff --git a/AudioManagerUtilities/include/CAmSerializer.h b/AudioManagerUtilities/include/CAmSerializer.h
index fbac255..ad0b2b1 100644
--- a/AudioManagerUtilities/include/CAmSerializer.h
+++ b/AudioManagerUtilities/include/CAmSerializer.h
@@ -29,34 +29,36 @@
/*!
* \brief Helper structures used within std::bind for automatically identification of all placeholders.
*/
-template<std::size_t ... Is>
+template<std::size_t... Is>
struct indices
{
};
-template<std::size_t N, std::size_t ... Is>
-struct build_indices: build_indices<N - 1, N - 1, Is...>
+template<std::size_t N, std::size_t... Is>
+struct build_indices : build_indices<N - 1, N - 1, Is...>
{
};
-template<std::size_t ... Is>
+template<std::size_t... Is>
struct build_indices<0, Is...> : indices<Is...>
{
};
-template<int I> struct placeholder
+template<int I>
+struct placeholder
{
};
namespace std
{
- template<int I>
- struct is_placeholder<::placeholder<I>> : std::integral_constant<int, I>
- {
- };
+template<int I>
+struct is_placeholder<::placeholder<I> > : std::integral_constant<int, I>
+{
+};
+
}
-#if defined(__GNUC__)
+#if defined (__GNUC__)
# define DEPRECATED(MSG) __attribute__ ((__deprecated__((#MSG))))
#else
# define DEPRECATED(MSG)
@@ -64,1154 +66,1195 @@ namespace std
namespace am
{
+/**
+ * magic class that does the serialization of functions calls
+ * The constructor must be called within the main threadcontext, after that using the
+ * overloaded template function call will serialize all calls and call them within the
+ * main thread context.\n
+ * More details can be found here: \ref util
+ * \warning asynchronous calls may be used in the mainthread context, but if you want to use synchronous calls make sure that you use one
+ * instance of this class per thread otherwise you could be lost in never returning calls.\n
+ * Examples of the usage can be found in IAmCommandReceiverShadow of the ControlPlugin or IAmRoutingReceiverShadow of the
+ * PluginRoutingInterfaceAsync.
+ *
+ */
+
+/**
+ * \defgroup Deprecated Obsolete class!
+ * @{
+ */
+
+namespace V1
+{
+class CAmSerializer
+{
+private:
+
/**
- * magic class that does the serialization of functions calls
- * The constructor must be called within the main threadcontext, after that using the
- * overloaded template function call will serialize all calls and call them within the
- * main thread context.\n
- * More details can be found here: \ref util
- * \warning asynchronous calls may be used in the mainthread context, but if you want to use synchronous calls make sure that you use one
- * instance of this class per thread otherwise you could be lost in never returning calls.\n
- * Examples of the usage can be found in IAmCommandReceiverShadow of the ControlPlugin or IAmRoutingReceiverShadow of the
- * PluginRoutingInterfaceAsync.
- *
+ * Prototype for a delegate
*/
+ class CAmDelegate
+ {
+ public:
+
+ typedef enum
+ : bool
+ {
+ SyncCallType = false, AsyncCallType = true
+ } CallType;
+
+ virtual ~CAmDelegate()
+ {
+ }
+
+ virtual CallType call(int *pipe) = 0;
+
+ };
/**
- * \defgroup Deprecated Obsolete class!
- * @{
+ * Prototype for a delegate with variadic template arguments in conjunction with the following class.
*/
+ template<class Class, typename Method, typename Tuple, bool Done, int Total, int... N>
+ class CAmDelegateAsyncImpl : public CAmDelegate
+ {
+ Class mInstance;
+ Method mMethod;
+ Tuple mArguments;
+ public:
+ friend class CAmSerializer;
+ static void call(Class instance, Method method, Tuple &&arguments)
+ {
+ CAmDelegateAsyncImpl<Class, Method, Tuple, Total == 1 + sizeof ... (N), Total, N..., sizeof ... (N)>::call(instance, method, std::forward<Tuple>(arguments));
+ }
+
+ CAmDelegateAsyncImpl(Class instance, Method method, Tuple &&arguments)
+ {
+ mInstance = instance;
+ mMethod = method;
+ mArguments = std::move(arguments);
+ }
+
+ CallType call(int *pipe)
+ {
+ (void)pipe;
+ call(mInstance, mMethod, std::forward<Tuple>(mArguments));
+ return (AsyncCallType);
+ }
+
+ };
- namespace V1
+ /**
+ * Prototype for a delegate with variadic template arguments.
+ */
+ template<class Class, typename Method, typename Tuple, int Total, int... N>
+ class CAmDelegateAsyncImpl<Class, Method, Tuple, true, Total, N...> : public CAmDelegate
{
- class CAmSerializer
+ Class mInstance;
+ Method mMethod;
+ Tuple mArguments;
+ public:
+ friend class CAmSerializer;
+ static void call(Class instance, Method method, Tuple &&t)
{
- private:
+ (*instance.*method)(std::get<N>(std::forward<Tuple>(t)) ...);
+ }
- /**
- * Prototype for a delegate
- */
- class CAmDelegate
- {
- public:
-
- typedef enum
- :bool
- {
- SyncCallType = false, AsyncCallType = true
- } CallType;
-
- virtual ~CAmDelegate()
- {
- }
- ;
- virtual CallType call(int* pipe)=0;
-
- };
-
- /**
- * Prototype for a delegate with variadic template arguments in conjunction with the following class.
- */
- template<class Class, typename Method, typename Tuple, bool Done, int Total, int ... N>
- class CAmDelegateAsyncImpl: public CAmDelegate
- {
- Class mInstance;
- Method mMethod;
- Tuple mArguments;
- public:
- friend class CAmSerializer;
- static void call(Class instance, Method method, Tuple && arguments)
- {
- CAmDelegateAsyncImpl<Class, Method, Tuple, Total == 1 + sizeof...(N), Total, N..., sizeof...(N)>::call(instance, method, std::forward<Tuple>(arguments));
- }
-
- CAmDelegateAsyncImpl(Class instance, Method method, Tuple && arguments)
- {
- mInstance = instance;
- mMethod = method;
- mArguments = std::move(arguments);
- }
-
- CallType call(int* pipe)
- {
- (void) pipe;
- call(mInstance, mMethod, std::forward<Tuple>(mArguments));
- return (AsyncCallType);
- }
- ;
- };
-
- /**
- * Prototype for a delegate with variadic template arguments.
- */
- template<class Class, typename Method, typename Tuple, int Total, int ... N>
- class CAmDelegateAsyncImpl<Class, Method, Tuple, true, Total, N...> : public CAmDelegate
- {
- Class mInstance;
- Method mMethod;
- Tuple mArguments;
- public:
- friend class CAmSerializer;
- static void call(Class instance, Method method, Tuple && t)
- {
- (*instance.*method)(std::get<N>(std::forward<Tuple>(t))...);
- }
-
- CAmDelegateAsyncImpl(Class instance, Method method, Tuple && arguments)
- {
- mInstance = instance;
- mMethod = method;
- mArguments = std::move(arguments);
- }
-
- CallType call(int* pipe)
- {
- (void) pipe;
- call(mInstance, mMethod, std::forward<Tuple>(mArguments));
- return (AsyncCallType);
- }
- ;
- };
-
- /**
- * Prototype for a delegate with variadic template arguments in conjunction with the following class.
- */
- template<class Class, typename Method, typename Return, typename Tuple, bool Done, int Total, int ... N>
- class CAmDelegateSyncImpl: public CAmDelegate
- {
- Class mInstance;
- Method mMethod;
- Tuple mArguments;
- Return mReturn;
- public:
- friend class CAmSerializer;
- static void call(Class instance, Method method, Return & result, Tuple && arguments)
- {
- CAmDelegateSyncImpl<Class, Method, Return, Tuple, Total == 1 + sizeof...(N), Total, N..., sizeof...(N)>::call(instance, method, result, std::forward<Tuple>(arguments));
- }
-
- CAmDelegateSyncImpl(Class instance, Method method, Tuple && arguments)
- {
- mInstance = instance;
- mMethod = method;
- mArguments = std::move(arguments);
- }
-
- CallType call(int* pipe)
- {
- call(mInstance, mMethod, mReturn, std::forward<Tuple>(mArguments));
- ssize_t result(-1);
- result = write(pipe[1], this, sizeof(this));
- if (result == -1)
- logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
- return (SyncCallType);
- }
- ;
- };
-
- /**
- * Prototype for a delegate with variadic template arguments.
- */
- template<class Class, typename Method, typename Return, typename Tuple, int Total, int ... N>
- class CAmDelegateSyncImpl<Class, Method, Return, Tuple, true, Total, N...> : public CAmDelegate
- {
- Class mInstance;
- Method mMethod;
- Tuple mArguments;
- Return mReturn;
- public:
- friend class CAmSerializer;
- static void call(Class instance, Method method, Return & result, Tuple && t)
- {
- result = (*instance.*method)(std::get<N>(t)...);
- }
-
- CAmDelegateSyncImpl(Class instance, Method method, Tuple && arguments)
- {
- mInstance = instance;
- mMethod = method;
- mArguments = std::move(arguments);
- }
-
- CallType call(int* pipe)
- {
- call(mInstance, mMethod, mReturn, std::forward<Tuple>(mArguments));
- ssize_t result(-1);
- result = write(pipe[1], this, sizeof(this));
- if (result == -1)
- logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
- return (SyncCallType);
- }
- ;
- };
-
- typedef CAmDelegate* CAmDelegagePtr; //!< pointer to a delegate
-
- public:
- /**
- * instantiates a async delegate with given arguments and sends the delegate pointer over the pipe
- */
- template<typename Class, typename Method, typename Tuple>
- void doAsyncCall(Class intsance, Method method, Tuple & arguments)
- {
- typedef typename std::decay<Tuple>::type ttype;
- typedef CAmDelegateAsyncImpl<Class, Method, Tuple, 0 == std::tuple_size<ttype>::value, std::tuple_size<ttype>::value> AsyncDelegate;
- AsyncDelegate *pImp = new AsyncDelegate(intsance, method, std::forward<Tuple>(arguments));
- send(pImp);
- //Do not delete the pointer. It will be deleted automatically later.
- }
+ CAmDelegateAsyncImpl(Class instance, Method method, Tuple &&arguments)
+ {
+ mInstance = instance;
+ mMethod = method;
+ mArguments = std::move(arguments);
+ }
- /**
- * instantiates a sync delegate with given arguments and sends the delegate pointer over the pipe
- */
- template<typename Class, typename Method, typename Return, typename Tuple>
- void doSyncCall(Class intsance, Method method, Return & result, Tuple & arguments)
- {
- typedef typename std::decay<Tuple>::type ttype;
- typedef CAmDelegateSyncImpl<Class, Method, Return, Tuple, 0 == std::tuple_size<ttype>::value, std::tuple_size<ttype>::value> SyncDelegate;
- SyncDelegate *pImp = new SyncDelegate(intsance, method, std::forward<Tuple>(arguments));
- send(pImp);
- int numReads;
- SyncDelegate *p = NULL;
- if ((numReads = read(mReturnPipe[0], &p, sizeof(p))) == -1)
- {
- logError("CAmSerializer::doSyncCall could not read pipe!");
- throw std::runtime_error("CAmSerializer Could not read pipe!");
- }
- result = std::move(pImp->mReturn);
- arguments = std::move(pImp->mArguments);
- //Delete the pointer.
- delete pImp;
- }
- private:
+ CallType call(int *pipe)
+ {
+ (void)pipe;
+ call(mInstance, mMethod, std::forward<Tuple>(mArguments));
+ return (AsyncCallType);
+ }
- /**
- * rings the line of the pipe and adds the delegate pointer to the queue
- * @param p delegate pointer
- */
- inline void send(CAmDelegagePtr p)
- {
- if (write(mPipe[1], &p, sizeof(p)) == -1)
- {
- throw std::runtime_error("could not write to pipe !");
- }
- }
+ };
- int mPipe[2]; //!< the pipe
- int mReturnPipe[2]; //!< pipe handling returns
- sh_pollHandle_t mHandle;
- CAmSocketHandler* mpSocketHandler;
- std::deque<CAmDelegagePtr> mListDelegatePoiters; //!< intermediate queue to store the pipe results
+ /**
+ * Prototype for a delegate with variadic template arguments in conjunction with the following class.
+ */
+ template<class Class, typename Method, typename Return, typename Tuple, bool Done, int Total, int... N>
+ class CAmDelegateSyncImpl : public CAmDelegate
+ {
+ Class mInstance;
+ Method mMethod;
+ Tuple mArguments;
+ Return mReturn;
+ public:
+ friend class CAmSerializer;
+ static void call(Class instance, Method method, Return &result, Tuple &&arguments)
+ {
+ CAmDelegateSyncImpl<Class, Method, Return, Tuple, Total == 1 + sizeof ... (N), Total, N..., sizeof ... (N)>::call(instance, method, result, std::forward<Tuple>(arguments));
+ }
- public:
+ CAmDelegateSyncImpl(Class instance, Method method, Tuple &&arguments)
+ {
+ mInstance = instance;
+ mMethod = method;
+ mArguments = std::move(arguments);
+ }
- /**
- * get the size of delegate pointers
- */
- int getListDelegatePoiters()
+ CallType call(int *pipe)
+ {
+ call(mInstance, mMethod, mReturn, std::forward<Tuple>(mArguments));
+ ssize_t result(-1);
+ result = write(pipe[1], this, sizeof(this));
+ if (result == -1)
{
- return mListDelegatePoiters.size();
+ logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
}
- /**
- * calls a function with variadic arguments threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as member function pointer.
- * @param output variable.
- * @tparam TClass the type of the Class to be called
- * @tparam TRet the type of the result
- * @tparam TArgs argument list
- * \section ex Example:
- * @code
- * class MyGreatClass
- * {
- * public:
- * int AGreatMethod(int x);
- * }
- * CAmSerializer serial(&Sockethandler);
- * MyGreatClass anInstance;
- * int result;
- * serial.syncCall<MyGreatClass, int, int>(&anInstance,&MyGreatClass::AGreatMethod, result, 100);
- * @endcode
- */
- template<class TClass, class TRet, class ... TArgs>
- void syncCall(TClass* instance, TRet (TClass::*method)(TArgs ...), TRet & result, TArgs & ... arguments)
- {
- auto t = std::make_tuple(arguments...);
- doSyncCall(instance, method, result, t);
- std::tie(arguments...) = t;
- }
+ return (SyncCallType);
+ }
- /**
- * calls a function with variadic arguments threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as member function pointer.
- * @tparam TClass the type of the Class to be called
- * @tparam TRet the type of the result
- * @tparam TArgs argument list
- * \section ex Example:
- * @code
- * class MyGreatClass
- * {
- * public:
- * int AGreatMethod(int x);
- * }
- * CAmSerializer serial(&Sockethandler);
- * MyGreatClass anInstance;
- * serial.asyncCall<MyGreatClass, void, int>(&anInstance,&MyGreatClass::AGreatMethod, 100);
- * @endcode
- */
- template<class TClass, class TRet, class ... TArgs>
- void asyncCall(TClass* instance, TRet (TClass::*method)(TArgs ...), TArgs & ... arguments)
- {
- auto t = std::make_tuple(arguments...);
- doAsyncCall(instance, method, t);
- }
+ };
- /**
- * calls a function with no arguments threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as memberfunction pointer.
- * @tparam TClass1 the type of the Class to be called
- * \section ex Example:
- * @code
- * class myClass
- * {
- * public:
- * void myfunction();
- * }
- * CAmSerializer serial(&Sockethandler);
- * myClass instanceMyClass;
- * serial<CommandSender>(&instanceMyClass,&myClass::myfunction);
- * @endcode
- */
- template<class TClass>
- void asyncCall(TClass* instance, void (TClass::*function)())
- {
- auto t = std::make_tuple();
- doAsyncCall(instance, function, t);
- }
+ /**
+ * Prototype for a delegate with variadic template arguments.
+ */
+ template<class Class, typename Method, typename Return, typename Tuple, int Total, int... N>
+ class CAmDelegateSyncImpl<Class, Method, Return, Tuple, true, Total, N...> : public CAmDelegate
+ {
+ Class mInstance;
+ Method mMethod;
+ Tuple mArguments;
+ Return mReturn;
+ public:
+ friend class CAmSerializer;
+ static void call(Class instance, Method method, Return &result, Tuple &&t)
+ {
+ result = (*instance.*method)(std::get<N>(t) ...);
+ }
- /**
- * calls a function with one arguments asynchronously threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as memberfunction pointer.
- * @param argument the argument
- * @tparam TClass1 the type of the Class to be called
- * @tparam Targ the type of the argument to be called
- * \section ex Example:
- * @code
- * class myClass
- * {
- * public:
- * void myfunction(int k);
- * }
- * CAmSerializer serial(&Sockethandler);
- * myClass instanceMyClass;
- * serial<CommandSender,int>(&instanceMyClass,&myClass::myfunction,k);
- * @endcode
- *
- */
- template<class TClass1, class Targ>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ), Targ argument)
- {
- auto t = std::make_tuple(argument);
- doAsyncCall(instance, function, t);
- }
+ CAmDelegateSyncImpl(Class instance, Method method, Tuple &&arguments)
+ {
+ mInstance = instance;
+ mMethod = method;
+ mArguments = std::move(arguments);
+ }
- /**
- * calls a function with one argument called by reference asynchronously threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as memberfunction pointer.
- * @param argument the argument
- * @tparam TClass1 the type of the Class to be called
- * @tparam Targ the type of the argument to be called
- * \section ex Example:
- * @code
- * class myClass
- * {
- * public:
- * void myfunction(int k);
- * }
- * CAmSerializer serial(&Sockethandler);
- * myClass instanceMyClass;
- * serial<CommandSender,int>(&instanceMyClass,&myClass::myfunction,k);
- * @endcode
- *
- */
- template<class TClass1, class Targ>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ&), Targ& argument)
+ CallType call(int *pipe)
+ {
+ call(mInstance, mMethod, mReturn, std::forward<Tuple>(mArguments));
+ ssize_t result(-1);
+ result = write(pipe[1], this, sizeof(this));
+ if (result == -1)
{
- auto t = std::make_tuple(argument);
- doAsyncCall(instance, function, t);
+ logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
}
- /**
- * calls a function with two arguments asynchronously threadsafe. for more see asyncCall with one argument
- * @param instance pointer to the instance of the class
- * @param function memberfunction poitner
- * @param argument the first argument
- * @param argument1 the second argument
- * @tparam TClass1 the type of the Class to be called
- * @tparam Targ the type of the argument to be called
- * @tparam Targ1 the type of the first argument to be called
- */
- template<class TClass1, class Targ, class Targ1>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1), Targ argument, Targ1 argument1)
- {
- auto t = std::make_tuple(argument, argument1);
- doAsyncCall(instance, function, t);
- }
+ return (SyncCallType);
+ }
- /**
- * calls a function with two arguments asynchronously threadsafe, first argument is a reference. for more see asyncCall with one argument
- * @param instance pointer to the instance of the class
- * @param function memberfunction poitner
- * @param argument the first argument
- * @param argument1 the second argument
- * @tparam TClass1 the type of the Class to be called
- * @tparam Targ the type of the argument to be called
- * @tparam Targ1 the type of the first argument to be called
- */
- template<class TClass1, class Targ, class Targ1>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1), Targ& argument, Targ1 argument1)
- {
- auto t = std::make_tuple(argument, argument1);
- doAsyncCall(instance, function, t);
- }
+ };
- /**
- * calls a function with two arguments asynchronously threadsafe, second argument is a reference. for more see asyncCall with one argument
- * @param instance pointer to the instance of the class
- * @param function memberfunction poitner
- * @param argument the first argument
- * @param argument1 the second argument
- * @tparam TClass1 the type of the Class to be called
- * @tparam Targ the type of the argument to be called
- * @tparam Targ1 the type of the first argument to be called
- */
- template<class TClass1, class Targ, class Targ1>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1& argument1), Targ argument, Targ1& argument1)
- {
- auto t = std::make_tuple(argument, argument1);
- doAsyncCall(instance, function, t);
- }
+ typedef CAmDelegate *CAmDelegagePtr; //!< pointer to a delegate
- /**
- * calls a function with two arguments asynchronously threadsafe, both arguments are references. for more see asyncCall with one argument
- * @param instance pointer to the instance of the class
- * @param function memberfunction poitner
- * @param argument the first argument
- * @param argument1 the second argument
- * @tparam TClass1 the type of the Class to be called
- * @tparam Targ the type of the argument to be called
- * @tparam Targ1 the type of the first argument to be called
- */
- template<class TClass1, class Targ, class Targ1>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1), Targ& argument, Targ1& argument1)
- {
- auto t = std::make_tuple(argument, argument1);
- doAsyncCall(instance, function, t);
- }
+public:
+ /**
+ * instantiates a async delegate with given arguments and sends the delegate pointer over the pipe
+ */
+ template<typename Class, typename Method, typename Tuple>
+ void doAsyncCall(Class intsance, Method method, Tuple &arguments)
+ {
+ typedef typename std::decay<Tuple>::type ttype;
+ typedef CAmDelegateAsyncImpl<Class, Method, Tuple, 0 == std::tuple_size<ttype>::value, std::tuple_size<ttype>::value> AsyncDelegate;
+ AsyncDelegate *pImp = new AsyncDelegate(intsance, method, std::forward<Tuple>(arguments));
+ send(pImp);
+ // Do not delete the pointer. It will be deleted automatically later.
+ }
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+ /**
+ * instantiates a sync delegate with given arguments and sends the delegate pointer over the pipe
+ */
+ template<typename Class, typename Method, typename Return, typename Tuple>
+ void doSyncCall(Class intsance, Method method, Return &result, Tuple &arguments)
+ {
+ typedef typename std::decay<Tuple>::type ttype;
+ typedef CAmDelegateSyncImpl<Class, Method, Return, Tuple, 0 == std::tuple_size<ttype>::value, std::tuple_size<ttype>::value> SyncDelegate;
+ SyncDelegate *pImp = new SyncDelegate(intsance, method, std::forward<Tuple>(arguments));
+ send(pImp);
+ int numReads;
+ SyncDelegate *p = NULL;
+ if ((numReads = read(mReturnPipe[0], &p, sizeof(p))) == -1)
+ {
+ logError("CAmSerializer::doSyncCall could not read pipe!");
+ throw std::runtime_error("CAmSerializer Could not read pipe!");
+ }
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1, Targ2 argument2), Targ& argument, Targ1 argument1, Targ2 argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+ result = std::move(pImp->mReturn);
+ arguments = std::move(pImp->mArguments);
+ // Delete the pointer.
+ delete pImp;
+ }
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1& argument1, Targ2 argument2), Targ argument, Targ1& argument1, Targ2 argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+private:
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2& argument2), Targ argument, Targ1 argument1, Targ2& argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+ /**
+ * rings the line of the pipe and adds the delegate pointer to the queue
+ * @param p delegate pointer
+ */
+ inline void send(CAmDelegagePtr p)
+ {
+ if (write(mPipe[1], &p, sizeof(p)) == -1)
+ {
+ throw std::runtime_error("could not write to pipe !");
+ }
+ }
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1& argument1, Targ2& argument2), Targ argument, Targ1& argument1, Targ2& argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+ int mPipe[2]; //!< the pipe
+ int mReturnPipe[2]; //!< pipe handling returns
+ sh_pollHandle_t mHandle;
+ CAmSocketHandler *mpSocketHandler;
+ std::deque<CAmDelegagePtr> mListDelegatePoiters; //!< intermediate queue to store the pipe results
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1, Targ2& argument2), Targ& argument, Targ1& argument1, Targ2& argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+public:
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1, Targ2 argument2), Targ& argument, Targ1& argument1, Targ2 argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+ /**
+ * get the size of delegate pointers
+ */
+ int getListDelegatePoiters()
+ {
+ return mListDelegatePoiters.size();
+ }
- /**
- * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1, Targ2& argument2), Targ& argument, Targ1 argument1, Targ2& argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doAsyncCall(instance, function, t);
- }
+ /**
+ * calls a function with variadic arguments threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as member function pointer.
+ * @param output variable.
+ * @tparam TClass the type of the Class to be called
+ * @tparam TRet the type of the result
+ * @tparam TArgs argument list
+ * \section ex Example:
+ * @code
+ * class MyGreatClass
+ * {
+ * public:
+ * int AGreatMethod(int x);
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * MyGreatClass anInstance;
+ * int result;
+ * serial.syncCall<MyGreatClass, int, int>(&anInstance,&MyGreatClass::AGreatMethod, result, 100);
+ * @endcode
+ */
+ template<class TClass, class TRet, class... TArgs>
+ void syncCall(TClass *instance, TRet (TClass::*method)(TArgs...), TRet &result, TArgs & ... arguments)
+ {
+ auto t = std::make_tuple(arguments...);
+ doSyncCall(instance, method, result, t);
+ std::tie(arguments...) = t;
+ }
- /**
- * calls a function with four arguments asynchronously threadsafe. for more see other asycCall
- */
- template<class TClass1, class Targ, class Targ1, class Targ2, class Targ3>
- void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3)
- {
- auto t = std::make_tuple(argument, argument1, argument2, argument3);
- doAsyncCall(instance, function, t);
- }
+ /**
+ * calls a function with variadic arguments threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as member function pointer.
+ * @tparam TClass the type of the Class to be called
+ * @tparam TRet the type of the result
+ * @tparam TArgs argument list
+ * \section ex Example:
+ * @code
+ * class MyGreatClass
+ * {
+ * public:
+ * int AGreatMethod(int x);
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * MyGreatClass anInstance;
+ * serial.asyncCall<MyGreatClass, void, int>(&anInstance,&MyGreatClass::AGreatMethod, 100);
+ * @endcode
+ */
+ template<class TClass, class TRet, class... TArgs>
+ void asyncCall(TClass *instance, TRet (TClass::*method)(TArgs...), TArgs & ... arguments)
+ {
+ auto t = std::make_tuple(arguments...);
+ doAsyncCall(instance, method, t);
+ }
- /**
- * calls a synchronous function with no arguments threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as memberfunction pointer.
- * @param retVal the return parameter, no const allowed !
- * @tparam TClass1 the type of the class to be called
- * @tparam TretVal the type of the return parameter
- * \section ex Example:
- * @code
- * class myClass
- * {
- * public:
- * am_Error_e myfunction();
- * }
- * CAmSerializer serial(&Sockethandler);
- * myClass instanceMyClass;
- * am_Error_e error;
- * serial<CommandSender,am_Error_e>(&instanceMyClass,&myClass::myfunction, error);
- * @endcode
- * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments.
- *
- */
- template<class TClass1, class TretVal>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(), TretVal& retVal)
- {
- auto t = std::make_tuple();
- doSyncCall(instance, function, retVal, t);
- }
+ /**
+ * calls a function with no arguments threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as memberfunction pointer.
+ * @tparam TClass1 the type of the Class to be called
+ * \section ex Example:
+ * @code
+ * class myClass
+ * {
+ * public:
+ * void myfunction();
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * myClass instanceMyClass;
+ * serial<CommandSender>(&instanceMyClass,&myClass::myfunction);
+ * @endcode
+ */
+ template<class TClass>
+ void asyncCall(TClass *instance, void (TClass::*function)())
+ {
+ auto t = std::make_tuple();
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a function with one argument synchronous threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as memberfunction pointer.
- * @param retVal the return parameter, no const allowed !
- * @param argument the argument, no const allowed !
- * @tparam TClass1 the type of the class to be called
- * @tparam TretVal the type of the return parameter
- * @tparam TargCall the type of the argument like in the function to be called. here all references and const must be
- * respected!
- * @tparam Targ the type of the argument, here no const and no references allowed !
- * \section ex Example:
- * @code
- * class myClass
- * {
- * public:
- * am_Error_e myfunction(int k);
- * }
- * CAmSerializer serial(&Sockethandler);
- * myClass instanceMyClass;
- * am_Error_e error;
- * int l;
- * serial<CommandSender,am_Error_e,int>(&instanceMyClass,&myClass::myfunction,error,l);
- * @endcode
- * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments.
- */
- template<class TClass1, class TretVal, class TargCall, class Targ>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall), TretVal& retVal, Targ& argument)
- {
- auto t = std::make_tuple(argument);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument) = t;
- }
+ /**
+ * calls a function with one arguments asynchronously threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as memberfunction pointer.
+ * @param argument the argument
+ * @tparam TClass1 the type of the Class to be called
+ * @tparam Targ the type of the argument to be called
+ * \section ex Example:
+ * @code
+ * class myClass
+ * {
+ * public:
+ * void myfunction(int k);
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * myClass instanceMyClass;
+ * serial<CommandSender,int>(&instanceMyClass,&myClass::myfunction,k);
+ * @endcode
+ *
+ */
+ template<class TClass1, class Targ>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ), Targ argument)
+ {
+ auto t = std::make_tuple(argument);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a function with one argument synchronous threadsafe for const functions. For more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class Targ>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall) const, TretVal& retVal, Targ& argument)
- {
- auto t = std::make_tuple(argument);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument) = t;
- }
+ /**
+ * calls a function with one argument called by reference asynchronously threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as memberfunction pointer.
+ * @param argument the argument
+ * @tparam TClass1 the type of the Class to be called
+ * @tparam Targ the type of the argument to be called
+ * \section ex Example:
+ * @code
+ * class myClass
+ * {
+ * public:
+ * void myfunction(int k);
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * myClass instanceMyClass;
+ * serial<CommandSender,int>(&instanceMyClass,&myClass::myfunction,k);
+ * @endcode
+ *
+ */
+ template<class TClass1, class Targ>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ &), Targ &argument)
+ {
+ auto t = std::make_tuple(argument);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a function with two arguments synchronously threadsafe. For more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class Targ1Call, class Targ, class Targ1>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, Targ1Call), TretVal& retVal, Targ& argument, Targ1& argument1)
- {
- auto t = std::make_tuple(argument, argument1);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument, argument1) = t;
- }
- /**
- * calls a function with two arguments synchronously threadsafe const. For more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class Targ1Call, class Targ, class Targ1>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, Targ1Call) const, TretVal& retVal, Targ& argument, Targ1& argument1)
- {
- auto t = std::make_tuple(argument, argument1);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument, argument1) = t;
- }
+ /**
+ * calls a function with two arguments asynchronously threadsafe. for more see asyncCall with one argument
+ * @param instance pointer to the instance of the class
+ * @param function memberfunction poitner
+ * @param argument the first argument
+ * @param argument1 the second argument
+ * @tparam TClass1 the type of the Class to be called
+ * @tparam Targ the type of the argument to be called
+ * @tparam Targ1 the type of the first argument to be called
+ */
+ template<class TClass1, class Targ, class Targ1>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ argument, Targ1 argument1), Targ argument, Targ1 argument1)
+ {
+ auto t = std::make_tuple(argument, argument1);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a function with three arguments synchronously threadsafe. for more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class Targ, class Targ1, class Targ2>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument, argument1, argument2) = t;
- }
+ /**
+ * calls a function with two arguments asynchronously threadsafe, first argument is a reference. for more see asyncCall with one argument
+ * @param instance pointer to the instance of the class
+ * @param function memberfunction poitner
+ * @param argument the first argument
+ * @param argument1 the second argument
+ * @tparam TClass1 the type of the Class to be called
+ * @tparam Targ the type of the argument to be called
+ * @tparam Targ1 the type of the first argument to be called
+ */
+ template<class TClass1, class Targ, class Targ1>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ & argument, Targ1 argument1), Targ &argument, Targ1 argument1)
+ {
+ auto t = std::make_tuple(argument, argument1);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a const function with three arguments synchronously threadsafe. for more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class Targ, class Targ1, class Targ2>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2) const, TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2)
- {
- auto t = std::make_tuple(argument, argument1, argument2);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument, argument1, argument2) = t;
- }
+ /**
+ * calls a function with two arguments asynchronously threadsafe, second argument is a reference. for more see asyncCall with one argument
+ * @param instance pointer to the instance of the class
+ * @param function memberfunction poitner
+ * @param argument the first argument
+ * @param argument1 the second argument
+ * @tparam TClass1 the type of the Class to be called
+ * @tparam Targ the type of the argument to be called
+ * @tparam Targ1 the type of the first argument to be called
+ */
+ template<class TClass1, class Targ, class Targ1>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ argument, Targ1 & argument1), Targ argument, Targ1 &argument1)
+ {
+ auto t = std::make_tuple(argument, argument1);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a function with four arguments synchronously threadsafe. for more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class TargCall3, class Targ, class Targ1, class Targ2, class Targ3>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3)
- {
- auto t = std::make_tuple(argument, argument1, argument2, argument3);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument, argument1, argument2, argument3) = t;
- }
+ /**
+ * calls a function with two arguments asynchronously threadsafe, both arguments are references. for more see asyncCall with one argument
+ * @param instance pointer to the instance of the class
+ * @param function memberfunction poitner
+ * @param argument the first argument
+ * @param argument1 the second argument
+ * @tparam TClass1 the type of the Class to be called
+ * @tparam Targ the type of the argument to be called
+ * @tparam Targ1 the type of the first argument to be called
+ */
+ template<class TClass1, class Targ, class Targ1>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ & argument, Targ1 & argument1), Targ &argument, Targ1 &argument1)
+ {
+ auto t = std::make_tuple(argument, argument1);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a function with five arguments synchronously threadsafe. for more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class TargCall3, class TargCall4, class Targ, class Targ1, class Targ2, class Targ3, class Targ4>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3, TargCall4), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3, Targ4& argument4)
- {
- auto t = std::make_tuple(argument, argument1, argument2, argument3, argument4);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument, argument1, argument2, argument3, argument4) = t;
- }
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * calls a function with six arguments synchronously threadsafe. for more see syncCall with one argument
- */
- template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class TargCall3, class TargCall4, class TargCall5, class Targ, class Targ1, class Targ2, class Targ3, class Targ4, class Targ5>
- void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3, TargCall4, TargCall5), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3,
- Targ4& argument4, Targ5& argument5)
- {
- auto t = std::make_tuple(argument, argument1, argument2, argument3, argument4, argument5);
- doSyncCall(instance, function, retVal, t);
- std::tie(argument, argument1, argument2, argument3, argument4, argument5) = t;
- }
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ & argument, Targ1 argument1, Targ2 argument2), Targ &argument, Targ1 argument1, Targ2 argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * receiver callback for sockethandling, for more, see CAmSocketHandler
- */
- void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)
- {
- (void) handle;
- (void) userData;
- int numReads;
- CAmDelegagePtr listPointers[3];
- if ((numReads = read(pollfd.fd, &listPointers, sizeof(listPointers))) == -1)
- {
- logError("CAmSerializer::receiverCallback could not read pipe!");
- throw std::runtime_error("CAmSerializer Could not read pipe!");
- }
- mListDelegatePoiters.assign(listPointers, listPointers + (numReads / sizeof(CAmDelegagePtr)));
- }
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ argument, Targ1 & argument1, Targ2 argument2), Targ argument, Targ1 &argument1, Targ2 argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * checker callback for sockethandling, for more, see CAmSocketHandler
- */
- bool checkerCallback(const sh_pollHandle_t handle, void* userData)
- {
- (void) handle;
- (void) userData;
- if (mListDelegatePoiters.empty())
- return (false);
- return (true);
- }
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 & argument2), Targ argument, Targ1 argument1, Targ2 &argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
- /**
- * dispatcher callback for sockethandling, for more, see CAmSocketHandler
- */
- bool dispatcherCallback(const sh_pollHandle_t handle, void* userData)
- {
- (void) handle;
- (void) userData;
- CAmDelegagePtr delegatePoiter = mListDelegatePoiters.front();
- mListDelegatePoiters.pop_front();
- if (delegatePoiter->call(mReturnPipe))
- delete delegatePoiter;
- if (mListDelegatePoiters.empty())
- return (false);
- return (true);
- }
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ argument, Targ1 & argument1, Targ2 & argument2), Targ argument, Targ1 &argument1, Targ2 &argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
- TAmShPollFired<CAmSerializer> receiverCallbackT;
- TAmShPollDispatch<CAmSerializer> dispatcherCallbackT;
- TAmShPollCheck<CAmSerializer> checkerCallbackT;
-
- /**
- * The constructor must be called in the mainthread context !
- * @param iSocketHandler pointer to the CAmSocketHandler
- */
- CAmSerializer(CAmSocketHandler *iSocketHandler) :
- mPipe(),
- mReturnPipe(),
- mHandle(),
- mpSocketHandler(iSocketHandler),
- mListDelegatePoiters(),
- receiverCallbackT(this, &CAmSerializer::receiverCallback),
- dispatcherCallbackT(this, &CAmSerializer::dispatcherCallback),
- checkerCallbackT(this, &CAmSerializer::checkerCallback)
- {
- assert(NULL!=iSocketHandler);
-
- if (pipe(mPipe) == -1)
- {
- logError("CAmSerializer could not create pipe!");
- throw std::runtime_error("CAmSerializer Could not open pipe!");
- }
-
- if (pipe(mReturnPipe) == -1)
- {
- logError("CAmSerializer could not create mReturnPipe!");
- throw std::runtime_error("CAmSerializer Could not open mReturnPipe!");
- }
-
- short event = 0;
- event |= POLLIN;
- mpSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, mHandle);
- }
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ & argument, Targ1 & argument1, Targ2 & argument2), Targ &argument, Targ1 &argument1, Targ2 &argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
- ~CAmSerializer()
- {
- mpSocketHandler->removeFDPoll(mHandle);
- close(mPipe[0]);
- close(mPipe[1]);
- close(mReturnPipe[0]);
- close(mReturnPipe[1]);
- }
- };
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ & argument, Targ1 & argument1, Targ2 argument2), Targ &argument, Targ1 &argument1, Targ2 argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
+
+ /**
+ * calls a function with three arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ & argument, Targ1 argument1, Targ2 & argument2), Targ &argument, Targ1 argument1, Targ2 &argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doAsyncCall(instance, function, t);
+ }
+
+ /**
+ * calls a function with four arguments asynchronously threadsafe. for more see other asycCall
+ */
+ template<class TClass1, class Targ, class Targ1, class Targ2, class Targ3>
+ void asyncCall(TClass1 *instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2, argument3);
+ doAsyncCall(instance, function, t);
+ }
- } /* namespace V1 */
+ /**
+ * calls a synchronous function with no arguments threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as memberfunction pointer.
+ * @param retVal the return parameter, no const allowed !
+ * @tparam TClass1 the type of the class to be called
+ * @tparam TretVal the type of the return parameter
+ * \section ex Example:
+ * @code
+ * class myClass
+ * {
+ * public:
+ * am_Error_e myfunction();
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * myClass instanceMyClass;
+ * am_Error_e error;
+ * serial<CommandSender,am_Error_e>(&instanceMyClass,&myClass::myfunction, error);
+ * @endcode
+ * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments.
+ *
+ */
+ template<class TClass1, class TretVal>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(), TretVal &retVal)
+ {
+ auto t = std::make_tuple();
+ doSyncCall(instance, function, retVal, t);
+ }
+
+ /**
+ * calls a function with one argument synchronous threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as memberfunction pointer.
+ * @param retVal the return parameter, no const allowed !
+ * @param argument the argument, no const allowed !
+ * @tparam TClass1 the type of the class to be called
+ * @tparam TretVal the type of the return parameter
+ * @tparam TargCall the type of the argument like in the function to be called. here all references and const must be
+ * respected!
+ * @tparam Targ the type of the argument, here no const and no references allowed !
+ * \section ex Example:
+ * @code
+ * class myClass
+ * {
+ * public:
+ * am_Error_e myfunction(int k);
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * myClass instanceMyClass;
+ * am_Error_e error;
+ * int l;
+ * serial<CommandSender,am_Error_e,int>(&instanceMyClass,&myClass::myfunction,error,l);
+ * @endcode
+ * All arguments given to synchronous functions must be non-const since the results of the operations will be written back to the arguments.
+ */
+ template<class TClass1, class TretVal, class TargCall, class Targ>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall), TretVal &retVal, Targ &argument)
+ {
+ auto t = std::make_tuple(argument);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument) = t;
+ }
+
+ /**
+ * calls a function with one argument synchronous threadsafe for const functions. For more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class Targ>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall) const, TretVal &retVal, Targ &argument)
+ {
+ auto t = std::make_tuple(argument);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument) = t;
+ }
+
+ /**
+ * calls a function with two arguments synchronously threadsafe. For more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class Targ1Call, class Targ, class Targ1>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall, Targ1Call), TretVal &retVal, Targ &argument, Targ1 &argument1)
+ {
+ auto t = std::make_tuple(argument, argument1);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument, argument1) = t;
+ }
+
+ /**
+ * calls a function with two arguments synchronously threadsafe const. For more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class Targ1Call, class Targ, class Targ1>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall, Targ1Call) const, TretVal &retVal, Targ &argument, Targ1 &argument1)
+ {
+ auto t = std::make_tuple(argument, argument1);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument, argument1) = t;
+ }
+
+ /**
+ * calls a function with three arguments synchronously threadsafe. for more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class Targ, class Targ1, class Targ2>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2), TretVal &retVal, Targ &argument, Targ1 &argument1, Targ2 &argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument, argument1, argument2) = t;
+ }
+
+ /**
+ * calls a const function with three arguments synchronously threadsafe. for more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class Targ, class Targ1, class Targ2>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2) const, TretVal &retVal, Targ &argument, Targ1 &argument1, Targ2 &argument2)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument, argument1, argument2) = t;
+ }
- /**@}*/
+ /**
+ * calls a function with four arguments synchronously threadsafe. for more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class TargCall3, class Targ, class Targ1, class Targ2, class Targ3>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3), TretVal &retVal, Targ &argument, Targ1 &argument1, Targ2 &argument2, Targ3 &argument3)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2, argument3);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument, argument1, argument2, argument3) = t;
+ }
- namespace V2
+ /**
+ * calls a function with five arguments synchronously threadsafe. for more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class TargCall3, class TargCall4, class Targ, class Targ1, class Targ2, class Targ3, class Targ4>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3, TargCall4), TretVal &retVal, Targ &argument, Targ1 &argument1, Targ2 &argument2, Targ3 &argument3, Targ4 &argument4)
+ {
+ auto t = std::make_tuple(argument, argument1, argument2, argument3, argument4);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument, argument1, argument2, argument3, argument4) = t;
+ }
+
+ /**
+ * calls a function with six arguments synchronously threadsafe. for more see syncCall with one argument
+ */
+ template<class TClass1, class TretVal, class TargCall, class TargCall1, class TargCall2, class TargCall3, class TargCall4, class TargCall5, class Targ, class Targ1, class Targ2, class Targ3, class Targ4, class Targ5>
+ void syncCall(TClass1 *instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3, TargCall4, TargCall5), TretVal &retVal, Targ &argument, Targ1 &argument1, Targ2 &argument2, Targ3 &argument3,
+ Targ4 &argument4, Targ5 &argument5)
{
- class CAmSerializer
+ auto t = std::make_tuple(argument, argument1, argument2, argument3, argument4, argument5);
+ doSyncCall(instance, function, retVal, t);
+ std::tie(argument, argument1, argument2, argument3, argument4, argument5) = t;
+ }
+
+ /**
+ * receiver callback for sockethandling, for more, see CAmSocketHandler
+ */
+ void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void *userData)
+ {
+ (void)handle;
+ (void)userData;
+ int numReads;
+ CAmDelegagePtr listPointers[3];
+ if ((numReads = read(pollfd.fd, &listPointers, sizeof(listPointers))) == -1)
{
- /**
- * Prototype for a delegate
- */
- class CAmDelegate
- {
- public:
- typedef enum
- :bool
- {
- SyncCallType = false, AsyncCallType = true
- } CallType;
-
- virtual ~CAmDelegate()
- {
- }
- ;
- virtual CallType call(int* pipe)=0;
- };
-
- /**
- * Prototype for a delegate with variadic template arguments.
- */
- template<class TInvocation>
- class CAmDelegateAsyncImpl: public CAmDelegate
- {
- TInvocation mInvocation;
- public:
- friend class CAmSerializer;
- CAmDelegateAsyncImpl(TInvocation && invocation) :
- mInvocation(std::move(invocation))
- {
- }
-
- CallType call(int* pipe)
- {
- (void) pipe;
- mInvocation();
- return (AsyncCallType);
- }
- ;
- };
-
- template<class TInvocation, class TRet>
- class CAmDelegateSyncImpl: public CAmDelegate
- {
- TInvocation mInvocation;
- TRet & mReturn;
- public:
- friend class CAmSerializer;
- CAmDelegateSyncImpl(TInvocation && invocation, TRet && ret) :
- mInvocation(std::move(invocation)), mReturn(ret)
- {
- }
-
- CallType call(int* pipe)
- {
- mReturn = mInvocation();
- ssize_t result(-1);
- result = write(pipe[1], this, sizeof(this));
- if (result == -1)
- logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
- return (SyncCallType);
- }
- ;
- };
-
- template<class TInvocation>
- class CAmDelegateSyncVoidImpl: public CAmDelegate
- {
- TInvocation mInvocation;
- public:
- friend class CAmSerializer;
- CAmDelegateSyncVoidImpl(TInvocation && invocation) :
- mInvocation(std::move(invocation))
- {
- }
-
- CallType call(int* pipe)
- {
- mInvocation();
- ssize_t result(-1);
- result = write(pipe[1], this, sizeof(this));
- if (result == -1)
- logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
- return (SyncCallType);
- }
- ;
- };
-
- typedef CAmDelegate* CAmDelegagePtr; //!< pointer to a delegate
-
- void sendSync(CAmDelegagePtr pDelegate)
- {
- send(pDelegate);
- int numReads;
- CAmDelegagePtr *p = NULL;
- if ((numReads = read(mReturnPipe[0], &p, sizeof(p))) == -1)
- {
- logError("CAmSerializer::doSyncCall could not read pipe!");
- throw std::runtime_error("CAmSerializer Could not read pipe!");
- }
- }
+ logError("CAmSerializer::receiverCallback could not read pipe!");
+ throw std::runtime_error("CAmSerializer Could not read pipe!");
+ }
- /**
- * rings the line of the pipe and adds the delegate pointer to the queue
- * @param p delegate pointer
- */
- inline void send(CAmDelegagePtr p)
- {
- if (write(mPipe[1], &p, sizeof(p)) == -1)
- {
- throw std::runtime_error("could not write to pipe !");
- }
- }
+ mListDelegatePoiters.assign(listPointers, listPointers + (numReads / sizeof(CAmDelegagePtr)));
+ }
- int mPipe[2]; //!< the pipe
- int mReturnPipe[2]; //!< pipe handling returns
- sh_pollHandle_t mHandle;
- CAmSocketHandler* mpSocketHandler;
- std::deque<CAmDelegagePtr> mListDelegatePointers; //!< intermediate queue to store the pipe results
+ /**
+ * checker callback for sockethandling, for more, see CAmSocketHandler
+ */
+ bool checkerCallback(const sh_pollHandle_t handle, void *userData)
+ {
+ (void)handle;
+ (void)userData;
+ if (mListDelegatePoiters.empty())
+ {
+ return (false);
+ }
- public:
+ return (true);
+ }
- /**
- * get the size of delegate pointers
- */
- size_t getListDelegatePointers()
- {
- return mListDelegatePointers.size();
- }
+ /**
+ * dispatcher callback for sockethandling, for more, see CAmSocketHandler
+ */
+ bool dispatcherCallback(const sh_pollHandle_t handle, void *userData)
+ {
+ (void)handle;
+ (void)userData;
+ CAmDelegagePtr delegatePoiter = mListDelegatePoiters.front();
+ mListDelegatePoiters.pop_front();
+ if (delegatePoiter->call(mReturnPipe))
+ {
+ delete delegatePoiter;
+ }
- /**
- * calls a function with variadic arguments threadsafe
- * @param invocation is a type is produced by std::bind
- * \section ex Example:
- * @code
- * CAmSerializer serial(&Sockethandler);
- * serial.asyncInvocation(std::bind([]()->bool{return true;}));
- * @endcode
- */
- template<class TFunc>
- void asyncInvocation(TFunc invocation)
- {
- static_assert(std::is_bind_expression<TFunc>::value,"The type is not produced by std::bind");
- typedef CAmDelegateAsyncImpl<TFunc> AsyncDelegate;
- AsyncDelegate *pImp = new AsyncDelegate(std::forward<TFunc>(invocation));
- send(pImp);
- //Do not delete the pointer. It will be deleted automatically later.
- }
+ if (mListDelegatePoiters.empty())
+ {
+ return (false);
+ }
- /**
- * calls a function with variadic arguments threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as member function pointer.
- * @tparam TClass the type of the Class to be called
- * @tparam TRet the type of the result
- * @tparam TArgs argument list
- * \section ex Example:
- * @code
- * class AClass
- * {
- * public:
- * void instanceMethod(int x);
- * }
- * CAmSerializer serial(&Sockethandler);
- * AClass anInstance;
- * serial.asyncCall(&anInstance,&AClass::instanceMethod, 100);
- * @endcode
- */
- template<class TClass, class TMeth, class TRet, class ... TArgs>
- void asyncCall(TClass* instance, TMeth method, TArgs && ... arguments)
- {
- auto invocation = std::bind(method, instance, std::forward<TArgs>(arguments)...);
- asyncInvocation(invocation);
- }
+ return (true);
+ }
- template<class TClass, class TMeth, class ... TArgs>
- void asyncCall(TClass* instance, TMeth method, TArgs && ... arguments)
- {
- auto invocation = std::bind(method, instance, std::forward<TArgs>(arguments)...);
- asyncInvocation(invocation);
- }
+ TAmShPollFired<CAmSerializer> receiverCallbackT;
+ TAmShPollDispatch<CAmSerializer> dispatcherCallbackT;
+ TAmShPollCheck<CAmSerializer> checkerCallbackT;
- /**
- * calls a function with variadic arguments threadsafe
- * @param invocation is a type is produced by std::bind
- * @param result from type TRet
- * \section ex Example:
- * @code
- * CAmSerializer serial(&Sockethandler);
- * bool result;
- * serial.syncCall(std::bind([]()->bool{return true;}), result);
- * @endcode
- */
- template<class TFunc, class TRet>
- void syncInvocation(TFunc invocation, TRet && result)
- {
- static_assert(std::is_bind_expression<TFunc>::value,"The type is not produced by std::bind");
+ /**
+ * The constructor must be called in the mainthread context !
+ * @param iSocketHandler pointer to the CAmSocketHandler
+ */
+ CAmSerializer(CAmSocketHandler *iSocketHandler)
+ : mPipe()
+ , mReturnPipe()
+ , mHandle()
+ , mpSocketHandler(iSocketHandler)
+ , mListDelegatePoiters()
+ , receiverCallbackT(this, &CAmSerializer::receiverCallback)
+ , dispatcherCallbackT(this, &CAmSerializer::dispatcherCallback)
+ , checkerCallbackT(this, &CAmSerializer::checkerCallback)
+ {
+ assert(NULL != iSocketHandler);
- typedef CAmDelegateSyncImpl<TFunc, TRet> SyncDelegate;
+ if (pipe(mPipe) == -1)
+ {
+ logError("CAmSerializer could not create pipe!");
+ throw std::runtime_error("CAmSerializer Could not open pipe!");
+ }
- SyncDelegate *pImp = new SyncDelegate(std::forward<TFunc>(invocation), std::forward<TRet>(result));
- sendSync(pImp);
- //Delete the pointer.
- delete pImp;
- }
+ if (pipe(mReturnPipe) == -1)
+ {
+ logError("CAmSerializer could not create mReturnPipe!");
+ throw std::runtime_error("CAmSerializer Could not open mReturnPipe!");
+ }
- /**
- * calls a function with variadic arguments threadsafe
- * @param invocation is a type produced by std::bind
- * \section ex Example:
- * @code
- * CAmSerializer serial(&Sockethandler);
- * serial.syncCall(std::bind([]()->bool{return true;}));
- * @endcode
- */
- template<class TFunc>
- void syncInvocation(TFunc invocation)
- {
- static_assert(std::is_bind_expression<TFunc>::value,"The type is not produced by std::bind");
+ short event = 0;
+ event |= POLLIN;
+ mpSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, mHandle);
+ }
- typedef CAmDelegateSyncVoidImpl<TFunc> SyncDelegate;
+ ~CAmSerializer()
+ {
+ mpSocketHandler->removeFDPoll(mHandle);
+ close(mPipe[0]);
+ close(mPipe[1]);
+ close(mReturnPipe[0]);
+ close(mReturnPipe[1]);
+ }
- SyncDelegate *pImp = new SyncDelegate(std::forward<TFunc>(invocation));
- sendSync(pImp);
- //Delete the pointer.
- delete pImp;
- }
- /**
- * calls a function with variadic arguments threadsafe
- * @param instance the instance of the class that shall be called
- * @param function the function that shall be called as member function pointer.
- * @param output variable.
- * @tparam TClass the type of the Class to be called
- * @tparam TRet the type of the result
- * @tparam TArgs argument list
- * \section ex Example:
- * @code
- * class AClass
- * {
- * public:
- * int instanceMethod(int x);
- * }
- * CAmSerializer serial(&Sockethandler);
- * AClass anInstance;
- * int result;
- * serial.syncCall(&anInstance,&AClass::instanceMethod, result, 100);
- * @endcode
- */
- template<class TClass, class TMeth, class TRet, class ... TArgs>
- void syncCall(TClass* instance, TMeth method, TRet & result, TArgs && ... arguments)
- {
- auto invocation = std::bind(method, instance, std::ref(arguments)...);
- syncInvocation(invocation, result);
- }
+};
- template<class TClass, class TMeth, class ... TArgs>
- void syncCall(TClass* instance, TMeth method, TArgs && ... arguments)
- {
- auto invocation = std::bind(method, instance, std::ref(arguments)...);
- syncInvocation(invocation);
- }
+} /* namespace V1 */
- /**
- * receiver callback for sockethandling, for more, see CAmSocketHandler
- */
- void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)
- {
- (void) handle;
- (void) userData;
- int numReads;
- CAmDelegagePtr listPointers[3];
- if ((numReads = read(pollfd.fd, &listPointers, sizeof(listPointers))) == -1)
- {
- logError("CAmSerializer::receiverCallback could not read pipe!");
- throw std::runtime_error("CAmSerializer Could not read pipe!");
- }
- mListDelegatePointers.assign(listPointers, listPointers + (numReads / sizeof(CAmDelegagePtr)));
- }
+/**@}*/
- /**
- * checker callback for sockethandling, for more, see CAmSocketHandler
- */
- bool checkerCallback(const sh_pollHandle_t handle, void* userData)
- {
- (void) handle;
- (void) userData;
- if (mListDelegatePointers.empty())
- return (false);
- return (true);
- }
+namespace V2
+{
+class CAmSerializer
+{
+ /**
+ * Prototype for a delegate
+ */
+ class CAmDelegate
+ {
+ public:
+ typedef enum
+ : bool
+ {
+ SyncCallType = false, AsyncCallType = true
+ } CallType;
- /**
- * dispatcher callback for sockethandling, for more, see CAmSocketHandler
- */
- bool dispatcherCallback(const sh_pollHandle_t handle, void* userData)
- {
- (void) handle;
- (void) userData;
- CAmDelegagePtr delegatePoiter = mListDelegatePointers.front();
- mListDelegatePointers.pop_front();
- if (delegatePoiter->call(mReturnPipe))
- delete delegatePoiter;
- if (mListDelegatePointers.empty())
- return (false);
- return (true);
- }
+ virtual ~CAmDelegate()
+ {
+ }
+
+ virtual CallType call(int *pipe) = 0;
+
+ };
+
+ /**
+ * Prototype for a delegate with variadic template arguments.
+ */
+ template<class TInvocation>
+ class CAmDelegateAsyncImpl : public CAmDelegate
+ {
+ TInvocation mInvocation;
+ public:
+ friend class CAmSerializer;
+ CAmDelegateAsyncImpl(TInvocation &&invocation)
+ : mInvocation(std::move(invocation))
+ {
+ }
+
+ CallType call(int *pipe)
+ {
+ (void)pipe;
+ mInvocation();
+ return (AsyncCallType);
+ }
+
+ };
- TAmShPollFired<CAmSerializer> receiverCallbackT;
- TAmShPollDispatch<CAmSerializer> dispatcherCallbackT;
- TAmShPollCheck<CAmSerializer> checkerCallbackT;
-
- /**
- * The constructor must be called in the mainthread context !
- * @param iSocketHandler pointer to the CAmSocketHandler
- */
- CAmSerializer(CAmSocketHandler *iSocketHandler) :
- mPipe(),
- mReturnPipe(),
- mHandle(),
- mpSocketHandler(iSocketHandler),
- mListDelegatePointers(),
- receiverCallbackT(this, &CAmSerializer::receiverCallback),
- dispatcherCallbackT(this, &CAmSerializer::dispatcherCallback),
- checkerCallbackT(this, &CAmSerializer::checkerCallback)
+ template<class TInvocation, class TRet>
+ class CAmDelegateSyncImpl : public CAmDelegate
+ {
+ TInvocation mInvocation;
+ TRet &mReturn;
+ public:
+ friend class CAmSerializer;
+ CAmDelegateSyncImpl(TInvocation &&invocation, TRet &&ret)
+ : mInvocation(std::move(invocation))
+ , mReturn(ret)
+ {
+ }
+
+ CallType call(int *pipe)
+ {
+ mReturn = mInvocation();
+ ssize_t result(-1);
+ result = write(pipe[1], this, sizeof(this));
+ if (result == -1)
{
- assert(NULL!=iSocketHandler);
-
- if (pipe(mPipe) == -1)
- {
- logError("CAmSerializer could not create pipe!");
- throw std::runtime_error("CAmSerializer Could not open pipe!");
- }
-
- if (pipe(mReturnPipe) == -1)
- {
- logError("CAmSerializer could not create mReturnPipe!");
- throw std::runtime_error("CAmSerializer Could not open mReturnPipe!");
- }
-
- short event = 0;
- event |= POLLIN;
- mpSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, mHandle);
+ logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
}
- ~CAmSerializer()
+ return (SyncCallType);
+ }
+
+ };
+
+ template<class TInvocation>
+ class CAmDelegateSyncVoidImpl : public CAmDelegate
+ {
+ TInvocation mInvocation;
+ public:
+ friend class CAmSerializer;
+ CAmDelegateSyncVoidImpl(TInvocation &&invocation)
+ : mInvocation(std::move(invocation))
+ {
+ }
+
+ CallType call(int *pipe)
+ {
+ mInvocation();
+ ssize_t result(-1);
+ result = write(pipe[1], this, sizeof(this));
+ if (result == -1)
{
- mpSocketHandler->removeFDPoll(mHandle);
- close(mPipe[0]);
- close(mPipe[1]);
- close(mReturnPipe[0]);
- close(mReturnPipe[1]);
+ logError("CAmSerializer: Problem writing into pipe! Error No:", errno);
}
- };
- } /* namespace V2 */
- typedef V1::CAmSerializer CAmSerializer DEPRECATED("You should use V2::CAmSerializer instead!");
+ return (SyncCallType);
+ }
+
+ };
+
+ typedef CAmDelegate *CAmDelegagePtr; //!< pointer to a delegate
+
+ void sendSync(CAmDelegagePtr pDelegate)
+ {
+ send(pDelegate);
+ int numReads;
+ CAmDelegagePtr *p = NULL;
+ if ((numReads = read(mReturnPipe[0], &p, sizeof(p))) == -1)
+ {
+ logError("CAmSerializer::doSyncCall could not read pipe!");
+ throw std::runtime_error("CAmSerializer Could not read pipe!");
+ }
+ }
+
+ /**
+ * rings the line of the pipe and adds the delegate pointer to the queue
+ * @param p delegate pointer
+ */
+ inline void send(CAmDelegagePtr p)
+ {
+ if (write(mPipe[1], &p, sizeof(p)) == -1)
+ {
+ throw std::runtime_error("could not write to pipe !");
+ }
+ }
+
+ int mPipe[2]; //!< the pipe
+ int mReturnPipe[2]; //!< pipe handling returns
+ sh_pollHandle_t mHandle;
+ CAmSocketHandler *mpSocketHandler;
+ std::deque<CAmDelegagePtr> mListDelegatePointers; //!< intermediate queue to store the pipe results
+
+public:
+
+ /**
+ * get the size of delegate pointers
+ */
+ size_t getListDelegatePointers()
+ {
+ return mListDelegatePointers.size();
+ }
+
+ /**
+ * calls a function with variadic arguments threadsafe
+ * @param invocation is a type is produced by std::bind
+ * \section ex Example:
+ * @code
+ * CAmSerializer serial(&Sockethandler);
+ * serial.asyncInvocation(std::bind([]()->bool{return true;}));
+ * @endcode
+ */
+ template<class TFunc>
+ void asyncInvocation(TFunc invocation)
+ {
+ static_assert(std::is_bind_expression<TFunc>::value, "The type is not produced by std::bind");
+ typedef CAmDelegateAsyncImpl<TFunc> AsyncDelegate;
+ AsyncDelegate *pImp = new AsyncDelegate(std::forward<TFunc>(invocation));
+ send(pImp);
+ // Do not delete the pointer. It will be deleted automatically later.
+ }
+
+ /**
+ * calls a function with variadic arguments threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as member function pointer.
+ * @tparam TClass the type of the Class to be called
+ * @tparam TRet the type of the result
+ * @tparam TArgs argument list
+ * \section ex Example:
+ * @code
+ * class AClass
+ * {
+ * public:
+ * void instanceMethod(int x);
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * AClass anInstance;
+ * serial.asyncCall(&anInstance,&AClass::instanceMethod, 100);
+ * @endcode
+ */
+ template<class TClass, class TMeth, class TRet, class... TArgs>
+ void asyncCall(TClass *instance, TMeth method, TArgs && ... arguments)
+ {
+ auto invocation = std::bind(method, instance, std::forward<TArgs>(arguments) ...);
+ asyncInvocation(invocation);
+ }
+
+ template<class TClass, class TMeth, class... TArgs>
+ void asyncCall(TClass *instance, TMeth method, TArgs && ... arguments)
+ {
+ auto invocation = std::bind(method, instance, std::forward<TArgs>(arguments) ...);
+ asyncInvocation(invocation);
+ }
+
+ /**
+ * calls a function with variadic arguments threadsafe
+ * @param invocation is a type is produced by std::bind
+ * @param result from type TRet
+ * \section ex Example:
+ * @code
+ * CAmSerializer serial(&Sockethandler);
+ * bool result;
+ * serial.syncCall(std::bind([]()->bool{return true;}), result);
+ * @endcode
+ */
+ template<class TFunc, class TRet>
+ void syncInvocation(TFunc invocation, TRet &&result)
+ {
+ static_assert(std::is_bind_expression<TFunc>::value, "The type is not produced by std::bind");
+
+ typedef CAmDelegateSyncImpl<TFunc, TRet> SyncDelegate;
+
+ SyncDelegate *pImp = new SyncDelegate(std::forward<TFunc>(invocation), std::forward<TRet>(result));
+ sendSync(pImp);
+ // Delete the pointer.
+ delete pImp;
+ }
+
+ /**
+ * calls a function with variadic arguments threadsafe
+ * @param invocation is a type produced by std::bind
+ * \section ex Example:
+ * @code
+ * CAmSerializer serial(&Sockethandler);
+ * serial.syncCall(std::bind([]()->bool{return true;}));
+ * @endcode
+ */
+ template<class TFunc>
+ void syncInvocation(TFunc invocation)
+ {
+ static_assert(std::is_bind_expression<TFunc>::value, "The type is not produced by std::bind");
+
+ typedef CAmDelegateSyncVoidImpl<TFunc> SyncDelegate;
+
+ SyncDelegate *pImp = new SyncDelegate(std::forward<TFunc>(invocation));
+ sendSync(pImp);
+ // Delete the pointer.
+ delete pImp;
+ }
+
+ /**
+ * calls a function with variadic arguments threadsafe
+ * @param instance the instance of the class that shall be called
+ * @param function the function that shall be called as member function pointer.
+ * @param output variable.
+ * @tparam TClass the type of the Class to be called
+ * @tparam TRet the type of the result
+ * @tparam TArgs argument list
+ * \section ex Example:
+ * @code
+ * class AClass
+ * {
+ * public:
+ * int instanceMethod(int x);
+ * }
+ * CAmSerializer serial(&Sockethandler);
+ * AClass anInstance;
+ * int result;
+ * serial.syncCall(&anInstance,&AClass::instanceMethod, result, 100);
+ * @endcode
+ */
+ template<class TClass, class TMeth, class TRet, class... TArgs>
+ void syncCall(TClass *instance, TMeth method, TRet &result, TArgs && ... arguments)
+ {
+ auto invocation = std::bind(method, instance, std::ref(arguments) ...);
+ syncInvocation(invocation, result);
+ }
+
+ template<class TClass, class TMeth, class... TArgs>
+ void syncCall(TClass *instance, TMeth method, TArgs && ... arguments)
+ {
+ auto invocation = std::bind(method, instance, std::ref(arguments) ...);
+ syncInvocation(invocation);
+ }
+
+ /**
+ * receiver callback for sockethandling, for more, see CAmSocketHandler
+ */
+ void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void *userData)
+ {
+ (void)handle;
+ (void)userData;
+ int numReads;
+ CAmDelegagePtr listPointers[3];
+ if ((numReads = read(pollfd.fd, &listPointers, sizeof(listPointers))) == -1)
+ {
+ logError("CAmSerializer::receiverCallback could not read pipe!");
+ throw std::runtime_error("CAmSerializer Could not read pipe!");
+ }
+
+ mListDelegatePointers.assign(listPointers, listPointers + (numReads / sizeof(CAmDelegagePtr)));
+ }
+
+ /**
+ * checker callback for sockethandling, for more, see CAmSocketHandler
+ */
+ bool checkerCallback(const sh_pollHandle_t handle, void *userData)
+ {
+ (void)handle;
+ (void)userData;
+ if (mListDelegatePointers.empty())
+ {
+ return (false);
+ }
+
+ return (true);
+ }
+
+ /**
+ * dispatcher callback for sockethandling, for more, see CAmSocketHandler
+ */
+ bool dispatcherCallback(const sh_pollHandle_t handle, void *userData)
+ {
+ (void)handle;
+ (void)userData;
+ CAmDelegagePtr delegatePoiter = mListDelegatePointers.front();
+ mListDelegatePointers.pop_front();
+ if (delegatePoiter->call(mReturnPipe))
+ {
+ delete delegatePoiter;
+ }
+
+ if (mListDelegatePointers.empty())
+ {
+ return (false);
+ }
+
+ return (true);
+ }
+
+ TAmShPollFired<CAmSerializer> receiverCallbackT;
+ TAmShPollDispatch<CAmSerializer> dispatcherCallbackT;
+ TAmShPollCheck<CAmSerializer> checkerCallbackT;
+
+ /**
+ * The constructor must be called in the mainthread context !
+ * @param iSocketHandler pointer to the CAmSocketHandler
+ */
+ CAmSerializer(CAmSocketHandler *iSocketHandler)
+ : mPipe()
+ , mReturnPipe()
+ , mHandle()
+ , mpSocketHandler(iSocketHandler)
+ , mListDelegatePointers()
+ , receiverCallbackT(this, &CAmSerializer::receiverCallback)
+ , dispatcherCallbackT(this, &CAmSerializer::dispatcherCallback)
+ , checkerCallbackT(this, &CAmSerializer::checkerCallback)
+ {
+ assert(NULL != iSocketHandler);
+
+ if (pipe(mPipe) == -1)
+ {
+ logError("CAmSerializer could not create pipe!");
+ throw std::runtime_error("CAmSerializer Could not open pipe!");
+ }
+
+ if (pipe(mReturnPipe) == -1)
+ {
+ logError("CAmSerializer could not create mReturnPipe!");
+ throw std::runtime_error("CAmSerializer Could not open mReturnPipe!");
+ }
+
+ short event = 0;
+ event |= POLLIN;
+ mpSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, mHandle);
+ }
+
+ ~CAmSerializer()
+ {
+ mpSocketHandler->removeFDPoll(mHandle);
+ close(mPipe[0]);
+ close(mPipe[1]);
+ close(mReturnPipe[0]);
+ close(mReturnPipe[1]);
+ }
+
+};
+
+} /* namespace V2 */
+
+typedef V1::CAmSerializer CAmSerializer DEPRECATED ("You should use V2::CAmSerializer instead!");
} /* namespace am */
#endif /* CAMSERIALIZER_H_ */
diff --git a/AudioManagerUtilities/include/CAmSocketHandler.h b/AudioManagerUtilities/include/CAmSocketHandler.h
index 04d19c3..ffd9e71 100644
--- a/AudioManagerUtilities/include/CAmSocketHandler.h
+++ b/AudioManagerUtilities/include/CAmSocketHandler.h
@@ -33,189 +33,205 @@
#ifdef WITH_TIMERFD
-#include <stdio.h>
-#include <string>
-#include <stdexcept>
-#include <unistd.h>
-#include <fcntl.h>
+# include <stdio.h>
+# include <string>
+# include <stdexcept>
+# include <unistd.h>
+# include <fcntl.h>
-#endif
+#endif // ifdef WITH_TIMERFD
namespace am
{
-#define MAX_NS 1000000000L
+#define MAX_NS 1000000000L
#define MAX_TIMERHANDLE UINT16_MAX
-#define MAX_POLLHANDLE UINT16_MAX
+#define MAX_POLLHANDLE UINT16_MAX
-typedef uint16_t sh_pollHandle_t; //!<this is a handle for a filedescriptor to be used with the SocketHandler
-typedef sh_pollHandle_t sh_timerHandle_t; //!<this is a handle for a timer to be used with the SocketHandler
+typedef uint16_t sh_pollHandle_t; //!< this is a handle for a filedescriptor to be used with the SocketHandler
+typedef sh_pollHandle_t sh_timerHandle_t; //!< this is a handle for a timer to be used with the SocketHandler
/**
- * prototype for poll prepared callback
- */
+ * prototype for poll prepared callback
+ */
class IAmShPollPrepare
{
public:
- virtual void Call(const sh_pollHandle_t handle, void* userData) = 0;
+ virtual void Call(const sh_pollHandle_t handle, void *userData) = 0;
+
virtual ~IAmShPollPrepare() {}
};
/**
- * prototype for poll fired callback
- */
+ * prototype for poll fired callback
+ */
class IAmShPollFired
{
public:
- virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) = 0;
- virtual ~ IAmShPollFired() {}
+ virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void *userData) = 0;
+
+ virtual ~IAmShPollFired() {}
};
/**
- * prototype for poll check callback
- */
+ * prototype for poll check callback
+ */
class IAmShPollCheck
{
public:
- virtual bool Call(const sh_pollHandle_t handle, void* userData) = 0;
- virtual ~ IAmShPollCheck() {}
+ virtual bool Call(const sh_pollHandle_t handle, void *userData) = 0;
+
+ virtual ~IAmShPollCheck() {}
};
/**
- * prototype for dispatch callback
- */
+ * prototype for dispatch callback
+ */
class IAmShPollDispatch
{
public:
- virtual bool Call(const sh_pollHandle_t handle, void* userData) = 0;
- virtual ~ IAmShPollDispatch() {}
+ virtual bool Call(const sh_pollHandle_t handle, void *userData) = 0;
+
+ virtual ~IAmShPollDispatch() {}
};
/**
- * prototype for the timer callback
- */
+ * prototype for the timer callback
+ */
class IAmShTimerCallBack
{
public:
- IAmShTimerCallBack(){};
- virtual void Call(const sh_timerHandle_t handle, void* userData) = 0;
+ IAmShTimerCallBack(){}
+ virtual void Call(const sh_timerHandle_t handle, void *userData) = 0;
+
virtual ~IAmShTimerCallBack(){}
};
/**make private, not public
- * template for a callback
- */
-template<class TClass> class TAmShPollFired: public IAmShPollFired
+ * template for a callback
+ */
+template<class TClass>
+class TAmShPollFired : public IAmShPollFired
{
private:
- TClass* mInstance;
- void (TClass::*mFunction)(const pollfd pollfd, const sh_pollHandle_t handle, void* userData);
+ TClass *mInstance;
+ void (TClass::*mFunction)(const pollfd pollfd, const sh_pollHandle_t handle, void *userData);
public:
- TAmShPollFired(TClass* instance, void (TClass::*function)(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)) :
- mInstance(instance),
- mFunction(function)
+ TAmShPollFired(TClass *instance, void (TClass::*function)(const pollfd pollfd, const sh_pollHandle_t handle, void *userData))
+ : mInstance(instance)
+ , mFunction(function)
{}
- virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)
+ virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void *userData)
{
(*mInstance.*mFunction)(pollfd, handle, userData);
}
+
};
/**
- * template for a callback
- */
-template<class TClass> class TAmShPollCheck: public IAmShPollCheck
+ * template for a callback
+ */
+template<class TClass>
+class TAmShPollCheck : public IAmShPollCheck
{
private:
- TClass* mInstance;
- bool (TClass::*mFunction)(const sh_pollHandle_t handle, void* userData);
+ TClass *mInstance;
+ bool (TClass::*mFunction)(const sh_pollHandle_t handle, void *userData);
public:
- TAmShPollCheck(TClass* instance, bool (TClass::*function)(const sh_pollHandle_t handle, void* userData)) :
- mInstance(instance),
- mFunction(function)
+ TAmShPollCheck(TClass *instance, bool (TClass::*function)(const sh_pollHandle_t handle, void *userData))
+ : mInstance(instance)
+ , mFunction(function)
{}
- virtual bool Call(const sh_pollHandle_t handle, void* userData)
+ virtual bool Call(const sh_pollHandle_t handle, void *userData)
{
return ((*mInstance.*mFunction)(handle, userData));
}
+
};
/**
- * template for a callback
- */
-template<class TClass> class TAmShPollDispatch: public IAmShPollDispatch
+ * template for a callback
+ */
+template<class TClass>
+class TAmShPollDispatch : public IAmShPollDispatch
{
private:
- TClass* mInstance;
- bool (TClass::*mFunction)(const sh_pollHandle_t handle, void* userData);
+ TClass *mInstance;
+ bool (TClass::*mFunction)(const sh_pollHandle_t handle, void *userData);
public:
- TAmShPollDispatch(TClass* instance, bool (TClass::*function)(const sh_pollHandle_t handle, void* userData)) :
- mInstance(instance),
- mFunction(function)
+ TAmShPollDispatch(TClass *instance, bool (TClass::*function)(const sh_pollHandle_t handle, void *userData))
+ : mInstance(instance)
+ , mFunction(function)
{}
- virtual bool Call(const sh_pollHandle_t handle, void* userData)
+ virtual bool Call(const sh_pollHandle_t handle, void *userData)
{
return ((*mInstance.*mFunction)(handle, userData));
}
+
};
/**
- * template to create the functor for a class
- */
-template<class TClass> class TAmShTimerCallBack: public IAmShTimerCallBack
+ * template to create the functor for a class
+ */
+template<class TClass>
+class TAmShTimerCallBack : public IAmShTimerCallBack
{
private:
- TClass* mInstance;
- void (TClass::*mFunction)(sh_timerHandle_t handle, void* userData);
+ TClass *mInstance;
+ void (TClass::*mFunction)(sh_timerHandle_t handle, void *userData);
public:
- TAmShTimerCallBack(TClass* instance, void (TClass::*function)(sh_timerHandle_t handle, void* userData)) :
- IAmShTimerCallBack(), mInstance(instance),
- mFunction(function)
+ TAmShTimerCallBack(TClass *instance, void (TClass::*function)(sh_timerHandle_t handle, void *userData))
+ : IAmShTimerCallBack()
+ , mInstance(instance)
+ , mFunction(function)
{}
- virtual void Call(sh_timerHandle_t handle, void* userData)
+ virtual void Call(sh_timerHandle_t handle, void *userData)
{
(*mInstance.*mFunction)(handle, userData);
}
+
};
/**
- * template for a callback
- */
+ * template for a callback
+ */
-template<class TClass> class TAmShPollPrepare: public IAmShPollPrepare
+template<class TClass>
+class TAmShPollPrepare : public IAmShPollPrepare
{
private:
- TClass* mInstance;
- void (TClass::*mFunction)(const sh_pollHandle_t handle, void* userData);
+ TClass *mInstance;
+ void (TClass::*mFunction)(const sh_pollHandle_t handle, void *userData);
public:
- TAmShPollPrepare(TClass* instance, void (TClass::*function)(const sh_pollHandle_t handle, void* userData)) :
- mInstance(instance),
- mFunction(function)
+ TAmShPollPrepare(TClass *instance, void (TClass::*function)(const sh_pollHandle_t handle, void *userData))
+ : mInstance(instance)
+ , mFunction(function)
{}
- virtual void Call(const sh_pollHandle_t handle, void* userData)
+ virtual void Call(const sh_pollHandle_t handle, void *userData)
{
(*mInstance.*mFunction)(handle, userData);
}
+
};
/**
- * The am::CAmSocketHandler implements a mainloop for the AudioManager. Plugins and different parts of the AudioManager add their filedescriptors to the handler
- * to get called on communication of the filedescriptors.\n
- * More information can be found here : \ref mainl
- */
+ * The am::CAmSocketHandler implements a mainloop for the AudioManager. Plugins and different parts of the AudioManager add their filedescriptors to the handler
+ * to get called on communication of the filedescriptors.\n
+ * More information can be found here : \ref mainl
+ */
class CAmSocketHandler
{
- typedef enum:uint8_t
+ typedef enum : uint8_t
{
ADD = 0u, // new, uninitialized element which needs to be added to ppoll array
UPDATE = 1u, // update of event information therefore update ppoll array
@@ -224,49 +240,60 @@ class CAmSocketHandler
INVALID = 4u // uninit element requested to be removed from internal map only
} poll_states_e;
- struct sh_poll_s //!<struct that holds information about polls
+ struct sh_poll_s //!< struct that holds information about polls
{
- 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
- std::function<void(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)> firedCB; //fired callback
- std::function<bool(const sh_pollHandle_t handle, void* userData)> checkCB; //check callback
- std::function<bool(const sh_pollHandle_t handle, void* userData)> dispatchCB; //dispatch callback
- void* userData;
+ 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
+ std::function<void(const pollfd pollfd, const sh_pollHandle_t handle, void *userData)> firedCB; // fired callback
+ std::function<bool(const sh_pollHandle_t handle, void *userData)> checkCB; // check callback
+ std::function<bool(const sh_pollHandle_t handle, void *userData)> dispatchCB; // dispatch callback
+ void *userData;
poll_states_e state;
- sh_poll_s() :
- handle(0), pollfdValue(), prepareCB(), firedCB(), checkCB(), dispatchCB(), userData(0), state(ADD)
+ sh_poll_s()
+ : handle(0)
+ , pollfdValue()
+ , prepareCB()
+ , firedCB()
+ , checkCB()
+ , dispatchCB()
+ , userData(0)
+ , state(ADD)
{}
};
- struct sh_timer_s //!<struct that holds information of timers
+ struct sh_timer_s //!< struct that holds information of timers
{
- sh_timerHandle_t handle; //!<the handle of the timer
-#ifdef WITH_TIMERFD
+ sh_timerHandle_t handle; //!< the handle of the timer
+#ifdef WITH_TIMERFD
int fd;
- itimerspec countdown; //!<the countdown, this value is decreased every time the timer is up
+ itimerspec countdown; //!< the countdown, this value is decreased every time the timer is up
#else
- timespec countdown; //!<the countdown, this value is decreased every time the timer is up
-#endif
- std::function<void(const sh_timerHandle_t handle, void* userData)> callback; //timer callback
- void* userData;
- sh_timer_s() :
- handle(0)
+ timespec countdown; //!< the countdown, this value is decreased every time the timer is up
+#endif
+ std::function<void(const sh_timerHandle_t handle, void *userData)> callback; // timer callback
+ void *userData;
+ sh_timer_s()
+ : handle(0)
#ifdef WITH_TIMERFD
- , fd(-1)
+ , fd(-1)
#endif
- , countdown(), callback(), userData(0)
+ , countdown()
+ , callback()
+ , userData(0)
{}
};
struct sh_signal_s
{
- sh_pollHandle_t handle; //!<handle to uniquely adress a filedesriptor
- std::function<void(const sh_pollHandle_t handle, const signalfd_siginfo & info, void* userData)> callback;
- void* userData;
- sh_signal_s() :
- handle(0), callback(), userData(0)
+ sh_pollHandle_t handle; //!< handle to uniquely adress a filedesriptor
+ std::function<void(const sh_pollHandle_t handle, const signalfd_siginfo &info, void *userData)> callback;
+ void *userData;
+ sh_signal_s()
+ : handle(0)
+ , callback()
+ , userData(0)
{}
};
@@ -275,17 +302,19 @@ class CAmSocketHandler
std::set<sh_pollHandle_t> pollHandles;
uint16_t limit;
uint16_t lastUsedID;
- sh_identifier_s(const uint16_t pollLimit = UINT16_MAX) :
- pollHandles(), limit(pollLimit), lastUsedID(0)
+ sh_identifier_s(const uint16_t pollLimit = UINT16_MAX)
+ : pollHandles()
+ , limit(pollLimit)
+ , lastUsedID(0)
{}
};
- typedef std::reverse_iterator<sh_timer_s> rListTimerIter; //!<typedef for reverseiterator on timer lists
- typedef std::vector<pollfd> VectorPollfd_t; //!<vector of filedescriptors
- typedef std::map<int, sh_poll_s> MapShPoll_t; //!<list for the callbacks
- typedef std::vector<sh_signal_s> VectorSignalHandlers_t; //!<list for the callbacks
+ typedef std::reverse_iterator<sh_timer_s> rListTimerIter; //!< typedef for reverseiterator on timer lists
+ typedef std::vector<pollfd> VectorPollfd_t; //!< vector of filedescriptors
+ typedef std::map<int, sh_poll_s> MapShPoll_t; //!< list for the callbacks
+ typedef std::vector<sh_signal_s> VectorSignalHandlers_t; //!< list for the callbacks
- typedef enum:uint8_t
+ typedef enum : uint8_t
{
NO_ERROR = 0u, // OK
FD_ERROR = 1u, // Invalid file descriptor
@@ -293,53 +322,55 @@ class CAmSocketHandler
} internal_codes_e;
typedef uint8_t internal_codes_t;
- int mEventFd;
- int mSignalFd;
- bool mDispatchDone; //this starts / stops the mainloop
- MapShPoll_t mMapShPoll; //!<list that holds all information for the ppoll
+ int mEventFd;
+ int mSignalFd;
+ bool mDispatchDone; // this starts / stops the mainloop
+ MapShPoll_t mMapShPoll; //!< list that holds all information for the ppoll
- sh_identifier_s mSetPollKeys; //!A set of all used ppoll keys
- sh_identifier_s mSetTimerKeys; //!A set of all used timer keys
- std::list<sh_timer_s> mListTimer; //!<list of all timers
+ sh_identifier_s mSetPollKeys; //! A set of all used ppoll keys
+ 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
+ std::list<sh_timer_s> mListActiveTimer; //!< list of all currently active timers
#endif
- sh_identifier_s mSetSignalhandlerKeys; //!A set of all used signal handler keys
+ sh_identifier_s mSetSignalhandlerKeys; //! A set of all used signal handler keys
VectorSignalHandlers_t mSignalHandlers;
- internal_codes_t mInternalCodes;
+ internal_codes_t mInternalCodes;
#ifndef WITH_TIMERFD
- timespec mStartTime; //!<here the actual time is saved for timecorrection
+ timespec mStartTime; //!< here the actual time is saved for timecorrection
#endif
private:
bool fdIsValid(const int fd) const;
- void wakeupWorker(const std::string & func, const uint64_t value = 1u);
+ void wakeupWorker(const std::string &func, const uint64_t value = 1u);
+
+ timespec *insertTime(timespec &buffertime);
- timespec* insertTime(timespec& buffertime);
-#ifdef WITH_TIMERFD
- am_Error_e createTimeFD(const itimerspec & timeouts, int & fd);
-#else
+#ifdef WITH_TIMERFD
+ am_Error_e createTimeFD(const itimerspec &timeouts, int &fd);
+
+#else
void timerUp();
void timerCorrection();
/**
- * compares countdown values
- * @param a
- * @param b
- * @return true if b greater a
- */
- inline static bool compareCountdown(const sh_timer_s& a, const sh_timer_s& b)
+ * compares countdown values
+ * @param a
+ * @param b
+ * @return true if b greater a
+ */
+ inline static bool compareCountdown(const sh_timer_s &a, const sh_timer_s &b)
{
return ((a.countdown.tv_sec == b.countdown.tv_sec) ? (a.countdown.tv_nsec < b.countdown.tv_nsec) : (a.countdown.tv_sec < b.countdown.tv_sec));
}
/**
- * Subtracts b from a
- * @param a
- * @param b
- * @return subtracted value
- */
- inline static timespec timespecSub(const timespec& a, const timespec& b)
+ * Subtracts b from a
+ * @param a
+ * @param b
+ * @return subtracted value
+ */
+ inline static timespec timespecSub(const timespec &a, const timespec &b)
{
timespec result;
@@ -360,136 +391,149 @@ private:
result.tv_nsec = a.tv_nsec - b.tv_nsec;
}
}
+
return (result);
}
/**
- * adds timespec values
- * @param a
- * @param b
- * @return the added values
- */
- inline timespec timespecAdd(const timespec& a, const timespec& b)
+ * adds timespec values
+ * @param a
+ * @param b
+ * @return the added values
+ */
+ inline timespec timespecAdd(const timespec &a, const timespec &b)
{
timespec result;
- result.tv_sec = a.tv_sec + b.tv_sec;
+ result.tv_sec = a.tv_sec + b.tv_sec;
result.tv_nsec = a.tv_nsec + b.tv_nsec;
if (result.tv_nsec >= MAX_NS)
{
result.tv_sec++;
result.tv_nsec = result.tv_nsec - MAX_NS;
}
+
return (result);
}
/**
- * comapares timespec values
- * @param a
- * @param b
- * @return
- */
- inline int timespecCompare(const timespec& a, const timespec& b)
+ * comapares timespec values
+ * @param a
+ * @param b
+ * @return
+ */
+ inline int timespecCompare(const timespec &a, const timespec &b)
{
- //less
+ // less
if (a.tv_sec < b.tv_sec)
- return (-1);
- //greater
+ {
+ return (-1);
+ }
+ // greater
else if (a.tv_sec > b.tv_sec)
- return (1);
- //less
+ {
+ return (1);
+ }
+ // less
else if (a.tv_nsec < b.tv_nsec)
- return (-1);
- //greater
+ {
+ return (-1);
+ }
+ // greater
else if (a.tv_nsec > b.tv_nsec)
- return (1);
- //equal
+ {
+ return (1);
+ }
+
+ // equal
return (0);
}
-#endif
+#endif // ifdef WITH_TIMERFD
/**
- * functor to prepare all fire events
- * @param a
- * @return
- */
- inline static void prepare(sh_poll_s& row);
+ * functor to prepare all fire events
+ * @param a
+ * @return
+ */
+ inline static void prepare(sh_poll_s &row);
/**
- * functor to return all fired events
- * @param a
- * @return
- */
- inline static void fire(const sh_poll_s& a);
+ * functor to return all fired events
+ * @param a
+ * @return
+ */
+ 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);
+ * functor to help find the items that do not need dispatching
+ * @param a
+ * @return
+ */
+ 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);
+ * checks if dispatching is already finished
+ * @param a
+ * @return
+ */
+ inline static bool dispatchingFinished(const sh_poll_s *a);
/**
- * timer fire callback
- * @param a
- * @return
- */
- inline static void callTimer(sh_timer_s& a);
+ * timer fire callback
+ * @param a
+ * @return
+ */
+ inline static void callTimer(sh_timer_s &a);
/**
- * next handle id
- * @param std::set handles
- * @return handle
- */
- bool nextHandle(sh_identifier_s & handle);
+ * next handle id
+ * @param std::set handles
+ * @return handle
+ */
+ bool nextHandle(sh_identifier_s &handle);
public:
CAmSocketHandler();
~CAmSocketHandler();
-
- /**
+
+ /**
* install the signal fd
*/
- am_Error_e listenToSignals(const std::vector<uint8_t> & listSignals);
-
- am_Error_e addFDPoll(const int fd, const short event, std::function<void(const sh_pollHandle_t handle, void* userData)> prepare, std::function<void(const pollfd pollfd, const sh_pollHandle_t handle, void* userData)> fired,
- std::function<bool(const sh_pollHandle_t handle, void* userData)> check, std::function<bool(const sh_pollHandle_t handle, void* userData)> dispatch, void* userData, sh_pollHandle_t& handle);
+ am_Error_e listenToSignals(const std::vector<uint8_t> &listSignals);
+
+ am_Error_e addFDPoll(const int fd, const short event, std::function<void(const sh_pollHandle_t handle, void *userData)> prepare, std::function<void(const pollfd pollfd, const sh_pollHandle_t handle, void *userData)> fired,
+ std::function<bool(const sh_pollHandle_t handle, void *userData)> check, std::function<bool(const sh_pollHandle_t handle, void *userData)> dispatch, void *userData, sh_pollHandle_t &handle);
- am_Error_e addFDPoll(const int fd, const short event, IAmShPollPrepare *prepare, IAmShPollFired *fired, IAmShPollCheck *check, IAmShPollDispatch *dispatch, void* userData, sh_pollHandle_t& handle);
+ am_Error_e addFDPoll(const int fd, const short event, IAmShPollPrepare *prepare, IAmShPollFired *fired, IAmShPollCheck *check, IAmShPollDispatch *dispatch, void *userData, sh_pollHandle_t &handle);
am_Error_e removeFDPoll(const sh_pollHandle_t handle);
am_Error_e updateEventFlags(const sh_pollHandle_t handle, const short events);
- am_Error_e addSignalHandler(std::function<void(const sh_pollHandle_t handle, const signalfd_siginfo & info, void* userData)> callback, sh_pollHandle_t& handle, void * userData);
+ am_Error_e addSignalHandler(std::function<void(const sh_pollHandle_t handle, const signalfd_siginfo &info, void *userData)> callback, sh_pollHandle_t &handle, void *userData);
am_Error_e removeSignalHandler(const sh_pollHandle_t handle);
- am_Error_e addTimer(const timespec & timeouts, IAmShTimerCallBack* callback, sh_timerHandle_t& handle, void * userData,
+
+ am_Error_e addTimer(const timespec &timeouts, IAmShTimerCallBack *callback, sh_timerHandle_t & handle, void *userData,
#ifndef WITH_TIMERFD
- const bool __attribute__((__unused__)) repeats = false
+ const bool __attribute__((__unused__)) repeats = false
#else
- const bool repeats = false
+ const bool repeats = false
#endif
- );
- am_Error_e addTimer(const timespec & timeouts, std::function<void(const sh_timerHandle_t handle, void* userData)> callback, sh_timerHandle_t& handle, void* userData,
+ );
+ am_Error_e addTimer(const timespec &timeouts, std::function<void(const sh_timerHandle_t handle, void *userData)> callback, sh_timerHandle_t & handle, void *userData,
#ifndef WITH_TIMERFD
- const bool __attribute__((__unused__)) repeats = false
+ const bool __attribute__((__unused__)) repeats = false
#else
- const bool repeats = false
+ const bool repeats = false
#endif
- );
+ );
am_Error_e removeTimer(const sh_timerHandle_t handle);
am_Error_e restartTimer(const sh_timerHandle_t handle);
- am_Error_e updateTimer(const sh_timerHandle_t handle, const timespec & timeouts);
+ am_Error_e updateTimer(const sh_timerHandle_t handle, const timespec &timeouts);
am_Error_e stopTimer(const sh_timerHandle_t handle);
void start_listenting();
void stop_listening();
void exit_mainloop();
-
+
bool fatalErrorOccurred();
+
};
} /* namespace am */
diff --git a/AudioManagerUtilities/include/CAmWatchdog.h b/AudioManagerUtilities/include/CAmWatchdog.h
index 4449c75..bbd2c00 100755..100644
--- a/AudioManagerUtilities/include/CAmWatchdog.h
+++ b/AudioManagerUtilities/include/CAmWatchdog.h
@@ -35,15 +35,16 @@ namespace am
class CAmWatchdog
{
public:
- CAmWatchdog(CAmSocketHandler* CAmSocketHandler);
+ CAmWatchdog(CAmSocketHandler *CAmSocketHandler);
virtual ~CAmWatchdog();
- void startWatchdog(); //!< starts the watchdog by sending ready to systemD
- void timerCallback(sh_timerHandle_t handle, void * userData); //!< the watchdog timer callback
+ void startWatchdog(); //!< starts the watchdog by sending ready to systemD
+ void timerCallback(sh_timerHandle_t handle, void *userData); //!< the watchdog timer callback
+
TAmShTimerCallBack<CAmWatchdog> TimerCallback;
private:
- CAmSocketHandler* mpCAmSocketHandler; //!< pointer to the sockethandler
- sh_timerHandle_t mHandle; //!< handle of the timer
+ CAmSocketHandler *mpCAmSocketHandler; //!< pointer to the sockethandler
+ sh_timerHandle_t mHandle; //!< handle of the timer
};
} /* namespace am */
diff --git a/AudioManagerUtilities/include/TAmPluginTemplate.h b/AudioManagerUtilities/include/TAmPluginTemplate.h
index 95523f1..b030123 100644
--- a/AudioManagerUtilities/include/TAmPluginTemplate.h
+++ b/AudioManagerUtilities/include/TAmPluginTemplate.h
@@ -37,24 +37,25 @@ namespace am
* @param libraryHandle the handle to the library that gets returned
* @return returns the pointer to the class to be loaded
*/
-template<class T> T* getCreateFunction(const std::string& libname, void*& libraryHandle)
+template<class T>
+T *getCreateFunction(const std::string &libname, void * &libraryHandle)
{
- logInfo("getCreateFunction : Trying to load library with name: ",libname);
+ logInfo("getCreateFunction : Trying to load library with name: ", libname);
// cut off directories
- char* fileWithPath = const_cast<char*>(libname.c_str());
- std::string libFileName = basename(fileWithPath);
+ char *fileWithPath = const_cast<char *>(libname.c_str());
+ std::string libFileName = basename(fileWithPath);
// cut off "lib" in front and cut off .so end"
std::string createFunctionName = libFileName.substr(3, libFileName.length() - 6) + "Factory";
// open library
dlerror(); // Clear any existing error
- libraryHandle = dlopen(libname.c_str(), RTLD_LAZY );
- const char* dlopen_error = dlerror();
+ libraryHandle = dlopen(libname.c_str(), RTLD_LAZY);
+ const char *dlopen_error = dlerror();
if (!libraryHandle || dlopen_error)
{
- logError("getCreateFunction : dlopen failed",dlopen_error);
+ logError("getCreateFunction : dlopen failed", dlopen_error);
return (0);
}
@@ -63,8 +64,8 @@ template<class T> T* getCreateFunction(const std::string& libname, void*& librar
union
{
- void* voidPointer;
- T* typedPointer;
+ void *voidPointer;
+ T *typedPointer;
} functionPointer;
// Note: direct cast is not allowed by ISO C++. e.g.
@@ -72,17 +73,18 @@ template<class T> T* getCreateFunction(const std::string& libname, void*& librar
// compiler warning: "forbids casting between pointer-to-function and pointer-to-object"
functionPointer.voidPointer = dlsym(libraryHandle, createFunctionName.c_str());
- T* createFunction = functionPointer.typedPointer;
+ T *createFunction = functionPointer.typedPointer;
- const char* dlsym_error = dlerror();
+ const char *dlsym_error = dlerror();
if (!createFunction || dlsym_error)
{
- logError("getCreateFunction: Failed to load shared lib entry point",dlsym_error);
+ logError("getCreateFunction: Failed to load shared lib entry point", dlsym_error);
}
else
{
logInfo("getCreateFunction : loaded successfully plugin", createFunctionName);
}
+
return (createFunction);
}
@@ -91,13 +93,14 @@ template<class T> T* getCreateFunction(const std::string& libname, void*& librar
* @param libname the full path to the library to be loaded
*
*/
-template<class T> T* getDestroyFunction(const std::string& libname,void* libraryHandle)
+template<class T>
+T *getDestroyFunction(const std::string &libname, void *libraryHandle)
{
- logInfo("destroy : Trying to destroy : ",libname);
+ logInfo("destroy : Trying to destroy : ", libname);
// cut off directories
- char* fileWithPath = const_cast<char*>(libname.c_str());
- std::string libFileName = basename(fileWithPath);
+ char *fileWithPath = const_cast<char *>(libname.c_str());
+ std::string libFileName = basename(fileWithPath);
// cut off "lib" in front and cut off .so end"
std::string destroyFunctionName = "destroy" + libFileName.substr(3, libFileName.length() - 6);
@@ -106,23 +109,24 @@ template<class T> T* getDestroyFunction(const std::string& libname,void* library
dlerror(); // Clear any existing error
union
{
- void* voidPointer;
- T* typedPointer;
+ void *voidPointer;
+ T *typedPointer;
} functionPointer;
functionPointer.voidPointer = dlsym(libraryHandle, destroyFunctionName.c_str());
- T* destroyFunction = functionPointer.typedPointer;
+ T *destroyFunction = functionPointer.typedPointer;
- const char* dlsym_error = dlerror();
+ const char *dlsym_error = dlerror();
if (!destroyFunction || dlsym_error)
{
logError("getDestroyFunction: Failed to load shared lib entry point function name=",
- destroyFunctionName, "error=",dlsym_error);
+ destroyFunctionName, "error=", dlsym_error);
}
else
{
logInfo("getDestroyFunction: loaded successfully plugin", destroyFunctionName);
}
+
return (destroyFunction);
}