c75d01fc4c709b52e0a1a2afe3d06010c475baa4
[metze/wireshark/wip.git] / conditions.h
1 /* conditions.h
2  * Header for condition handler.
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #ifndef CONDITIONS_H
24 #define CONDITIONS_H
25
26 #include <stdarg.h>
27
28 #include <glib.h>
29
30 /* forward declaration for type 'condition' */
31 typedef struct condition condition;
32
33 /* condition evaluation handler type */
34 typedef gboolean (*_cnd_eval)(condition *, va_list);
35
36 /* condition reset handler type */
37 typedef void (*_cnd_reset)(condition *);
38
39 /* condition class constructor type */
40 typedef condition *(*_cnd_constr)(condition *, va_list);
41
42 /* condition class destructor type */
43 typedef void (*_cnd_destr)(condition *);
44
45 /*
46  * Conditions must be created with this function. They can be created for
47  * registered classes only.
48  *
49  * parameter: const char * - Identification of a registered condition class.
50  *            ...          - Any number of class specific initial values.
51  * returns:   Pointer to a initialized condition of the particular class on
52  *            success or NULL on failure.
53  */
54 condition *cnd_new(const char *, ...);
55
56 /*
57  * Conditions must be deleted with this function when not used anymore.
58  *
59  * parameter: condition * - Pointer to a condition created with 'cnd_new()'.
60  * returns:   -
61  */
62 void cnd_delete(condition *);
63
64 /*
65  * Call this function to check whether or not a particular condition is true.
66  *
67  * parameter: condition * - Pointer to an initialized condition.
68  *            ...         - Any number of condition specific arguments.
69  * returns:   TRUE  - Condition is true.
70  *            FALSE - Condition is false.
71  */
72 gboolean cnd_eval(condition *, ...);
73
74 /*
75  * Call this function to reset this condition to its initial state, i.e. the
76  * state it was in right after creation.
77  *
78  * parameter: condition * - Pointer to an initialized condition.
79  * returns:   -
80  */
81 void cnd_reset(condition *);
82
83 /*
84  * Register a new conditon class.
85  * New conditions of this class can be created by calling 'cnd_new()' and
86  * supplying the appropriate class id.
87  *
88  * parameter: const char * - The class id.
89  *            _cnd_constr  - User supplied constructor function for this
90  *                           class.
91  *            _cnd_destr   - User supplied destructor function for this
92  *                           class.
93  *            _cnd_eval    - User supplied evaluation handler function for this
94                              class.
95  *            _cnd_reset   - User supplied reset handler for this class.
96  * returns:   TRUE  - Success.
97  *            FALSE - Failure.
98  */
99 gboolean cnd_register_class(const char *,
100                             _cnd_constr,
101                             _cnd_destr,
102                             _cnd_eval,
103                             _cnd_reset);
104
105 /*
106  * Unregister a previously registered conditon class. After unregistration
107  * of a class it is no longer possible to create conditions of this kind by
108  * calling 'cnd_new()'.
109  *
110  * parameter: const char * - An identification for this condition class.
111  * returns:   -
112  */
113 void cnd_unregister_class(const char *);
114
115 /*
116  * This function returns the user data of the condition.
117  *
118  * parameter: condition * - Pointer to an initialized condition.
119  * returns:   void *      - Pointer to user data of this condition.
120  */
121 void* cnd_get_user_data(condition*);
122
123 /*
124  * This function sets the user data of the condition.
125  *
126  * parameter: condition * - Pointer to an initialized condition.
127  *            void *      - Pointer to user specified data structure.
128  * returns:   -
129  */
130 void cnd_set_user_data(condition *, void *);
131
132 #endif /* CONDITIONS_H */