################################################################################
# TEST:	emosinit
################################################################################
# Copyright (C) 2000  EMOS Computer Consulting GmbH
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# For further information please contact:
#
#	Dean Rajovic
#	EMOS Computer Consulting GmbH
#	Oskar-Messter-Strae 25
#	85737 Ismaning
#	Germany
#	tel.: +49 89 608 765-0
#	mailto:drajovic@emos.de
#	http://www.emos.de
################################################################################
# $Revision: 1.2 $
# $Author: drajovic $
# $Date: 2004/03/24 22:16:21 $
# $Source: d:\\Archive/FRAMEWORK\\EMOS_GPL/emosinit/script,v $
# $NoKeywords: $
################################################################################

#/*** 
#*	Loads/unloads all EMOS libraries. 
#*/

static const LIBS[] = { 
	 "EMOS_GPL/STD/EMOS_STD_misc_lib"
	,"EMOS_GPL/STD/EMOS_STD_attr_lib"
	,"EMOS_GPL/STD/EMOS_STD_list_lib"
	,"EMOS_GPL/STD/EMOS_STD_menue_lib"
	,"EMOS_GPL/STD/EMOS_STD_string_lib"
	,"EMOS_GPL/STD/EMOS_STD_win_lib"
	,"EMOS_GPL/STD/EMOS_STD_registry_lib"
	,"EMOS_GPL/STD/MISHA_STD_re_func_lib"
	,"EMOS_GPL/STD/EMOS_STD_err_lib"
	,"EMOS_GPL/DDT/EMOS_DDT_lib"
	,"EMOS_GPL/DDT/EMOS_DDT_ACCESS_lib"
	#,"DDT/EMOS_DDT_ACCESS_Range_lib"
	,"EMOS_GPL/FRM/EMOS_FRM_lib"
	,"EMOS_GPL/FRM/EMOS_FRM_driver_lib"
	,"EMOS_GPL/FRM/EMOS_FRM_driver_retry_lib"
	,"EMOS_GPL/FRM/EMOS_FRM_stp_lib"
	,"EMOS_GPL/FRM/EMOS_FRM_gui_lib"
	,"EMOS_GPL/FRM/EMOS_FRM_web_lib"
	,"EMOS_GPL/FRM/EMOS_FRM_result_lib"
};

#/**
#* Reloads all EMOS libraries.
#*@param p1 (in)	1 = load all as system modules
#*			0 = load all as user modules [default = 0]
#*@param p2 (in)	1 = close after load, do not animate
#*			0 = leave open after load, animate [default = 0]
#*@return
#*	E_OK:	success
#*	!E_OK:	failure
#*/

public function reload_all_emos_libs( in p1, in p2 )
{
	auto i, count = 0, rc = 0;
	for ( i in LIBS )
		count++;
	# we do this to ensure the load sequence
	for ( i=0; i<count; i++ )
		rc+=reload( LIBS[i], p1, p2 );
	rc+=reload_wrlog( p1, p2 );
	rc+=reload_wrsync( p1, p2 );
	return rc;
}

#/**
#*	Unloads all EMOS libraries.
#*@return
#*	E_OK:	success
#*	!E_OK:	failure
#*/

public function unload_all_emos_libs()
{
	auto i, rc = 0;
	for ( i in LIBS )
		rc+=unload( LIBS[i] );
	rc+=unload_wrlog();
	rc+=unload_wrsync();
	return rc;
}

#/**
#* Loads WrLog interface. If real interface is not found, then dummy interface is loaded.
#*@param p1 (in)	1 = load all as system modules
#*			0 = load all as user modules [default = 0]
#*@param p2 (in)	1 = close after load, do not animate
#*			0 = leave open after load, animate [default = 0]
#*@return
#*	E_OK:	success
#*	!E_OK:	failure
#*/

