event.h 8.12 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1 2 3 4 5 6
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2000-2002 University of Utah and the Flux Group.
 * 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 30 31 32 33 34 35 36 37 38 39 40
    /* 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
41 42 43 44 45 46 47 48 49
};
typedef struct event_handle * event_handle_t;

/* Event notification: */
typedef elvin_notification_t event_notification_t;

/* Event subscription: */
typedef elvin_subscription_t event_subscription_t;

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
/*
 * A tuple defines the target of the event, or if you are a subscriber,
 * what events you want to subscribe to.
 */
typedef struct {
	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"
Mike Hibler's avatar
Mike Hibler committed
67
#define OBJECTTYPE_TRAFGEN	"TRAFGEN"
68 69 70 71

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

72
#ifndef NO_EVENT_MACROS
73 74 75 76 77 78 79 80 81 82 83 84 85 86
#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)
87 88 89 90
#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)
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
/*
 * 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)

/*
 * 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)
112
#endif /* ifndef NO_EVENT_MACROS */
113

114

Ian Murdock's avatar
Ian Murdock committed
115 116 117
/* The "any host" string: */
#define EVENT_HOST_ANY "*"

Ian Murdock's avatar
Ian Murdock committed
118 119
/* Supported event types: */
typedef enum {
Ian Murdock's avatar
Ian Murdock committed
120
    EVENT_NULL,
Ian Murdock's avatar
Ian Murdock committed
121
    EVENT_TEST,
122
    EVENT_SCHEDULE,
Ian Murdock's avatar
Ian Murdock committed
123 124 125 126
    EVENT_TRAFGEN_START,
    EVENT_TRAFGEN_STOP
} event_type_t;

127 128 129 130
/* 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
131 132
   event_subscribe (argument 4).
 */
133 134 135 136
typedef void (*event_notify_callback_t)(event_handle_t handle,
                                        event_notification_t notification,
                                        void *data);

Ian Murdock's avatar
Ian Murdock committed
137 138 139 140 141
/*
 * Function prototypes:
 */

/* event.c */
142
event_handle_t event_register(char *name, int threaded);
Ian Murdock's avatar
Ian Murdock committed
143
int event_unregister(event_handle_t handle);
Mike Hibler's avatar
Mike Hibler committed
144
int event_poll(event_handle_t handle);
145
int event_poll_blocking(event_handle_t handle, unsigned int timeout);
Ian Murdock's avatar
Ian Murdock committed
146 147
int event_main(event_handle_t handle);
int event_notify(event_handle_t handle, event_notification_t notification);
148 149
int event_schedule(event_handle_t handle, event_notification_t notification,
                   struct timeval *time);
Ian Murdock's avatar
Ian Murdock committed
150
event_notification_t event_notification_alloc(event_handle_t handle,
151
                                              address_tuple_t tuple);
Ian Murdock's avatar
Ian Murdock committed
152 153
int event_notification_free(event_handle_t handle,
                            event_notification_t notification);
154 155
event_notification_t event_notification_clone(event_handle_t handle,
					event_notification_t notification);
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
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
188 189
event_subscription_t event_subscribe(event_handle_t handle,
                                     event_notify_callback_t callback,
190
                                     address_tuple_t tuple, void *data);
Ian Murdock's avatar
Ian Murdock committed
191 192 193 194 195 196

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

#endif /* __EVENT_H__ */