event.pm 23.4 KB
Newer Older
1
2
3
4
5
# This file was automatically generated by SWIG
package event;
require Exporter;
require DynaLoader;
@ISA = qw(Exporter DynaLoader);
6
@EXPORT = qw(address_tuple_alloc address_tuple_free event_register event_register_withkeyfile event_register_withkeydata event_unregister c_event_poll c_event_poll_blocking dont_use_this_function_because_it_does_not_work event_notify event_schedule event_notification_alloc event_notification_free event_notification_clone event_notification_get_double event_notification_get_int32 event_notification_get_int64 event_notification_get_opaque c_event_notification_get_string event_notification_put_double event_notification_put_int32 event_notification_put_int64 event_notification_put_opaque event_notification_put_string event_notification_remove c_event_subscribe event_notification_insert_hmac event_notification_pack event_notification_unpack xmalloc xrealloc allocate_callback_data free_callback_data dequeue_callback_data enqueue_callback_data perl_stub_callback stub_event_subscribe event_notification_get_string event_notification_get_site event_notification_get_expt event_notification_get_group event_notification_get_host event_notification_get_objtype event_notification_get_objname event_notification_get_eventtype event_notification_get_arguments event_notification_set_arguments event_notification_get_sender event_notification_set_sender event_handle_server_set event_handle_server_get event_handle_status_set event_handle_status_get event_handle_keydata_set event_handle_keydata_get event_handle_keylen_set event_handle_keylen_get event_notification_elvin_notification_set event_notification_elvin_notification_get event_notification_has_hmac_set event_notification_has_hmac_get address_tuple_site_set address_tuple_site_get address_tuple_expt_set address_tuple_expt_get address_tuple_group_set address_tuple_group_get address_tuple_host_set address_tuple_host_get address_tuple_objtype_set address_tuple_objtype_get address_tuple_objname_set address_tuple_objname_get address_tuple_eventtype_set address_tuple_eventtype_get address_tuple_scheduler_set address_tuple_scheduler_get callback_data_callback_notification_set callback_data_callback_notification_get callback_data_next_set callback_data_next_get  );
7
8
9
package eventc;
bootstrap event;
var_event_init();
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
# ---------- BASE METHODS -------------

package event;

sub TIEHASH {
    my ($classname,$obj) = @_;
    return bless $obj, $classname;
}

sub CLEAR { }

sub this {
    my $ptr = shift;
    return tied(%$ptr);
}


# ------- FUNCTION WRAPPERS --------

package event;

