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

execphandler.h

Go to the documentation of this file.
00001 
00002 /*
00003 ** Copyright (C) 2002 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_EXECP__
00023 #define __AWHANDLER_EXECP__
00024 
00025 #include <stdio.h>
00026 
00027 #include "monitor.h"
00028 #include "wire.h"
00029 
00030 #include "regexmatch.h"
00031 
00033 /*\@{*/
00034 
00194 /* 
00195 Changes:
00196 
00197 3/20/02 Russell Leighton
00198 Added macro substition to the subst on regex
00199 
00200 3/20/02 Russell Leighton
00201 Added an optional 'complete' event that is generated with the command completes.
00202 
00203 3/20/02 Russell Leighton
00204 Added regex matching on output.
00205 
00206 3/20/02 Russell Leighton
00207 Switched from popen() to execvp method inside tasklet
00208 
00209 */
00210 
00214 typedef struct {
00215 
00216   aw_event_sig_t
00217    complete;                  /* execp went off */
00218 
00219 } aw_execphandler_events_t;
00220 
00224 typedef struct {
00225 
00226   aw_event_sig_t
00227    match,                    /* regex matched */
00228    nomatch;                  /* regex did NOT match */
00229 
00230 } aw_execphandler_revents_t;
00231 
00235 typedef struct {
00236 
00237   /* array 1-1 with the watchers, each val marks
00238      if a match occured during the handle, could be a bitmap, but I am being lazy */
00239   u_int32_t
00240    *match_markers;
00241 
00242 } aw_execphandler_state_t;
00243 
00247 typedef struct {
00248 
00249   aw_execphandler_revents_t
00250     revents;
00251 
00252   /* regex string */
00253   const byte_t
00254    *regex;
00255 
00256   /* holds substitution string, may be NULL */
00257   const byte_t
00258    *subst;
00259 
00260 } aw_execphandler_regex_t;
00261 
00265 typedef struct {
00266 
00267   aw_execphandler_revents_t
00268     revents;
00269 
00270   /* holds compiled regular expression  */
00271   regex_t
00272    pattern;
00273 
00274   /* holds substitution string, may be NULL */
00275   byte_t
00276    *subst;
00277 
00278 } aw_execphandler_watcher_t;
00279 
00280 
00284 typedef struct {
00285 
00286   aw_handler_t
00287    handler_header;
00288 
00289   aw_execphandler_state_t
00290    state;
00291 
00292   /* how long to wait, ... 0 means no timeout */
00293   aw_timestamp_t
00294    timeout;
00295 
00296   u_int32_t
00297    max_line_len;
00298 
00299   byte_t
00300    *line;
00301 
00302   byte_t
00303    *input;
00304 
00305   /* cmd */
00306   byte_t
00307    *cmd;
00308 
00309   aw_execphandler_events_t
00310    events;
00311 
00312   u_int32_t
00313    nwatchers;
00314 
00315   aw_execphandler_watcher_t
00316    *watchers;
00317 
00318 } aw_execphandler_t;
00319 
00335 aw_execphandler_t *aw_create_execphandler(const byte_t *cmd,
00336                                           const byte_t *input,
00337                                           u_int32_t max_line_len,
00338                                           u_int32_t timeout,
00339                                           const aw_execphandler_events_t *events,
00340                                           u_int32_t nregexs,
00341                                           const aw_execphandler_regex_t *regexs,  
00342                                           int32_t (*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00343                                           int32_t (*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00344                                           const aw_alarm_sched_t *sched,
00345                                           aw_logger_t *aware_logger);
00346 
00347 
00352 void aw_free_execphandler(aw_execphandler_t *h);
00353 
00354 
00355 
00359 aw_handler_t *aw_wire_execphandler(aw_wire_mkhandler_args_t *args);
00360 
00361 /*\@}*/
00362 
00363 #endif
00364 
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)