event.pm 23.3 KB
Newer Older
1
# This file was automatically generated by SWIG (http://www.swig.org).
2
# Version 2.0.12
3 4 5 6
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.

7
package event;
8 9
use base qw(Exporter);
use base qw(DynaLoader);
10 11
package eventc;
bootstrap event;
12
package event;
13
@EXPORT = qw($EVENT_LIBRARY_VERSION $MAXHOSTNAMELEN 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_handle_do_loop_set event_handle_do_loop_get event_handle_connect_set event_handle_connect_get event_handle_disconnect_set event_handle_disconnect_get event_handle_mainloop_set event_handle_mainloop_get event_handle_notify_set event_handle_notify_get event_handle_subscribe_set event_handle_subscribe_get event_handle_unsubscribe_set event_handle_unsubscribe_get new_event_handle delete_event_handle event_notification_pubsub_notification_set event_notification_pubsub_notification_get event_notification_has_hmac_set event_notification_has_hmac_get new_event_notification delete_event_notification 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 address_tuple_timeline_set address_tuple_timeline_get new_address_tuple delete_address_tuple $ADDRESSTUPLE_ALL $OBJECTTYPE_TESTBED $OBJECTTYPE_TRAFGEN address_tuple_alloc address_tuple_free $EVENT_HOST_ANY $EVENT_NULL $EVENT_TEST $EVENT_SCHEDULE $EVENT_TRAFGEN_START $EVENT_TRAFGEN_STOP event_register event_register_withssl event_register_withkeyfile event_register_withkeyfile event_register_withkeydata event_register_withkeyfile_withretry event_register_withkeydata_withretry event_unregister c_event_poll c_event_poll_blocking dont_use_this_function_because_it_does_not_work event_stop_main 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_length event_notification_get_string_length 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_subscribe_auth event_async_subscribe event_unsubscribe event_async_unsubscribe event_notification_insert_hmac event_set_idle_period event_set_failover event_set_sockbufsizes event_arg_get event_arg_dup $EA_TAG_DONE $EA_Site $EA_Experiment $EA_Group $EA_Host $EA_Type $EA_Name $EA_Event $EA_Arguments $EA_ArgInteger $EA_ArgFloat $EA_ArgString $EA_When event_notification_create_v event_notification_create event_do_v event_do xmalloc xrealloc make_timestamp timeval_tv_sec_set timeval_tv_sec_get timeval_tv_usec_set timeval_tv_usec_get new_timeval delete_timeval callback_data_callback_notification_set callback_data_callback_notification_get callback_data_next_set callback_data_next_get new_callback_data delete_callback_data $callback_data_list allocate_callback_data free_callback_data dequeue_callback_data enqueue_callback_data perl_stub_callback stub_event_subscribe $event_string_buffer 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 );
14

15 16 17 18 19 20 21 22 23 24 25
# ---------- BASE METHODS -------------

package event;

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

sub CLEAR { }

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
sub FIRSTKEY { }

sub NEXTKEY { }

sub FETCH {
    my ($self,$field) = @_;
    my $member_func = "swig_${field}_get";
    $self->$member_func();
}

sub STORE {
    my ($self,$field,$newval) = @_;
    my $member_func = "swig_${field}_set";
    $self->$member_func($newval);
}

42 43 44 45 46 47 48 49 50 51
sub this {
    my $ptr = shift;
    return tied(%$ptr);
}


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

package event;

