#!/usr/bin/perl -w
#
# ecaccess-event-clear: Clear an ECaccess Event
#
# Laurent.Gougeon@ecmwf.int - 2010-10-15

use ECMWF::ECaccess;
use Getopt::Long;
use Pod::Usage;
use Term::ReadKey;

my %opt = ( version => 0, help => 0, manual => 0, debug => 0 );

pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions(
	\%opt,
	qw(
	  version
	  help|?
	  manual
	  debug
	  )
);

# Display version if requested
die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} );

my $eventid = $ARGV[0];

pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} );
pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} );
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No event-id specified!\n" ) if not($eventid);

# Create the ECaccess Controler
my $ecaccess = ECMWF::ECaccess->new();
$ecaccess->setDebug( $opt{debug} );

# Get the Token (using the Certificate in $HOME)
my $token = $ecaccess->getToken();

# Get the Control Channel
my $controlChannel = $ecaccess->getControlChannel();

# Delete the event
$controlChannel->clearEvent( $token, $eventid );

# Logout
$ecaccess->releaseToken($token);

__END__

=head1 NAME

ecaccess-event-clear - Clear an ECaccess Event

=head1 SYNOPSIS

B<ecaccess-event-clear -version|-help|-manual>

B<ecaccess-event-clear> I<event-id>

=head1 DESCRIPTION

Allow clearing the event specified by its I<event-id>. Delete all the subscritions to
this event and reset the sequence number.

=head1 ARGUMENTS

=over 8

=item I<event-id>

The identifier of the Event to clear.

=back

=head1 OPTIONS

=over 8

=item B<-version>

Display version number and exits.

=item B<-help>

Print a brief help message and exits.

=item B<-manual>

Prints the manual page and exits.

=item B<-debug>

Display the SOAP messages exchanged.

=back

=head1 EXAMPLES

B<ecaccess-event-clear> I<167>

Clear the event I<167>.

=head1 SEE ALSO

B<ecaccess-event-grant>, B<ecaccess-event-delete>, B<ecaccess-event-send>, B<ecaccess-event-list>,
B<ecaccess-event-create> and B<ecaccess>.

=cut
