From 6ffbf25bacf589879198e49ac227cb56e261b7c9 Mon Sep 17 00:00:00 2001 From: Christian Linke Date: Thu, 12 Mar 2015 13:43:48 +0100 Subject: * fully rework. Plugins have now a new own git repository * building out of source of plugins without AM workss * build system cmake contructions is different now Signed-off-by: Christian Linke --- include/shared/CAmCommonAPIWrapper.h | 143 ---- include/shared/CAmDbusWrapper.h | 92 --- include/shared/CAmDltWrapper.h | 914 --------------------- include/shared/CAmSerializer.h | 1508 ---------------------------------- include/shared/CAmSocketHandler.h | 576 ------------- 5 files changed, 3233 deletions(-) delete mode 100644 include/shared/CAmCommonAPIWrapper.h delete mode 100644 include/shared/CAmDbusWrapper.h delete mode 100644 include/shared/CAmDltWrapper.h delete mode 100644 include/shared/CAmSerializer.h delete mode 100644 include/shared/CAmSocketHandler.h (limited to 'include') diff --git a/include/shared/CAmCommonAPIWrapper.h b/include/shared/CAmCommonAPIWrapper.h deleted file mode 100644 index dd0d983..0000000 --- a/include/shared/CAmCommonAPIWrapper.h +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * \author Aleksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2013 - * - * \copyright - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * \file CAmCommonAPIWrapper.h - * For further information see http://www.genivi.org/. - */ - - -#ifndef COMMONAPIWRAPPER_H_ -#define COMMONAPIWRAPPER_H_ - -#include -#include -#include -#include -#include -#include -#include "config.h" -#include "CAmSocketHandler.h" - - -/** - * A Common-API wrapper class, that loads the common-api runtime and instantiates all necessary other objects. Works with the CAmSocketHandler. - * It is implemented as singleton and usually once instantiated at the beginning with CAmSocketHandler. - * Example: CAmCommonAPIWrapper *pCAPIWrapper = CAmCommonAPIWrapper::instantiateOnce( aSocketHandlerPointer ); - */ - -namespace am -{ -using namespace CommonAPI; - -class CAmSocketHandler; - -class CAmCommonAPIWrapper -{ -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 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); - - void registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority); - void deregisterDispatchSource(DispatchSource* dispatchSource); - void registerWatch(Watch* watch, const DispatchPriority dispatchPriority); - void deregisterWatch(Watch* watch); - void registerTimeout(Timeout* timeout, const DispatchPriority dispatchPriority); - void deregisterTimeout(Timeout* timeout); - void wakeup(); - - std::shared_ptr factory() const; - std::shared_ptr runtime() const; - //Wraps the invitation to the service publisher - template bool registerStub(const std::shared_ptr & shStub, const std::string & aCommonAPIAddress) - { - return runtime()->getServicePublisher()->registerService(shStub, aCommonAPIAddress, factory()); - } - bool unregisterStub(const std::string & aCommonAPIAddress) - { - (void)aCommonAPIAddress; - /** Not implemented yet - todo: Check whether the appropriate method is available and uncomment... - - return runtime()->getServicePublisher()->unregisterService(aCommonAPIAddress); - */ - return true; - } - - -protected: - CAmCommonAPIWrapper(CAmSocketHandler* socketHandler) ; -private: - void commonPrepareCallback(const sh_pollHandle_t handle, void* userData); - TAmShPollPrepare pCommonPrepareCallback; - - bool commonDispatchCallback(const sh_pollHandle_t handle, void* userData); - TAmShPollDispatch pCommonDispatchCallback; - - void commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void*); - TAmShPollFired pCommonFireCallback; - - bool commonCheckCallback(const sh_pollHandle_t handle, void*); - TAmShPollCheck pCommonCheckCallback; - - void commonTimerCallback(sh_timerHandle_t handle, void* userData); - TAmShTimerCallBack pCommonTimerCallback; - - struct timerHandles - { - sh_timerHandle_t handle; - Timeout* timeout; - }; - //!< reference to the dbus instance - CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler - - std::shared_ptr mFactory; - std::shared_ptr mContext; - - DispatchSourceListenerSubscription mDispatchSourceListenerSubscription; - WatchListenerSubscription mWatchListenerSubscription; - TimeoutSourceListenerSubscription mTimeoutSourceListenerSubscription; - WakeupListenerSubscription mWakeupListenerSubscription; - std::multimap mRegisteredDispatchSources; - std::map mMapWatches; - Watch* mWatchToCheck; - std::list mSourcesToDispatch; - std::vector mpListTimerhandles; -}; - -#define Am_CAPI CAmCommonAPIWrapper::getInstance() - -} - -#endif /* COMMONAPIWRAPPER_H_ */ diff --git a/include/shared/CAmDbusWrapper.h b/include/shared/CAmDbusWrapper.h deleted file mode 100644 index 35b5e77..0000000 --- a/include/shared/CAmDbusWrapper.h +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * - * \copyright - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * \file CAmDbusWrapper.h - * For further information see http://www.genivi.org/. - */ - -/** - * todo add removeCallback ... - */ - -#ifndef DBUSWRAPPER_H_ -#define DBUSWRAPPER_H_ - -#include -#include -#include -#include -#include "config.h" -#include "CAmSocketHandler.h" - -namespace am -{ - -/** - * This wraps dbus and provides everything needed to anyone who wants to use dbus (including plugins). Works on the basis of CAmSocketHandler - */ -class CAmDbusWrapper -{ -public: - CAmDbusWrapper(CAmSocketHandler* socketHandler,DBusBusType type=DBUS_BUS_SESSION); - virtual ~CAmDbusWrapper(); - - void registerCallback(const DBusObjectPathVTable* vtable, const std::string& path, 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); - - void dbusPrepareCallback(const sh_pollHandle_t handle, void* userData); - TAmShPollPrepare pDbusPrepareCallback; - - bool dbusDispatchCallback(const sh_pollHandle_t handle, void* userData); - TAmShPollDispatch pDbusDispatchCallback; - - void dbusFireCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData); - TAmShPollFired pDbusFireCallback; - - bool dbusCheckCallback(const sh_pollHandle_t handle, void* userData); - TAmShPollCheck pDbusCheckCallback; - - void dbusTimerCallback(sh_timerHandle_t handle, void* userData); - TAmShTimerCallBack pDbusTimerCallback; - -private: - 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); - 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 mListNodes; //!< holds a list of all nodes of the dbus - std::vector mpListTimerhandles; //!< pointer to the timer handles - CAmSocketHandler *mpSocketHandler; //!< pointer to the sockethandler - std::map mMapHandleWatch; //!< map to the handle watches - DBusBusType mDbusType; -}; - -} - -#endif /* DBUSWRAPPER_H_ */ diff --git a/include/shared/CAmDltWrapper.h b/include/shared/CAmDltWrapper.h deleted file mode 100644 index 49cae31..0000000 --- a/include/shared/CAmDltWrapper.h +++ /dev/null @@ -1,914 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * Jens Lorenz, jlorenz@de.adit-jv.com ADIT 2014 - * - * \copyright - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * \file CAmDltWrapper.h - * For further information see http://www.genivi.org/. - */ - -#ifndef DLTWRAPPER_H_ -#define DLTWRAPPER_H_ - -#include "config.h" -#include -#include -#include "audiomanagertypes.h" - -#ifdef WITH_DLT -#include -namespace am -{ -#else -#include -#include - -#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 */ -} DltContext; - -/** - * 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; - -/** - * 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; - -#define DLT_DECLARE_CONTEXT(CONTEXT) \ -DltContext CONTEXT; - -#define DLT_IMPORT_CONTEXT(CONTEXT) \ -extern DltContext CONTEXT; -namespace am -{ -#endif // WITH_DLT - -/** - * Wraps around the dlt. This class is instantiated as a singleton and offers a default - * context (maincontext) that is registered to log to. - * Logging under the default context can simply be done with the logInfo/logError templates with up to 10 values at a time. - * For logging with a different context, you can use the log template. First register a context with registerContext. - */ -class CAmDltWrapper -{ -public: - static CAmDltWrapper* instance(const bool enableNoDLTDebug = false); - void registerApp(const char *appid, const char * description); - void registerContext(DltContext& handle, const char *contextid, const char * description); - void unregisterContext(DltContext& handle); - - bool init(DltLogLevelType loglevel, DltContext* context = NULL); - void deinit(); - void send(); - void append(const int8_t value); - void append(const uint8_t value); - void append(const int16_t value); - void append(const uint16_t value); - void append(const int32_t value); - void append(const uint32_t value); - void append(const uint64_t value); - void append(const int64_t value); - void append(const char*& value); - void append(const std::string& value); - void append(const bool value); - void append(const am_Error_e value); -#ifndef WITH_DLT - void enableNoDLTDebug(const bool enableNoDLTDebug = true); -#endif - ~CAmDltWrapper(); -private: - CAmDltWrapper(const bool enableNoDLTDebug); //is private because of singleton pattern -#ifndef WITH_DLT - template void appendNoDLT(T value); - bool mEnableNoDLTDebug; -#endif - DltContext mDltContext; //!< the default context - DltContextData mDltContextData; //!< contextdata - static CAmDltWrapper* mpDLTWrapper; //!< pointer to the wrapper instance - static pthread_mutex_t mMutex; - -}; - -/** - * returns the instance of the CAmDltWrapper - * @return - */ -inline CAmDltWrapper* getWrapper() -{ - return (CAmDltWrapper::instance()); -} - -/** - * logs a given value with infolevel with the default context - * @param value - */ -template void logInfo(T value) -{ - CAmDltWrapper* inst(getWrapper()); - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->send(); -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1mDltContext - */ -template void logInfo(T value, T1 value1) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - */ -template void logInfo(T value, T1 value1, T2 value2) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - * @param value8 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - * @param value8 - * @param value9 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->send(); - -} - -/** - * logs a given value with infolevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - * @param value8 - * @param value9 - * @param value10 - */ -template void logInfo(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9, T10 value10) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_INFO)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->append(value10); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - */ -template void logError(T value) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - */ -template void logError(T value, T1 value1) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - */ -template void logError(T value, T1 value1, T2 value2) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - * @param value8 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - * @param value8 - * @param value9 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->send(); - -} - -/** - * logs a given value with errorlevel with the default context - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - * @param value8 - * @param value9 - * @param value10 - */ -template void logError(T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8, T9 value9, T10 value10) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(DLT_LOG_ERROR)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->append(value9); - inst->append(value10); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - * @param value2 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - * @param value2 - * @param value3 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->send(); - -} - -/** - * logs a given value with a given context (register first!) and given loglevel - * @param context - * @param loglevel - * @param value - * @param value1 - * @param value2 - * @param value3 - * @param value4 - * @param value5 - * @param value6 - * @param value7 - * @param value8 - */ -template void log(DltContext* const context, DltLogLevelType loglevel, T value, T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) -{ - CAmDltWrapper* inst(getWrapper()); - - if (!inst->init(loglevel, context)) - return; - inst->append(value); - inst->append(value1); - inst->append(value2); - inst->append(value3); - inst->append(value4); - inst->append(value5); - inst->append(value6); - inst->append(value7); - inst->append(value8); - inst->send(); - -} -} - -#endif /* DLTWRAPPER_H_ */ diff --git a/include/shared/CAmSerializer.h b/include/shared/CAmSerializer.h deleted file mode 100644 index 7d6cf80..0000000 --- a/include/shared/CAmSerializer.h +++ /dev/null @@ -1,1508 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * - * \copyright - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * \file CAmSerializer.h - * For further information see http://www.genivi.org/. - */ - -#ifndef CAMSERIALIZER_H_ -#define CAMSERIALIZER_H_ - -#include -#include -#include -#include -#include -#include -#include "CAmDltWrapper.h" -#include "CAmSocketHandler.h" - -/** - * todo: performance improvement we could implement a memory pool that is more efficient here and avoids - * allocation and deallocation times. - */ - -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. - * - */ -class CAmSerializer -{ -private: - - /** - * Prototype for a delegate - */ - class CAmDelegate - { - public: - virtual ~CAmDelegate() - {}; - virtual bool call(int* pipe)=0; - - }; - - typedef CAmDelegate* CAmDelegagePtr; //!< pointer to a delegate - - /** - * delegate template for no argument - */ - template class CAmNoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(); - - public: - CAmNoArgDelegate(TClass* instance, void (TClass::*function)()) : - mInstance(instance), // - mFunction(function) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(); - return (true); - }; - }; - - /** - * delegate template for one argument - */ - template class CAmOneArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ); - Targ mArgument; - - public: - CAmOneArgDelegate(TClass* instance, void (TClass::*function)(Targ), Targ argument) : - mInstance(instance), // - mFunction(function), // - mArgument(argument) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument); - return (true); - }; - }; - - /** - * delegate template for one argument - */ - template class CAmOneArgDelegateRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ&); - Targ mArgument; - - public: - CAmOneArgDelegateRef(TClass* instance, void (TClass::*function)(Targ&), Targ& argument) : - mInstance(instance), // - mFunction(function), // - mArgument(argument) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument); - return (true); - }; - }; - - /** - * delegate template for two arguments - */ - template class CAmTwoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1 argument1); - Targ mArgument; - Targ1 mArgument1; - - public: - CAmTwoArgDelegate(TClass* instance, void (TClass::*function)(Targ argument, Targ1 argument1), Targ argument, Targ1 argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1) - { }; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1); - return (true); - }; - }; - - /** - * delegate template for two arguments - */ - template class CAmTwoArgDelegateFirstRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ& argument, Targ1 argument1); - Targ mArgument; - Targ1 mArgument1; - - public: - CAmTwoArgDelegateFirstRef(TClass* instance, void (TClass::*function)(Targ& argument, Targ1 argument1), Targ& argument, Targ1 argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1) - { }; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1); - return (true); - }; - }; - - - template class CAmTwoArgDelegateSecondRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1& argument1); - Targ mArgument; - Targ1 mArgument1; - - public: - CAmTwoArgDelegateSecondRef(TClass* instance, void (TClass::*function)(Targ argument, Targ1& argument1), Targ argument, Targ1& argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1); - return (true); - }; - }; - - /** - * delegate template for two arguments - */ - template class CAmTwoArgDelegateAllRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ& argument, Targ1& argument1); - Targ mArgument; - Targ1 mArgument1; - - public: - CAmTwoArgDelegateAllRef(TClass* instance, void (TClass::*function)(Targ& argument, Targ1& argument1), Targ& argument, Targ1& argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1) - { }; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1); - return (true); - }; - }; - - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegate(TClass* instance, void (TClass::*function)(Targ argument, Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - { - } - ; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - } - ; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegateFirstRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ& argument, Targ1 argument1, Targ2 argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegateFirstRef(TClass* instance, void (TClass::*function)(Targ& argument, Targ1 argument1, Targ2 argument2), Targ& argument, Targ1 argument1, Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - }; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegateSecondRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1& argument1, Targ2 argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegateSecondRef(TClass* instance, void (TClass::*function)(Targ argument, Targ1& argument1, Targ2 argument2), Targ argument, Targ1& argument1, Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - }; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegateThirdRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2& argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegateThirdRef(TClass* instance, void (TClass::*function)(Targ argument, Targ1 argument1, Targ2& argument2), Targ argument, Targ1 argument1, Targ2& argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - }; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegateFirstSecondRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ& argument, Targ1& argument1, Targ2 argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegateFirstSecondRef(TClass* instance, void (TClass::*function)(Targ& argument, Targ1& argument1, Targ2 argument2), Targ& argument, Targ1& argument1, Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - }; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegateFirstThirdRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ& argument, Targ1 argument1, Targ2& argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegateFirstThirdRef(TClass* instance, void (TClass::*function)(Targ& argument, Targ1 argument1, Targ2& argument2), Targ& argument, Targ1 argument1, Targ2& argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - }; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegateSecondThirdRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1& argument1, Targ2& argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegateSecondThirdRef(TClass* instance, void (TClass::*function)(Targ argument, Targ1& argument1, Targ2& argument2), Targ argument, Targ1& argument1, Targ2& argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - }; - }; - - /** - * delegate template for three arguments - */ - template class CAmThreeArgDelegateAllRef: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ& argument, Targ1& argument1, Targ2& argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - - public: - CAmThreeArgDelegateAllRef(TClass* instance, void (TClass::*function)(Targ& argument, Targ1& argument1, Targ2& argument2), Targ& argument, Targ1& argument1, Targ2& argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2) - {}; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - return (true); - }; - }; - - /** - * delegate template for four arguments - */ - template class CAmFourArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - void (TClass::*mFunction)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - Targ3 mArgument3; - - public: - CAmFourArgDelegate(TClass* instance, void (TClass::*function)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mArgument3(argument3) - { - } - ; - - bool call(int* pipe) - { - (void) pipe; - (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2, mArgument3); - return (true); - } - ; - }; - - /** - * Template for synchronous calls with no argument - */ - template class CAmSyncNoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(); - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncNoArgDelegate(TClass* instance, TretVal (TClass::*function)()) : - mInstance(instance), // - mFunction(function), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults() - { - return (mRetval); - } - }; - - /** - * template for synchronous calls with one argument - */ - template class CAmSyncOneArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCall argument); - Targ mArgument; - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncOneArgDelegate(TClass* instance, TretVal (TClass::*function)(TargCall argument), Targ argument) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument) - { - argument = mArgument; - return (mRetval); - } - }; - - /** - * template for synchronous calls with one argument on a const function - */ - template class CAmSyncOneArgConstDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCall argument) const; - Targ mArgument; - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncOneArgConstDelegate(TClass* instance, TretVal (TClass::*function)(TargCall argument) const, Targ argument) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument) - { - argument = mArgument; - return (mRetval); - } - }; - - /** - * template for synchronous calls with two arguments - */ - template class CAmSyncTwoArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCall, TargCall1); - Targ mArgument; - Targ1 mArgument1; - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncTwoArgDelegate(TClass* instance, TretVal (TClass::*function)(TargCall, TargCall1), Targ& argument, Targ1& argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument, Targ1& argument1) - { - argument = mArgument; - argument1 = mArgument1; - return (mRetval); - } - }; - - /** - * template for synchronous calls with two arguments on a const function - */ - template class CAmSyncTwoArgConstDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCall, TargCall1) const; - Targ mArgument; - Targ1 mArgument1; - TretVal mRetval; - - public: - friend class CAmSerializer; - CAmSyncTwoArgConstDelegate(TClass* instance, TretVal (TClass::*function)(TargCall, TargCall1) const, Targ& argument, Targ1& argument1) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument, Targ1& argument1) - { - argument = mArgument; - argument1 = mArgument1; - return (mRetval); - } - }; - - /** - * template for synchronous calls with three arguments - */ - template class CAmSyncThreeArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCall argument, TargCall1 argument1, TargCall2 argument2); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - TretVal mRetval; - - public: - CAmSyncThreeArgDelegate(TClass* instance, TretVal (TClass::*function)(TargCall argument, TargCall1 argument1, TargCall2 argument2), Targ argument, Targ1 argument1, Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2) - { - argument = mArgument; - argument1 = mArgument1; - argument2 = mArgument2; - return (mRetval); - } - }; - - /** - * template for synchronous const calls with three arguments - */ - template class CAmSyncThreeArgConstDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCall argument, TargCall1 argument1, TargCall2 argument2) const; - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - TretVal mRetval; - - public: - CAmSyncThreeArgConstDelegate(TClass* instance, TretVal (TClass::*function)(TargCall argument, TargCall1 argument1, TargCall2 argument2) const, Targ argument, Targ1 argument1, Targ2 argument2) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2) - { - argument = mArgument; - argument1 = mArgument1; - argument2 = mArgument2; - return (mRetval); - } - }; - - /** - * template for synchronous calls with four arguments - */ - template class CAmSyncFourArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCAll argument, TargCall1 argument1, TargCall2 argument2, TargCall3 argument3); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - Targ3 mArgument3; - TretVal mRetval; - public: - CAmSyncFourArgDelegate(TClass* instance, TretVal (TClass::*function)(TargCAll argument, TargCall1 argument1, TargCall2 argument2, TargCall3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mArgument3(argument3), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2, mArgument3); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3) - { - argument = mArgument; - argument1 = mArgument1; - argument2 = mArgument2; - argument3 = mArgument3; - return (mRetval); - } - }; - - /** - * delegate template for five arguments - */ - template class CAmSyncFiveArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCAll argument, TargCall1 argument1, TargCall2 argument2, TargCall3 argument3, TargCall4); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - Targ3 mArgument3; - Targ4 mArgument4; - TretVal mRetval; - public: - - CAmSyncFiveArgDelegate(TClass* instance, TretVal (TClass::*function)(TargCAll argument, TargCall1 argument1, TargCall2 argument2, TargCall3 argument3, TargCall4 argument4), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3, Targ4 argument4) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mArgument3(argument3), // - mArgument4(argument4), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2, mArgument3, mArgument4); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3, Targ4& argument4) - { - argument = mArgument; - argument1 = mArgument1; - argument2 = mArgument2; - argument3 = mArgument3; - argument4 = mArgument4; - return (mRetval); - } - }; - - /** - * template for synchronous calls with six arguments - */ - template class CAmSyncSixArgDelegate: public CAmDelegate - { - private: - TClass* mInstance; - TretVal (TClass::*mFunction)(TargCAll argument, TargCall1 argument1, TargCall2 argument2, TargCall3 argument3, TargCall4, TargCall5); - Targ mArgument; - Targ1 mArgument1; - Targ2 mArgument2; - Targ3 mArgument3; - Targ4 mArgument4; - Targ5 mArgument5; - TretVal mRetval; - - CAmSyncSixArgDelegate(TClass* instance, TretVal (TClass::*function)(TargCAll, TargCall1, TargCall2, TargCall3, TargCall4, TargCall5), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3, Targ4 argument4, Targ5 argument5) : - mInstance(instance), // - mFunction(function), // - mArgument(argument), // - mArgument1(argument1), // - mArgument2(argument2), // - mArgument3(argument3), // - mArgument4(argument4), // - mArgument5(argument5), // - mRetval() - { - } - ; - - bool call(int* pipe) - { - mRetval = (*mInstance.*mFunction)(mArgument, mArgument1, mArgument2, mArgument3, mArgument4, mArgument5); - write(pipe[1], this, sizeof(this)); - return (false); - } - ; - - TretVal returnResults(Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3, Targ4& argument4, Targ5& argument5) - { - argument = mArgument; - argument1 = mArgument1; - argument2 = mArgument2; - argument3 = mArgument3; - argument4 = mArgument4; - argument5 = mArgument5; - return (mRetval); - } - }; - - /** - * 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 - std::deque mListDelegatePoiters; //!< intermediate queue to store the pipe results - -public: - - /** - * 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(&instanceMyClass,&myClass::myfunction); - * @endcode - */ - template - void asyncCall(TClass* instance, void (TClass::*function)()) - { - CAmDelegagePtr p(new CAmNoArgDelegate(instance, function)); - send(p); - } - - /** - * 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(&instanceMyClass,&myClass::myfunction,k); - * @endcode - * - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ), Targ argument) - { - CAmDelegagePtr p(new CAmOneArgDelegate(instance, function, argument)); - send(p); - } - - /** - * 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(&instanceMyClass,&myClass::myfunction,k); - * @endcode - * - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ&), Targ& argument) - { - CAmDelegagePtr p(new CAmOneArgDelegateRef(instance, function, argument)); - send(p); - } - - /** - * 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1), Targ argument, Targ1 argument1) - { - CAmDelegagePtr p(new CAmTwoArgDelegate(instance, function, argument, argument1)); - send(p); - } - - /** - * 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1), Targ& argument, Targ1 argument1) - { - CAmDelegagePtr p(new CAmTwoArgDelegateFirstRef(instance, function, argument, argument1)); - send(p); - } - - /** - * 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1& argument1), Targ argument, Targ1& argument1) - { - CAmDelegagePtr p(new CAmTwoArgDelegateSecondRef(instance, function, argument, argument1)); - send(p); - } - - /** - * 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1), Targ& argument, Targ1& argument1) - { - CAmDelegagePtr p(new CAmTwoArgDelegateAllRef(instance, function, argument, argument1)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 argument2), Targ argument, Targ1 argument1, Targ2 argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegate(instance, function, argument, argument1, argument2)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1, Targ2 argument2), Targ& argument, Targ1 argument1, Targ2 argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegateFirstRef(instance, function, argument, argument1, argument2)); - send(p); - } - - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1& argument1, Targ2 argument2), Targ argument, Targ1& argument1, Targ2 argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegateSecondRef(instance, function, argument, argument1, argument2)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2& argument2), Targ argument, Targ1 argument1, Targ2& argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegateThirdRef(instance, function, argument, argument1, argument2)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1& argument1, Targ2& argument2), Targ argument, Targ1& argument1, Targ2& argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegateSecondThirdRef(instance, function, argument, argument1, argument2)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1, Targ2& argument2), Targ& argument, Targ1& argument1, Targ2& argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegateAllRef(instance, function, argument, argument1, argument2)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1, Targ2 argument2), Targ& argument, Targ1& argument1, Targ2 argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegateFirstSecondRef(instance, function, argument, argument1, argument2)); - send(p); - } - - /** - * calls a function with three arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1, Targ2& argument2), Targ& argument, Targ1 argument1, Targ2& argument2) - { - CAmDelegagePtr p(new CAmThreeArgDelegateFirstThirdRef(instance, function, argument, argument1, argument2)); - send(p); - } - - /** - * calls a function with four arguments asynchronously threadsafe. for more see other asycCall - */ - template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) - { - CAmDelegagePtr p(new CAmFourArgDelegate(instance, function, argument, argument1, argument2, argument3)); - send(p); - } - - /** - * 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(&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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(), TretVal& retVal) - { - CAmSyncNoArgDelegate* p(new CAmSyncNoArgDelegate(instance, function)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal = p->returnResults(); - delete p; - } - - /** - * 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(&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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall), TretVal& retVal, Targ& argument) - { - CAmSyncOneArgDelegate* p(new CAmSyncOneArgDelegate(instance, function, argument)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal = p->returnResults(argument); - delete p; - } - - /** - * calls a function with one argument synchronous threadsafe for const functions. For more see syncCall with one argument - */ - template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall) const, TretVal& retVal, Targ& argument) - { - CAmSyncOneArgConstDelegate* p(new CAmSyncOneArgConstDelegate(instance, function, argument)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal = p->returnResults(argument); - delete p; - } - - /** - * calls a function with two arguments synchronously threadsafe. For more see syncCall with one argument - */ - template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, Targ1Call), TretVal& retVal, Targ& argument, Targ1& argument1) - { - CAmSyncTwoArgDelegate* p(new CAmSyncTwoArgDelegate(instance, function, argument, argument1)); - send(dynamic_cast(p)); - - CAmDelegagePtr ptr; - if (read(mReturnPipe[0], &ptr, sizeof(ptr)) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - retVal = p->returnResults(argument, argument1); - delete p; - } - /** - * calls a function with two arguments synchronously threadsafe const. For more see syncCall with one argument - */ - template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, Targ1Call) const, TretVal& retVal, Targ& argument, Targ1& argument1) - { - CAmSyncTwoArgConstDelegate* p(new CAmSyncTwoArgConstDelegate(instance, function, argument, argument1)); - send(dynamic_cast(p)); - - CAmDelegagePtr ptr; - if (read(mReturnPipe[0], &ptr, sizeof(ptr)) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - retVal = p->returnResults(argument, argument1); - delete p; - } - - /** - * calls a function with three arguments synchronously threadsafe. for more see syncCall with one argument - */ - template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2) - { - CAmSyncThreeArgDelegate* p(new CAmSyncThreeArgDelegate(instance, function, argument, argument1, argument2)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it worCAmTwoArgDelegateks... - retVal = p->returnResults(argument, argument1, argument2); - delete p; - } - - /** - * calls a const function with three arguments synchronously threadsafe. for more see syncCall with one argument - */ - template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2) const, TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2) - { - CAmSyncThreeArgConstDelegate* p(new CAmSyncThreeArgConstDelegate(instance, function, argument, argument1, argument2)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it worCAmTwoArgDelegateks... - retVal = p->returnResults(argument, argument1, argument2); - delete p; - } - - /** - * calls a function with four arguments synchronously threadsafe. for more see syncCall with one argument - */ - template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3) - { - CAmSyncFourArgDelegate* p(new CAmSyncFourArgDelegate(instance, function, argument, argument1, argument2, argument3)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal = p->returnResults(argument, argument1, argument2, argument3); - delete p; - } - - /** - * calls a function with five arguments synchronously threadsafe. for more see syncCall with one argument - */ - template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3, TargCall4), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3, Targ4& argument4) - { - CAmSyncFiveArgDelegate* p(new CAmSyncFiveArgDelegate(instance, function, argument, argument1, argument2, argument3, argument4)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal = p->returnResults(argument, argument1, argument2, argument3, argument4); - delete p; - } - - /** - * calls a function with six arguments synchronously threadsafe. for more see syncCall with one argument - */ - template - 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) - { - CAmSyncSixArgDelegate* p(new CAmSyncSixArgDelegate(instance, function, argument, argument1, argument2, argument3, argument4, argument5)); - send(static_cast(p)); - int numReads; - CAmDelegagePtr ptr; - if ((numReads = read(mReturnPipe[0], &ptr, sizeof(ptr))) == -1) - { - logError("CAmSerializer::receiverCallback could not read pipe!"); - throw std::runtime_error("CAmSerializer Could not read pipe!"); - } - //working with friend class here is not the finest of all programming stiles but it works... - retVal = p->returnResults(argument, argument1, argument2, argument3, argument4, argument5); - delete p; - } - - /** - * 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))); - } - - /** - * 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); - } - - /** - * 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); - } - - TAmShPollFired receiverCallbackT; - TAmShPollDispatch dispatcherCallbackT; - TAmShPollCheck checkerCallbackT; - - /** - * The constructor must be called in the mainthread context ! - * @param iSocketHandler pointer to the CAmSocketHandler - */ - CAmSerializer(CAmSocketHandler *iSocketHandler) : - mPipe(), // - mListDelegatePoiters(), // - receiverCallbackT(this, &CAmSerializer::receiverCallback), // - dispatcherCallbackT(this, &CAmSerializer::dispatcherCallback), // - checkerCallbackT(this, &CAmSerializer::checkerCallback) - { - 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; - sh_pollHandle_t handle; - event |= POLLIN; - iSocketHandler->addFDPoll(mPipe[0], event, NULL, &receiverCallbackT, &checkerCallbackT, &dispatcherCallbackT, NULL, handle); - } - - ~CAmSerializer() - { - } -}; -} /* namespace am */ -#endif /* CAMSERIALIZER_H_ */ diff --git a/include/shared/CAmSocketHandler.h b/include/shared/CAmSocketHandler.h deleted file mode 100644 index 1e91b5f..0000000 --- a/include/shared/CAmSocketHandler.h +++ /dev/null @@ -1,576 +0,0 @@ -/** - * Copyright (C) 2012, BMW AG - * - * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 - * - * \copyright - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR - * THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * \file CAmSocketHandler.h - * For further information see http://www.genivi.org/. - */ - -#ifndef SOCKETHANDLER_H_ -#define SOCKETHANDLER_H_ - -#include "audiomanagertypes.h" -#include -#include -#include -#include -#include -#include - -#include //todo: remove me -namespace am -{ - -#define MAX_NS 1000000000L - -typedef uint16_t sh_timerHandle_t; //! class TAmShPollFired: public IAmShPollFired - { - private: - 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) {}; - - virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) - { - (*mInstance.*mFunction)(pollfd, handle, userData); - }; - }; - - template class TAmShPollCheck: public IAmShPollCheck - { - private: - 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) {}; - - virtual bool Call(const sh_pollHandle_t handle, void* userData) - { - return ((*mInstance.*mFunction)(handle, userData)); - }; - }; - - CAmSocketHandler(); - ~CAmSocketHandler(); - - 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 addTimer(const timespec timeouts, IAmShTimerCallBack* callback, sh_timerHandle_t& handle, void* userData); - 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 stopTimer(const sh_timerHandle_t handle); - void start_listenting(); - void stop_listening(); - void exit_mainloop(); - void receiverCallback(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) - { - (void) pollfd; - (void) handle; - (void) userData; - }; - bool checkerCallback(const sh_pollHandle_t handle, void* userData) - { - (void) handle; - (void) userData; - return (false); - }; - - TAmShPollFired receiverCallbackT; - TAmShPollCheck checkerCallbackT; - -private: - - static CAmSocketHandler* mInstance; - int mPipe[2]; - int mDispatchDone; //this starts / stops the mainloop - struct sh_timer_s //! rListTimerIter; //! mListPollfd_t; //! mListPoll_t; //!= 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) - { - //less - if (a.tv_sec < b.tv_sec) - return (-1); - //greater - else if (a.tv_sec > b.tv_sec) - return (1); - //less - else if (a.tv_nsec < b.tv_nsec) - return (-1); - //greater - else if (a.tv_nsec > b.tv_nsec) - return (1); - //equal - else - return (0); - } - - /** - * functor to return all fired events - * @param a - * @return - */ - inline static bool eventFired(const pollfd& a) - { - return (a.revents == 0 ? false : true); - } - - /** - * functor to help find the items that do not need dispatching - * @param a - * @return - */ - inline static bool noDispatching(const sh_poll_s& a) - { - //remove from list of there is no checkCB - if (!a.checkCB) - return (true); - return (!a.checkCB->Call(a.handle, a.userData)); - } - - /** - * checks if dispatching is already finished - * @param a - * @return - */ - inline static bool dispatchingFinished(const sh_poll_s& a) - { - //remove from list of there is no dispatchCB - if (!a.dispatchCB) - return (true); - return (!a.dispatchCB->Call(a.handle, a.userData)); - } - - class CAmShCopyPollfd //!< functor to copy filedescriptors into the poll array - { - private: - mListPollfd_t& mArray; - public: - CAmShCopyPollfd(mListPollfd_t& dest) : - mArray(dest) - { - } - void operator()(const sh_poll_s& row) - { - pollfd temp = row.pollfdValue; - temp.revents = 0; - mArray.push_back(temp); - } - }; - - class CAmShCallFire //!< functor to call the firecallbacks - { - public: - CAmShCallFire() - { - } - ; - void operator()(sh_poll_s& row) - { - row.firedCB->Call(row.pollfdValue, row.handle, row.userData); - } - }; - - class CAmShCallPrep //!< functor to call the preparation callbacks - { - public: - CAmShCallPrep() - { - } - ; - void operator()(sh_poll_s& row) - { - if (row.prepareCB) - row.prepareCB->Call(row.handle, row.userData); - } - }; - - class CAmShCallTimer //!Call(row.handle, row.userData); - } - }; - - class CAmShCountdownUp //! mListTimer; //! mListActiveTimer; //!::iterator it(mListActiveTimer.begin()); -// for(;it!=mListActiveTimer.end();++it) -// { -// std::cout<< "Handle " << it->handle << "sec " << it->countdown.tv_sec << "nsec " << it->countdown.tv_nsec< class TAmShTimerCallBack: public IAmShTimerCallBack -{ -private: - TClass* mInstance; - void (TClass::*mFunction)(sh_timerHandle_t handle, void* userData); - -public: - TAmShTimerCallBack(TClass* instance, void (TClass::*function)(sh_timerHandle_t handle, void* userData)) : - mInstance(instance), // - mFunction(function) - { - } - ; - - virtual void Call(sh_timerHandle_t handle, void* userData) - { - (*mInstance.*mFunction)(handle, userData); - } -}; - -/** - * template for a callback - */ -template class TAmShPollPrepare: public IAmShPollPrepare -{ -private: - TClass* mInstance; - void (TClass::*mFunction)(const sh_timerHandle_t handle, void* userData); - -public: - TAmShPollPrepare(TClass* instance, void (TClass::*function)(const sh_timerHandle_t handle, void* userData)) : - mInstance(instance), // - mFunction(function) - { - } - ; - - virtual void Call(const sh_timerHandle_t handle, void* userData) - { - (*mInstance.*mFunction)(handle, userData); - } - ; -}; - -/**make private, not public - * template for a callback - */ -template class TAmShPollFired: public IAmShPollFired -{ -private: - 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) - { - } - ; - - virtual void Call(const pollfd pollfd, const sh_pollHandle_t handle, void* userData) - { - (*mInstance.*mFunction)(pollfd, handle, userData); - } - ; -}; - -/** - * template for a callback - */ -template class TAmShPollCheck: public IAmShPollCheck -{ -private: - 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) - { - } - ; - - virtual bool Call(const sh_pollHandle_t handle, void* userData) - { - return ((*mInstance.*mFunction)(handle, userData)); - } - ; -}; - -/** - * template for a callback - */ -template class TAmShPollDispatch: public IAmShPollDispatch -{ -private: - 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) - { - } - ; - - virtual bool Call(const sh_pollHandle_t handle, void* userData) - { - return ((*mInstance.*mFunction)(handle, userData)); - } - ; -}; -} /* namespace am */ -#endif /* SOCKETHANDLER_H_ */ -- cgit v1.2.1