52 53 54
*address_tuple_alloc = *eventc::address_tuple_alloc;
*address_tuple_free = *eventc::address_tuple_free;
*event_register = *eventc::event_register;
55
*event_register_withssl = *eventc::event_register_withssl;
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
*event_register_withkeyfile = *eventc::event_register_withkeyfile;
*event_register_withkeydata = *eventc::event_register_withkeydata;
*event_register_withkeyfile_withretry = *eventc::event_register_withkeyfile_withretry;
*event_register_withkeydata_withretry = *eventc::event_register_withkeydata_withretry;
*event_unregister = *eventc::event_unregister;
*c_event_poll = *eventc::c_event_poll;
*c_event_poll_blocking = *eventc::c_event_poll_blocking;
*dont_use_this_function_because_it_does_not_work = *eventc::dont_use_this_function_because_it_does_not_work;
*event_stop_main = *eventc::event_stop_main;
*event_notify = *eventc::event_notify;
*event_schedule = *eventc::event_schedule;
*event_notification_alloc = *eventc::event_notification_alloc;
*event_notification_free = *eventc::event_notification_free;
*event_notification_clone = *eventc::event_notification_clone;
*event_notification_get_double = *eventc::event_notification_get_double;
*event_notification_get_int32 = *eventc::event_notification_get_int32;
*event_notification_get_int64 = *eventc::event_notification_get_int64;
73 74
*event_notification_get_opaque_length = *eventc::event_notification_get_opaque_length;
*event_notification_get_string_length = *eventc::event_notification_get_string_length;
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
*event_notification_get_opaque = *eventc::event_notification_get_opaque;
*c_event_notification_get_string = *eventc::c_event_notification_get_string;
*event_notification_put_double = *eventc::event_notification_put_double;
*event_notification_put_int32 = *eventc::event_notification_put_int32;
*event_notification_put_int64 = *eventc::event_notification_put_int64;
*event_notification_put_opaque = *eventc::event_notification_put_opaque;
*event_notification_put_string = *eventc::event_notification_put_string;
*event_notification_remove = *eventc::event_notification_remove;
*c_event_subscribe = *eventc::c_event_subscribe;
*event_subscribe_auth = *eventc::event_subscribe_auth;
*event_async_subscribe = *eventc::event_async_subscribe;
*event_unsubscribe = *eventc::event_unsubscribe;
*event_async_unsubscribe = *eventc::event_async_unsubscribe;
*event_notification_insert_hmac = *eventc::event_notification_insert_hmac;
*event_set_idle_period = *eventc::event_set_idle_period;
*event_set_failover = *eventc::event_set_failover;
91
*event_set_sockbufsizes = *eventc::event_set_sockbufsizes;
92 93 94 95 96 97
*event_arg_get = *eventc::event_arg_get;
*event_arg_dup = *eventc::event_arg_dup;
*event_notification_create_v = *eventc::event_notification_create_v;
*event_notification_create = *eventc::event_notification_create;
*event_do_v = *eventc::event_do_v;
*event_do = *eventc::event_do;
98 99
*xmalloc = *eventc::xmalloc;
*xrealloc = *eventc::xrealloc;
100
*make_timestamp = *eventc::make_timestamp;
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
*allocate_callback_data = *eventc::allocate_callback_data;
*free_callback_data = *eventc::free_callback_data;
*dequeue_callback_data = *eventc::dequeue_callback_data;
*enqueue_callback_data = *eventc::enqueue_callback_data;
*perl_stub_callback = *eventc::perl_stub_callback;
*stub_event_subscribe = *eventc::stub_event_subscribe;
*event_notification_get_string = *eventc::event_notification_get_string;
*event_notification_get_site = *eventc::event_notification_get_site;
*event_notification_get_expt = *eventc::event_notification_get_expt;
*event_notification_get_group = *eventc::event_notification_get_group;
*event_notification_get_host = *eventc::event_notification_get_host;
*event_notification_get_objtype = *eventc::event_notification_get_objtype;
*event_notification_get_objname = *eventc::event_notification_get_objname;
*event_notification_get_eventtype = *eventc::event_notification_get_eventtype;
*event_notification_get_arguments = *eventc::event_notification_get_arguments;
*event_notification_set_arguments = *eventc::event_notification_set_arguments;
*event_notification_get_sender = *eventc::event_notification_get_sender;
*event_notification_set_sender = *eventc::event_notification_set_sender;

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

