001package jmri.jmrit.withrottle;
002
003import org.slf4j.Logger;
004import org.slf4j.LoggerFactory;
005
006/**
007 * Interface for WiThrottle device managers.
008 *
009 * @author Randall Wood Copyright 2011, 2017
010 */
011public interface DeviceManager {
012
013    void listen();
014
015    default void createServerThread() {
016        new DeviceManagerThread(this).start();
017    }
018
019    /**
020     * Add a device listener that will be added for each new
021     * device connection
022     *
023     * @param dl the device listener to add 
024     */
025    void addDeviceListener(DeviceListener dl);
026
027    /**
028     * Remove a device listener from the list that will be added for each new
029     * device connection
030     *
031     * @param dl the device listener to remove
032     */
033    void removeDeviceListener(DeviceListener dl);
034
035    /**
036     * Specify a roster group to send
037     *
038     * @param group the roster group. 
039     */
040    void setSelectedRosterGroup(String group);
041
042    /**
043     * the roster group to send. 
044     *
045     * @return the roster group
046     */
047    String getSelectedRosterGroup();
048
049    /**
050     * Container for running {@link #listen() } in a separate thread.
051     */
052    class DeviceManagerThread extends Thread {
053
054        DeviceManager manager;
055
056        DeviceManagerThread(DeviceManager manager) {
057            this.manager = manager;
058            this.setName("WiThrottleServer"); // NOI18N
059        }
060
061        @Override
062        public void run() {
063            manager.listen();
064            log.debug("Leaving DeviceManagerThread.run()");
065        }
066
067        private final static Logger log = LoggerFactory.getLogger(DeviceManagerThread.class);
068    }
069}