package de.geis.printserver;

import org.tanukisoftware.wrapper.WrapperManager;

import java.io.File;

import org.tanukisoftware.wrapper.WrapperListener;

public class Main
    implements WrapperListener
{
    private FileSystemWatcher m_watcher;

    private Main()
    {
    }

    @Override
	public Integer start( String[] args ) {	
    	
    	Parameters.setConfigFolder(new File(args[0]));
    	Parameters.setErrorFolder(new File(args[1]));
    	Parameters.setFileFolder(new File(args[2]));
    	
    	Parameters.setDelayTime(Integer.parseInt(new File(args[3]).toString()));
    	Parameters.setVersuche(Integer.parseInt(new File(args[4]).toString()));

    	System.out.println("DELAY = " + Parameters.getDelayTime());
    	System.out.println("VERSUCHE = " + Parameters.getVersuche()); 
    	
    	m_watcher = new FileSystemWatcher();
    	
    	try {
			m_watcher.start();
			
		} catch (Exception e) {
		
		}
    	System.out.println("STARTED");
    	
        return null;
    }

    @Override
	public int stop( int exitCode )
    {
        return exitCode;
    }
    
    @Override
	public void controlEvent( int event )
    {
        if ( ( event == WrapperManager.WRAPPER_CTRL_LOGOFF_EVENT )
                && ( WrapperManager.isLaunchedAsService() || WrapperManager.isIgnoreUserLogoffs() ) )
        {
                // Ignore
        }
        else
        {
                WrapperManager.stop( 0 );
                // Will not get here.
        }
    }

    public static void main( String[] args )
    {    	
        WrapperManager.start( new Main(), args );
    }
}