From 12ba57296f4e0d21e26156a14b42581a48658d00 Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Fri, 26 Jun 2015 16:39:42 +0200 Subject: * Serializer reworked to offer convenient async and sync method calls. Signed-off-by: Christian Linke --- AudioManagerUtilities/include/CAmSerializer.h | 1370 ++++++------------------- 1 file changed, 321 insertions(+), 1049 deletions(-) diff --git a/AudioManagerUtilities/include/CAmSerializer.h b/AudioManagerUtilities/include/CAmSerializer.h index fc336fc..40d4b6c 100644 --- a/AudioManagerUtilities/include/CAmSerializer.h +++ b/AudioManagerUtilities/include/CAmSerializer.h @@ -4,6 +4,7 @@ * Copyright (C) 2012, BMW AG * * \author Christian Linke, christian.linke@bmw.de BMW 2011,2012 + * \author Alesksandar Donchev, aleksander.donchev@partner.bmw.de BMW 2015 * * \copyright * This Source Code Form is subject to the terms of the @@ -49,882 +50,187 @@ class CAmSerializer { private: - /** - * Prototype for a delegate - */ - class CAmDelegate - { - public: - virtual ~CAmDelegate() - {}; - virtual bool call(int* pipe)=0; - - }; + /** + * 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 CAmDelegateAsyncImpl : public CAmDelegate + { + Class mInstance; + Method mMethod; + Tuple mArguments; + public: + friend class CAmSerializer; + static void call(Class instance, Method method, Tuple && arguments) + { + CAmDelegateAsyncImpl::call(instance, method, std::forward(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(mArguments)); + return (AsyncCallType); + }; + }; + + /** + * Prototype for a delegate with variadic template arguments. + */ + template + class CAmDelegateAsyncImpl : 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(std::forward(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(mArguments)); + return (AsyncCallType); + }; + }; + + /** + * Prototype for a delegate with variadic template arguments in conjunction with the following class. + */ + template + 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::call(instance, method, result, std::forward(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(mArguments)); + write(pipe[1], this, sizeof(this)); + return (SyncCallType); + }; + }; + + /** + * Prototype for a delegate with variadic template arguments. + */ + template + 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 && t) + { + result = (*instance.*method)(std::get(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(mArguments)); + write(pipe[1], this, sizeof(this)); + return (SyncCallType); + }; + }; 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); - } - }; + /** + * instantiates a async delegate with given arguments and sends the delegate pointer over the pipe + */ + template + void doAsyncCall(Class intsance, Method method, Tuple & arguments) + { + typedef typename std::decay::type ttype; + typedef CAmDelegateAsyncImpl::value, std::tuple_size::value> AsyncDelegate; + AsyncDelegate *pImp = new AsyncDelegate(intsance, method, std::forward(arguments)); + send(pImp); + //Do not delete the pointer. It will be deleted automatically later. + } + + /** + * instantiates a sync delegate with given arguments and sends the delegate pointer over the pipe + */ + template + void doSyncCall(Class intsance, Method method, Return & result, Tuple & arguments) + { + typedef typename std::decay::type ttype; + typedef CAmDelegateSyncImpl::value, std::tuple_size::value> SyncDelegate; + SyncDelegate *pImp = new SyncDelegate(intsance, method, std::forward(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; + } /** * rings the line of the pipe and adds the delegate pointer to the queue @@ -944,6 +250,61 @@ private: public: + /** + * 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(&anInstance,&MyGreatClass::AGreatMethod, result, 100); + * @endcode + */ + template + 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 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(&anInstance,&MyGreatClass::AGreatMethod, 100); + * @endcode + */ + template + 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 @@ -962,10 +323,10 @@ public: * @endcode */ template - void asyncCall(TClass* instance, void (TClass::*function)()) + void asyncCall(TClass* instance, void (TClass::*function)()) { - CAmDelegagePtr p(new CAmNoArgDelegate(instance, function)); - send(p); + auto t = std::make_tuple(); + doAsyncCall(instance, function, t); } /** @@ -989,10 +350,10 @@ public: * */ template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ), Targ argument) + void asyncCall(TClass1* instance, void (TClass1::*function)(Targ), Targ argument) { - CAmDelegagePtr p(new CAmOneArgDelegate(instance, function, argument)); - send(p); + auto t = std::make_tuple(argument); + doAsyncCall(instance, function, t); } /** @@ -1016,10 +377,10 @@ public: * */ template - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ&), Targ& argument) + void asyncCall(TClass1* instance, void (TClass1::*function)(Targ&), Targ& argument) { - CAmDelegagePtr p(new CAmOneArgDelegateRef(instance, function, argument)); - send(p); + auto t = std::make_tuple(argument); + doAsyncCall(instance, function, t); } /** @@ -1033,10 +394,10 @@ public: * @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) + 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); + auto t = std::make_tuple(argument,argument1); + doAsyncCall(instance, function, t); } /** @@ -1050,10 +411,10 @@ public: * @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) + 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); + auto t = std::make_tuple(argument,argument1); + doAsyncCall(instance, function, t); } /** @@ -1067,10 +428,10 @@ public: * @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) + 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); + auto t = std::make_tuple(argument,argument1); + doAsyncCall(instance, function, t); } /** @@ -1084,30 +445,30 @@ public: * @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) + 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); + auto t = std::make_tuple(argument,argument1); + doAsyncCall(instance, function, t); } /** * 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) + 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); + 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1, Targ2 argument2), Targ& argument, Targ1 argument1, Targ2 argument2) + 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); + auto t = std::make_tuple(argument,argument1, argument2); + doAsyncCall(instance, function, t); } @@ -1115,70 +476,70 @@ public: * 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) + 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); + 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2& argument2), Targ argument, Targ1 argument1, Targ2& argument2) + 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); + 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1& argument1, Targ2& argument2), Targ argument, Targ1& argument1, Targ2& argument2) + 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); + 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1, Targ2& argument2), Targ& argument, Targ1& argument1, Targ2& argument2) + 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); + 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1& argument1, Targ2 argument2), Targ& argument, Targ1& argument1, Targ2 argument2) + 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); + 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ& argument, Targ1 argument1, Targ2& argument2), Targ& argument, Targ1 argument1, Targ2& argument2) + 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); + 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 - void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3), Targ argument, Targ1 argument1, Targ2 argument2, Targ3 argument3) + 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); + auto t = std::make_tuple(argument,argument1, argument2,argument3); + doAsyncCall(instance, function, t); } /** @@ -1204,20 +565,10 @@ public: * */ template - void syncCall(TClass1* instance, TretVal (TClass1::*function)(), TretVal& retVal) + 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; + auto t = std::make_tuple(); + doSyncCall(instance, function, retVal, t); } /** @@ -1247,177 +598,98 @@ public: * 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) + 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; + 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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall) const, TretVal& retVal, Targ& argument) + 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; + 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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, Targ1Call), TretVal& retVal, Targ& argument, Targ1& argument1) + 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; + 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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, Targ1Call) const, TretVal& retVal, Targ& argument, Targ1& argument1) + 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; + 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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2) + 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; + 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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2) const, TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2) + 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; + 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 - void syncCall(TClass1* instance, TretVal (TClass1::*function)(TargCall, TargCall1, TargCall2, TargCall3), TretVal& retVal, Targ& argument, Targ1& argument1, Targ2& argument2, Targ3& argument3) + 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; + 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 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) + 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; + 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 - 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) + 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; + 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; } /** -- cgit v1.2.1