event.h 9.16 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1 2
/*
 * EMULAB-COPYRIGHT
3
 * Copyright (c) 2000-2004 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
4 5 6
 * All rights reserved.
 */

Ian Murdock's avatar
Ian Murdock committed
7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * event.h --
 *
 *      Definitions for the testbed event library.
 *
 */

#ifndef __EVENT_H__
#define __EVENT_H__

#include <stdio.h>
#include <elvin/elvin.h>

Ian Murdock's avatar
Ian Murdock committed
20 21 22 23
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif /* MAXHOSTNAMELEN */

Ian Murdock's avatar
Ian Murdock committed
24 25 26 27
/* Handle to the event server: */
struct event_handle {
    elvin_handle_t server;
    elvin_error_t status;
28 29
    unsigned char *keydata;
    int keylen;
30 31 32 33 34 35 36 37 38 39 40 41 42
    /* API function pointers: */
    elvin_error_t (*init)(void);
    int (*connect)(elvin_handle_t handle, elvin_error_t error);
    int (*disconnect)(elvin_handle_t handle, elvin_error_t error);
    int (*cleanup)(int force, elvin_error_t error);
    int (*mainloop)(int *do_loop, elvin_error_t error);
    int (*notify)(elvin_handle_t handle, elvin_notification_t notification,
                  int deliver_insecure, elvin_keys_t keys,
                  elvin_error_t error);
    elvin_subscription_t (*subscribe)(elvin_handle_t handle, char *sub_exp,
                                      elvin_keys_t keys, int accept_insecure,
                                      elvin_notify_cb_t callback, void *rock,
                                      elvin_error_t error);
Ian Murdock's avatar
Ian Murdock committed
43 44 45 46
};
typedef struct event_handle * event_handle_t;

/* Event notification: */
47 48 49 50 51 52
struct event_notification {
	elvin_notification_t elvin_notification;
	int		     has_hmac;
	
};
typedef struct event_notification *event_notification_t;
Ian Murdock's avatar
Ian Murdock committed
53 54 55 56

/* Event subscription: */
typedef elvin_subscription_t event_subscription_t;

57 58 59 60
/*
 * A tuple defines the target of the event, or if you are a subscriber,
 * what events you want to subscribe to.
 */
61
typedef struct _address_tuple {
62 63 64 65 66 67 68 69 70 71 72 73
	char		*site;		/* Which Emulab site. God only */
	char		*expt;		/* Project and experiment IDs */
	char		*group;		/* User defined group of nodes */
	char		*host;		/* A specific host */		
	char		*objtype;	/* LINK, TRAFGEN, etc ... */
        char		*objname;	/* link0, cbr0, cbr1, etc ... */
        char		*eventtype;	/* START, STOP, UP, DOWN, etc ... */
	int		scheduler;	/* A dynamic event to schedule */
} address_tuple, *address_tuple_t;
#define ADDRESSTUPLE_ANY	NULL
#define ADDRESSTUPLE_ALL	"*"
#define OBJECTTYPE_TESTBED	"TBCONTROL"
74
#define OBJECTTYPE_TRAFGEN	"TRAFGEN"
75 76 77 78

address_tuple_t	address_tuple_alloc(void);
int		address_tuple_free(address_tuple_t);

79
#ifndef SWIG /* SWIG doesn't handle these, so we have to hide them from it */
80
#ifndef NO_EVENT_MACROS
81 82 83 84 85 86 87 88 89 90 91 92 93 94
#define event_notification_get_site(handle, note, buf, len) \
        event_notification_get_string(handle, note, "SITE", buf, len)
#define event_notification_get_expt(handle, note, buf, len) \
        event_notification_get_string(handle, note, "EXPT", buf, len)
#define event_notification_get_group(handle, note, buf, len) \
        event_notification_get_string(handle, note, "GROUP", buf, len)
#define event_notification_get_host(handle, note, buf, len) \
        event_notification_get_string(handle, note, "HOST", buf, len)
#define event_notification_get_objtype(handle, note, buf, len) \
        event_notification_get_string(handle, note, "OBJTYPE", buf, len)
#define event_notification_get_objname(handle, note, buf, len) \
        event_notification_get_string(handle, note, "OBJNAME", buf, len)
#define event_notification_get_eventtype(handle, note, buf, len) \
        event_notification_get_string(handle, note, "EVENTTYPE", buf, len)
95 96 97 98
#define event_notification_get_arguments(handle, note, buf, len) \
        event_notification_get_string(handle, note, "ARGS", buf, len)
#define event_notification_set_arguments(handle, note, buf) \
        event_notification_put_string(handle, note, "ARGS", buf)
99

100 101 102 103 104 105 106 107 108 109 110
/*
 * For dynamic events.
 */
#define event_notification_clear_host(handle, note) \
	event_notification_remove(handle, note, "HOST")
#define event_notification_set_host(handle, note, buf) \
        event_notification_put_string(handle, note, "HOST", buf)
#define event_notification_clear_objtype(handle, note) \
	event_notification_remove(handle, note, "OBJTYPE")
#define event_notification_set_objtype(handle, note, buf) \
        event_notification_put_string(handle, note, "OBJTYPE", buf)
