File: gsCore.h

package info (click to toggle)
openmohaa 0.81.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: trixie
  • size: 29,124 kB
  • sloc: ansic: 270,865; cpp: 250,173; sh: 234; asm: 141; xml: 64; makefile: 7
file content (128 lines) | stat: -rw-r--r-- 4,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#ifndef __CORE_H__
#define __CORE_H__


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Core task/callback manager
#include "gsCommon.h"
#include "../darray.h"

#if defined(__cplusplus)
extern "C"
{
#endif


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#define GSICORE_DYNAMIC_TASK_LIST
#define GSICORE_MAXTASKS       40


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
typedef enum
{
	GSCore_IN_USE,
	GSCore_SHUTDOWN_PENDING,
	GSCore_SHUTDOWN_COMPLETE
} GSCoreValue;


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
typedef enum
{
	GSTaskResult_None,
	GSTaskResult_InProgress,
	GSTaskResult_Canceled,
	GSTaskResult_TimedOut,
	GSTaskResult_Finished
} GSTaskResult;


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// delegates (optional, may be NULL)
typedef void(*GSTaskExecuteFunc) (void* theTaskData);
typedef void(*GSTaskCallbackFunc)(void* theTaskData, GSTaskResult theResult);
typedef void(*GSTaskCancelFunc)  (void* theTaskData);
typedef gsi_bool(*GSTaskCleanupFunc) (void* theTaskData); // post run cleanup
typedef GSTaskResult(*GSTaskThinkFunc)(void* theTaskData);


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// "Private" struct for dispatching tasks.  Once tasks have been put in the queue
// they should only be modified from the think thread.
//      - When creating a task, you should set only the task data and delegates
typedef struct 
{
	int mId;
	gsi_time mTimeout;
	gsi_time mStartTime;
	gsi_bool mAutoThink;

	// These are not exclusive states (use bit flags?)
	gsi_i32  mIsStarted;   
	gsi_i32  mIsRunning;
	gsi_i32  mIsCanceled;
	gsi_i32  mIsCallbackPending; // does the task require a callback?

	// delegates
	void* mTaskData;
	GSTaskExecuteFunc  mExecuteFunc;
	GSTaskCallbackFunc mCallbackFunc;
	GSTaskCancelFunc   mCancelFunc;
	GSTaskCleanupFunc  mCleanupFunc;
	GSTaskThinkFunc    mThinkFunc;
} GSTask;


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
typedef struct 
{
	gsi_u32  mRefCount;

	gsi_bool volatile mIsStaticInitComplete;  // once per application init
	gsi_bool volatile mIsInitialized;  // gsi_true when ready to use
	gsi_bool volatile mIsShuttingDown; // gsi_true when shutting down

	GSICriticalSection mQueueCrit;
	#ifdef GSICORE_DYNAMIC_TASK_LIST
		DArray mTaskArray;
	#else
		GSTask* mTaskArray[GSICORE_MAXTASKS];
	#endif
		
} GSCoreMgr;


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void gsCoreInitialize       (void);
void gsCoreThink            (gsi_time theMS);
void gsCoreShutdown         (void);
GSCoreValue gsCoreIsShutdown(void);

GSTaskResult gsCoreTaskThink(GSTask* theTask);
void gsiCoreExecuteTask     (GSTask* theTask, gsi_time theTimeoutMs);
void gsiCoreCancelTask      (GSTask* theTask);

GSTask* gsiCoreCreateTask(void);


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
}
#endif


///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#endif // __CORE_H__