From 174df12c9b14cbce0bdad7c197f80ce7efd55cb6 Mon Sep 17 00:00:00 2001 From: christian mueller Date: Mon, 10 Sep 2012 17:41:30 +0200 Subject: * [GAM-91] make CAmSerializer calls with references safer Signed-off-by: christian mueller --- include/shared/CAmSerializer.h | 154 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 153 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/shared/CAmSerializer.h b/include/shared/CAmSerializer.h index 39b6c90..5a1cde5 100644 --- a/include/shared/CAmSerializer.h +++ b/include/shared/CAmSerializer.h @@ -140,6 +140,7 @@ private: }; }; + /** * delegate template for three arguments */ @@ -646,6 +647,33 @@ public: 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 CAmOneArgDelegate(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 @@ -659,10 +687,63 @@ public: template void asyncCall(TClass1* instance, void (TClass1::*function)(Targ argument, Targ1 argument1), Targ argument, Targ1 argument1) { + logInfo("took without ref"); 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 CAmTwoArgDelegate(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) + { + logInfo("took ref"); + CAmDelegagePtr p(new CAmTwoArgDelegate(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 CAmTwoArgDelegate(instance, function, argument, argument1)); + send(p); + } + /** * calls a function with three arguments asynchronously threadsafe. for more see other asycCall */ @@ -673,6 +754,77 @@ public: 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 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 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 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 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 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 CAmThreeArgDelegate(instance, function, argument, argument1, argument2)); + send(p); + } + /** * calls a function with four arguments asynchronously threadsafe. for more see other asycCall */ @@ -837,7 +989,7 @@ public: 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... + //working with friend class here is not the finest of all programming stiles but it worCAmTwoArgDelegateks... retVal = p->returnResults(argument, argument1, argument2); delete p; } -- cgit v1.2.1