From 0a338945f3132116b62672a13e3a326b34686aba Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Sat, 26 Jul 2014 18:50:47 +0200 Subject: [PATCH] refs #241 Callback wrapper, wrapping a C style callback to member function --- src/plugins/simulator/fs9/callback_wrapper.h | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/plugins/simulator/fs9/callback_wrapper.h diff --git a/src/plugins/simulator/fs9/callback_wrapper.h b/src/plugins/simulator/fs9/callback_wrapper.h new file mode 100644 index 000000000..3b0f74bdb --- /dev/null +++ b/src/plugins/simulator/fs9/callback_wrapper.h @@ -0,0 +1,52 @@ +/* Copyright (C) 2014 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKSIMPLUGIN_FS9_CALLBACK_WRAPPER_H +#define BLACKSIMPLUGIN_FS9_CALLBACK_WRAPPER_H + +#include +#include +#include +#include + +namespace BlackSimPlugin +{ + namespace Fs9 + { + //! Template, wrapping the C-style DirectPlay handler callback to a class member + template + struct CallbackWrapper + { + //! Typedef to a MemberFunction + typedef ReturnType (Object::*MemberFunction)(Argument1, Argument2); + + //! Constructor + CallbackWrapper(Object *obj, MemberFunction memberFunction) : + m_object(obj), m_memberFunction(memberFunction) + {} + + //! FS9 message handler callback + static ReturnType WINAPI messageHandler(void *userContext, Argument1 arg1, Argument2 arg2) + { + CallbackWrapper *_this = static_cast(userContext); + Object *obj = _this->m_object; + MemberFunction func = _this->m_memberFunction; + ReturnType result = (obj->*func)(arg1, arg2); + return result; + } + + private: + + QPointer m_object; + MemberFunction m_memberFunction; + }; + } +} + +#endif //BLACKSIMPLUGIN_FS9_CALLBACK_WRAPPER_H