package event::event_handle;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
124 125 126
@ISA = qw( event );
%OWNER = ();
%ITERATORS = ();
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
*swig_server_get = *eventc::event_handle_server_get;
*swig_server_set = *eventc::event_handle_server_set;
*swig_status_get = *eventc::event_handle_status_get;
*swig_status_set = *eventc::event_handle_status_set;
*swig_keydata_get = *eventc::event_handle_keydata_get;
*swig_keydata_set = *eventc::event_handle_keydata_set;
*swig_keylen_get = *eventc::event_handle_keylen_get;
*swig_keylen_set = *eventc::event_handle_keylen_set;
*swig_do_loop_get = *eventc::event_handle_do_loop_get;
*swig_do_loop_set = *eventc::event_handle_do_loop_set;
*swig_connect_get = *eventc::event_handle_connect_get;
*swig_connect_set = *eventc::event_handle_connect_set;
*swig_disconnect_get = *eventc::event_handle_disconnect_get;
*swig_disconnect_set = *eventc::event_handle_disconnect_set;
*swig_mainloop_get = *eventc::event_handle_mainloop_get;
*swig_mainloop_set = *eventc::event_handle_mainloop_set;
*swig_notify_get = *eventc::event_handle_notify_get;
*swig_notify_set = *eventc::event_handle_notify_set;
*swig_subscribe_get = *eventc::event_handle_subscribe_get;
*swig_subscribe_set = *eventc::event_handle_subscribe_set;
*swig_unsubscribe_get = *eventc::event_handle_unsubscribe_get;
*swig_unsubscribe_set = *eventc::event_handle_unsubscribe_set;
sub new {
    my $pkg = shift;
    my $self = eventc::new_event_handle(@_);
    bless $self, $pkg if defined($self);
}

sub DESTROY {
    return unless $_[0]->isa('HASH');
    my $self = tied(%{$_[0]});
    return unless defined $self;
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        eventc::delete_event_handle($self);
        delete $OWNER{$self};
    }
}

166 167 168 169
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
170
}
171 172 173 174 175

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


179
############# Class : event::event_notification ##############
180

181 182
package event::event_notification;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
183 184 185
@ISA = qw( event );
%OWNER = ();
%ITERATORS = ();
186 187
*swig_pubsub_notification_get = *eventc::event_notification_pubsub_notification_get;
*swig_pubsub_notification_set = *eventc::event_notification_pubsub_notification_set;
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
*swig_has_hmac_get = *eventc::event_notification_has_hmac_get;
*swig_has_hmac_set = *eventc::event_notification_has_hmac_set;
sub new {
    my $pkg = shift;
    my $self = eventc::new_event_notification(@_);
    bless $self, $pkg if defined($self);
}

sub DESTROY {
    return unless $_[0]->isa('HASH');
    my $self = tied(%{$_[0]});
    return unless defined $self;
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        eventc::delete_event_notification($self);
        delete $OWNER{$self};
    }
}

207 208 209 210
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
211
}
212 213 214 215 216 217 218

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

219

220
############# Class : event::address_tuple ##############
221

222 223
package event::address_tuple;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
224 225 226
@ISA = qw( event );
%OWNER = ();
%ITERATORS = ();
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
*swig_site_get = *eventc::address_tuple_site_get;
*swig_site_set = *eventc::address_tuple_site_set;
*swig_expt_get = *eventc::address_tuple_expt_get;
*swig_expt_set = *eventc::address_tuple_expt_set;
*swig_group_get = *eventc::address_tuple_group_get;
*swig_group_set = *eventc::address_tuple_group_set;
*swig_host_get = *eventc::address_tuple_host_get;
*swig_host_set = *eventc::address_tuple_host_set;
*swig_objtype_get = *eventc::address_tuple_objtype_get;
*swig_objtype_set = *eventc::address_tuple_objtype_set;
*swig_objname_get = *eventc::address_tuple_objname_get;
*swig_objname_set = *eventc::address_tuple_objname_set;
*swig_eventtype_get = *eventc::address_tuple_eventtype_get;
*swig_eventtype_set = *eventc::address_tuple_eventtype_set;
*swig_scheduler_get = *eventc::address_tuple_scheduler_get;
*swig_scheduler_set = *eventc::address_tuple_scheduler_set;
*swig_timeline_get = *eventc::address_tuple_timeline_get;
*swig_timeline_set = *eventc::address_tuple_timeline_set;
sub new {
    my $pkg = shift;
    my $self = eventc::new_address_tuple(@_);
    bless $self, $pkg if defined($self);
}

