Package uk.co.nimp.scardterminalmanager

Source Code of uk.co.nimp.scardterminalmanager.TerminalLoggingWindow

/**
*
* @author Sebastien Riou
*/

package uk.co.nimp.scardterminalmanager;

import uk.co.nimp.scardterminalmanager.TerminalInfo;
import com.atolsystems.atolutilities.ATimeUtilities;
import com.atolsystems.atolutilities.LoggingWindow;
import java.io.IOException;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import uk.co.nimp.scard.GenericTerminal;
import uk.co.nimp.scard.ScardLogHandler;
import uk.co.nimp.scard.log.ScardPrintStreamLogHandler;


public class TerminalLoggingWindow extends LoggingWindow {
   
    final TerminalInfo tI;
    final GenericTerminal terminal;
    final String terminalName;
    ScardPrintStreamLogHandler logHandler;
    PrintStream outStream;
    PipedOutputStream pos;

    public TerminalInfo gettI() {
        return tI;
    }

    public GenericTerminal getTerminal() {
        return terminal;
    }

    public String getTerminalName() {
        return terminalName;
    }

    public TerminalLoggingWindow(TerminalInfo tI) throws IOException {
        super();
        this.tI=tI;
        this.terminal = tI.getTerminal();
        this.terminalName=this.terminal.getName();
        //this.streamMonitor.setTextMaxSize(0x8000);
        monitorStream();
    }

    public boolean isMonitoring(){
        return (null!=logHandler) ? true : false;
    }

    public void monitorStream() throws IOException{
        if(null==logHandler){
            pos = new PipedOutputStream();
            outStream=new PrintStream(pos);
            logHandler=new ScardPrintStreamLogHandler(outStream, this);
            terminal.addLogHandler(logHandler);
            super.monitorStream(pos);
        }
    }

    @Override
    public void monitorStream(PipedOutputStream pos){
        throw new RuntimeException();
    }

    @Override
    public void stopMonitoring(){
        try {
            super.stopMonitoring();
            terminal.removeLog(logHandler);
            logHandler=null;
            outStream=null;
            pos=null;
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    public void logAbsence(){
        terminal.logLine(ScardLogHandler.LOG_ERROR, ATimeUtilities.getTimeForUi()+" TERMINAL ABSENT");
    }

    public PipedOutputStream getStream(){
        return pos;
    }
}
TOP

Related Classes of uk.co.nimp.scardterminalmanager.TerminalLoggingWindow

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.