Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
async_task.h
Go to the documentation of this file.
1 /*
2  * async_task.h
3  *
4  * Created on: 3 May 2017
5  * Author: billy
6  */
7 
8 #ifndef CORE_SERVER_TASK_INCLUDE_ASYNC_TASK_H_
9 #define CORE_SERVER_TASK_INCLUDE_ASYNC_TASK_H_
10 
12 #include "typedefs.h"
13 #include "linked_list.h"
14 #include "sync_data.h"
15 #include "memory_allocations.h"
16 #include "event_consumer.h"
17 #include "operation.h"
18 
19 struct AsyncTasksManager;
20 
25 typedef struct AsyncTask
26 {
28  char *at_name_s;
29 
35 
38 
45  void *(*at_run_fn) (void *data_p);
46 
50  void *at_data_p;
51 
56 
59 
60 
61 
66 
67 } AsyncTask;
68 
69 
73 typedef struct AsyncTaskNode
74 {
77 
80 
88 
89 
90 #ifdef __cplusplus
91 extern "C"
92 {
93 #endif
94 
95 
108 GRASSROOTS_TASK_API AsyncTask *AllocateAsyncTask (const char *name_s, struct AsyncTasksManager *manager_p, bool add_flag);
109 
110 
119 
120 
135 GRASSROOTS_TASK_API bool InitialiseAsyncTask (AsyncTask *task_p, const char *name_s, struct AsyncTasksManager *manager_p, bool add_flag);
136 
137 
146 
147 
148 
149 
157 
158 
170 GRASSROOTS_TASK_API bool SetAsyncTaskSyncData (AsyncTask *task_p, SyncData *sync_data_p, MEM_FLAG mem);
171 
183 GRASSROOTS_TASK_API void SetAsyncTaskRunData (AsyncTask *task_p, void *(*run_fn) (void *data_p), void *data_p);
184 
185 
186 
196 
197 
207 
208 
216 
217 
228 
229 
237 
238 
249 
250 
258 
259 
260 
261 GRASSROOTS_TASK_API OperationStatus RunProcess (const char *const command_line_s);
262 
263 
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 
270 #endif /* CORE_SERVER_TASK_INCLUDE_ASYNC_TASK_H_ */
AsyncTask::RunAsyncTask
bool RunAsyncTask(AsyncTask *task_p)
Run an AsyncTask.
AsyncTask::AllocateAsyncTaskNode
AsyncTaskNode * AllocateAsyncTaskNode(AsyncTask *task_p, MEM_FLAG mem)
Create an AsyncTaskNode.
AsyncTask::at_sync_data_p
struct SyncData * at_sync_data_p
The SyncData used to coordinate data access between the AsyncTask and other processes.
Definition: async_task.h:34
MEM_FLAG
MEM_FLAG
An enum specifying the particular status of a piece of dynamically allocated memory for a particular ...
Definition: memory_allocations.h:38
grassroots_task_library.h
AsyncTask::SetAsyncTaskConsumer
void SetAsyncTaskConsumer(AsyncTask *task_p, EventConsumer *consumer_p, MEM_FLAG mem)
Set the EventConsumer for a given AsyncTask.
event_consumer.h
event_consumer.h
operation.h
sync_data.h
AsyncTask::FreeAsyncTaskNode
void FreeAsyncTaskNode(ListItem *node_p)
Free an AsyncTaskNode.
AsyncTask::SetAsyncTaskRunData
void SetAsyncTaskRunData(AsyncTask *task_p, void *(*run_fn)(void *data_p), void *data_p)
Set the callback function that an AsyncTask will call when it is ran.
AsyncTaskNode::atn_mem
MEM_FLAG atn_mem
The memory flag indicating what action to perform upon atn_task_p when this AsyncTaskNode is freed.
Definition: async_task.h:86
CloseAllAsyncTasks
bool CloseAllAsyncTasks(void)
Close all currently running AsyncTasks for the current process.
AsyncTask
A datatype to use to run tasks asynchronously.
Definition: async_task.h:25
typedefs.h
AsyncTask::at_consumer_mem
MEM_FLAG at_consumer_mem
The memory flag indicating the ownership of the EventConsumer.
Definition: async_task.h:58
AsyncTaskNode::atn_task_p
AsyncTask * atn_task_p
The AsyncTask to store on the list.
Definition: async_task.h:79
GRASSROOTS_TASK_API
#define GRASSROOTS_TASK_API
Definition: grassroots_task_library.h:46
AsyncTask::RunEventConsumerFromAsyncTask
void RunEventConsumerFromAsyncTask(AsyncTask *task_p)
Run the EventConsumer for the given AsyncTask.
AsyncTask::SetAsyncTaskSyncData
bool SetAsyncTaskSyncData(AsyncTask *task_p, SyncData *sync_data_p, MEM_FLAG mem)
Set the SyncData for an AsyncTask.
AsyncTaskNode
A datatype to allow storing AsynTasks on a LinkedList.
Definition: async_task.h:73
OperationStatus
OperationStatus
The current status of an Operation.
Definition: operation.h:96
AsyncTask::at_consumer_p
EventConsumer * at_consumer_p
An EventConsumer to notify when the AsyncTask has finished running.
Definition: async_task.h:55
AsyncTask::FreeAsyncTask
void FreeAsyncTask(AsyncTask *task_p)
Free an AsyncTask.
SyncData
A datatype that allows data to be shared between tasks (e.g.
Definition: linux_sync_data.h:30
AsyncTasksManager
A datatype for storing AsyncTasks in a collection.
Definition: async_tasks_manager.h:24
AsyncTask::ClearAsyncTask
void ClearAsyncTask(AsyncTask *task_p)
Clear an AsyncTask.
AsyncTask::InitialiseAsyncTask
bool InitialiseAsyncTask(AsyncTask *task_p, const char *name_s, struct AsyncTasksManager *manager_p, bool add_flag)
Initialise an AsyncTask.
EventConsumer
An EvenetConsumer is a datatype to allow an object to be notified when an AsyncTask has completed run...
Definition: event_consumer.h:44
AsyncTask::IsAsyncTaskRunning
bool IsAsyncTaskRunning(const AsyncTask *task_p)
Check whether an AsyncTask is currently running.
memory_allocations.h
linked_list.h
A doubly-linked list.
AsyncTask::at_sync_data_mem
MEM_FLAG at_sync_data_mem
The memory flag indicating the ownership of the SyncData.
Definition: async_task.h:37
AsyncTask::at_manager_p
struct AsyncTasksManager * at_manager_p
The AsyncTasksManager that has this AsyncTask.
Definition: async_task.h:65
AsyncTask::AllocateAsyncTask
AsyncTask * AllocateAsyncTask(const char *name_s, struct AsyncTasksManager *manager_p, bool add_flag)
Create an AsyncTask.
RunProcess
OperationStatus RunProcess(const char *const command_line_s)
AsyncTaskNode::atn_node
ListItem atn_node
The base list node.
Definition: async_task.h:76
AsyncTask::CloseAsyncTask
void CloseAsyncTask(AsyncTask *task_p)
Stop a the given AsyncTask if it is currently running.
AsyncTask::at_data_p
void * at_data_p
Any custom data that will be passed to at_fun_fn.
Definition: async_task.h:50
AsyncTask::at_name_s
char * at_name_s
The name of the AsyncTask.
Definition: async_task.h:28
ListItem
A doubly-linked node that points to its predecessor and successor.
Definition: linked_list.h:43