/*
This source file is part of Scol
For the latest info, see http://www.scolring.org

Copyright (c) 2010 Stephane Bisaro, aka Iri <iri@irizone.net>

This program 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 of the License, or (at your option) any later
version.

This program 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 program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt

For others informations, please contact us from http://www.scolring.org/
*/

#include "main.h"

#if defined _WIN32 || defined __WIN32__
cbmachine ww;
#endif
mmachine  mm;


int initSPP (void)
{
    spPartition = malloc (sizeof (struct scolPathPartition));
    if (spPartition == NULL)
        return 1;
    spPartition->admin = NULL;
    spPartition->admin = malloc (sizeof (char) * SIZESIGN);
    memset (spPartition->admin, '\0', SIZESIGN-1);
    spPartition->admin = lib_sys_getDatasFromUsm (spPartition->admin, NULL, 16665, lib_sys_getPathAdminPartition);

    spPartition->cache = NULL;
    spPartition->cache = malloc (sizeof (char) * SIZESIGN);
    memset (spPartition->cache, '\0', SIZESIGN-1);

    spPartition->log = NULL;
    spPartition->log = malloc (sizeof (char) * SIZESIGN);
    memset (spPartition->log, '\0', SIZESIGN-1);

    spPartition->user = NULL;
    spPartition->user = malloc (sizeof (char) * SIZESIGN);
    memset (spPartition->user, '\0', SIZESIGN-1);
    spPartition->user = lib_sys_getDatasFromUsm (spPartition->user, NULL, 16665, lib_sys_getPathPartition);
    return 0;
}

void endSPP (void)
{
    free (spPartition->admin);
    free (spPartition->cache);
    free (spPartition->log);
    free (spPartition->user);
    free (spPartition);
    return;
}




/* Loading library ...*/

int SCOLinitSYSPACKclass (mmachine m)
{
    int k = 0;
    MMechostr (MSKDEBUG, "SCOLinitSYSPACKclass library : entering\n");

    if ((k = initSPP ())) return k;

    /* load tempfile */
    if ((k = SCOLinitTEMPFILEclass (m))) return k;
    /* load standard library */
    if ((k = SCOLinitSTANDARDLIBRARYclass (m))) return k;
    /* load benchmark lib */
    if ((k = SCOLinitBENCHMARKclass (m))) return k;
    /* load update lib */
    if ((k = SCOLinitUPDATEclass (m))) return k;

    return k;
}

/*
    Fonctions de chargement / déchargement de la librairie / bibliothèque
    - Version MS Windows
    - Version GNU / Linux
    - Version Apple MacOS X : à faire ... :)
*/
#if defined _WIN32 || defined __WIN32__
# define SCOL_SYSPACK_PLUGIN_EXPORT __declspec (dllexport)
#elif defined linux || defined __linux
# define SCOL_SYSPACK_PLUGIN_EXPORT
#else
# error no platform supported
#endif

SCOL_SYSPACK_PLUGIN_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
{
    ww = w;
    mm = m;

    SCOLinitplugin (w);
    return SCOLinitSYSPACKclass (m);
}

/*
  Fonction de déchargement de la librairie
*/
SCOL_SYSPACK_PLUGIN_EXPORT int ScolUnloadPlugin()
{
    endSPP ();
    return 0;
}