sub address_tuple_alloc {
    my @args = @_;
    my $result = eventc::address_tuple_alloc(@args);
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "address_tuple", $result;
    return bless \%resulthash, "address_tuple";
}
sub address_tuple_free {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::address_tuple_free(@args);
    return $result;
}
sub event_register {
    my @args = @_;
    my $result = eventc::event_register(@args);
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "event_handle", $result;
    return bless \%resulthash, "event_handle";
}
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
sub event_register_withkeyfile {
    my @args = @_;
    my $result = eventc::event_register_withkeyfile(@args);
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "event_handle", $result;
    return bless \%resulthash, "event_handle";
}
sub event_register_withkeydata {
    my @args = @_;
    my $result = eventc::event_register_withkeydata(@args);
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "event_handle", $result;
    return bless \%resulthash, "event_handle";
}
70
71
72
73
74
75
76
77
78
79
80
81
sub event_unregister {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::event_unregister(@args);
    return $result;
}
sub c_event_poll {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::c_event_poll(@args);
    return $result;
}
82
83
84
85
86
87
sub c_event_poll_blocking {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::c_event_poll_blocking(@args);
    return $result;
}
88
89
90
91
92
93
94
95
96
sub dont_use_this_function_because_it_does_not_work {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::dont_use_this_function_because_it_does_not_work(@args);
    return $result;
}
sub event_notify {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
97
    $args[1] = tied(%{$args[1]});
98
99
100
101
102
103
    my $result = eventc::event_notify(@args);
    return $result;
}
sub event_schedule {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
104
    $args[1] = tied(%{$args[1]});
105
106
107
108
109
110
111
112
    my $result = eventc::event_schedule(@args);
    return $result;
}
sub event_notification_alloc {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    $args[1] = tied(%{$args[1]});
    my $result = eventc::event_notification_alloc(@args);
113
114
115
116
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "event_notification", $result;
    return bless \%resulthash, "event_notification";
117
118
119
120
}
sub event_notification_free {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
121
    $args[1] = tied(%{$args[1]});
122
123
124
125
126
127
    my $result = eventc::event_notification_free(@args);
    return $result;
}
sub event_notification_clone {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
128
    $args[1] = tied(%{$args[1]});
129
    my $result = eventc::event_notification_clone(@args);
130
131
132
133
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "event_notification", $result;
    return bless \%resulthash, "event_notification";
134
135
136
137
}
sub event_notification_get_double {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
138
    $args[1] = tied(%{$args[1]});
139
140
141
142
143
144
    my $result = eventc::event_notification_get_double(@args);
    return $result;
}
sub event_notification_get_int32 {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
145
    $args[1] = tied(%{$args[1]});
146
147
148
149
150
151
    my $result = eventc::event_notification_get_int32(@args);
    return $result;
}
sub event_notification_get_int64 {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
152
    $args[1] = tied(%{$args[1]});
153
154
155
156
157
158
    my $result = eventc::event_notification_get_int64(@args);
    return $result;
}
sub event_notification_get_opaque {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
159
    $args[1] = tied(%{$args[1]});
160
161
162
163
164
165
    my $result = eventc::event_notification_get_opaque(@args);
    return $result;
}
sub c_event_notification_get_string {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
166
    $args[1] = tied(%{$args[1]});
167
168
169
170
171
172
    my $result = eventc::c_event_notification_get_string(@args);
    return $result;
}
sub event_notification_put_double {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
173
    $args[1] = tied(%{$args[1]});
174
175
176
177
178
179
    my $result = eventc::event_notification_put_double(@args);
    return $result;
}
sub event_notification_put_int32 {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
180
    $args[1] = tied(%{$args[1]});
181
182
183
184
185
186
    my $result = eventc::event_notification_put_int32(@args);
    return $result;
}
sub event_notification_put_int64 {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
187
    $args[1] = tied(%{$args[1]});
188
189
190
191
192
193
    my $result = eventc::event_notification_put_int64(@args);
    return $result;
}
sub event_notification_put_opaque {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
194
    $args[1] = tied(%{$args[1]});
195
196
197
198
199
200
    my $result = eventc::event_notification_put_opaque(@args);
    return $result;
}
sub event_notification_put_string {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
201
    $args[1] = tied(%{$args[1]});
202
203
204
205
206
207
    my $result = eventc::event_notification_put_string(@args);
    return $result;
}
sub event_notification_remove {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
208
    $args[1] = tied(%{$args[1]});
209
210
211
212
213
214
215
216
217
218
    my $result = eventc::event_notification_remove(@args);
    return $result;
}
sub c_event_subscribe {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    $args[2] = tied(%{$args[2]});
    my $result = eventc::c_event_subscribe(@args);
    return $result;
}
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
sub event_notification_insert_hmac {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    $args[1] = tied(%{$args[1]});
    my $result = eventc::event_notification_insert_hmac(@args);
    return $result;
}
sub event_notification_pack {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    $args[1] = tied(%{$args[1]});
    my $result = eventc::event_notification_pack(@args);
    return $result;
}
sub event_notification_unpack {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::event_notification_unpack(@args);
    return $result;
}
239
240
*xmalloc = *eventc::xmalloc;
*xrealloc = *eventc::xrealloc;
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
sub allocate_callback_data {
    my @args = @_;
    my $result = eventc::allocate_callback_data(@args);
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "callback_data", $result;
    return bless \%resulthash, "callback_data";
}
sub free_callback_data {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::free_callback_data(@args);
    return $result;
}
sub dequeue_callback_data {
    my @args = @_;
    my $result = eventc::dequeue_callback_data(@args);
    return undef if (!defined($result));
    my %resulthash;
    tie %resulthash, "callback_data", $result;
    return bless \%resulthash, "callback_data";
}
sub enqueue_callback_data {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    my $result = eventc::enqueue_callback_data(@args);
    return $result;
}
269
270
271
sub perl_stub_callback {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
272
    $args[1] = tied(%{$args[1]});
273
274
275
276
277
278
279
280
281
282
283
284
285
    my $result = eventc::perl_stub_callback(@args);
    return $result;
}
sub stub_event_subscribe {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
    $args[1] = tied(%{$args[1]});
    my $result = eventc::stub_event_subscribe(@args);
    return $result;
}
sub event_notification_get_string {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
286
    $args[1] = tied(%{$args[1]});
287
288
289
290
291
292
    my $result = eventc::event_notification_get_string(@args);
    return $result;
}
sub event_notification_get_site {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
293
    $args[1] = tied(%{$args[1]});
294
295
296
297
298
299
    my $result = eventc::event_notification_get_site(@args);
    return $result;
}
sub event_notification_get_expt {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
300
    $args[1] = tied(%{$args[1]});
301
302
303
304
305
306
    my $result = eventc::event_notification_get_expt(@args);
    return $result;
}
sub event_notification_get_group {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
307
    $args[1] = tied(%{$args[1]});
308
309
310
311
312
313
    my $result = eventc::event_notification_get_group(@args);
    return $result;
}
sub event_notification_get_host {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
314
    $args[1] = tied(%{$args[1]});
315
316
317
318
319
320
    my $result = eventc::event_notification_get_host(@args);
    return $result;
}
sub event_notification_get_objtype {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
321
    $args[1] = tied(%{$args[1]});
322
323
324
325
326
327
    my $result = eventc::event_notification_get_objtype(@args);
    return $result;
}
sub event_notification_get_objname {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
328
    $args[1] = tied(%{$args[1]});
329
330
331
332
333
334
    my $result = eventc::event_notification_get_objname(@args);
    return $result;
}
sub event_notification_get_eventtype {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
335
    $args[1] = tied(%{$args[1]});
336
337
338
339
340
341
    my $result = eventc::event_notification_get_eventtype(@args);
    return $result;
}
sub event_notification_get_arguments {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
342
    $args[1] = tied(%{$args[1]});
343
344
345
346
347
348
    my $result = eventc::event_notification_get_arguments(@args);
    return $result;
}
sub event_notification_set_arguments {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
349
    $args[1] = tied(%{$args[1]});
350
351
352
353
354
355
    my $result = eventc::event_notification_set_arguments(@args);
    return $result;
}
sub event_notification_get_sender {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
356
    $args[1] = tied(%{$args[1]});
357
358
359
360
361
362
    my $result = eventc::event_notification_get_sender(@args);
    return $result;
}
sub event_notification_set_sender {
    my @args = @_;
    $args[0] = tied(%{$args[0]});
363
    $args[1] = tied(%{$args[1]});
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
    my $result = eventc::event_notification_set_sender(@args);
    return $result;
}

