001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.rGUI.server.controllers;
020
021import java.rmi.RemoteException;
022import java.util.ArrayList;
023import java.util.concurrent.Semaphore;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028import pt.ua.dicoogle.core.ServerSettings;
029import pt.ua.dicoogle.rGUI.interfaces.controllers.INetworkInterfaces;
030
031/**
032 *
033 * @author Carlos Ferreira
034 */
035@Deprecated
036public class NetworkInterfaces implements INetworkInterfaces
037{
038    private ServerSettings settings;
039    private static Semaphore sem = new Semaphore(1, true);
040    private static NetworkInterfaces instance = null;
041
042    public static synchronized NetworkInterfaces getInstance()
043    {
044        try
045        {
046            sem.acquire();
047            if (instance == null)
048            {
049                instance = new NetworkInterfaces();
050            }
051            sem.release();
052        } catch (InterruptedException ex)
053        {
054            LoggerFactory.getLogger(QRServers.class).error(ex.getMessage(), ex);
055        }
056        return instance;
057    }
058
059    private NetworkInterfaces()
060    {
061        settings = ServerSettings.getInstance();
062    }
063
064    @Override
065    public ArrayList<String> getNetworkInterfaces() throws RemoteException
066    {
067        return this.settings.getNetworkInterfacesNames();
068    }
069
070    @Override
071    public void setNetworkInterface(String name) throws RemoteException
072    {
073        if(name != null)
074        {
075            //System.out.println("interface chosen: " + name);
076            this.settings.setNetworkInterfaceName(name);
077        }
078    }
079
080    @Override
081    public String getNetworkInterface() throws RemoteException
082    {
083        return this.settings.getNetworkInterfaceName();
084    }
085
086
087}