###
###  Copyright 2000-2007 University of Illinois Board of Trustees
###  All rights reserved. 
###
###  dtlogin.pm - psgconf module for CDE Login Manager configuration
###
###  Campus Information Technologies and Educational Services
###  University of Illinois at Urbana-Champaign
###


package PSGConf::Control::dtlogin;

use strict;

use PSGConf::Action::GenerateFile::EnvFile;
use PSGConf::Action::RestartDaemon;
use PSGConf::Data::Boolean;
use PSGConf::Data::Hash;


###############################################################################
###  Policy methods
###############################################################################

sub _policy_enable_rc
{
	my ($self, $psgconf) = @_;

	return
		if ( $psgconf->data_obj('dtlogin_enable')->equals('false') );

	if ( $psgconf->data_obj('dtlogin_uses_inittab')->equals('true') ) {
		$psgconf->data_obj('inittab')->replace_row_cells(
			{ 0 => 'dt_nogb' },
			{ 2 => 'respawn' }
		);
	} else {
     	$psgconf->data_obj('rc_scripts')->insert(
			{ 'dtlogin' => { 'state' => 'enable' }}
		);
	}
}

###############################################################################
###  decide() method
###############################################################################

sub decide
{
	my ($self, $psgconf) = @_;

	return
		if ( $psgconf->data_obj('dtlogin_enable')->equals('false') );

	$psgconf->register_actions(
		PSGConf::Action::GenerateFile::EnvFile->new(
			name		=> '/etc/dt/config/Xconfig',
			description	=> 'config file for dtlogin',
			seperator	=> ":\t",
			vars		=> $psgconf->data_obj('dtlogin_options')->get()
		),
		PSGConf::Action::RestartDaemon->new(
			name			=> 'dtlogin',
			pidfile		=> $psgconf->data_obj('dtlogin_options')->find('Dtlogin.pidFile'),
			filename		=> [ '/etc/dt/config/Xconfig' ]
		)
	);
}


###############################################################################
###  constructor
###############################################################################

sub new
{
	my ($class, $psgconf) = @_;
	my ($self);

	$self = {};
	bless($self, $class);

	$self->{name} = 'dtlogin';
	$self->{enable} = $self->{name} . '_enable';

	$psgconf->register_data(
		dtlogin_enable		=> PSGConf::Data::Boolean->new(
						value => 'false'
					   ),
		dtlogin_uses_inittab	=> PSGConf::Data::Boolean->new(
						value => 'false'
					   ),
		dtlogin_options		=> PSGConf::Data::Hash->new()
	);

	$psgconf->register_policy($self,
		dtlogin_enable_rc_scripts	=> '_policy_enable_rc',
	);

	return $self;
}


###############################################################################
###  documentation
###############################################################################

1;

__END__

=head1 NAME

PSGConf::Control::dtlogin - psgconf module for CDE Login Manager configuration

=head1 SYNOPSIS

In F<psgconf_modules>:

  Control PSGConf::Control::dtlogin

=head1 DESCRIPTION

The B<PSGConf::Control::dtlogin> module provides a B<psgconf> control object
for configuring the CDE Login Manager.  It supports the following methods:

=over 4

=item new()

The constructor.  Its parameter is a reference to the B<PSGConf>
object.  It registers the following data objects:

=over 4

=item I<dtlogin_enable>

A B<PSGConf::Data::Boolean> object to determine whether or not to
write F</etc/dt/config/Xconfig>.

=item I<dtlogin_uses_inittab>

A B<PSGConf::Data::Boolean> object to determine how to configure the
RC startup script.  The two choices are to use I<rc_scripts> or the
I<inittab> hashes.  Defaults to false, which means using the
I<rc_scripts> hash.

=item I<dtlogin_options>

A B<PSGConf::Data::Hash> object that contains the options to put
into F</etc/dt/config/Xconfig>.

=back

=item decide()

If I<dtlogin_enable> is set, instantiates and registers a
B<PSGConf::Action::GenerateFile::EnvFile> object to create
F</etc/dt/config/Xconfig>.

If the file has been changed, it will also restart the C<dtlogin>
daemon via the B<PSGConf::Action::RestartDaemon> object.

=back

=head1 SEE ALSO

L<perl>

L<PSGConf>

L<PSGConf::Action::GenerateFile::EnvFile>

L<PSGConf::Action::RestartDaemon>

L<PSGConf::Data::Boolean>

L<PSGConf::Data::Hash>

L<psgconf-intro>

=cut



syntax highlighted by Code2HTML, v. 0.9.1