/**
 * File:	modules/NetworkConfig.ycp
 * Package:	Network configuration
 * Summary:	Network configuration data
 * Authors:	Michal Svec <msvec@suse.cz>
 *
 * $Id: NetworkConfig.ycp 18046 2004-07-08 06:18:16Z mvidner $
 *
 * Representation of the configuration of network cards.
 * Input and output routines.
 * A simple container for /etc/sysconfig/network/{config,dhcp}
 */

{

module "NetworkConfig";
textdomain "network";

include "network/config.ycp";

/**
 * Basic network settings (/etc/sysconfig/network/config)
 */
global map Config = $[];

/**
 * DHCP settings (/etc/sysconfig/network/dhcp)
 */
global map DHCP = $[];

/**
 * Basic network settings
 */
map Orig_Config = nil;

/**
 * DHCP settings
 */
map Orig_DHCP = nil;

/*--------------*/
/* PRIVATE DATA */

/**
 * True if data are already read
 */
boolean initialized = false;

/*------------------*/
/* GLOBAL FUNCTIONS */

/**
 * Data was modified?
 * @return true if modified
 */
global define boolean Modified() {
    boolean ret = (DHCP != Orig_DHCP || Config != Orig_Config);
    y2debug("ret=%1", ret);
    return ret;
}

/**
 * Read all network settings from the SCR
 * @return true on success
 */
global define boolean Read() {

    if(initialized == true) return true;

    Config = ReadConfig(.sysconfig.network.config);
    DHCP = ReadConfig(.sysconfig.network.dhcp);

    Orig_Config = (map) eval(Config);
    Orig_DHCP = (map) eval(DHCP);

    initialized = true;
    return true;
}

/**
 * Update the SCR according to network settings
 * @return true on success
 */
global define boolean Write() {

    y2milestone("Writing configuration");
    if(!Modified()) {
	y2milestone("No changes to NetworkConfig -> nothing to write");
	return true;
    }

    WriteConfig(.sysconfig.network.dhcp, DHCP);
    WriteConfig(.sysconfig.network.config, Config);

    return true;
}

/**
 * Import data
 * @param settings settings to be imported
 * @return true on success
 */
global define boolean Import(map settings) {

    Config = (map) eval(settings["config"]:$[]);
    DHCP = (map) eval(settings["dhcp"]:$[]);

    Orig_Config = nil;
    Orig_DHCP = nil;

    return true;
}

/**
 * Export data
 * @return dumped settings (later acceptable by Import())
 */
global define map Export() {

    return (map) eval($[
	"config"	: Config,
	"dhcp"		: DHCP,
    ]);

}

/* EOF */
}