############# Class : event_handle ##############

package event_handle;
@ISA = qw( event );
%OWNER = ();
%BLESSEDMEMBERS = (
);

%ITERATORS = ();
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
    };

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
    };

sub FETCH {
    my ($self,$field) = @_;
    my $member_func = "eventc::event_handle_${field}_get";
    my $val = &$member_func($self);
    if (exists $BLESSEDMEMBERS{$field}) {
        return undef if (!defined($val));
        my %retval;
        tie %retval,$BLESSEDMEMBERS{$field},$val;
        return bless \%retval, $BLESSEDMEMBERS{$field};
    }
    return $val;
}

sub STORE {
    my ($self,$field,$newval) = @_;
    my $member_func = "eventc::event_handle_${field}_set";
    if (exists $BLESSEDMEMBERS{$field}) {
        &$member_func($self,tied(%{$newval}));
    } else {
        &$member_func($self,$newval);
    }
}

sub FIRSTKEY {
    my $self = shift;
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
    $ITERATORS{$self} = ['server', 'status', 'keydata', 'keylen', ];
    my $first = shift @{$ITERATORS{$self}};
    return $first;
}

sub NEXTKEY {
    my $self = shift;
    $nelem = scalar @{$ITERATORS{$self}};
    if ($nelem > 0) {
        my $member = shift @{$ITERATORS{$self}};
        return $member;
    } else {
        $ITERATORS{$self} = ['server', 'status', 'keydata', 'keylen', ];
        return ();
    }
}


