package org.aohe.scan;


import org.aohe.core.twain.Twain;
import org.aohe.core.twain.TwainScanner;
import org.aohe.exceptions.TwainException;

import java.util.ArrayList;
import java.util.List;

public class SourceManager {

    private static SourceManager instance;

    public static SourceManager instance() {
        if (instance == null) {
            instance = new SourceManager();
        }
        return instance;
    }

    public List<Source> getSources() throws TwainException {
        List<Source> ret = new ArrayList<>();

        for (String s : TwainScanner.getScanner().getDeviceNames()) {
            Source source = new Source();
            source.setName(s);

            ret.add(source);
        }

        return ret;
    }

    public void freeResources() {
        Twain.done();
    }

}
