00001 /* 00002 * Copyright 2008-2010 Arsen Chaloyan 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 * $Id: apt_poller_task.h 1822 2011-12-22 00:37:45Z achaloyan $ 00017 */ 00018 00019 #ifndef APT_POLLER_TASK_H 00020 #define APT_POLLER_TASK_H 00021 00022 /** 00023 * @file apt_poller_task.h 00024 * @brief Poller Task 00025 */ 00026 00027 #include "apt_pollset.h" 00028 #include "apt_task.h" 00029 #include "apt_timer_queue.h" 00030 00031 APT_BEGIN_EXTERN_C 00032 00033 /** Opaque poller task declaration */ 00034 typedef struct apt_poller_task_t apt_poller_task_t; 00035 00036 /** Function prototype to handle signalled descripors */ 00037 typedef apt_bool_t (*apt_poll_signal_f)(void *obj, const apr_pollfd_t *descriptor); 00038 00039 00040 /** 00041 * Create poller task. 00042 * @param max_pollset_size the maximum number of descriptors pollset can hold 00043 * @param signal_handler the handler of signalled descriptors 00044 * @param obj the external object to pass to callback 00045 * @param msg_pool the pool of task messages 00046 * @param pool the pool to allocate memory from 00047 */ 00048 APT_DECLARE(apt_poller_task_t*) apt_poller_task_create( 00049 apr_size_t max_pollset_size, 00050 apt_poll_signal_f signal_handler, 00051 void *obj, 00052 apt_task_msg_pool_t *msg_pool, 00053 apr_pool_t *pool); 00054 00055 /** 00056 * Destroy poller task. 00057 * @param task the task to destroy 00058 */ 00059 APT_DECLARE(apt_bool_t) apt_poller_task_destroy(apt_poller_task_t *task); 00060 00061 /** 00062 * Cleanup poller task. 00063 * @param task the task to cleanup 00064 * 00065 * @remark This function should be considered in protected scope. 00066 * It will be called on task destroy unless you override the behavior. 00067 */ 00068 APT_DECLARE(void) apt_poller_task_cleanup(apt_poller_task_t *task); 00069 00070 /** 00071 * Start poller task and wait for incoming messages. 00072 * @param task the task to start 00073 */ 00074 APT_DECLARE(apt_bool_t) apt_poller_task_start(apt_poller_task_t *task); 00075 00076 /** 00077 * Terminate poller task. 00078 * @param task the task to terminate 00079 */ 00080 APT_DECLARE(apt_bool_t) apt_poller_task_terminate(apt_poller_task_t *task); 00081 00082 /** 00083 * Get task base. 00084 * @param task the poller task to get task base from 00085 */ 00086 APT_DECLARE(apt_task_t*) apt_poller_task_base_get(const apt_poller_task_t *task); 00087 00088 /** 00089 * Get task vtable. 00090 * @param task the poller task to get vtable from 00091 */ 00092 APT_DECLARE(apt_task_vtable_t*) apt_poller_task_vtable_get(apt_poller_task_t *task); 00093 00094 /** 00095 * Get external object. 00096 * @param task the poller task to get object from 00097 */ 00098 APT_DECLARE(void*) apt_poller_task_object_get(const apt_poller_task_t *task); 00099 00100 /** 00101 * Add descriptor to pollset. 00102 * @param task the task which holds the pollset 00103 * @param descriptor the descriptor to add 00104 */ 00105 APT_DECLARE(apt_bool_t) apt_poller_task_descriptor_add(const apt_poller_task_t *task, const apr_pollfd_t *descriptor); 00106 00107 /** 00108 * Remove descriptor from pollset. 00109 * @param task the task which holds the pollset 00110 * @param descriptor the descriptor to remove 00111 */ 00112 APT_DECLARE(apt_bool_t) apt_poller_task_descriptor_remove(const apt_poller_task_t *task, const apr_pollfd_t *descriptor); 00113 00114 /** 00115 * Create timer. 00116 * @param task the poller task to create timer in the scope of 00117 * @param proc the timer callback 00118 * @param obj the object to pass to callback 00119 * @param pool the pool to allocate memory from 00120 */ 00121 APT_DECLARE(apt_timer_t*) apt_poller_task_timer_create( 00122 apt_poller_task_t *task, 00123 apt_timer_proc_f proc, 00124 void *obj, 00125 apr_pool_t *pool); 00126 00127 00128 APT_END_EXTERN_C 00129 00130 #endif /* APT_POLLER_TASK_H */