############# Class : event_notification ##############

package event_notification;
@ISA = qw( event );
%OWNER = ();
%BLESSEDMEMBERS = (
);

%ITERATORS = ();
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
    };

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
    };

sub FETCH {
    my ($self,$field) = @_;
    my $member_func = "eventc::event_notification_${field}_get";
    my $val = &$member_func($self);
    if (exists $BLESSEDMEMBERS{$field}) {
        return undef if (!defined($val));
        my %retval;
        tie %retval,$BLESSEDMEMBERS{$field},$val;
        return bless \%retval, $BLESSEDMEMBERS{$field};
    }
    return $val;
}

sub STORE {
    my ($self,$field,$newval) = @_;
    my $member_func = "eventc::event_notification_${field}_set";
    if (exists $BLESSEDMEMBERS{$field}) {
        &$member_func($self,tied(%{$newval}));
    } else {
        &$member_func($self,$newval);
    }
}

sub FIRSTKEY {
    my $self = shift;
    $ITERATORS{$self} = ['elvin_notification', 'has_hmac', ];
479
480
481
482
483
484
485
486
487
488
489
    my $first = shift @{$ITERATORS{$self}};
    return $first;
}

sub NEXTKEY {
    my $self = shift;
    $nelem = scalar @{$ITERATORS{$self}};
    if ($nelem > 0) {
        my $member = shift @{$ITERATORS{$self}};
        return $member;
    } else {
490
        $ITERATORS{$self} = ['elvin_notification', 'has_hmac', ];
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
        return ();
    }
}


############# Class : address_tuple ##############

package address_tuple;
@ISA = qw( event );
%OWNER = ();
%BLESSEDMEMBERS = (
);

%ITERATORS = ();
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
    };

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
    };

sub FETCH {
    my ($self,$field) = @_;
    my $member_func = "eventc::address_tuple_${field}_get";
    my $val = &$member_func($self);
    if (exists $BLESSEDMEMBERS{$field}) {
        return undef if (!defined($val));
        my %retval;
        tie %retval,$BLESSEDMEMBERS{$field},$val;
        return bless \%retval, $BLESSEDMEMBERS{$field};
    }
    return $val;
}

sub STORE {
    my ($self,$field,$newval) = @_;
    my $member_func = "eventc::address_tuple_${field}_set";
    if (exists $BLESSEDMEMBERS{$field}) {
        &$member_func($self,tied(%{$newval}));
    } else {
        &$member_func($self,$newval);
    }
}

sub FIRSTKEY {
    my $self = shift;
    $ITERATORS{$self} = ['site', 'expt', 'group', 'host', 'objtype', 'objname', 'eventtype', 'scheduler', ];
    my $first = shift @{$ITERATORS{$self}};
    return $first;
}

sub NEXTKEY {
    my $self = shift;
    $nelem = scalar @{$ITERATORS{$self}};
    if ($nelem > 0) {
        my $member = shift @{$ITERATORS{$self}};
        return $member;
    } else {
        $ITERATORS{$self} = ['site', 'expt', 'group', 'host', 'objtype', 'objname', 'eventtype', 'scheduler', ];
        return ();
    }
}


560
561
562
563
564
565
############# Class : callback_data ##############

package callback_data;
@ISA = qw( event );
%OWNER = ();
%BLESSEDMEMBERS = (
566
    callback_notification => 'event_notification',
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
    next => 'callback_data',
);

%ITERATORS = ();
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
    };

sub ACQUIRE {
    my $self = shift;
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
    };

