UniMRCP  1.7.0
apt_task.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef APT_TASK_H
18 #define APT_TASK_H
19 
20 /**
21  * @file apt_task.h
22  * @brief Thread Execution Abstraction
23  */
24 
25 #include "apt.h"
26 #include "apt_task_msg.h"
27 
29 
30 /** Opaque task declaration */
31 typedef struct apt_task_t apt_task_t;
32 /** Opaque task virtual table declaration */
34 /** Opaque task method declaration */
36 /** Opaque task event declaration */
37 typedef void (*apt_task_event_f)(apt_task_t *task);
38 
39 
40 /**
41  * Create task.
42  * @param obj the external object to associate with the task
43  * @param msg_pool the pool of task messages
44  * @param pool the pool to allocate memory from
45  */
47  void *obj,
48  apt_task_msg_pool_t *msg_pool,
49  apr_pool_t *pool);
50 
51 /**
52  * Destroy task.
53  * @param task the task to destroy
54  */
56 
57 /**
58  * Add child task.
59  * @param task the task to add child task to
60  * @param child_task the child task to add
61  */
63 
64 /**
65  * Start task.
66  * @param task the task to start
67  */
69 
70 /**
71  * Take task offline.
72  * @param task the task to take offline
73  */
75 
76 /**
77  * Bring task online.
78  * @param task the task to bring online
79  */
81 
82 /**
83  * Terminate task.
84  * @param task the task to terminate
85  * @param wait_till_complete whether to wait for task to complete or
86  * process termination asynchronously
87  */
89 
90 /**
91  * Wait for task till complete.
92  * @param task the task to wait for
93  */
95 
96 /**
97  * Get (acquire) task message.
98  * @param task the task to get task message from
99  */
101 
102 /**
103  * Signal (post) message to the task.
104  * @param task the task to signal message to
105  * @param msg the message to signal
106  */
108 
109 /**
110  * Signal (post) message to the parent of the specified task.
111  * @param task the task to signal message to
112  * @param msg the message to signal
113  */
115 
116 /**
117  * Process message signaled to the task.
118  * @param task the task to process message
119  * @param msg the message to process
120  */
122 
123 /**
124  * Process task start request.
125  * @param task the task being started
126  */
128 
129 /**
130  * Process task termination request.
131  * @param task the task being terminated
132  */
134 
135 
136 /**
137  * Get parent (master) task.
138  * @param task the task to get parent from
139  */
141 
142 /**
143  * Get memory pool associated with task.
144  * @param task the task to get pool from
145  */
146 APT_DECLARE(apr_pool_t*) apt_task_pool_get(const apt_task_t *task);
147 
148 /**
149  * Get external object associated with the task.
150  * @param task the task to get object from
151  */
152 APT_DECLARE(void*) apt_task_object_get(const apt_task_t *task);
153 
154 /**
155  * Get task vtable.
156  * @param task the task to get vtable from
157  */
159 
160 /**
161  * Give a name to the task.
162  * @param task the task to give name for
163  * @param name the name to set
164  */
165 APT_DECLARE(void) apt_task_name_set(apt_task_t *task, const char *name);
166 
167 /**
168  * Get task name.
169  * @param task the task to get name from
170  */
171 APT_DECLARE(const char*) apt_task_name_get(const apt_task_t *task);
172 
173 /**
174  * Enable/disable auto ready mode.
175  * @param task the task to set mode for
176  * @param auto_ready the enabled/disabled auto ready mode
177  */
179 
180 /**
181  * Explicitly indicate task is ready to process messages.
182  * @param task the task
183  */
185 
186 /**
187  * Get the running flag.
188  * @param task the task
189  */
191 
192 /**
193  * Add start request.
194  * @param task the task
195  */
197 
198 /**
199  * Remove start request.
200  * @param task the task
201  */
203 
204 /**
205  * Add termination request.
206  * @param task the task
207  */
209 
210 /**
211  * Remove termination request.
212  * @param task the task
213  */
215 
216 /**
217  * Hold task execution.
218  * @param msec the time to hold
219  */
220 APT_DECLARE(void) apt_task_delay(apr_size_t msec);
221 
222 
223 /** Table of task virtual methods */
225  /** Virtual destroy method */
227  /** Virtual start method*/
229  /** Virtual terminate method */
231  /** Virtual run method*/
233 
234  /** Virtual signal_msg method */
236  /** Virtual process_msg method */
238 
239  /** Virtual process_start method */
241  /** Virtual process_terminate method */
243 
244  /** Virtual pre-run event handler */
246  /** Virtual post-run event handler */
248  /** Virtual start-complete event handler */
250  /** Virtual terminate-complete event handler */
252  /** Virtual take-offline-complete event handler */
254  /** Virtual bring-online-complete event handler */
256 };
257 
259 
260 #endif /* APT_TASK_H */
apt_task_t * apt_task_create(void *obj, apt_task_msg_pool_t *msg_pool, apr_pool_t *pool)
apt_bool_t * apt_task_running_flag_get(apt_task_t *task)
Definition: apt_task_msg.h:53
apt_bool_t apt_task_terminate(apt_task_t *task, apt_bool_t wait_till_complete)
void(* apt_task_event_f)(apt_task_t *task)
Definition: apt_task.h:37
apt_task_vtable_t * apt_task_vtable_get(apt_task_t *task)
apt_task_event_f on_post_run
Definition: apt_task.h:247
void * apt_task_object_get(const apt_task_t *task)
void apt_task_auto_ready_set(apt_task_t *task, apt_bool_t auto_ready)
apt_bool_t apt_task_msg_signal(apt_task_t *task, apt_task_msg_t *msg)
apt_bool_t apt_task_terminate_request_process(apt_task_t *task)
apt_bool_t apt_task_wait_till_complete(apt_task_t *task)
#define APT_END_EXTERN_C
Definition: apt.h:38
apt_task_method_f terminate
Definition: apt_task.h:230
apt_bool_t apt_task_terminate_request_remove(apt_task_t *task)
int apt_bool_t
Definition: apt.h:57
apt_bool_t apt_task_offline(apt_task_t *task)
apt_bool_t apt_task_ready(apt_task_t *task)
apt_bool_t apt_task_start_request_process(apt_task_t *task)
apt_task_msg_t * apt_task_msg_get(apt_task_t *task)
Task Message Base Definition.
apt_task_event_f on_online_complete
Definition: apt_task.h:255
apt_bool_t(* process_start)(apt_task_t *task)
Definition: apt_task.h:240
apt_task_event_f on_start_complete
Definition: apt_task.h:249
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
apt_task_method_f destroy
Definition: apt_task.h:226
#define APT_DECLARE(type)
Definition: apt.h:53
apt_bool_t apt_task_start_request_add(apt_task_t *task)
APR Toolkit Definitions.
apt_bool_t(* signal_msg)(apt_task_t *task, apt_task_msg_t *msg)
Definition: apt_task.h:235
apt_task_event_f on_pre_run
Definition: apt_task.h:245
const char * apt_task_name_get(const apt_task_t *task)
apt_bool_t apt_task_start(apt_task_t *task)
apt_bool_t apt_task_add(apt_task_t *task, apt_task_t *child_task)
apt_task_event_f on_terminate_complete
Definition: apt_task.h:251
apt_bool_t(* process_msg)(apt_task_t *task, apt_task_msg_t *msg)
Definition: apt_task.h:237
apt_bool_t(* process_terminate)(apt_task_t *task)
Definition: apt_task.h:242
typedefAPT_BEGIN_EXTERN_C struct apt_task_t apt_task_t
Definition: apt_task.h:31
apt_bool_t(* apt_task_method_f)(apt_task_t *task)
Definition: apt_task.h:35
apt_bool_t apt_task_online(apt_task_t *task)
apt_bool_t apt_task_destroy(apt_task_t *task)
void apt_task_name_set(apt_task_t *task, const char *name)
apt_task_method_f run
Definition: apt_task.h:232
apt_bool_t apt_task_msg_process(apt_task_t *task, apt_task_msg_t *msg)
apr_pool_t * apt_task_pool_get(const apt_task_t *task)
Definition: apt_task.h:224
struct apt_task_msg_pool_t apt_task_msg_pool_t
Definition: apt_task_msg.h:50
apt_task_event_f on_offline_complete
Definition: apt_task.h:253
void apt_task_delay(apr_size_t msec)
apt_task_t * apt_task_parent_get(const apt_task_t *task)
apt_task_method_f start
Definition: apt_task.h:228
apt_bool_t apt_task_start_request_remove(apt_task_t *task)
apt_bool_t apt_task_terminate_request_add(apt_task_t *task)
apt_bool_t apt_task_msg_parent_signal(apt_task_t *task, apt_task_msg_t *msg)