public function reload_wrlog ( in p1, in p2 )
{
	auto dummy_lib = "EMOS_GPL/STD/EMOS_STD_wrlog_lib";
	auto real_lib = "EMOS/WrLogBrowser/WR/EMOS_wrlog_lib";
	auto lib, fil;
	auto rc;
    # first try the real wrlog interface
	lib = sprintf( "%s/lib/%s", getenv ("M_ROOT"), real_lib );
	fil = sprintf( "%s/script", lib );
	if ( file_open( fil, FO_MODE_READ ) == E_OK )
	{
	    file_close( fil );
	    return reload( lib, p1, p2 );
	}
    # second try the dummy wrlog interface
	lib = sprintf( "%s/lib/%s", getenv ("M_ROOT"), dummy_lib );
	fil = sprintf( "%s/script", lib );
	if ( file_open( fil, FO_MODE_READ ) == E_OK )
	{
	    file_close( fil );
	    return reload( lib, p1, p2 );
	}
	return E_FILE_NOT_FOUND;
}

#/**
#*	Unloads WrLog interface.
#*@return
#*	E_OK:	success
#*	!E_OK:	failure
#*/

public function unload_wrlog ()
{
	auto dummy_lib = "EMOS_GPL/STD/EMOS_STD_wrlog_lib";
	auto real_lib = "EMOS/WrLog/EMOS_wrlog_lib";
	auto lib, fil;
	auto rc;
    # first try the real wrlog interface
	lib = sprintf( "%s/lib/%s", getenv ("M_ROOT"), real_lib );
	fil = sprintf( "%s/script", lib );
	if ( file_open( fil, FO_MODE_READ ) == E_OK )
	{
	    file_close( fil );
	    return unload( lib );
	}
    # second try the dummy wrlog interface
	lib = sprintf( "%s/lib/%s", getenv ("M_ROOT"), dummy_lib );
	fil = sprintf( "%s/script", lib );
	if ( file_open( fil, FO_MODE_READ ) == E_OK )
	{
	    file_close( fil );
	    return unload( lib );
	}
	return E_FILE_NOT_FOUND;
}

#/**
#* Loads WrSync interface. If interface is not found, nothing is loaded 
#* and E_OK is returned.
#*@param p1 (in)	1 = load all as system modules
#*			0 = load all as user modules [default = 0]
#*@param p2 (in)	1 = close after load, do not animate
#*			0 = leave open after load, animate [default = 0]
#*@return
#*	E_OK:	success or wrsync not present
#*	!E_OK:	failure
#*/

public function reload_wrsync ( in p1, in p2 )
{
	auto real_lib = "EMOS/WrSync/EMOS_wrsync_lib";
	auto lib, fil;
	auto rc;

	lib = sprintf( "%s/lib/%s", getenv ("M_ROOT"), real_lib );
	fil = sprintf( "%s/script", lib );
	if ( file_open( fil, FO_MODE_READ ) == E_OK )
	{
	    file_close( fil );
	    return reload( lib, p1, p2 );
	}
	return E_OK;
}

#/**
#*	Unloads WrSync interface.
#*@return
#*	E_OK:	success or wrsync not present
#*	!E_OK:	failure
#*/

public function unload_wrsync ()
{
	auto real_lib = "EMOS/WrSync/EMOS_wrsync_lib";
	auto lib, fil;
	auto rc;

	lib = sprintf( "%s/lib/%s", getenv ("M_ROOT"), real_lib );
	fil = sprintf( "%s/script", lib );
	if ( file_open( fil, FO_MODE_READ ) == E_OK )
	{
	    file_close( fil );
	    return unload( lib );
	}
	return E_OK;
}

#===============================================================================
# function prototypes
#===============================================================================

static const FUNCS[] = { 
#	 "FRM/EMOS_FRM_funcs"
	 "EMOS_GPL/FRM/EMOS_FRM_GUI_funcs"
#	,"FRM/EMOS_FRM_UTIL_funcs"
};

#/**
#*	Generates function prototypes for selected EMOS_GPL functions.
#*/

public function generate_emos_function_prototypes( )
{
	auto i;
	for ( i in FUNCS )
		eval( "call \"" & FUNCS[i] & "\"();" );
}

#public const MROOT = getenv ("M_ROOT");

#reload (MROOT & "\\lib\\EMOS_GPL\\emos_libs", 0, 1 );
reload_all_emos_libs( 0, 1 );
generate_emos_function_prototypes();
