update to 9.7.1-P2
[tridge/bind9.git] / lib / isc / include / isc / timer.h
index a4b2df7a54b06bb4837808513339b18ac3b1a74b..fa9abb16aa9d56a455cdc748700ab61b78a17997 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (C) 2004-2009  Internet Systems Consortium, Inc. ("ISC")
  * Copyright (C) 1998-2002  Internet Software Consortium.
  *
  * Permission to use, copy, modify, and/or distribute this software for any
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: timer.h,v 1.40 2008/06/23 23:47:11 tbox Exp $ */
+/* $Id: timer.h,v 1.43 2009/09/02 23:48:03 tbox Exp $ */
 
 #ifndef ISC_TIMER_H
 #define ISC_TIMER_H 1
@@ -103,6 +103,61 @@ typedef struct isc_timerevent {
 #define ISC_TIMEREVENT_LIFE            (ISC_EVENTCLASS_TIMER + 3)
 #define ISC_TIMEREVENT_LASTEVENT       (ISC_EVENTCLASS_TIMER + 65535)
 
+/*% Timer and timer manager methods */
+typedef struct {
+       void            (*destroy)(isc_timermgr_t **managerp);
+       isc_result_t    (*timercreate)(isc_timermgr_t *manager,
+                                      isc_timertype_t type,
+                                      isc_time_t *expires,
+                                      isc_interval_t *interval,
+                                      isc_task_t *task,
+                                      isc_taskaction_t action,
+                                      const void *arg,
+                                      isc_timer_t **timerp);
+} isc_timermgrmethods_t;
+
+typedef struct {
+       void            (*attach)(isc_timer_t *timer, isc_timer_t **timerp);
+       void            (*detach)(isc_timer_t **timerp);
+       isc_result_t    (*reset)(isc_timer_t *timer, isc_timertype_t type,
+                                isc_time_t *expires, isc_interval_t *interval,
+                                isc_boolean_t purge);
+       isc_result_t    (*touch)(isc_timer_t *timer);
+} isc_timermethods_t;
+
+/*%
+ * This structure is actually just the common prefix of a timer manager
+ * object implementation's version of an isc_timermgr_t.
+ * \brief
+ * Direct use of this structure by clients is forbidden.  timer implementations
+ * may change the structure.  'magic' must be ISCAPI_TIMERMGR_MAGIC for any
+ * of the isc_timer_ routines to work.  timer implementations must maintain
+ * all timer invariants.
+ */
+struct isc_timermgr {
+       unsigned int            impmagic;
+       unsigned int            magic;
+       isc_timermgrmethods_t   *methods;
+};
+
+#define ISCAPI_TIMERMGR_MAGIC          ISC_MAGIC('A','t','m','g')
+#define ISCAPI_TIMERMGR_VALID(m)       ((m) != NULL && \
+                                        (m)->magic == ISCAPI_TIMERMGR_MAGIC)
+
+/*%
+ * This is the common prefix of a timer object.  The same note as
+ * that for the timermgr structure applies.
+ */
+struct isc_timer {
+       unsigned int            impmagic;
+       unsigned int            magic;
+       isc_timermethods_t      *methods;
+};
+
+#define ISCAPI_TIMER_MAGIC     ISC_MAGIC('A','t','m','r')
+#define ISCAPI_TIMER_VALID(s)  ((s) != NULL && \
+                                (s)->magic == ISCAPI_TIMER_MAGIC)
+
 /***
  *** Timer and Timer Manager Functions
  ***
@@ -288,10 +343,15 @@ isc_timer_gettype(isc_timer_t *timer);
  *\li  'timer' to be a valid timer.
  */
 
+isc_result_t
+isc_timermgr_createinctx(isc_mem_t *mctx, isc_appctx_t *actx,
+                        isc_timermgr_t **managerp);
+
 isc_result_t
 isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp);
 /*%<
- * Create a timer manager.
+ * Create a timer manager.  isc_timermgr_createinctx() also associates
+ * the new manager with the specified application context.
  *
  * Notes:
  *
@@ -303,6 +363,8 @@ isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp);
  *
  *\li  'managerp' points to a NULL isc_timermgr_t.
  *
+ *\li  'actx' is a valid application context (for createinctx()).
+ *
  * Ensures:
  *
  *\li  '*managerp' is a valid isc_timermgr_t.
@@ -339,6 +401,31 @@ isc_timermgr_destroy(isc_timermgr_t **managerp);
 
 void isc_timermgr_poke(isc_timermgr_t *m);
 
+#ifdef USE_TIMERIMPREGISTER
+/*%<
+ * See isc_timermgr_create() above.
+ */
+typedef isc_result_t
+(*isc_timermgrcreatefunc_t)(isc_mem_t *mctx, isc_timermgr_t **managerp);
+
+isc_result_t
+isc__timer_register(void);
+/*%<
+ * Register a new timer management implementation and add it to the list of
+ * supported implementations.  This function must be called when a different
+ * event library is used than the one contained in the ISC library.
+ */
+
+isc_result_t
+isc_timer_register(isc_timermgrcreatefunc_t createfunc);
+/*%<
+ * A short cut function that specifies the timer management module in the ISC
+ * library for isc_timer_register().  An application that uses the ISC library
+ * usually do not have to care about this function: it would call
+ * isc_lib_register(), which internally calls this function.
+ */
+#endif /* USE_TIMERIMPREGISTER */
+
 ISC_LANG_ENDDECLS
 
 #endif /* ISC_TIMER_H */