package Statusmon::Statusmon;

# no warnings qw( uninitialized );

use Schedule;
use bbdisp;

@Statusmon::Statusmon::ISA = qw(Schedule);

%Statusmon::feature_providers = ();




sub init {
    $Statusmon::display = new bbdisp( "$BigSister::common::fs{'adm'}/bb-display.cfg" );
    add_feature_provider( $Statusmon::display, "display" );
}


sub new {
    print STDERR "new what??\n";
}


sub setarg {
    my( $self, $name, $val ) = @_;

    unless( defined $self->{"arguments"} ) {
	$self->{"arguments"} = {};
    }
    $self->{"arguments"}->{$name} = $val;
}



sub getarg {
    my( $self, $name ) = @_;

    return( $self->{"arguments"}->{$name} );
}


sub start {
    ;
}


sub register {
    my( $self, @masks ) = @_;
    my $add = 1;

    unless( defined $self->{"reqmask"} ) {
	$self->{"reqmask"} = 0;
    }
    my $mask;
    foreach $mask (@masks) {
	if( substr( $mask, 0, 1 ) eq "+" ) {
	    $add = 1;
	    $mask = substr( $mask, 1 );
	}
	elsif( substr( $mask, 0, 1 ) eq "-" ) {
	    $add = 0;
	    $mask = substr( $mask, 1 );
	}
	$mask = $BigSister::common::cmd_groups{$mask};
	if( $add ) {
	    $self->{"reqmask"} |= $mask;
	}
	else {
	    $self->{"reqmask"} &= ~$mask;
	}
    }
}


sub event {
    my( $self, $cmd ) = @_;
    ;
}


sub post_event {
    my( $self, $cmd, $org_event ) = @_;

    if( $org_event ) {
        $cmd->{"id"} = $org_event->{"id"};
    }
    main::event( $cmd );
}


sub add_feature_provider {
    my( $self, $feature ) = @_;

    $Statusmon::feature_providers{$feature} = $self;
}


sub get_feature_provider {
    my( $self, $feature ) = @_;

    return(undef) unless( defined $Statusmon::feature_providers{$feature} );
    return( $Statusmon::feature_providers{$feature} );
}


sub get_statustext {
    my( $self, $code ) = @_;

    return $BigSister::common::status_texts{$code};
}


sub get_statuscode {
    my( $self, $text ) = @_;

    return $BigSister::common::status_codes{$text};
}


sub get_current_status {
    my( $self, $check ) = @_;

    if( defined $BigSister::common::current_status{$check} ) {
	return( $BigSister::common::current_status{$check}->{"status"} );
    }
    return undef;
}


sub get_current_text {
    my( $self, $check ) = @_;

    if( defined $BigSister::common::current_text{$check} ) {
	return( $BigSister::common::current_text{$check}->{"text"} );
    }
    return undef;
}



sub get_checks {
    my( $self, $group ) = @_;

    if( defined $BigSister::common::current_status_c{$group} ) {
	return( keys %{$BigSister::common::current_status_c{$group}} );
    }
    return ();
}


sub get_hosts {
    my( $self ) = @_;

    return( keys %BigSister::common::current_status_c );
}


sub abort {
}


sub loopback {
    my( $self, $cmd ) = @_;

    main::decode( $cmd );
}


sub background {
    my( $self ) = @_;

    if( ! $Platform::has_fork ) {
	return -1;
    }
    my $pid = fork();
    if( ($pid == -1) || ($pid > 0) ) { return $pid; }
    abort();
    return 0;
}

1;