sub DESTROY {
    return unless $_[0]->isa('HASH');
    my $self = tied(%{$_[0]});
    return unless defined $self;
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        eventc::delete_address_tuple($self);
        delete $OWNER{$self};
    }
}

262 263 264 265
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
266
}
267 268 269 270 271 272 273 274

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


275
############# Class : event::timeval ##############
276

277 278
package event::timeval;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
279 280 281
@ISA = qw( event );
%OWNER = ();
%ITERATORS = ();
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
*swig_tv_sec_get = *eventc::timeval_tv_sec_get;
*swig_tv_sec_set = *eventc::timeval_tv_sec_set;
*swig_tv_usec_get = *eventc::timeval_tv_usec_get;
*swig_tv_usec_set = *eventc::timeval_tv_usec_set;
sub new {
    my $pkg = shift;
    my $self = eventc::new_timeval(@_);
    bless $self, $pkg if defined($self);
}

sub DESTROY {
    return unless $_[0]->isa('HASH');
    my $self = tied(%{$_[0]});
    return unless defined $self;
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        eventc::delete_timeval($self);
        delete $OWNER{$self};
    }
}

303 304 305 306
sub DISOWN {
    my $self = shift;
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
307
}
308 309 310 311 312 313 314

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

315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340

############# Class : event::callback_data ##############

package event::callback_data;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
@ISA = qw( event );
%OWNER = ();
%ITERATORS = ();
*swig_callback_notification_get = *eventc::callback_data_callback_notification_get;
*swig_callback_notification_set = *eventc::callback_data_callback_notification_set;
*swig_next_get = *eventc::callback_data_next_get;
*swig_next_set = *eventc::callback_data_next_set;
sub new {
    my $pkg = shift;
    my $self = eventc::new_callback_data(@_);
    bless $self, $pkg if defined($self);
}

sub DESTROY {
    return unless $_[0]->isa('HASH');
    my $self = tied(%{$_[0]});
    return unless defined $self;
    delete $ITERATORS{$self};
    if (exists $OWNER{$self}) {
        eventc::delete_callback_data($self);
        delete $OWNER{$self};
341 342 343
    }
}

344
sub DISOWN {
345
    my $self = shift;
346 347
    my $ptr = tied(%$self);
    delete $OWNER{$ptr};
348 349
}

350
sub ACQUIRE {
351
    my $self = shift;
352 353
    my $ptr = tied(%$self);
    $OWNER{$ptr} = 1;
354 355 356
}


357 358 359 360
# ------- VARIABLE STUBS --------

package event;

361
*EVENT_LIBRARY_VERSION = *eventc::EVENT_LIBRARY_VERSION;
362 363 364 365 366 367 368 369 370 371
*MAXHOSTNAMELEN = *eventc::MAXHOSTNAMELEN;
*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;
372 373 374 375 376 377 378 379 380 381 382 383 384
*EA_TAG_DONE = *eventc::EA_TAG_DONE;
*EA_Site = *eventc::EA_Site;
*EA_Experiment = *eventc::EA_Experiment;
*EA_Group = *eventc::EA_Group;
*EA_Host = *eventc::EA_Host;
*EA_Type = *eventc::EA_Type;
*EA_Name = *eventc::EA_Name;
*EA_Event = *eventc::EA_Event;
*EA_Arguments = *eventc::EA_Arguments;
*EA_ArgInteger = *eventc::EA_ArgInteger;
*EA_ArgFloat = *eventc::EA_ArgFloat;
*EA_ArgString = *eventc::EA_ArgString;
*EA_When = *eventc::EA_When;
385 386

my %__callback_data_list_hash;
387
tie %__callback_data_list_hash,"event::callback_data", $eventc::callback_data_list;
388
$callback_data_list= \%__callback_data_list_hash;
389
bless $callback_data_list, event::callback_data;
390 391 392 393 394
*event_string_buffer = *eventc::event_string_buffer;
1;
#
# CODE PAST THIS POINT WAS NOT AUTOMATICALLY GENERATED BY SWIG
#
395
#
396
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file 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 Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
416
#
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
# 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
436 437
# did, call the perl callback function. Handle both blocking and non-blocking
# versions of the call
438
#
439 440 441 442 443 444 445 446 447
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);
	}
