LRT14  1.0
 All Classes Namespaces Functions Variables Enumerations Enumerator
do_async_static.h
1 #ifndef RHESUS_DO_ASYNC_STATIC_H_
2 #define RHESUS_DO_ASYNC_STATIC_H_
3 
4 #include "TaskPool.h"
5 
6 #include "../Defines.h"
7 
8 namespace Rhesus
9 {
10 namespace Toolkit
11 {
12 namespace Tasks
13 {
14  class do_async_static
15  {
16  private:
17  typedef INT32 (*AsyncMethodFuncPtr)(UINT32 p0, UINT32 p1, UINT32 p2, UINT32 p3, UINT32 p4, UINT32 p5,
18  UINT32 p6, UINT32 p7);
19 
20  typedef void (*AsyncCallbackFuncPtr)(INT32 retCode);
21 
22  struct TaskStruct
23  {
24  AsyncMethodFuncPtr mptr;
25  AsyncCallbackFuncPtr cptr;
26  UINT32 arg0;
27  UINT32 arg1;
28  UINT32 arg2;
29  UINT32 arg3;
30  UINT32 arg4;
31  UINT32 arg5;
32  UINT32 arg6;
33  UINT32 arg7;
34  };
35 
36  public:
37  static INT32 AsyncMethodWrapper(TaskStruct* t)
38  {
39  INT32 retCode = (t->mptr)(t->arg0, t->arg1, t->arg2, t->arg3, t->arg4, t->arg5, t->arg6, t->arg7);
40 
41  //callback
42  if (t->cptr != NULL)
43  (t->cptr)(retCode);
44 
45  DELETE(t);
46 
47  return 0;
48  }
49 
50  do_async_static(AsyncMethodFuncPtr asyncFunc, AsyncCallbackFuncPtr callback = NULL, UINT32 p0 = 0, UINT32 p1 = 0, UINT32 p2 = 0, UINT32 p3 = 0, UINT32 p4 = 0, UINT32 p5 = 0,
51  UINT32 p6 = 0, UINT32 p7 = 0)
52  {
53  TaskPool::EnqueueTask((FUNCPTR)AsyncMethodWrapper, (UINT32)create(asyncFunc, callback, p0, p1, p2, p3, p4, p5, p6, p7));
54  }
55 
56  private:
57  TaskStruct* create(AsyncMethodFuncPtr mptr, AsyncCallbackFuncPtr cptr, UINT32 arg0, UINT32 arg1, UINT32 arg2,
58  UINT32 arg3, UINT32 arg4, UINT32 arg5, UINT32 arg6, UINT32 arg7)
59  {
60  TaskStruct* t = new TaskStruct();
61  t->mptr = mptr;
62  t->cptr = cptr;
63  t->arg0 = arg0;
64  t->arg1 = arg1;
65  t->arg2 = arg2;
66  t->arg3 = arg3;
67  t->arg4 = arg4;
68  t->arg5 = arg5;
69  t->arg6 = arg6;
70  t->arg7 = arg7;
71  return t;
72  }
73 
74 // RhesusTask& m_asyncTask;
75 //
76 // AsyncMethodFuncPtr m_asyncFunc;
77 // AsyncCallbackFuncPtr m_asyncCallback;
78  };
79 }
80 }
81 }
82 
83 #endif