cisst-saw
Loading...
Searching...
No Matches
osaThreadAdapter.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5
6 Author(s): Ankur Kapoor, Min Yang Jung
7 Created on: 2004-04-30
8
9 (C) Copyright 2004-2009 Johns Hopkins University (JHU), All Rights
10 Reserved.
11
12--- begin cisst license - do not edit ---
13
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://www.cisst.org/cisst/license.txt.
17
18--- end cisst license ---
19*/
20
21
27
28#ifndef _osaThreadAdapter_h
29#define _osaThreadAdapter_h
30
32
40template<class _objectType, class _callBackMethodType, class _userDataType>
44
57 osaCallBackBase(_objectType* obj, _callBackMethodType callBackFunction,
58 _userDataType userData)
59 : Obj(obj), CallBackFunction(callBackFunction), UserData(userData) {}
60
61
63 _objectType* Obj;
64
66 _callBackMethodType CallBackFunction;
67
69 _userDataType UserData;
70};
71
72
83template<class _objectType, class _userDataType,
84 class _callBackReturnType, class _callBackArgumentType >
85struct osaHeapCallBack: public osaCallBackBase<_objectType, _callBackReturnType(_objectType::*)(_userDataType), _userDataType> {
86
88 static osaHeapCallBack* Create(_objectType* obj,
89 _callBackReturnType (_objectType::*callBackFunction)(_userDataType),
90 _userDataType userData) {
91 return new osaHeapCallBack(obj, callBackFunction, userData);
92 }
93
94 typedef osaCallBackBase<_objectType, _callBackReturnType(_objectType::*)(_userDataType), _userDataType> BaseType;
95
109#if (CISST_OS == CISST_LINUX_RTAI) || (CISST_OS == CISST_LINUX) || (CISST_OS == CISST_DARWIN) || (CISST_OS == CISST_SOLARIS) || (CISST_OS == CISST_QNX) || (CISST_OS == CISST_LINUX_XENOMAI)
110 static void * CallbackAndDestroy(_callBackArgumentType obj) {
111 osaHeapCallBack* _this = (osaHeapCallBack*) obj;
112 _callBackReturnType result = (_this->Obj->*_this->CallBackFunction)(_this->UserData);
113 delete _this;
114 return (void*)result;
115 }
116#elif (CISST_OS == CISST_WINDOWS)
117 // To avoid including <windows.h>, use the unsigned long and __stdcall rather than
118 // DWORD and WINAPI, respectively. This is slightly risky, since <windows.h> could
119 // change, but that is not likely.
120 static unsigned long __stdcall CallbackAndDestroy(_callBackArgumentType obj) {
121 osaHeapCallBack* _this = (osaHeapCallBack*) obj;
122 _callBackReturnType result = (_this->Obj->*_this->CallBackFunction)(_this->UserData );
123 delete _this;
124#if (CISST_COMPILER == CISST_GCC)
125 return (unsigned long)(unsigned long long)result; // For MingW64
126#else
127 return (unsigned long)result;
128#endif
129 }
130#endif
131
132
133protected:
135 osaHeapCallBack( _objectType* obj,
136 _callBackReturnType (_objectType::*callBackFunction)(_userDataType),
137 _userDataType userData )
138 : BaseType(obj, callBackFunction , userData) {}
139};
140
141
142#endif // _osaThreadAdapter_h
143
Portability across compilers and operating systems tools.
osaCallBackBase(_objectType *obj, _callBackMethodType callBackFunction, _userDataType userData)
Definition osaThreadAdapter.h:57
_callBackReturnType(_objectType::*)(_userDataType) CallBackFunction
Definition osaThreadAdapter.h:66
osaCallBackBase osaCallBackBaseType
Definition osaThreadAdapter.h:43
Definition osaThreadAdapter.h:85
osaHeapCallBack(_objectType *obj, _callBackReturnType(_objectType::*callBackFunction)(_userDataType), _userDataType userData)
Definition osaThreadAdapter.h:135
static void * CallbackAndDestroy(_callBackArgumentType obj)
Definition osaThreadAdapter.h:110
osaCallBackBase< _objectType, _callBackReturnType(_objectType::*)(_userDataType), _userDataType > BaseType
Definition osaThreadAdapter.h:94
static osaHeapCallBack * Create(_objectType *obj, _callBackReturnType(_objectType::*callBackFunction)(_userDataType), _userDataType userData)
Definition osaThreadAdapter.h:88