swift
callbackwrapper.h
1 // SPDX-FileCopyrightText: Copyright (C) 2014 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_SIMPLUGIN_FS9_CALLBACK_WRAPPER_H
5 #define SWIFT_SIMPLUGIN_FS9_CALLBACK_WRAPPER_H
6 
7 #include <dplay8.h>
8 
9 #include <functional>
10 
11 #include <QObject>
12 #include <QPointer>
13 
14 namespace swift::simplugin::fs9
15 {
17  template <class Object, class ReturnType, class Argument1, class Argument2>
19  {
21  using MemberFunction = ReturnType (Object::*)(Argument1, Argument2);
22 
24  CallbackWrapper(Object *obj, MemberFunction memberFunction) : m_object(obj), m_memberFunction(memberFunction) {}
25 
27  static ReturnType WINAPI messageHandler(void *userContext, Argument1 arg1, Argument2 arg2)
28  {
29  CallbackWrapper *_this = static_cast<CallbackWrapper *>(userContext);
30  Object *obj = _this->m_object;
31  MemberFunction func = _this->m_memberFunction;
32  ReturnType result = (obj->*func)(arg1, arg2);
33  return result;
34  }
35 
36  private:
37  QPointer<Object> m_object;
38  MemberFunction m_memberFunction;
39  };
40 } // namespace swift::simplugin::fs9
41 
42 #endif // SWIFT_SIMPLUGIN_FS9_CALLBACK_WRAPPER_H
Template, wrapping the C-style DirectPlay handler callback to a class member.
static ReturnType WINAPI messageHandler(void *userContext, Argument1 arg1, Argument2 arg2)
FS9 message handler callback.
CallbackWrapper(Object *obj, MemberFunction memberFunction)
Constructor.
ReturnType(Object::*)(Argument1, Argument2) MemberFunction
Typedef to a MemberFunction.