448 449

	if ($rv) {
450
		die "Trouble in event_poll - returned $rv\n";
451 452
	}

453 454
	while (my $data = dequeue_callback_data() ) {
		&$event::callback($handle,$data->{callback_notification},
455
				$event::callback_data);
456 457
		event_notification_free($handle,$data->{callback_notification});
		free_callback_data($data);
458 459 460 461 462
	}

	return 0;
}

463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
#
# 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);
}

479 480 481 482 483 484 485
#
# 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.)
#
486 487
use English;
use Carp qw(cluck);
488 489 490 491 492 493 494 495
use libtestbed;

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

#
496
# Warn after a failed event send. First argument is the error
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
# 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";
	}

514
	$text = "$message - In $progname - $EventErrorString";
515

516
	cluck($text);
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
}

#
# 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) {
557
		EventWarn("Event Send failed");
558 559 560 561 562
	}

	return $result;
}

Leigh Stoller's avatar
Leigh Stoller committed
563 564 565 566 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
#
# Register with the event system. You would use this if you are not
# running on boss. The inline registration below is a convenience for
# testbed software, but is technically bad practice. See the END block
# below where we disconnect at exit.
#
sub EventRegister(;$$) {
        my ($host, $port) = @_;

	if ($event::EventSendHandle) {
	        if (event_unregister($event::EventSendHandle) == 0) {
			warn "Could not unregister with event system";
		}
		$event::EventSendHandle = undef;
	}

	$host = TB_EVENTSERVER()
	    if (!defined($host));

	my $URL = "elvin://$host";
	$URL   .= ":$port"
	    if (defined($port));
	
	$event::EventSendHandle = event_register($URL,0);
	
	if (!$event::EventSendHandle) {
		$EventErrorString = "Unable to register with the event system";
		return undef;
	}

	return 1;
}

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 626
#
# SSL variant.
#
sub EventRegisterWithSSL($$$$) {
        my ($host, $port, $certfile, $keyfile) = @_;

	if ($event::EventSendHandle) {
	        if (event_unregister($event::EventSendHandle) == 0) {
			warn "Could not unregister with event system";
		}
		$event::EventSendHandle = undef;
	}

	$host = TB_EVENTSERVER()
	    if (!defined($host));

	my $URL = "elvin://$host";
	$URL   .= ":$port"
	    if (defined($port));
	
	$event::EventSendHandle = event_register_withssl($URL, 0,
							 $certfile, $keyfile);
	
	if (!$event::EventSendHandle) {
		$EventErrorString = "Unable to register with the event system";
		return undef;
	}

	return 1;
}

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

630 631 632 633 634
	#
	# Only connect on the first call - thereafter, just use the existing
	# handle. The handle gets disconnected in the END block below
	#
	if (!$event::EventSendHandle) {
Leigh Stoller's avatar
Leigh Stoller committed
635
		EventRegister("localhost", TB_BOSSEVENTPORT());
636 637 638 639 640 641

		if (!$event::EventSendHandle) {
			$EventErrorString =
				"Unable to register with the event system";
			return undef;
		}
642 643 644 645 646 647 648 649 650 651 652 653 654
	}

	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;

655 656
	my $notification = event_notification_alloc($event::EventSendHandle,
		$tuple);
657 658 659 660 661
	if (!$notification) {
		$EventErrorString = "Could not allocate notification";
		return undef;
	}

662
	if (!event_notify($event::EventSendHandle, $notification)) {
663 664 665 666
		$EventErrorString = "Could not send event notification";
		return undef;
	}

667
	event_notification_free($event::EventSendHandle, $notification);
668 669 670 671 672
	address_tuple_free($tuple);

	return 1;
}

673 674 675 676 677 678 679 680 681
#
# 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;
}

682 683 684 685 686 687 688 689 690 691 692
#
# 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";
		}
	}
}

693
push @EXPORT, qw(event_subscribe event_poll event_poll_blocking EventSend
694 695
	EventSendFatal EventSendWarn EventFork EventRegister
        EventRegisterWithSSL);
696 697
1;