yumapro  20.10-12
YumaPro SDK
agt_timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3  * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4  *
5  * Unless required by applicable law or agreed to in writing,
6  * software distributed under the License is distributed on an
7  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8  * KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations
10  * under the License.
11  */
12 #ifndef _H_agt_timer
13 #define _H_agt_timer
14 
15 /* FILE: agt_timer.h
16 *********************************************************************
17 * *
18 * P U R P O S E *
19 * *
20 *********************************************************************/
21 
28 /*********************************************************************
29 * *
30 * C H A N G E H I S T O R Y *
31 * *
32 *********************************************************************
33 
34 date init comment
35 ----------------------------------------------------------------------
36 23-jan-07 abb Begun
37 
38 */
39 
40 #include <time.h>
41 
42 #ifndef _H_dlq
43 #include "dlq.h"
44 #endif
45 
46 #ifndef _H_status
47 #include "status.h"
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
67 /********************************************************************
68 * *
69 * T Y P E S *
70 * *
71 *********************************************************************/
72 
85 typedef int (*agt_timer_fn_t) (uint32 timer_id,
86  void *cookie);
87 
88 
90 typedef struct agt_timer_cb_t_ {
92  dlq_hdr_t qhdr;
93 
95  boolean timer_periodic;
96 
98  uint32 timer_id;
99 
102 
105 
108 
111 } agt_timer_cb_t;
112 
113 
114 /********************************************************************
115 * *
116 * F U N C T I O N S *
117 * *
118 *********************************************************************/
119 
120 
126 extern void
127  agt_timer_init (void);
128 
129 
135 extern void
136  agt_timer_cleanup (void);
137 
138 
144 extern void
145  agt_timer_handler (void);
146 
147 
165 extern status_t
166  agt_timer_create (uint32 seconds,
167  boolean is_periodic,
168  agt_timer_fn_t timer_fn,
169  void *cookie,
170  uint32 *ret_timer_id);
171 
172 
184 extern status_t
185  agt_timer_restart (uint32 timer_id,
186  uint32 seconds);
187 
188 
198 extern void
199  agt_timer_delete (uint32 timer_id);
200 
201 
215 extern void
216  agt_timer_get_timenow (time_t *tnow);
217 
218 
238 extern void
239  agt_timer_get_centi_timenow (uint64 *tnow);
240 
241 
245 #ifdef __cplusplus
246 } /* end extern 'C' */
247 #endif
248 
249 #endif /* _H_agt_timer */
log_error
void log_error(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_ERROR log entry.
agt_timer_cleanup
void agt_timer_cleanup(void)
Cleanup the agt_timer module.
Definition: agt_timer.c:222
log_debug3
void void void void void void void void void void void log_debug3(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG3 log entry.
agt_timer_cb_t_::timer_cbfn
agt_timer_fn_t timer_cbfn
timer popped callback
Definition: agt_timer.h:101
agt_timer_cb_t_::timer_duration
uint32 timer_duration
timer duration in seconds, must be 1 - N
Definition: agt_timer.h:107
log_debug2
void void void void void void void void void log_debug2(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG2 log entry.
errno_to_status
status_t errno_to_status(void)
Get the errno variable and convert it to a status_t.
Definition: status.c:968
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
log_debug4
void void void void void void void void void void void void void log_debug4(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG4 log entry.
LOGDEBUG2
#define LOGDEBUG2
Check if at least log-level=debug2.
Definition: log.h:292
dlq_createSQue
void dlq_createSQue(dlq_hdrT *queAddr)
create a static queue header
Definition: dlq.c:177
log_warn
void void void log_warn(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_WARN log entry.
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
dlq_remove
void dlq_remove(void *nodeP)
remove the queue entry from its queue list entry MUST have been enqueued somehow before this function...
Definition: dlq.c:519
agt_timer_restart
status_t agt_timer_restart(uint32 timer_id, uint32 seconds)
Restart a timer with a new timeout value.
Definition: agt_timer.c:390
agt_timer_fn_t
int(* agt_timer_fn_t)(uint32 timer_id, void *cookie)
timer callback function
Definition: agt_timer.h:85
ERR_INTERNAL_MEM
@ ERR_INTERNAL_MEM
003
Definition: status_enum.h:193
get_error_string
const char * get_error_string(status_t res)
Get the error message for a specific internal error.
Definition: status.c:239
ERR_INTERNAL_PTR
@ ERR_INTERNAL_PTR
002
Definition: status_enum.h:192
dlq_nextEntry
#define dlq_nextEntry(nodeP)
get the next queue entry after the current entry
Definition: dlq.h:265
agt.h
Multi-Protocol Network Management Server.
ERR_NCX_RESOURCE_DENIED
@ ERR_NCX_RESOURCE_DENIED
269
Definition: status_enum.h:310
ERR_NCX_NOT_FOUND
@ ERR_NCX_NOT_FOUND
225
Definition: status_enum.h:264
agt_timer_handler
void agt_timer_handler(void)
Handle an incoming server timer polling interval.
Definition: agt_timer.c:245
LOGDEBUG4
#define LOGDEBUG4
Check if at least log-level=debug4.
Definition: log.h:302
log.h
NCX System Logging Manager.
agt_timer_cb_t_::timer_cookie
void * timer_cookie
timer cookie passed in timer registration
Definition: agt_timer.h:110
dlq_deque
void * dlq_deque(dlq_hdrT *listP)
remove the first queue node from the queue list
Definition: dlq.c:286
dlq_empty
#define dlq_empty(listP)
check if queue list is empty
Definition: dlq.h:367
agt_timer_delete
void agt_timer_delete(uint32 timer_id)
Remove and delete a timer control block.
Definition: agt_timer.c:426
agt_timer_get_timenow
void agt_timer_get_timenow(time_t *tnow)
Get the current time using the system or monotonic clock.
Definition: agt_timer.c:457
dlq_firstEntry
#define dlq_firstEntry(listP)
get the first entry in the queue list
Definition: dlq.h:337
ncx.h
YANG module utility functions.
agt_timer_cb_t_
Internal Timer control block, not for use outside agt_timer.c.
Definition: agt_timer.h:90
dlq_enque
void dlq_enque(REG void *newP, REG dlq_hdrT *listP)
add a queue node to the end of a queue list Add newP to listP
Definition: dlq.c:246
agt_timer_cb_t_::timer_periodic
boolean timer_periodic
TRUE if periodic timer, FALSE for 1-shot.
Definition: agt_timer.h:95
agt_timer.h
Handle timer services for the server.
SET_ERROR
#define SET_ERROR(E)
macro SET_ERROR
Definition: status_enum.h:103
agt_timer_cb_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: agt_timer.h:92
agt_timer_get_centi_timenow
void agt_timer_get_centi_timenow(uint64 *tnow)
Get the current time using the system or monotonic clock.
Definition: agt_timer.c:514
agt_timer_cb_t_::timer_start_time
time_t timer_start_time
save timestamp last timer start
Definition: agt_timer.h:104
status.h
Global error messages for status code enumerations.
dlq.h
dlq provides general double-linked list and queue support:
agt_timer_cb_t_::timer_id
uint32 timer_id
assigned timer ID
Definition: agt_timer.h:98
agt_timer_create
status_t agt_timer_create(uint32 seconds, boolean is_periodic, agt_timer_fn_t timer_fn, void *cookie, uint32 *ret_timer_id)
Malloc and start a new timer control block.
Definition: agt_timer.c:327
LOGDEBUG3
#define LOGDEBUG3
Check if at least log-level=debug3.
Definition: log.h:297
agt_timer_init
void agt_timer_init(void)
Initialize the agt_timer module.
Definition: agt_timer.c:199