111 112 113 114
#define event_notification_clear_objname(handle, note) \
	event_notification_remove(handle, note, "OBJNAME")
#define event_notification_set_objname(handle, note, buf) \
        event_notification_put_string(handle, note, "OBJNAME", buf)
115 116 117 118 119 120 121 122 123

/*
 * Event library sets this field. Holds the sender of the event, as 
 * determined by the library when it is initialized. 
 */
#define event_notification_get_sender(handle, note, buf, len) \
        event_notification_get_string(handle, note, "___SENDER___", buf, len)
#define event_notification_set_sender(handle, note, buf) \
        event_notification_put_string(handle, note, "___SENDER___", buf)
124
#endif /* ifndef NO_EVENT_MACROS */
125
#endif /* ifndef SWIG */
126

127

Ian Murdock's avatar
Ian Murdock committed
128 129 130
/* The "any host" string: */
#define EVENT_HOST_ANY "*"

Ian Murdock's avatar
Ian Murdock committed
131 132
/* Supported event types: */
typedef enum {
Ian Murdock's avatar
Ian Murdock committed
133
    EVENT_NULL,
Ian Murdock's avatar
Ian Murdock committed
134
    EVENT_TEST,
135
    EVENT_SCHEDULE,
Ian Murdock's avatar
Ian Murdock committed
136 137 138 139
    EVENT_TRAFGEN_START,
    EVENT_TRAFGEN_STOP
} event_type_t;

140 141 142 143
/* Event notification callback function.  Passed to event_subscribe
   and called whenever the specified event is triggered.
   HANDLE is the handle to the event server, NOTIFICATION is the event
   notification itself, and DATA is an arbitrary value passed to
144 145
   event_subscribe (argument 4).
 */
146 147 148 149
typedef void (*event_notify_callback_t)(event_handle_t handle,
                                        event_notification_t notification,
                                        void *data);

Ian Murdock's avatar
Ian Murdock committed
150 151 152 153 154
/*
 * Function prototypes:
 */

/* event.c */
155
event_handle_t event_register(char *name, int threaded);
156 157 158 159
event_handle_t event_register_withkeyfile(char *name, int threaded,
					  char *keyfile);
event_handle_t event_register_withkeydata(char *name, int threaded,
					  unsigned char *keydata, int len);
Ian Murdock's avatar
Ian Murdock committed
160
int event_unregister(event_handle_t handle);
161
int event_poll(event_handle_t handle);
162
int event_poll_blocking(event_handle_t handle, unsigned int timeout);
Ian Murdock's avatar
Ian Murdock committed
163 164
int event_main(event_handle_t handle);
int event_notify(event_handle_t handle, event_notification_t notification);
165 166
int event_schedule(event_handle_t handle, event_notification_t notification,
                   struct timeval *time);
Ian Murdock's avatar
Ian Murdock committed
167
event_notification_t event_notification_alloc(event_handle_t handle,
168
                                              address_tuple_t tuple);
Ian Murdock's avatar
Ian Murdock committed
169 170
int event_notification_free(event_handle_t handle,
                            event_notification_t notification);
171 172
event_notification_t event_notification_clone(event_handle_t handle,
					event_notification_t notification);
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
int event_notification_get_double(event_handle_t handle,
                                  event_notification_t notification,
                                  char *name, double *value);
int event_notification_get_int32(event_handle_t handle,
                                 event_notification_t notification,
                                 char *name, int32_t *value);
int event_notification_get_int64(event_handle_t handle,
                                 event_notification_t notification,
                                 char *name, int64_t *value);
int event_notification_get_opaque(event_handle_t handle,
                                  event_notification_t notification,
                                  char *name, void *buffer, int length);
int event_notification_get_string(event_handle_t handle,
                                  event_notification_t notification,
                                  char *name, char *buffer, int length);
int event_notification_put_double(event_handle_t handle,
                                  event_notification_t notification,
                                  char *name, double value);
int event_notification_put_int32(event_handle_t handle,
                                 event_notification_t notification,
                                 char *name, int32_t value);
int event_notification_put_int64(event_handle_t handle,
                                 event_notification_t notification,
                                 char *name, int64_t value);
int event_notification_put_opaque(event_handle_t handle,
                                  event_notification_t notification,
                                  char *name, void *buffer, int length);
int event_notification_put_string(event_handle_t handle,
                                  event_notification_t notification,
                                  char *name, char *value);
int event_notification_remove(event_handle_t handle,
                              event_notification_t notification, char *name);
Ian Murdock's avatar
Ian Murdock committed
205 206
event_subscription_t event_subscribe(event_handle_t handle,
                                     event_notify_callback_t callback,
207
                                     address_tuple_t tuple, void *data);
208 209
int event_notification_insert_hmac(event_handle_t handle,
				   event_notification_t notification);
210 211 212 213 214 215
int event_notification_pack(event_handle_t handle,
			    event_notification_t notification,
			    unsigned char *data, int *len);
int event_notification_unpack(event_handle_t handle,
			    event_notification_t *notification,
			    unsigned char *data, int len);
Ian Murdock's avatar
Ian Murdock committed
216 217 218 219 220 221

/* util.c */
void *xmalloc(int size);
void *xrealloc(void *p, int size);

#endif /* __EVENT_H__ */