sub FETCH {
    my ($self,$field) = @_;
    my $member_func = "eventc::callback_data_${field}_get";
    my $val = &$member_func($self);
    if (exists $BLESSEDMEMBERS{$field}) {
        return undef if (!defined($val));
        my %retval;
        tie %retval,$BLESSEDMEMBERS{$field},$val;
        return bless \%retval, $BLESSEDMEMBERS{$field};
    }
    return $val;
}

sub STORE {
    my ($self,$field,$newval) = @_;
    my $member_func = "eventc::callback_data_${field}_set";
    if (exists $BLESSEDMEMBERS{$field}) {
        &$member_func($self,tied(%{$newval}));
    } else {
        &$member_func($self,$newval);
    }
}

sub FIRSTKEY {
    my $self = shift;
    $ITERATORS{$self} = ['callback_notification', 'next', ];
    my $first = shift @{$ITERATORS{$self}};
    return $first;
}

sub NEXTKEY {
    my $self = shift;
    $nelem = scalar @{$ITERATORS{$self}};
    if ($nelem > 0) {
        my $member = shift @{$ITERATORS{$self}};
        return $member;
    } else {
        $ITERATORS{$self} = ['callback_notification', 'next', ];
        return ();
    }
}


626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
# ------- VARIABLE STUBS --------

package event;

*MAXHOSTNAMELEN = *eventc::MAXHOSTNAMELEN;
*ADDRESSTUPLE_ANY = *eventc::ADDRESSTUPLE_ANY;
*ADDRESSTUPLE_ALL = *eventc::ADDRESSTUPLE_ALL;
*OBJECTTYPE_TESTBED = *eventc::OBJECTTYPE_TESTBED;
*OBJECTTYPE_TRAFGEN = *eventc::OBJECTTYPE_TRAFGEN;
*EVENT_HOST_ANY = *eventc::EVENT_HOST_ANY;
*EVENT_NULL = *eventc::EVENT_NULL;
*EVENT_TEST = *eventc::EVENT_TEST;
*EVENT_SCHEDULE = *eventc::EVENT_SCHEDULE;
*EVENT_TRAFGEN_START = *eventc::EVENT_TRAFGEN_START;
*EVENT_TRAFGEN_STOP = *eventc::EVENT_TRAFGEN_STOP;
641
642
643
644
645

my %__callback_data_list_hash;
tie %__callback_data_list_hash,"callback_data", $eventc::callback_data_list;
$callback_data_list= \%__callback_data_list_hash;
bless $callback_data_list, callback_data;
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
*event_string_buffer = *eventc::event_string_buffer;
1;
#
# CODE PAST THIS POINT WAS NOT AUTOMATICALLY GENERATED BY SWIG
#
# For now, this has to get cat'ed onto the end of event.pm, since it
# doesn't seem possible to get SWIG to just pass it through into the
# output file
#

#
# Stash away the given callback and data, and call the C event_subscribe
# function that uses a stub callback
#
sub event_subscribe($$$;$) {
	my ($handle,$function,$tuple,$data) = @_;
	$event::callback = $function;
	$event::callback_data = $data;
	return stub_event_subscribe($handle,$tuple);
}

#
# Clear $callback_ready, call the C event_poll function, and see if the
# C callback got called (as evidenced by $callback_ready getting set) If it
670
671
# did, call the perl callback function. Handle both blocking and non-blocking
# versions of the call
672
#
673
674
675
676
677
678
679
680
681
sub internal_event_poll($$$) {
	my ($handle, $block, $timeout) = @_;

	my $rv;
	if ($block) {
		$rv = c_event_poll_blocking($handle,$timeout);
	} else {
		$rv = c_event_poll($handle);
	}
682
683
684
685
686

	if ($rv) {
		die "Trouble in event_poll - returned $rv\h";
	}

687
688
	while (my $data = dequeue_callback_data() ) {
		&$event::callback($handle,$data->{callback_notification},
689
				$event::callback_data);
690
691
		event_notification_free($handle,$data->{callback_notification});
		free_callback_data($data);
692
693
694
695
696
	}

	return 0;
}

697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
#
# Wrapper for the internal polling function, non-blocking version
#
sub event_poll($) {
	my $handle = shift;
	return &internal_event_poll($handle,0,0);
}

