Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

handler.h

Go to the documentation of this file.
00001 
00002 /*
00003 ** Copyright (C) 2004 Russell Leighton
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 
00021 
00022 #ifndef __AWHANDLER__
00023 #define __AWHANDLER__
00024 
00025 #include "alarm.h"
00026 
00027 /* do not include this directly, included in monitor.h */
00028 
00038 typedef u_int32_t aw_handlerid_t;
00039 
00043 typedef struct {
00044 
00045   struct aw_handler_s *h;             /* this handler */
00046 
00047   aw_timestamp_t currenttime;         /* now */
00048 
00049   aw_timestamp_t starttime;           /* when monitor started */
00050 
00051   aw_event_q_t *in_q;                 /* events dispatched to this handler */
00052 
00053   aw_event_q_t *out_q;                /* events generated from this handler to be dispatched to other handlers */
00054 
00055   aw_cache_allocator_t *ef;           /* event factory to create/free events */
00056 
00057   byte_t *desc;                     /* text string, may be NULL */
00058 
00059   struct aw_monitor_s *mon;           /* monitor */
00060 
00061 } aw_handler_args_t;
00062 
00072 typedef enum {
00073   AW_HANDLER_OK,                 /* handler method ok, must be 1st! */
00074   AW_HANDLER_REMOVE,             /* handler method wants to be removed from monitor  */
00075   AW_HANDLER_RUNNING,            /* handler is currently running (perhaps in a tasklet thread) */
00076   AW_HANDLER_STOPPED,            /* handler is finished running */
00077   AW_HANDLER_NCODES              /* must be last! */
00078 } aw_handler_code_t;
00079 
00080 
00084 typedef struct {
00085 
00086   /* the run schedule for alarm */
00087   aw_alarm_sched_t
00088    sched;
00089 
00090   /* the alarm for scheduled actions */
00091   aw_alarm_t
00092    *alarm;
00093 
00094   /* reflects current state */
00095   aw_handler_code_t
00096    status;
00097 
00098   /* my id */
00099   aw_handlerid_t
00100    id;
00101 
00102   /* ptr to my handler_q */
00103   struct aw_handler_q_s
00104    *handler_q;
00105 
00106   /* count of registered fd callbacks */
00107   u_int32_t
00108    fd_refcount;
00109 
00110   /* count of registered ire callbacks */
00111   u_int32_t
00112    ire_refcount;
00113 
00114   /* holds any generated events */
00115   aw_event_q_t
00116    q;
00117 
00118 } aw_handler_state_t;
00119 
00123 typedef struct {
00124 
00125   aw_event_sig_t
00126    start,              /* handler started */
00127    stop;               /* handler stopped */
00128 
00129 } aw_handler_events_t;
00130 
00134 typedef struct aw_handler_s {
00135 
00136   /* internal state */
00137   aw_handler_state_t
00138    state;
00139 
00140   /* if non-zero means run as tasklet */
00141   u_int32_t
00142    tasklet;
00143 
00144   /* if non-zero means wait to process events on xaction signal */
00145   int32_t
00146    wait;
00147 
00148   /* each time the handler is run, should be assigned a new xactionid */
00149   u_int32_t
00150    xactionid;
00151 
00152   /* logger for warning/error messages */
00153   aw_logger_t
00154    *logger;
00155 
00156   /* generic events generated */
00157   aw_handler_events_t
00158    events;
00159 
00160   /* applications can use as back pointer/tag */
00161   union {
00162     void *ptr;
00163     int32_t tag;
00164   } user;
00165 
00166   /* 
00167      called when monitor is started , before start()
00168      to register recieving events of a particular id.
00169 
00170      this function should fill the <eventid> with
00171      the address of an event of interest and return
00172      non-zero.
00173 
00174      it should return 0 when done.
00175 
00176      the monitor will call this repeatedly, setting
00177      <index> to zero initialliy and incrementing it
00178      each time until zero is returned from the function
00179      
00180    */
00181   int32_t (*regevent)(struct aw_handler_s *h, aw_address_t *eventid, u_int32_t index);
00182 
00183   /* 
00184      called when monitor is started , before start()
00185      to register recieving events that *match* a 
00186      mask. Eventids are said to *match* if:
00187           (mask & eventid) == mask
00188 
00189      this function should fill the <maskid> with
00190      the address of an event of interest and return
00191      non-zero.
00192 
00193      it should return 0 when done.
00194 
00195      the monitor will call this repeatedly, setting
00196      <index> to zero initialliy and incrementing it
00197      each time until zero is returned from the function
00198      
00199    */
00200   int32_t (*regmaskevent)(struct aw_handler_s *h, aw_address_t *eventmask, u_int32_t index);
00201 
00202   /* called when monitor is started, may be NULL */
00203   aw_handler_code_t (*start)(struct aw_monitor_s *mon, struct aw_handler_s *h);
00204 
00205   /* called when monitor is stopped, may be NULL */
00206   aw_handler_code_t (*stop)(struct aw_monitor_s *mon, struct aw_handler_s *h);
00207 
00208   /* called when handler is removed from monitor, may be NULL */
00209   aw_handler_code_t (*postremove)(struct aw_monitor_s *mon, struct aw_handler_s *handler);
00210 
00211   /* does the event handling, likely add events to q (for self) or to hq (TO BE dispatched to handlers), may be NULL  */
00212   aw_handler_code_t (*handle)(aw_handler_args_t *args);
00213 
00214 } aw_handler_t;
00215 
00216 
00224 void aw_handler_append_outq(aw_event_t *e, aw_event_t *te, aw_handler_args_t *args);
00225 
00234 void aw_handler_int32_event(aw_handler_args_t *args, aw_event_t *trigger_event, aw_event_sig_t *event_sig, u_int32_t val);
00235 
00244 void aw_handler_int64_event(aw_handler_args_t *args, aw_event_t *trigger_event, aw_event_sig_t *event_sig, u_int64_t val);
00245 
00246 
00255 void aw_handler_float32_event(aw_handler_args_t *args, aw_event_t *trigger_event, aw_event_sig_t *event_sig, float32_t val);
00256 
00265 void aw_handler_float64_event(aw_handler_args_t *args, aw_event_t *trigger_event, aw_event_sig_t *event_sig, float64_t val);
00266 
00267 
00268 
00277 void aw_handler_timestamp_event(aw_handler_args_t *args, aw_event_t *trigger_event, aw_event_sig_t *event_sig, aw_timestamp_t val);
00278 
00279 
00289 void aw_handler_string_event(aw_handler_args_t *args, aw_event_t *trigger_event, aw_event_sig_t *event_sig, byte_t *val, int32_t dup);
00290 
00291 #endif
00292 
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)