00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __AWEVENT__
00028 #define __AWEVENT__
00029
00030
00036 #include <sys/bitypes.h>
00037 #include <time.h>
00038 #include <sys/time.h>
00039 #include <unistd.h>
00040 #include <string.h>
00041
00042 #include "util.h"
00043 #include "address.h"
00044
00045
00046 #define AW_EVENT_NET_FMTVERSION 2
00047
00048
00049 #define AW_EVENT_NET_MAXSIZE 0xffff
00050
00054 typedef int64_t aw_timestamp_t;
00055 #define AW_TIMESTAMP_PER_SEC ((aw_timestamp_t)1000000)
00056
00061 inline static aw_timestamp_t aw_gettimestamp(void)
00062 {
00063 aw_timestamp_t
00064 stamp;
00065
00066
00067 struct timeval
00068 tval;
00069 gettimeofday(&tval, NULL);
00070 stamp = (tval.tv_sec * AW_TIMESTAMP_PER_SEC) + tval.tv_usec ;
00071
00072 return stamp ;
00073 }
00074
00078 typedef enum {
00079
00080 AW_EVENT_CONTEXT_CONTROL,
00082 AW_EVENT_CONTEXT_ALARM,
00084 AW_EVENT_CONTEXT_HANDLER,
00086 AW_EVENT_CONTEXT_EXTERNAL,
00088 } aw_event_context_t;
00089
00093 typedef enum {
00094
00095 AW_EVENT_TYPE_UNKNOWN,
00096
00097
00098 AW_EVENT_TYPE_MON_ADD_ALARM,
00099 AW_EVENT_TYPE_MON_REMOVE_ALARM,
00100 AW_EVENT_TYPE_MON_ADD_HANDLER_FDCALLBACK,
00101 AW_EVENT_TYPE_MON_REMOVE_HANDLER_FDCALLBACK,
00102 AW_EVENT_TYPE_MON_ADD_HANDLER_IRECALLBACK,
00103 AW_EVENT_TYPE_MON_REMOVE_HANDLER_IRECALLBACK,
00104 AW_EVENT_TYPE_MON_ADD_HANDLER,
00105 AW_EVENT_TYPE_MON_REMOVE_HANDLER,
00106
00107
00108 AW_EVENT_TYPE_INT32,
00109 AW_EVENT_TYPE_INT64,
00110 AW_EVENT_TYPE_TIMESTAMP,
00111 AW_EVENT_TYPE_FLOAT32,
00112 AW_EVENT_TYPE_FLOAT64,
00113 AW_EVENT_TYPE_STRING,
00114 AW_EVENT_TYPE_PTR,
00115
00116 AW_EVENT_NTYPES
00117
00118 } aw_event_payload_t;
00119
00120
00121 #define AW_EVENT_SIGNAME_SIZE 64
00122
00126 typedef struct {
00127
00128
00129 byte_t
00130 name[AW_EVENT_SIGNAME_SIZE];
00131
00132
00133 byte_t
00134 source[AW_EVENT_SIGNAME_SIZE];
00135
00136
00137 int32_t
00138 priority;
00139
00140
00141 aw_address_t
00142 id;
00143
00144 } aw_event_sig_t;
00145
00149 typedef struct
00150 {
00151
00152 int32_t
00153 xactionid;
00154
00155 } aw_event_xactioninfo_t;
00156
00160 typedef struct aw_event_s
00161 {
00162
00163
00164 struct
00165 aw_event_s *next;
00166
00167
00168 aw_event_context_t
00169 context;
00170
00171
00172 aw_timestamp_t
00173 tstamp;
00174
00175
00176 aw_event_sig_t
00177 sig;
00178
00179
00180 aw_event_xactioninfo_t
00181 xactioninfo;
00182
00183
00184 aw_event_payload_t
00185 payload_type;
00186
00187
00188 union {
00189
00190 int32_t
00191 int32_value;
00192
00193 int64_t
00194 int64_value;
00195
00196 float32_t
00197 float32_value;
00198
00199 float64_t
00200 float64_value;
00201
00202 aw_timestamp_t
00203 tstamp;
00204
00205 byte_t
00206 *string;
00207
00208 void
00209 *valueptr ;
00210
00211 } payload;
00212
00213
00214
00215
00216
00217
00218 void * (*copy_valueptr)(void *valueptr);
00219
00220
00221 void (*finalize)(struct aw_event_s *e);
00222
00223
00224 void (*tostring)(struct aw_event_s *e, byte_t *s, u_int32_t size);
00225
00226
00227 aw_cache_allocator_t
00228 *factory;
00229
00230 } aw_event_t;
00231
00235 typedef struct
00236 {
00237
00238
00239 u_int32_t count;
00240
00241
00242 aw_event_t *first;
00243
00244
00245 aw_event_t *last;
00246
00247 } aw_event_q_t;
00248
00249
00250
00251
00252
00253
00254
00255
00262 inline static void aw_append_q(aw_event_t *e, aw_event_q_t *q)
00263 {
00264 u_int32_t
00265 count = q->count;
00266
00267 if ( count == 0 ) {
00268
00269 q->first = e;
00270
00271 } else {
00272
00273 q->last->next = e;
00274
00275 }
00276
00277 q->last = e;
00278 q->count = count + 1;
00279 e->next = NULL;
00280 }
00281
00287 inline static void aw_push_q(aw_event_t *e, aw_event_q_t *q)
00288 {
00289 u_int32_t
00290 count = q->count;
00291
00292 if ( count == 0 ) q->last = e;
00293
00294 q->count = count + 1;
00295 e->next = q->first;
00296 q->first = e;
00297
00298 }
00299
00305 inline static aw_event_t * aw_dq_q(aw_event_q_t *q)
00306 {
00307 aw_event_t
00308 *last, *e;
00309 u_int32_t
00310 count = q->count;
00311
00312 if (count != 0) {
00313
00314 q->count = count - 1;
00315 e = q->last;
00316 last = e->next;
00317 e->next = NULL ;
00318 q->last = last;
00319 if ( last == NULL ) q->first = last;
00320
00321 } else {
00322
00323 e = NULL ;
00324
00325 }
00326
00327 return e ;
00328 }
00329
00330
00336 inline static aw_event_t * aw_pop_q(aw_event_q_t *q)
00337 {
00338 aw_event_t
00339 *first, *e;
00340 u_int32_t
00341 count = q->count;
00342
00343 if (count != 0) {
00344
00345 q->count = count - 1;
00346 e = q->first;
00347 first = e->next;
00348 e->next = NULL;
00349 q->first = first;
00350 if ( first == NULL ) q->last = first;
00351
00352 } else {
00353
00354 e = NULL ;
00355
00356 }
00357
00358 return e ;
00359 }
00360
00361
00367 inline static void aw_append_qs(aw_event_q_t *q1, aw_event_q_t *q2)
00368 {
00369 u_int32_t
00370 count = q1->count;
00371
00372
00373 if ( q2->count == 0 ) goto done;
00374
00375
00376 if (count == 0) {
00377
00378
00379 memcpy( q1, q2, sizeof(aw_event_q_t));
00380
00381 } else {
00382
00383 count += q2->count;
00384
00385 q1->count = count;
00386 q1->last->next = q2->first;
00387 q1->last = q2->last;
00388
00389 }
00390
00391
00392 memset(q2, 0, sizeof(aw_event_q_t));
00393
00394 done:;
00395
00396 }
00397
00398
00405 const aw_event_t *aw_findin_q(const aw_event_t *e, const aw_event_q_t *q);
00406
00411 void aw_clear_q(aw_event_q_t *q);
00412
00413
00414
00421 aw_event_t * aw_create_event(aw_event_context_t context, aw_cache_allocator_t *f);
00422
00427 void aw_destroy_event(aw_event_t *e);
00428
00435 aw_event_t *aw_dup_event(const aw_event_t *e, aw_cache_allocator_t *f);
00436
00444 void aw_event_format(aw_event_t *e, byte_t *format, byte_t *s, u_int32_t size);
00445
00446
00454 int32_t aw_event2n(aw_event_t *e, int32_t size, byte_t *buffer);
00455
00456
00463 int32_t aw_n2event(aw_event_t *e, const byte_t *buffer);
00464
00465 #endif