1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/* upstart
*
* Copyright © 2009 Canonical Ltd.
* Author: Scott James Remnant <scott@netsplit.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef INIT_EVENT_OPERATOR_H
#define INIT_EVENT_OPERATOR_H
#include <nih/macros.h>
#include <nih/tree.h>
#include "event.h"
/**
* EventOperatorType:
*
* This is used to distinguish between the different boolean behaviours of
* the EventOperator structure.
**/
typedef enum event_operator_type {
EVENT_OR,
EVENT_AND,
EVENT_MATCH
} EventOperatorType;
/**
* EventOperator:
* @node: tree node,
* @type: operator type,
* @value: operator value,
* @name: name of event to match (EVENT_MATCH only),
* @env: environment variables of event to match (EVENT_MATCH only),
* @event: event matched (EVENT_MATCH only).
*
* This structure is used to build up an event expression tree; the leaf
* nodes are all of EVENT_MATCH type which match a specific event, the other
* nodes are built up of EVENT_OR and EVENT_AND operators that combine the
* EventOperators to their left and right in interesting ways.
*
* @value indicates whether this operator is currently TRUE or FALSE.
* For EVENT_MATCH operators, a TRUE @value means that @event is set to
* the matched event; for EVENT_OR and EVENT_AND operators, @value is set
* depending on the value of both immediate children.
*
* Once an event has been matched, the @event member is set and a reference
* held until the structure is cleared.
**/
typedef struct event_operator {
NihTree node;
EventOperatorType type;
int value;
char *name;
char **env;
Event *event;
} EventOperator;
NIH_BEGIN_EXTERN
EventOperator *event_operator_new (const void *parent,
EventOperatorType type,
const char *name, char **env)
__attribute__ ((warn_unused_result));
EventOperator *event_operator_copy (const void *parent,
const EventOperator *old_oper)
__attribute__ ((warn_unused_result));
int event_operator_destroy (EventOperator *oper);
void event_operator_update (EventOperator *oper);
int event_operator_match (EventOperator *oper, Event *event,
char * const *env);
int event_operator_handle (EventOperator *root, Event *event,
char * const *env);
char ** event_operator_environment (EventOperator *root, char ***env,
const void *parent, size_t *len,
const char *key);
int *
event_operator_fds (EventOperator *root,
const void *parent,
int **fds,
size_t *num_fds,
char ***env,
size_t *len,
const char *key);
void event_operator_events (EventOperator *root,
const void *parent, NihList *list);
void event_operator_reset (EventOperator *root);
const char *
event_operator_type_enum_to_str (EventOperatorType type)
__attribute__ ((warn_unused_result));
EventOperatorType
event_operator_type_str_to_enum (const char *type)
__attribute__ ((warn_unused_result));
json_object *
event_operator_serialise (const EventOperator *oper)
__attribute__ ((warn_unused_result));
json_object *
event_operator_serialise_all (EventOperator *root)
__attribute__ ((warn_unused_result));
EventOperator *
event_operator_deserialise (void *parent, json_object *json)
__attribute__ ((warn_unused_result));
EventOperator *
event_operator_deserialise_all (void *parent, json_object *json)
__attribute__ ((warn_unused_result));
char *event_operator_collapse (EventOperator *condition)
__attribute__ ((warn_unused_result, unused));
NIH_END_EXTERN
#endif /* INIT_EVENT_OPERATOR_H */
|