#
# Same as above, but for the blocking version
#
sub event_poll_blocking($$) {
	my ($handle, $timeout) = @_;
	return &internal_event_poll($handle,1,$timeout);
}

713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
#
# NOTE: The following line will only work if this module is included by
# a file that has already done a 'use lib' to get the path to testbed
# libraries in the INC path. But, since they had to do that to get this
# library anyway, shouldn't be a problem. (Didn't want to have to make
# this a .in file.)
#
use libtestbed;

#
# Conveniece functions - Intended to work like DBQuery* from libdb .
# Much of this code shamlessly ripped off from libdb.pm
#

#
728
# Warn after a failed event send. First argument is the error
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# message to display. The contents of $EventErrorString is also printed.
# 
# usage: EventWarn(char *message)
#
sub EventWarn($) {
	my($message) = $_[0];
	my($text, $progname);

	#
	# Must taint check $PROGRAM_NAME cause it comes from outside. Silly!
	#
	if ($PROGRAM_NAME =~ /^([-\w.\/]+)$/) {
		$progname = $1;
	} else {
		$progname = "Tainted";
	}

	$text = "$message - In $progname\n" .
		"$EventErrorString\n";

	print STDERR "*** $text";
}

#
# Same as above, but die after the warning.
# 
# usage: EventFatal(char *message);
#
sub EventFatal($) {
	my($message) = $_[0];

	EventWarn($message);

	die("\n");
}


#
# Conveniece function - Intended to work like DBQueryFatal from libdb
#
sub EventSendFatal(@) {
	my @tuple = @_;
    
	my $result = EventSend(@tuple);

	if (!$result) {
		EventFatal("Event Send failed");
	}

	return $result;
}

#
# Conveniece function - Intended to work like DBQueryWarn from libdb
#
sub EventSendWarn(@) {
	my @tuple = @_;
    
	my $result = EventSend(@tuple);

	if (!$result) {
790
		EventWarn("Event Send failed");
791
792
793
794
795
796
797
798
	}

	return $result;
}

sub EventSend(@) {
	my %tuple_values = @_;

799
800
801
802
803
804
805
806
807
808
809
810
811
	#
	# Only connect on the first call - thereafter, just use the existing
	# handle. The handle gets disconnected in the END block below
	#
	if (!$event::EventSendHandle) {
		my $URL = "elvin://" . TB_BOSSNODE;

		$event::EventSendHandle = event_register($URL,0);
		if (!$event::EventSendHandle) {
			$EventErrorString =
				"Unable to register with the event system";
			return undef;
		}
812
813
814
815
816
817
818
819
820
821
822
823
824
	}

	my $tuple = address_tuple_alloc();
	if (!$tuple) {
		$EventErrorString = "Unable to allocate an address tuple";
		return undef;
	}

	#
	# Set the values the user requested
	#
	%$tuple = %tuple_values;

825
826
	my $notification = event_notification_alloc($event::EventSendHandle,
		$tuple);
827
828
829
830
831
	if (!$notification) {
		$EventErrorString = "Could not allocate notification";
		return undef;
	}

832
	if (!event_notify($event::EventSendHandle, $notification)) {
833
834
835
836
		$EventErrorString = "Could not send event notification";
		return undef;
	}

837
	event_notification_free($event::EventSendHandle, $notification);
838
839
840
841
842
	address_tuple_free($tuple);

	return 1;
}

843
844
845
846
847
848
849
850
851
#
# After a fork, undef the handle to the event system so that we form a
# a new connection in the child. Do not disconnect from the child; I have
# no idea what that will do to the parent connection.
#
sub EventFork() {
    $event::EventSendHandle = undef;
}

852
853
854
855
856
857
858
859
860
861
#
# When we exit, unregister with the event system if we're connected
#
END {
    	if ($event::EventSendHandle) {
		if (event_unregister($event::EventSendHandle) == 0) {
			warn "Could not unregister with event system";
		}
	}
}
862

863
push @EXPORT, qw(event_subscribe event_poll event_poll_blocking EventSend
864
	EventSendFatal EventSendWarn EventFork);
865
866
1;