From c405ddad96be9e6ad0cd9510f8d4066abf7861d1 Mon Sep 17 00:00:00 2001 From: denny Date: Sat, 2 Jan 2016 12:29:40 -0500 Subject: [PATCH] Work in progress - program compiles and runs --- license/copyright_header.txt | 2 +- src/alias/action/AliasActionManager.java | 11 +- src/audio/AudioModule.java | 4 +- .../ConfigurationControllerModel.java | 64 ++-- src/controller/ControllerPanel.java | 24 +- src/controller/ResourceManager.java | 36 +- src/controller/channel/Channel.java | 343 ++---------------- src/controller/channel/ChannelEditor.java | 6 +- src/controller/channel/ChannelEvent.java | 67 ++-- .../channel/ChannelEventListener.java | 2 +- src/controller/channel/ChannelManager.java | 143 -------- src/controller/channel/ChannelNode.java | 20 +- src/controller/channel/ChannelUtils.java | 8 +- src/controller/site/SiteNode.java | 4 +- src/gui/ChannelMemoryLogger.java | 40 +- src/gui/SDRTrunk.java | 47 ++- src/instrument/gui/DecoderSelectionFrame.java | 10 +- src/instrument/gui/DecoderViewFrame.java | 4 +- src/map/MapPanel.java | 6 +- src/module/decode/DecodeComponentEditor.java | 2 +- src/module/decode/DecoderFactory.java | 8 +- src/module/decode/event/CallEventPanel.java | 6 +- .../decode/event/MessageActivityPanel.java | 6 +- .../decode/p25/audio/P25AudioModule.java | 4 +- src/module/decode/state/ChannelList.java | 4 +- .../decode/state/ChannelStatePanel.java | 4 +- .../decode/state/TrafficChannelManager.java | 19 +- src/playlist/Playlist.java | 24 ++ src/playlist/PlaylistManager.java | 59 ++- src/source/SourceComponentEditor.java | 2 +- src/source/config/SourceConfigMixer.java | 1 + src/source/tuner/TunerNode.java | 8 +- src/spectrum/ChannelSpectrumPanel.java | 6 +- src/spectrum/OverlayPanel.java | 59 ++- src/spectrum/SpectralDisplayPanel.java | 7 +- src/spectrum/SpectrumFrame.java | 8 +- 36 files changed, 374 insertions(+), 694 deletions(-) delete mode 100644 src/controller/channel/ChannelManager.java diff --git a/license/copyright_header.txt b/license/copyright_header.txt index 62c7ab8b..3eaea8b8 100644 --- a/license/copyright_header.txt +++ b/license/copyright_header.txt @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2015 Dennis Sheirer + * Copyright (C) 2014-2016 Dennis Sheirer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/alias/action/AliasActionManager.java b/src/alias/action/AliasActionManager.java index 3451dbdb..d59737f7 100644 --- a/src/alias/action/AliasActionManager.java +++ b/src/alias/action/AliasActionManager.java @@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory; import sample.Listener; import alias.Alias; -import controller.ResourceManager; +import controller.ThreadPoolManager; /** * Manages all alias action events. Each received message is interrogated for @@ -23,11 +23,11 @@ public class AliasActionManager implements Listener private final static Logger mLog = LoggerFactory.getLogger( AliasActionManager.class ); - private ResourceManager mResourceManager; + private ThreadPoolManager mThreadPoolManager; - public AliasActionManager( ResourceManager resourceManager ) + public AliasActionManager( ThreadPoolManager threadPoolManager ) { - mResourceManager = resourceManager; + mThreadPoolManager = threadPoolManager; } @Override @@ -51,8 +51,7 @@ public class AliasActionManager implements Listener * action needs to setup a timer, and provide the original * message to be used as part of the action (e.g. sending * the message as a text message to a cell phone */ - action.execute( mResourceManager.getThreadPoolManager(), - alias, message ); + action.execute( mThreadPoolManager, alias, message ); } } } diff --git a/src/audio/AudioModule.java b/src/audio/AudioModule.java index 572b3b71..7e28b70d 100644 --- a/src/audio/AudioModule.java +++ b/src/audio/AudioModule.java @@ -183,10 +183,10 @@ public class AudioModule extends Module implements IAudioPacketProvider, { switch( event.getEvent() ) { - case CHANNEL_STATE_RESET: + case NOTIFICATION_STATE_RESET: mAudioMetadata.reset(); break; - case CHANGE_SELECTED: + case NOTIFICATION_SELECTION_CHANGE: mAudioMetadata.setSelected( event.getChannel().isSelected() ); break; default: diff --git a/src/controller/ConfigurationControllerModel.java b/src/controller/ConfigurationControllerModel.java index 99115842..8bbd48c3 100644 --- a/src/controller/ConfigurationControllerModel.java +++ b/src/controller/ConfigurationControllerModel.java @@ -30,21 +30,14 @@ import javax.swing.tree.TreePath; import map.IconManager; import module.decode.DecoderType; -import module.decode.config.DecodeConfigFactory; import playlist.PlaylistNode; -import source.config.SourceConfigTuner; import source.tuner.Tuner; import source.tuner.TunerGroupNode; import source.tuner.TunerNode; import source.tuner.TunerSelectionListener; import controller.channel.Channel; -import controller.channel.ChannelEvent; -import controller.channel.ChannelEvent.Event; +import controller.channel.ChannelModel; import controller.channel.ChannelNode; -import controller.site.Site; -import controller.system.System; -import controller.system.SystemListNode; -import controller.system.SystemNode; public class ConfigurationControllerModel extends DefaultTreeModel { @@ -62,6 +55,7 @@ public class ConfigurationControllerModel extends DefaultTreeModel // private RecordingGroupNode mRecordingGroupNode; private IconManager mIconManagerFrame; + private ChannelModel mChannelModel; /** * Implements a merged system controller and (tree) model. The user will @@ -69,9 +63,12 @@ public class ConfigurationControllerModel extends DefaultTreeModel * design perspective, the model and the control are necessarily merged to * work well with the JTree as the system view. */ - public ConfigurationControllerModel( ResourceManager resourceManager ) + public ConfigurationControllerModel( ChannelModel channelModel, + ResourceManager resourceManager ) { super( new BaseNode( null ) ); + + mChannelModel = channelModel; mResourceManager = resourceManager; @@ -156,7 +153,7 @@ public class ConfigurationControllerModel extends DefaultTreeModel for( Tuner tuner: tuners ) { - TunerNode child = new TunerNode( tuner ); + TunerNode child = new TunerNode( mChannelModel, tuner ); insertNodeInto( child, parent, parent.getChildCount() ); @@ -173,29 +170,30 @@ public class ConfigurationControllerModel extends DefaultTreeModel */ public void createChannel( long frequency, DecoderType decoder ) { - System system = new System(); - - Site site = new Site(); - system.addSite( site ); - - Channel channel = new Channel(); - channel.setDecodeConfiguration( - DecodeConfigFactory.getDecodeConfiguration( decoder ) ); - SourceConfigTuner sourceConfig = new SourceConfigTuner(); - sourceConfig.setFrequency( frequency ); - channel.setSourceConfiguration( sourceConfig ); - mResourceManager.getChannelManager().channelChanged( new ChannelEvent( channel, Event.CHANNEL_ADDED ) ); - channel.setEnabled( true, true ); - site.addChannel( channel ); - - mPlaylistNode.getPlaylist().getSystemList().addSystem( system ); - - SystemNode systemNode = new SystemNode( system ); - SystemListNode systemListNode = mPlaylistNode.getSystemListNode(); - addNode( systemNode, systemListNode, systemListNode.getChildCount() ); - systemNode.init(); - - systemNode.save(); + throw new UnsupportedOperationException( "This has to be updated to new channel model format" ); +// System system = new System(); +// +// Site site = new Site(); +// system.addSite( site ); +// +// Channel channel = new Channel(); +// channel.setDecodeConfiguration( +// DecodeConfigFactory.getDecodeConfiguration( decoder ) ); +// SourceConfigTuner sourceConfig = new SourceConfigTuner(); +// sourceConfig.setFrequency( frequency ); +// channel.setSourceConfiguration( sourceConfig ); +// mResourceManager.getChannelManager().channelChanged( new ChannelEvent( channel, Event.NOTIFICATION_ADD ) ); +// channel.setEnabled( true, true ); +// site.addChannel( channel ); +// +// mPlaylistNode.getPlaylist().getSystemList().addSystem( system ); +// +// SystemNode systemNode = new SystemNode( system ); +// SystemListNode systemListNode = mPlaylistNode.getSystemListNode(); +// addNode( systemNode, systemListNode, systemListNode.getChildCount() ); +// systemNode.init(); +// +// systemNode.save(); } public void addNode( BaseNode child, BaseNode parent, int index ) diff --git a/src/controller/ControllerPanel.java b/src/controller/ControllerPanel.java index cb409dda..64b40a6d 100644 --- a/src/controller/ControllerPanel.java +++ b/src/controller/ControllerPanel.java @@ -42,7 +42,8 @@ import audio.AudioPanel; import com.jidesoft.swing.JideSplitPane; import com.jidesoft.swing.JideTabbedPane; -import controller.channel.ChannelManager; +import controller.channel.ChannelModel; +import controller.channel.ChannelProcessingManager; public class ControllerPanel extends JPanel { @@ -67,24 +68,25 @@ public class ControllerPanel extends JPanel private AudioPanel mAudioPanel; private MapPanel mMapPanel; - private ChannelManager mChannelManager; + private ChannelModel mChannelModel; private ConfigurationControllerModel mController; protected SettingsManager mSettingsManager; public ControllerPanel( AudioManager audioManager, ConfigurationControllerModel controller, - ChannelManager channelManager, + ChannelModel channelModel, + ChannelProcessingManager channelProcessingManager, MapService mapService, PlaylistManager playlistManager, SettingsManager settingsManager ) { - mChannelManager = channelManager; + mChannelModel = channelModel; mController = controller; mSettingsManager = settingsManager; mAudioPanel = new AudioPanel( mSettingsManager, audioManager ); - mMapPanel = new MapPanel( mapService, mSettingsManager, mChannelManager ); + mMapPanel = new MapPanel( mapService, mSettingsManager, channelProcessingManager ); mCallEventPanel = new CallEventPanel( mSettingsManager ); @@ -120,6 +122,10 @@ public class ControllerPanel extends JPanel mTabbedPane.addTab( "Channel Spectrum", mChannelSpectrumPanel ); mTabbedPane.addTab( "Events", mCallEventPanel ); mTabbedPane.addTab( "Messages", mMessageActivityPanel ); + + JTable channelsTable = new JTable( mChannelModel ); + JScrollPane channelsScroller = new JScrollPane( channelsTable ); + mTabbedPane.addTab( "Channels", channelsScroller ); /** * Change listener to enable/disable the channel spectrum display @@ -152,10 +158,10 @@ public class ControllerPanel extends JPanel /* Register each of the components to receive channel events when the * channels are selected or change */ - mChannelManager.addListener( mCallEventPanel ); - mChannelManager.addListener( mChannelStateList ); - mChannelManager.addListener( mChannelSpectrumPanel ); - mChannelManager.addListener( mMessageActivityPanel ); + mChannelModel.addListener( mCallEventPanel ); + mChannelModel.addListener( mChannelStateList ); + mChannelModel.addListener( mChannelSpectrumPanel ); + mChannelModel.addListener( mMessageActivityPanel ); JScrollPane channelStateListScroll = new JScrollPane(); channelStateListScroll.getViewport().setView( mChannelStateList ); diff --git a/src/controller/ResourceManager.java b/src/controller/ResourceManager.java index 91256fda..a71de851 100644 --- a/src/controller/ResourceManager.java +++ b/src/controller/ResourceManager.java @@ -26,7 +26,7 @@ import source.SourceManager; import source.recording.RecordingSourceManager; import source.tuner.TunerManager; import audio.AudioManager; -import controller.channel.ChannelManager; +import controller.channel.ChannelModel; /** * Manager for system wide resources @@ -34,7 +34,6 @@ import controller.channel.ChannelManager; public class ResourceManager { private AudioManager mAudioManager; - private ChannelManager mChannelManager; private EventLogManager mEventLogManager; private PlaylistManager mPlaylistManager; private RecorderManager mRecorderManager; @@ -46,17 +45,24 @@ public class ResourceManager private MapService mMapService; private ThreadPoolManager mThreadPoolManager; - public ResourceManager() + public ResourceManager( PlaylistManager playlistManager, + ThreadPoolManager threadPoolManager, + ChannelModel channelModel ) { - this( new SettingsManager(), - new PlaylistManager(), - new EventLogManager() ); + this( threadPoolManager, + new SettingsManager(), + playlistManager, + new EventLogManager(), + channelModel ); } - public ResourceManager( SettingsManager settingsManager, + public ResourceManager( ThreadPoolManager threadPoolManager, + SettingsManager settingsManager, PlaylistManager playlistManager, - EventLogManager eventLogManager ) + EventLogManager eventLogManager, + ChannelModel channelModel ) { + mThreadPoolManager = threadPoolManager; mSettingsManager = settingsManager; mPlaylistManager = playlistManager; mEventLogManager = eventLogManager; @@ -65,14 +71,12 @@ public class ResourceManager * ChannelManager requires a reference to the ResourceManager so that * channel processing chains can access system wide resources */ - mThreadPoolManager = new ThreadPoolManager(); mAudioManager = new AudioManager( mThreadPoolManager ); mRecorderManager = new RecorderManager( mThreadPoolManager ); - mChannelManager = new ChannelManager( this ); mSourceManager = new SourceManager( this ); mRecordingSourceManager = new RecordingSourceManager( this ); mTunerManager = new TunerManager( this ); - mController = new ConfigurationControllerModel( this ); + mController = new ConfigurationControllerModel( channelModel, this ); mMapService = new MapService( this ); } @@ -170,14 +174,4 @@ public class ResourceManager { mRecordingSourceManager = manager; } - - public ChannelManager getChannelManager() - { - return mChannelManager; - } - - public void setChannelManager( ChannelManager channelManager ) - { - mChannelManager = channelManager; - } } diff --git a/src/controller/channel/Channel.java b/src/controller/channel/Channel.java index e23e5d30..3da95791 100644 --- a/src/controller/channel/Channel.java +++ b/src/controller/channel/Channel.java @@ -17,12 +17,7 @@ ******************************************************************************/ package controller.channel; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; @@ -49,7 +44,6 @@ import org.slf4j.LoggerFactory; import record.RecorderManager; import record.RecorderType; import record.config.RecordConfiguration; -import sample.Listener; import source.Source; import source.SourceException; import source.SourceType; @@ -63,10 +57,7 @@ import alias.AliasList; import audio.metadata.Metadata; import audio.metadata.MetadataType; import controller.ResourceManager; -import controller.channel.ChannelEvent.Event; import controller.config.Configuration; -import controller.site.Site; -import controller.system.System; import filter.FilterSet; @XmlSeeAlso( { Configuration.class } ) @@ -75,9 +66,7 @@ public class Channel extends Configuration { private final static Logger mLog = LoggerFactory.getLogger( Channel.class ); - private static final boolean ENABLED = true; private static final boolean DISABLED = false; - private static final boolean BROADCAST_CHANGE = true; public enum ChannelType { @@ -85,15 +74,6 @@ public class Channel extends Configuration TRAFFIC }; - - private CopyOnWriteArrayList mChannelListeners = - new CopyOnWriteArrayList(); - - private CopyOnWriteArrayList> mMessageListeners = - new CopyOnWriteArrayList>(); - - private Map mTrafficChannels = new HashMap<>(); - private DecodeConfiguration mDecodeConfiguration = DecodeConfigFactory.getDefaultDecodeConfiguration(); private AuxDecodeConfiguration mAuxDecodeConfiguration = @@ -106,19 +86,19 @@ public class Channel extends Configuration private ResourceManager mResourceManager; private String mAliasListName; - private System mSystem; - private Site mSite; + private String mSystem; + private String mSite; private String mName; private boolean mEnabled; private boolean mSelected; private ChannelType mChannelType; + private ChannelState mChannelState; private CallEventModel mCallEventModel; private MessageActivityModel mMessageActivityModel; private MessageEventLogger mEventLogger; private ProcessingChain mProcessingChain; - private ChannelState mChannelState; private long mTrafficChannelTimeout = DecodeConfiguration.DEFAULT_CALL_TIMEOUT_SECONDS; @@ -191,13 +171,12 @@ public class Channel extends Configuration * Note: resource manager instance is applied after object construction * since we construct the channel objects from the xml playlist */ + + //TODO: remove this public void setResourceManager( ResourceManager resourceManager ) { mResourceManager = resourceManager; - /* Add system-wide channel listeners onto this channel */ - addListeners( mResourceManager.getChannelManager().getChannelListeners() ); - /* If we're enabled, fire enable changed event to get processing started */ if( mEnabled ) { @@ -205,6 +184,7 @@ public class Channel extends Configuration } } +//TODO: remove this @XmlTransient public ResourceManager getResourceManager() { @@ -242,8 +222,6 @@ public class Channel extends Configuration public void setSelected( boolean selected ) { mSelected = selected; - - fireChannelEvent( Event.CHANGE_SELECTED ); } @XmlTransient @@ -293,10 +271,7 @@ public class Channel extends Configuration */ public void dispose() { - setEnabled( DISABLED, BROADCAST_CHANGE ); - - /* Broadcast channel deleted event */ - fireChannelEvent( Event.CHANNEL_DELETED ); + setEnabled( DISABLED ); } /** @@ -306,28 +281,8 @@ public class Channel extends Configuration { StringBuilder sb = new StringBuilder(); - if( mSystem != null ) - { - sb.append( mSystem.getName() ); - } - else - { - sb.append( "-" ); - } - - sb.append( "/" ); - - if( mSite != null ) - { - sb.append( mSite.getName() ); - } - else - { - sb.append( "-" ); - } - - sb.append( "/" ); - + sb.append( ( mSystem == null ? "-" : mSystem ) ); + sb.append( ( mSite == null ? "-" : mSite ) ); sb.append( mName ); return sb.toString(); @@ -366,57 +321,41 @@ public class Channel extends Configuration /** * Returns the owning system for this channel. */ - public System getSystem() + @XmlAttribute( name = "system" ) + public String getSystem() { return mSystem; } + + public void setSystem( String system ) + { + mSystem = system; + } public boolean hasSystem() { return mSystem != null; } - /** - * Sets the owning system for this channel and optionally broadcasts a - * system change channel event. - */ - public void setSystem( System system, boolean fireChangeEvent ) - { - mSystem = system; - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_SYSTEM ); - } - } - /** * Returns the owning site for this channel. */ - public Site getSite() + @XmlAttribute( name = "site" ) + public String getSite() { return mSite; } + + public void setSite( String site ) + { + mSite = site; + } public boolean hasSite() { return mSite != null; } - /** - * Sets the owning site for this channel and optionally broadcasts a site - * change channel event. - */ - public void setSite( Site site, boolean fireChangeEvent ) - { - mSite = site; - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_SITE ); - } - } - /** * Default display string for this channel -- the channel name. */ @@ -444,28 +383,6 @@ public class Channel extends Configuration enableChanged(); } - - /** - * Enables/disables this channel for processing. Automatically starts or - * stops channel processing in response to this change. Optionally - * broadcasts a enabled change channel event. - */ - public void setEnabled( boolean enabled, boolean fireChannelEvent ) - { - setEnabled( enabled ); - - if( fireChannelEvent ) - { - if( enabled ) - { - fireChannelEvent( Event.CHANNEL_ENABLED ); - } - else - { - fireChannelEvent( Event.CHANNEL_DISABLED ); - } - } - } /** * Returns the alias list that is used by this channel for looking up alias @@ -485,22 +402,6 @@ public class Channel extends Configuration { mAliasListName = name; } - - /** - * Sets the alias list to be used for looking up the alias values for the - * various identifiers produced by the decoder. This method is the same - * as setAliasName(name) and optionally broadcasts an alias list change - * channel event. - */ - public void setAliasListName( String name, boolean fireChangeEvent ) - { - mAliasListName = name; - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_ALIAS_LIST ); - } - } /** * Gets the decoder configuration used by this channel @@ -536,21 +437,6 @@ public class Channel extends Configuration mAuxDecodeConfiguration = config; } - /** - * Sets the decoder configuration used by this channel and optionally - * broadcasts a decoder change channel event. - */ - public void setDecodeConfiguration( DecodeConfiguration config, - boolean fireChangeEvent ) - { - setDecodeConfiguration( config ); - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_DECODER ); - } - } - /** * Returns the source configuration for this channel. */ @@ -568,21 +454,6 @@ public class Channel extends Configuration mSourceConfiguration = config; } - /** - * Sets the source configuration for this channel and optionally broadcasts - * a source change channel event. - */ - public void setSourceConfiguration( SourceConfiguration config, - boolean fireChangeEvent ) - { - setSourceConfiguration( config ); - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_SOURCE ); - } - } - /** * Returns the event logger configuration for this channel. */ @@ -600,21 +471,6 @@ public class Channel extends Configuration mEventLogConfiguration = config; } - /** - * Sets the event logger configuration for this channel and optionally - * broadcasts an event logger change channel event. - */ - public void setEventLogConfiguration( EventLogConfiguration config, - boolean fireChangeEvent ) - { - setEventLogConfiguration( config ); - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_EVENT_LOGGER ); - } - } - /** * Returns the recorder configuration for this channel. */ @@ -632,21 +488,6 @@ public class Channel extends Configuration mRecordConfiguration = config; } - /** - * Sets the recorder configuration for this channel and optionally broadcasts - * a recorder configuration change channel event. - */ - public void setRecordConfiguration( RecordConfiguration config, - boolean fireChangeEvent ) - { - setRecordConfiguration( config ); - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_RECORDER ); - } - } - /** * Returns the name of this channel. */ @@ -664,20 +505,6 @@ public class Channel extends Configuration mName = name; } - /** - * Sets the name of this channel and optionally broadcasts a name change - * channel event. - */ - public void setName( String name, boolean fireChangeEvent ) - { - mName = name; - - if( fireChangeEvent ) - { - fireChannelEvent( Event.CHANGE_NAME ); - } - } - /** * Responds to changes in the enabled setting by starting the processing * change if the channel is now enabled, or stopping the procesing chain @@ -709,8 +536,6 @@ public class Channel extends Configuration setup(); mProcessingChain.start(); - - fireChannelEvent( Event.CHANNEL_PROCESSING_STARTED ); } catch( SourceException se ) { @@ -837,13 +662,6 @@ public class Channel extends Configuration mProcessingChain.addAudioPacketListener( mResourceManager.getAudioManager() ); - /* Add system-wide message listeners */ - mProcessingChain.addMessageListeners( - mResourceManager.getChannelManager().getMessageListeners() ); - - /* Add individual message listeners */ - mProcessingChain.addMessageListeners( mMessageListeners ); - /* Create the call event model to receive call events */ mCallEventModel = new CallEventModel(); mProcessingChain.addCallEventListener( mCallEventModel ); @@ -855,9 +673,9 @@ public class Channel extends Configuration /* Inject channel metadata that will be inserted into audio packets * for the recorder manager and streaming */ mProcessingChain.broadcast( - new Metadata( MetadataType.SYSTEM, mSystem.getName() ) ); + new Metadata( MetadataType.SYSTEM, mSystem ) ); mProcessingChain.broadcast( - new Metadata( MetadataType.SITE_ID, mSite.getName() ) ); + new Metadata( MetadataType.SITE_ID, mSite ) ); mProcessingChain.broadcast( new Metadata( MetadataType.CHANNEL_NAME, mName ) ); } @@ -914,86 +732,6 @@ public class Channel extends Configuration } } - /** - * Broadcasts a channel change event to all registered listeners - */ - public void fireChannelEvent( Event event ) - { - ChannelEvent channelEvent = new ChannelEvent( this, event ); - - for( ChannelEventListener listener: mChannelListeners ) - { - listener.channelChanged( channelEvent ); - } - - /* Send event to processing chain so modules can respond to channel - * selection events */ - if( mProcessingChain != null ) - { - mProcessingChain.getChannelEventListener().receive( channelEvent ); - } - } - - /** - * Adds a channel listener to receive all channel events from this channel - * and automatically sends the listener a channel add event. - */ - public void addListener( ChannelEventListener listener ) - { - if( !mChannelListeners.contains( listener ) ) - { - mChannelListeners.add( listener ); - - listener.channelChanged( - new ChannelEvent( this, Event.CHANNEL_ADDED ) ); - } - else - { - mLog.error( "Channel - attempt to add already existing channel " - + "listener [" + listener.getClass() + "]" ); - } - } - - /** - * Adds a list of channel listeners to receive all channel events from this - * channel and automatically sends each one a channel add event. - */ - public void addListeners( List listeners ) - { - for( ChannelEventListener listener: listeners ) - { - addListener( listener ); - } - } - - /** - * Removes a channel listener from receiving channel events from this channel - */ - public void removeListener( ChannelEventListener listener ) - { - mChannelListeners.remove( listener ); - } - - public void addListener( Listener listener ) - { - mMessageListeners.add( listener ); - - if( isProcessing() ) - { - mProcessingChain.addMessageListener( listener ); - } - } - - public void removeListener( Listener listener ) - { - mMessageListeners.remove( listener ); - - if( mProcessingChain != null ) - { - mProcessingChain.removeMessageListener( listener ); - } - } - /** * Indicates if any part of this channel is contained within the * minimum and maximum frequency values. @@ -1005,35 +743,4 @@ public class Channel extends Configuration return tunerChannel != null && tunerChannel.overlaps( minimum, maximum ); } - - public void addTrafficChannel( String channelID, Channel channel ) - { - mTrafficChannels.put( channelID, channel ); - } - - public boolean hasTrafficChannel( Channel channel ) - { - return mTrafficChannels.containsValue( channel ); - } - - public void removeTrafficChannel( Channel channel ) - { - String name = channel.getChannelDisplayName(); - - if( mTrafficChannels.containsKey( name ) ) - { - mTrafficChannels.remove( name ); - } - } - - public Collection getTrafficChannels() - { - return Collections.unmodifiableCollection( mTrafficChannels.values() ); - } - - public boolean hasTrafficChannel( String name ) - { - return mTrafficChannels.containsKey( name ); - } - } diff --git a/src/controller/channel/ChannelEditor.java b/src/controller/channel/ChannelEditor.java index 21306577..c9935088 100644 --- a/src/controller/channel/ChannelEditor.java +++ b/src/controller/channel/ChannelEditor.java @@ -200,14 +200,14 @@ public class ChannelEditor extends Editor implements ActionListener mEventLogEditor.save(); mRecordEditor.save(); - mChannelNode.getChannel().setName( mChannelName.getText(), false ); - mChannelNode.getChannel().setEnabled( mChannelEnabled.isSelected(), false ); + mChannelNode.getChannel().setName( mChannelName.getText() ); + mChannelNode.getChannel().setEnabled( mChannelEnabled.isSelected() ); AliasList selected = mComboAliasLists.getItemAt( mComboAliasLists.getSelectedIndex() ); if( selected != null ) { - mChannelNode.getChannel().setAliasListName( selected.getName(), false ); + mChannelNode.getChannel().setAliasListName( selected.getName() ); } diff --git a/src/controller/channel/ChannelEvent.java b/src/controller/channel/ChannelEvent.java index a8b88eab..93bb94fc 100644 --- a/src/controller/channel/ChannelEvent.java +++ b/src/controller/channel/ChannelEvent.java @@ -1,3 +1,20 @@ +/******************************************************************************* + * SDR Trunk + * Copyright (C) 2014,2015 Dennis Sheirer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + ******************************************************************************/ package controller.channel; public class ChannelEvent @@ -27,33 +44,33 @@ public class ChannelEvent } /** - * Channel Events - used to specify channel events and changes to channel - * configurations and settings. + * Channel events to describe the specific event */ public enum Event { - CHANGE_ALIAS_LIST, - CHANGE_DECODER, - CHANGE_EVENT_LOGGER, - CHANGE_NAME, - CHANGE_SELECTED, - CHANGE_SITE, - CHANGE_RECORDER, - CHANGE_SOURCE, - CHANGE_SYSTEM, - - CHANNEL_ADDED, - CHANNEL_DELETED, - - CHANNEL_ENABLED, - CHANNEL_DISABLED, - - CHANNEL_PROCESSING_STARTED, - CHANNEL_PROCESSING_STOPPED, - - CHANNEL_STATE_RESET, - - TRAFFIC_CHANNEL_ADDED, - TRAFFIC_CHANNEL_DELETED; + //Channel is added + NOTIFICATION_ADD, + //Channel configuration has changed + NOTIFICATION_CONFIGURATION_CHANGE, + //Channel is deleted/removed + NOTIFICATION_DELETE, + //Channel enable request was rejected + NOTIFICATION_ENABLE_REJECTED, + //Channel has started processing/decoding + NOTIFICATION_PROCESSING_START, + //Channel has stopped processing/decoding + NOTIFICATION_PROCESSING_STOP, + //Channel's selection state has changed + NOTIFICATION_SELECTION_CHANGE, + //Channel's channel-state has been reset + NOTIFICATION_STATE_RESET, + //Request to deselect the channel + REQUEST_DESELECT, + //Request to disable a channel - response will be a PROCESSING_STOP_NOTIFICATION + REQUEST_DISABLE, + //Request to enable a channel - response will be a PROCESSING_START_NOTIFICATION + REQUEST_ENABLE, + //Request to select the channel + REQUEST_SELECT; } } diff --git a/src/controller/channel/ChannelEventListener.java b/src/controller/channel/ChannelEventListener.java index 7c5405db..ad223435 100644 --- a/src/controller/channel/ChannelEventListener.java +++ b/src/controller/channel/ChannelEventListener.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 Dennis Sheirer + * Copyright (C) 2014-2016 Dennis Sheirer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/controller/channel/ChannelManager.java b/src/controller/channel/ChannelManager.java deleted file mode 100644 index 4c594824..00000000 --- a/src/controller/channel/ChannelManager.java +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2014,2015 Dennis Sheirer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - ******************************************************************************/ -package controller.channel; - -import java.util.ArrayList; -import java.util.List; - -import message.Message; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import sample.Listener; -import alias.action.AliasActionManager; -import controller.ResourceManager; - -public class ChannelManager implements ChannelEventListener -{ - private final static Logger mLog = LoggerFactory.getLogger( ChannelManager.class ); - - private List mChannels = new ArrayList<>(); - private List mChannelListeners = new ArrayList<>(); - private List> mMessageListeners = new ArrayList<>(); - - private AliasActionManager mAliasActionManager; - - public ChannelManager( ResourceManager resourceManager ) - { - mAliasActionManager = new AliasActionManager( resourceManager ); - - mChannelListeners.add( this ); - - /* Add alias action manager as listener to all channels/messages */ - mMessageListeners.add( mAliasActionManager ); - } - - /** - * Notification that a channel has been added or deleted, so that we can - * keep track of all channels and manage system-wide listeners for each - * of those channels - */ - @SuppressWarnings( "incomplete-switch" ) - @Override - public void channelChanged( ChannelEvent event ) - { - switch( event.getEvent() ) - { - case CHANNEL_ADDED: - if( !mChannels.contains( event.getChannel() ) ) - { - mChannels.add( event.getChannel() ); - } - break; - case CHANNEL_DELETED: - mChannels.remove( event.getChannel() ); - break; - } - } - - /** - * Adds a channel listener that will be added to all channels to receive - * any channel change events. This listener will automatically receive - * a channel add event as it is added to each of the existing channels. - */ - public void addListener( ChannelEventListener listener ) - { - mChannelListeners.add( listener ); - - for( Channel channel: mChannels ) - { - channel.addListener( listener ); - } - } - - public List getChannels() - { - return mChannels; - } - - /** - * Removes a channel listener from being automatically added to all channels - * to receive channel change events. - */ - public void removeListener( ChannelEventListener listener ) - { - mChannelListeners.remove( listener ); - - for( Channel channel: mChannels ) - { - channel.removeListener( listener ); - } - } - - /** - * Returns the list of channel change listeners that will be automatically - * added to all channels to receive channel change events - */ - public List getChannelListeners() - { - return mChannelListeners; - } - - /** - * Returns the list of channel change listeners that will be automatically - * added to all channels to receive channel change events - */ - public List> getMessageListeners() - { - return mMessageListeners; - } - - /** - * Adds a message listener that will be added to all channels to receive - * any messages. - */ - public void addListener( Listener listener ) - { - mMessageListeners.add( listener ); - } - - /** - * Removes a message listener. - */ - public void removeListener( Listener listener ) - { - mMessageListeners.remove( listener ); - } -} diff --git a/src/controller/channel/ChannelNode.java b/src/controller/channel/ChannelNode.java index 3c5d70ab..acaa0222 100644 --- a/src/controller/channel/ChannelNode.java +++ b/src/controller/channel/ChannelNode.java @@ -56,18 +56,18 @@ public class ChannelNode extends ConfigurableNode implements ChannelEventListene if( siteNode != null ) { - getChannel().setSite( siteNode.getSite(), false ); + getChannel().setSite( siteNode.getSite().getName() ); SystemNode systemNode = (SystemNode)siteNode.getParent(); if( systemNode != null ) { - getChannel().setSystem( systemNode.getSystem(), false ); + getChannel().setSystem( systemNode.getSystem().getName() ); } } /* Add this node as listener to receive changes from underlying channel */ - getChannel().addListener( this ); +// getChannel().addListener( this ); /* Add the resource manager to the channel so that the channel * can provide channel change events to all system resources */ @@ -83,19 +83,13 @@ public class ChannelNode extends ConfigurableNode implements ChannelEventListene switch( event.getEvent() ) { /* Refresh the node for each of these events */ - case CHANGE_DECODER: - case CHANGE_NAME: - case CHANGE_SELECTED: - case CHANGE_SITE: - case CHANGE_SYSTEM: - case CHANNEL_ENABLED: - case CHANNEL_DISABLED: - case CHANNEL_PROCESSING_STARTED: - case CHANNEL_PROCESSING_STOPPED: + case NOTIFICATION_SELECTION_CHANGE: + case NOTIFICATION_PROCESSING_START: + case NOTIFICATION_PROCESSING_STOP: this.refresh(); break; /* We're being deleted, so cleanup */ - case CHANNEL_DELETED: + case NOTIFICATION_DELETE: delete(); break; default: diff --git a/src/controller/channel/ChannelUtils.java b/src/controller/channel/ChannelUtils.java index 5f50f6e6..f4fd2bf1 100644 --- a/src/controller/channel/ChannelUtils.java +++ b/src/controller/channel/ChannelUtils.java @@ -39,7 +39,7 @@ public class ChannelUtils @Override public void actionPerformed( ActionEvent e ) { - channel.setEnabled( DISABLED, BROADCAST_CHANGE ); + channel.setEnabled( DISABLED ); if( playlistManager != null ) { @@ -82,7 +82,7 @@ public class ChannelUtils @Override public void actionPerformed( ActionEvent e ) { - channel.setEnabled( ENABLED, BROADCAST_CHANGE ); + channel.setEnabled( ENABLED ); if( playlistManager != null ) { @@ -109,10 +109,10 @@ public class ChannelUtils if( response == JOptionPane.YES_OPTION ) { /* Disable the channel */ - channel.setEnabled( DISABLED, BROADCAST_CHANGE ); + channel.setEnabled( DISABLED ); /* Broadcast channel deleted event */ - channel.fireChannelEvent( Event.CHANNEL_DELETED ); +// channel.fireChannelEvent( Event.NOTIFICATION_DELETE ); if( playlistManager != null ) { diff --git a/src/controller/site/SiteNode.java b/src/controller/site/SiteNode.java index 21ec08d8..b1184ab3 100644 --- a/src/controller/site/SiteNode.java +++ b/src/controller/site/SiteNode.java @@ -125,8 +125,8 @@ public class SiteNode extends ConfigurableNode System system = ((SystemNode)getParent()).getSystem(); Channel channel = new Channel(); - channel.setSystem( system, false ); - channel.setSite( getSite(), false ); + channel.setSystem( system.getName() ); + channel.setSite( getSite().getName() ); getSite().addChannel( channel ); diff --git a/src/gui/ChannelMemoryLogger.java b/src/gui/ChannelMemoryLogger.java index 9cf11951..39b1085b 100644 --- a/src/gui/ChannelMemoryLogger.java +++ b/src/gui/ChannelMemoryLogger.java @@ -5,6 +5,7 @@ import java.text.NumberFormat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import controller.channel.Channel.ChannelType; import controller.channel.ChannelEvent; import controller.channel.ChannelEventListener; @@ -46,33 +47,40 @@ public class ChannelMemoryLogger implements Runnable, ChannelEventListener { switch( event.getEvent() ) { - case CHANNEL_ADDED: - mChannelCount++; + case NOTIFICATION_ADD: + if( event.getChannel().getChannelType() == ChannelType.TRAFFIC ) + { + mTrafficChannelCount++; + } + else + { + mChannelCount++; + } break; - case CHANNEL_DELETED: - mChannelCount--; + case NOTIFICATION_DELETE: + if( event.getChannel().getChannelType() == ChannelType.TRAFFIC ) + { + mTrafficChannelCount--; + } + else + { + mChannelCount--; + } break; - case CHANNEL_DISABLED: + case REQUEST_DISABLE: break; - case CHANNEL_ENABLED: + case REQUEST_ENABLE: break; - case CHANNEL_PROCESSING_STARTED: + case NOTIFICATION_PROCESSING_START: mChannelProcessingCount++; break; - case CHANNEL_PROCESSING_STOPPED: + case NOTIFICATION_PROCESSING_STOP: mChannelProcessingCount--; break; - case CHANNEL_STATE_RESET: - break; - case TRAFFIC_CHANNEL_ADDED: - mTrafficChannelCount++; - break; - case TRAFFIC_CHANNEL_DELETED: - mTrafficChannelCount--; + case NOTIFICATION_STATE_RESET: break; default: break; - } } } diff --git a/src/gui/SDRTrunk.java b/src/gui/SDRTrunk.java index 80d3c8fb..79345b07 100644 --- a/src/gui/SDRTrunk.java +++ b/src/gui/SDRTrunk.java @@ -56,6 +56,7 @@ import source.tuner.Tuner; import source.tuner.TunerSelectionListener; import spectrum.SpectralDisplayPanel; import util.TimeStamp; +import alias.action.AliasActionManager; import audio.AudioManager; import com.jidesoft.swing.JideSplitPane; @@ -63,9 +64,12 @@ import com.jidesoft.swing.JideSplitPane; import controller.ConfigurationControllerModel; import controller.ControllerPanel; import controller.ResourceManager; +import controller.ThreadPoolManager; import controller.ThreadPoolManager.ThreadType; import controller.channel.ChannelEventListener; -import controller.channel.ChannelManager; +import controller.channel.ChannelModel; +import controller.channel.ChannelProcessingManager; +import controller.channel.ChannelSelectionManager; public class SDRTrunk { @@ -104,27 +108,48 @@ public class SDRTrunk //Log current properties setting SystemProperties.getInstance().logCurrentSettings(); + ChannelModel channelModel = new ChannelModel(); + + ChannelProcessingManager channelProcessingManager = + new ChannelProcessingManager( channelModel ); + channelModel.addListener( channelProcessingManager ); + + ThreadPoolManager threadPoolManager = new ThreadPoolManager(); + + AliasActionManager aliasActionManager = new AliasActionManager( threadPoolManager ); + channelProcessingManager.addListener( aliasActionManager ); + + ChannelSelectionManager channelSelectionManager = + new ChannelSelectionManager( channelModel ); + channelModel.addListener( channelSelectionManager ); + + /** * Construct the resource manager now, so that it can use the system * properties that were just loaded */ - ResourceManager resource = new ResourceManager(); - //TODO: get rid of resource manager ... below is start of breaking out //the encapsulated pieces from the resource manager + PlaylistManager playlistManager = new PlaylistManager( channelModel ); + ResourceManager resource = + new ResourceManager( playlistManager, threadPoolManager, channelModel ); AudioManager audio = resource.getAudioManager(); - ChannelManager channel = resource.getChannelManager(); - ConfigurationControllerModel controller = resource.getController(); + ConfigurationControllerModel configurationControllerModel = resource.getController(); MapService map = resource.getMapService(); - PlaylistManager playlist = resource.getPlaylistManager(); SettingsManager settings = resource.getSettingsManager(); - mControllerPanel = new ControllerPanel( audio, controller, channel, - map, playlist, settings ); + mControllerPanel = + new ControllerPanel( audio, + configurationControllerModel, + channelModel, + channelProcessingManager, + map, + playlistManager, + settings ); - mSpectralPanel = new SpectralDisplayPanel( channel, controller, - playlist, settings ); + mSpectralPanel = new SpectralDisplayPanel( channelModel, + configurationControllerModel, playlistManager, settings ); mTitle = getTitle(); @@ -136,7 +161,7 @@ public class SDRTrunk if( mLogChannelAndMemoryUsage ) { Runnable cml = new ChannelMemoryLogger(); - resource.getChannelManager().addListener( (ChannelEventListener)cml ); + channelModel.addListener( (ChannelEventListener)cml ); resource.getThreadPoolManager().scheduleFixedRate( ThreadType.DECODER, cml, 5, TimeUnit.SECONDS ); } diff --git a/src/instrument/gui/DecoderSelectionFrame.java b/src/instrument/gui/DecoderSelectionFrame.java index 3faccf90..b2b6a32d 100644 --- a/src/instrument/gui/DecoderSelectionFrame.java +++ b/src/instrument/gui/DecoderSelectionFrame.java @@ -11,15 +11,18 @@ import javax.swing.JInternalFrame; import module.decode.DecodeComponentEditor; import module.decode.config.DecodeConfiguration; import net.miginfocom.swing.MigLayout; +import playlist.PlaylistManager; import source.IControllableFileSource; import controller.ResourceManager; +import controller.ThreadPoolManager; +import controller.channel.ChannelModel; public class DecoderSelectionFrame extends JInternalFrame { private static final long serialVersionUID = 1L; private DecodeComponentEditor mDecodeEditor = new DecodeComponentEditor( null ); - private ResourceManager mResourceManager = new ResourceManager(); + private ResourceManager mResourceManager; private IControllableFileSource mSource; private JDesktopPane mDesktop; @@ -27,6 +30,11 @@ public class DecoderSelectionFrame extends JInternalFrame public DecoderSelectionFrame( JDesktopPane desktop, IControllableFileSource source ) { + ChannelModel channelModel = new ChannelModel(); + + mResourceManager = new ResourceManager( new PlaylistManager( channelModel ), + new ThreadPoolManager(), channelModel ); + mDesktop = desktop; mSource = source; diff --git a/src/instrument/gui/DecoderViewFrame.java b/src/instrument/gui/DecoderViewFrame.java index 08738bdb..9cdfe1c5 100644 --- a/src/instrument/gui/DecoderViewFrame.java +++ b/src/instrument/gui/DecoderViewFrame.java @@ -108,8 +108,8 @@ public class DecoderViewFrame extends JInternalFrame recordConfig, auxConfig, aliasList, - new System( "Instrumented" ), - new Site( "Instrumented" ), + "Instrumented", + "Instrumented", "Channel Name" ); mProcessingChain.addModules( modules ); diff --git a/src/map/MapPanel.java b/src/map/MapPanel.java index 9a0a1e5c..e9b66045 100644 --- a/src/map/MapPanel.java +++ b/src/map/MapPanel.java @@ -35,7 +35,7 @@ import org.jdesktop.swingx.mapviewer.TileFactoryInfo; import sample.Listener; import settings.MapViewSetting; import settings.SettingsManager; -import controller.channel.ChannelManager; +import controller.channel.ChannelProcessingManager; public class MapPanel extends JPanel implements PlottableUpdateListener { @@ -48,14 +48,14 @@ public class MapPanel extends JPanel implements PlottableUpdateListener public MapPanel( MapService mapService, SettingsManager settingsManager, - ChannelManager channelManager ) + ChannelProcessingManager channelProcessingManager ) { mSettingsManager = settingsManager; mMapService = mapService; mMapPainter = new PlottableEntityPainter( mSettingsManager ); /* Add Map Service as message listener to receive all messages */ - channelManager.addListener( (Listener)mMapService ); + channelProcessingManager.addListener( (Listener)mMapService ); init(); } diff --git a/src/module/decode/DecodeComponentEditor.java b/src/module/decode/DecodeComponentEditor.java index 46092365..bec8de84 100644 --- a/src/module/decode/DecodeComponentEditor.java +++ b/src/module/decode/DecodeComponentEditor.java @@ -156,7 +156,7 @@ public class DecodeComponentEditor extends AbstractChannelEditor //The component that calls save will invoke the change broadcast mChannelNode.getChannel() - .setDecodeConfiguration( mEditor.getConfig(), false ); + .setDecodeConfiguration( mEditor.getConfig() ); } /** diff --git a/src/module/decode/DecoderFactory.java b/src/module/decode/DecoderFactory.java index 2f40e741..2acc06b1 100644 --- a/src/module/decode/DecoderFactory.java +++ b/src/module/decode/DecoderFactory.java @@ -135,8 +135,8 @@ public class DecoderFactory RecordConfiguration recordConfig, AuxDecodeConfiguration auxConfig, AliasList aliasList, - System system, - Site site, + String system, + String site, String channelName ) { List modules = getPrimaryModules( channelType, decodeConfig, @@ -176,8 +176,8 @@ public class DecoderFactory DecodeConfiguration decodeConfig, RecordConfiguration recordConfig, AliasList aliasList, - System system, - Site site, + String system, + String site, String channelName, ResourceManager resourceManager ) { diff --git a/src/module/decode/event/CallEventPanel.java b/src/module/decode/event/CallEventPanel.java index c56f53bf..c9ac7ac0 100644 --- a/src/module/decode/event/CallEventPanel.java +++ b/src/module/decode/event/CallEventPanel.java @@ -62,7 +62,7 @@ public class CallEventPanel extends JPanel implements ChannelEventListener @Override public void channelChanged( final ChannelEvent event ) { - if( event.getEvent() == Event.CHANGE_SELECTED && + if( event.getEvent() == Event.NOTIFICATION_SELECTION_CHANGE && event.getChannel().isSelected() ) { if( mDisplayedChannel == null || @@ -99,8 +99,8 @@ public class CallEventPanel extends JPanel implements ChannelEventListener } } - else if( event.getEvent() == Event.CHANNEL_PROCESSING_STOPPED || - event.getEvent() == Event.CHANNEL_DISABLED ) + else if( event.getEvent() == Event.NOTIFICATION_PROCESSING_STOP || + event.getEvent() == Event.REQUEST_DISABLE ) { if( mDisplayedChannel != null && mDisplayedChannel == event.getChannel() ) diff --git a/src/module/decode/event/MessageActivityPanel.java b/src/module/decode/event/MessageActivityPanel.java index ae026b14..9f84d619 100644 --- a/src/module/decode/event/MessageActivityPanel.java +++ b/src/module/decode/event/MessageActivityPanel.java @@ -82,7 +82,7 @@ public class MessageActivityPanel extends JPanel implements ChannelEventListener { boolean changed = false; - if( event.getEvent() == Event.CHANGE_SELECTED && + if( event.getEvent() == Event.NOTIFICATION_SELECTION_CHANGE && event.getChannel().isSelected() ) { if( mDisplayedChannel == null || @@ -105,8 +105,8 @@ public class MessageActivityPanel extends JPanel implements ChannelEventListener changed = true; } } - else if( event.getEvent() == Event.CHANNEL_PROCESSING_STOPPED || - event.getEvent() == Event.CHANNEL_DISABLED ) + else if( event.getEvent() == Event.NOTIFICATION_PROCESSING_STOP || + event.getEvent() == Event.REQUEST_DISABLE ) { if( mDisplayedChannel != null && mDisplayedChannel == event.getChannel() ) diff --git a/src/module/decode/p25/audio/P25AudioModule.java b/src/module/decode/p25/audio/P25AudioModule.java index 4fa08148..6e5bfdf9 100644 --- a/src/module/decode/p25/audio/P25AudioModule.java +++ b/src/module/decode/p25/audio/P25AudioModule.java @@ -232,10 +232,10 @@ public class P25AudioModule extends Module implements Listener, { switch( event.getEvent() ) { - case CHANNEL_STATE_RESET: + case NOTIFICATION_STATE_RESET: mAudioMetadata.reset(); break; - case CHANGE_SELECTED: + case NOTIFICATION_SELECTION_CHANGE: mAudioMetadata.setSelected( event.getChannel().isSelected() ); break; default: diff --git a/src/module/decode/state/ChannelList.java b/src/module/decode/state/ChannelList.java index 96b07d96..aff58241 100644 --- a/src/module/decode/state/ChannelList.java +++ b/src/module/decode/state/ChannelList.java @@ -81,10 +81,10 @@ public class ChannelList extends JPanel implements ChannelEventListener { switch( event.getEvent() ) { - case CHANNEL_PROCESSING_STARTED: + case NOTIFICATION_PROCESSING_START: addChannelPanel( event.getChannel() ); break; - case CHANNEL_PROCESSING_STOPPED: + case NOTIFICATION_PROCESSING_STOP: removeChannelPanel( event.getChannel() ); break; default: diff --git a/src/module/decode/state/ChannelStatePanel.java b/src/module/decode/state/ChannelStatePanel.java index 3ce05a01..0559da06 100644 --- a/src/module/decode/state/ChannelStatePanel.java +++ b/src/module/decode/state/ChannelStatePanel.java @@ -111,12 +111,12 @@ public class ChannelStatePanel extends JPanel setLayout( new MigLayout( "insets 1 1 1 1", "[grow,fill]", "[]0[]0[]") ); - mSystemLabel = new JLabel( mChannel.getSystem().getName() ); + mSystemLabel = new JLabel( mChannel.getSystem() ); mSystemLabel.setFont( mFontDetails ); mSystemLabel.setForeground( mColorLabelDetails ); add( mSystemLabel ); - mSiteLabel = new JLabel( mChannel.getSite().getName() ); + mSiteLabel = new JLabel( mChannel.getSite() ); mSiteLabel.setFont( mFontDetails ); mSiteLabel.setForeground( mColorLabelDetails ); add( mSiteLabel ); diff --git a/src/module/decode/state/TrafficChannelManager.java b/src/module/decode/state/TrafficChannelManager.java index 34bb2ecc..18d90d74 100644 --- a/src/module/decode/state/TrafficChannelManager.java +++ b/src/module/decode/state/TrafficChannelManager.java @@ -15,7 +15,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import record.config.RecordConfiguration; -import sample.Broadcaster; import sample.Listener; import source.config.SourceConfigTuner; import source.tuner.TunerChannel; @@ -44,8 +43,8 @@ public class TrafficChannelManager extends Module private DecodeConfiguration mDecodeConfiguration; private RecordConfiguration mRecordConfiguration; private ResourceManager mResourceManager; - private System mSystem; - private Site mSite; + private String mSystem; + private String mSite; private String mAliasListName; private long mTrafficChannelTimeout; private CallEvent mPreviousDoNotMonitorCallEvent; @@ -72,8 +71,8 @@ public class TrafficChannelManager extends Module public TrafficChannelManager( ResourceManager resourceManager, DecodeConfiguration decodeConfiguration, RecordConfiguration recordConfiguration, - System system, - Site site, + String system, + String site, String aliasListName, long trafficChannelTimeout, int trafficChannelPoolSize ) @@ -145,8 +144,8 @@ public class TrafficChannelManager extends Module { channel.setSourceConfiguration( new SourceConfigTuner( tunerChannel ) ); - channel.setSystem( mSystem, false ); - channel.setSite( mSite, false ); + channel.setSystem( mSystem ); + channel.setSite( mSite ); channel.setName( channelNumber ); channel.setEnabled( true ); @@ -160,8 +159,8 @@ public class TrafficChannelManager extends Module { channel.setEnabled( false ); - channel.setSystem( mSystem, false ); - channel.setSite( mSite, false ); + channel.setSystem( mSystem ); + channel.setSite( mSite ); channel.setName( "Traffic" ); } } @@ -399,7 +398,7 @@ public class TrafficChannelManager extends Module mTrafficChannelsInUse.remove( channelNumber ); /* Disable the channel and broadcast a notification */ - channel.setEnabled( false, true ); + channel.setEnabled( false ); } } } diff --git a/src/playlist/Playlist.java b/src/playlist/Playlist.java index 859f3968..0d63153f 100644 --- a/src/playlist/Playlist.java +++ b/src/playlist/Playlist.java @@ -17,15 +17,20 @@ ******************************************************************************/ package playlist; +import java.util.ArrayList; +import java.util.List; + import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; import alias.AliasDirectory; +import controller.channel.Channel; import controller.channel.map.ChannelMapList; import controller.system.SystemList; @XmlSeeAlso( { AliasDirectory.class, + Channel.class, ChannelMapList.class, SystemList.class } ) @@ -35,11 +40,23 @@ public class Playlist private AliasDirectory mAliasDirectory = new AliasDirectory(); private ChannelMapList mChannelMapList = new ChannelMapList(); private SystemList mSystemList = new SystemList(); + private List mChannels = new ArrayList<>(); public Playlist() { } + @XmlElement( name = "channel" ) + public List getChannels() + { + return mChannels; + } + + public void setChannels( List channels ) + { + mChannels = channels; + } + @XmlElement( name = "alias_directory" ) public AliasDirectory getAliasDirectory() { @@ -64,6 +81,13 @@ public class Playlist mSystemList = list; } + public boolean hasSystemList() + { + return mSystemList != null && + mSystemList.getSystem() != null && + !mSystemList.getSystem().isEmpty(); + } + @XmlElement( name = "channel_maps" ) public ChannelMapList getChannelMapList() { diff --git a/src/playlist/PlaylistManager.java b/src/playlist/PlaylistManager.java index c3a973b4..f23f7075 100644 --- a/src/playlist/PlaylistManager.java +++ b/src/playlist/PlaylistManager.java @@ -35,6 +35,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import properties.SystemProperties; +import controller.channel.Channel; +import controller.channel.ChannelModel; +import controller.site.Site; +import controller.system.SystemList; public class PlaylistManager { @@ -43,8 +47,11 @@ public class PlaylistManager private Playlist mPlaylist = new Playlist(); - public PlaylistManager() + private ChannelModel mChannelModel; + + public PlaylistManager( ChannelModel channelModel ) { + mChannelModel = channelModel; init(); } @@ -52,6 +59,15 @@ public class PlaylistManager { return mPlaylist; } + + /** + * Transfers data from persisted playlist into system models + */ + private void transferPlaylistToModels() + { + //Load channels + mChannelModel.addChannels( mPlaylist.getChannels() ); + } /** * Loads playlist from the current playlist file, or the default playlist file, @@ -70,6 +86,8 @@ public class PlaylistManager props.get( "playlist.currentfilename", defaultPlaylistFile ); load( playlistFolder.resolve( playlistFile ) ); + + transferPlaylistToModels(); } @@ -205,5 +223,44 @@ public class PlaylistManager { mPlaylist = new Playlist(); } + + //Check for and convert from legacy play list format + if( mPlaylist.hasSystemList() ) + { + convertPlaylistFormat(); + } + } + + /** + * Converts playlist data over to new format + */ + private void convertPlaylistFormat() + { + mLog.info( "Legacy playlist format detected - converting ..." ); + + //Playlist version 1 to version 2 format conversion. In order to keep + //backwards compatibility, transfer all of the System-Site-Channel + //objects over to the new channel list format + SystemList systemList = mPlaylist.getSystemList(); + + for( controller.system.System system: systemList.getSystem() ) + { + for( Site site: system.getSite() ) + { + for( Channel channel: site.getChannel() ) + { + channel.setSystem( system.getName() ); + channel.setSite( site.getName() ); + + mPlaylist.getChannels().add( channel ); + } + } + } + + mPlaylist.getSystemList().clearSystems(); + + mLog.info( "Converted [" + mPlaylist.getChannels().size() + "] channels to new playlist format" ); + + save(); } } diff --git a/src/source/SourceComponentEditor.java b/src/source/SourceComponentEditor.java index 0cf4f186..c4d4e4a2 100644 --- a/src/source/SourceComponentEditor.java +++ b/src/source/SourceComponentEditor.java @@ -124,6 +124,6 @@ public class SourceComponentEditor extends AbstractChannelEditor //Let the calling save method send the config change event mChannelNode.getChannel() - .setSourceConfiguration( mEditor.getConfig(), false ); + .setSourceConfiguration( mEditor.getConfig() ); } } diff --git a/src/source/config/SourceConfigMixer.java b/src/source/config/SourceConfigMixer.java index 1074b3cf..01a9e1af 100644 --- a/src/source/config/SourceConfigMixer.java +++ b/src/source/config/SourceConfigMixer.java @@ -42,6 +42,7 @@ public class SourceConfigMixer extends SourceConfiguration { StringBuilder sb = new StringBuilder(); + sb.append( "Mixer: " ); sb.append( mMixer ); sb.append( "-" ); sb.append( mChannel.toString() ); diff --git a/src/source/tuner/TunerNode.java b/src/source/tuner/TunerNode.java index 9d2f4d99..626cda6b 100644 --- a/src/source/tuner/TunerNode.java +++ b/src/source/tuner/TunerNode.java @@ -34,6 +34,7 @@ import source.tuner.frequency.FrequencyChangeListener; import spectrum.SpectrumFrame; import controller.BaseNode; import controller.ResourceManager; +import controller.channel.ChannelModel; public class TunerNode extends BaseNode implements FrequencyChangeListener { @@ -46,11 +47,14 @@ public class TunerNode extends BaseNode implements FrequencyChangeListener private long mFrequency; private int mSampleRate; + private ChannelModel mChannelModel; - public TunerNode( Tuner tuner ) + public TunerNode( ChannelModel channelModel, Tuner tuner ) { super( tuner ); //does this make it a super tuner? + mChannelModel = channelModel; + tuner.addListener( this ); try @@ -115,7 +119,7 @@ public class TunerNode extends BaseNode implements FrequencyChangeListener { ResourceManager rm = getModel().getResourceManager(); - SpectrumFrame frame = new SpectrumFrame( rm.getChannelManager(), + SpectrumFrame frame = new SpectrumFrame( mChannelModel, rm.getController(), rm.getPlaylistManager(), rm.getSettingsManager(), getTuner() ); } diff --git a/src/spectrum/ChannelSpectrumPanel.java b/src/spectrum/ChannelSpectrumPanel.java index 96cbefa1..5a87dc4c 100644 --- a/src/spectrum/ChannelSpectrumPanel.java +++ b/src/spectrum/ChannelSpectrumPanel.java @@ -166,7 +166,7 @@ public class ChannelSpectrumPanel extends JPanel { switch( event.getEvent() ) { - case CHANGE_SELECTED: + case NOTIFICATION_SELECTION_CHANGE: if( !event.getChannel().isSelected() ) { stop(); @@ -192,7 +192,7 @@ public class ChannelSpectrumPanel extends JPanel start(); } break; - case CHANNEL_DISABLED: + case REQUEST_DISABLE: if( event.getChannel() == mCurrentChannel ) { if( mEnabled.get() ) @@ -203,7 +203,7 @@ public class ChannelSpectrumPanel extends JPanel mCurrentChannel = null; } break; - case CHANNEL_ENABLED: + case REQUEST_ENABLE: if( event.getChannel() == mCurrentChannel && !event.getChannel().isProcessing() ) { diff --git a/src/spectrum/OverlayPanel.java b/src/spectrum/OverlayPanel.java index b22896b5..f51f744d 100644 --- a/src/spectrum/OverlayPanel.java +++ b/src/spectrum/OverlayPanel.java @@ -32,7 +32,6 @@ import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import javax.swing.JPanel; @@ -52,7 +51,7 @@ import controller.channel.Channel; import controller.channel.Channel.ChannelType; import controller.channel.ChannelEvent; import controller.channel.ChannelEventListener; -import controller.channel.ChannelManager; +import controller.channel.ChannelModel; public class OverlayPanel extends JPanel implements ChannelEventListener, @@ -111,14 +110,14 @@ public class OverlayPanel extends JPanel private LabelSizeManager mLabelSizeMonitor = new LabelSizeManager(); private SettingsManager mSettingsManager; - private ChannelManager mChannelManager; + private ChannelModel mChannelModel; /** * Translucent overlay panel for displaying channel configurations, * processing channels, selected channels, frequency labels and lines, and * a cursor with a frequency readout. */ public OverlayPanel( SettingsManager settingsManager, - ChannelManager channelManager ) + ChannelModel channelModel ) { mSettingsManager = settingsManager; @@ -127,11 +126,11 @@ public class OverlayPanel extends JPanel mSettingsManager.addListener( this ); } - mChannelManager = channelManager; + mChannelModel = channelModel; - if( mChannelManager != null ) + if( mChannelModel != null ) { - mChannelManager.addListener( this ); + mChannelModel.addListener( this ); } addComponentListener( mLabelSizeMonitor ); @@ -145,14 +144,13 @@ public class OverlayPanel extends JPanel public void dispose() { - if( mChannelManager != null ) + if( mChannelModel != null ) { - mChannelManager.removeListener( this ); + mChannelModel.removeListener( this ); } - mChannelManager = null; + mChannelModel = null; -// mChannels.clear(); mVisibleChannels.clear(); if( mSettingsManager != null ) @@ -571,7 +569,7 @@ public class OverlayPanel extends JPanel double yAxis = 0; //Draw the system label and adjust the y-axis position - String system = channel.hasSystem() ? channel.getSystem().getName() : " "; + String system = channel.hasSystem() ? channel.getSystem() : " "; yAxis += drawLabel( graphics, system, @@ -581,7 +579,7 @@ public class OverlayPanel extends JPanel width ); //Draw the site label and adjust the y-axis position - String site = channel.hasSite() ? channel.getSite().getName() : " "; + String site = channel.hasSite() ? channel.getSite() : " "; yAxis += drawLabel( graphics, site, @@ -689,20 +687,12 @@ public class OverlayPanel extends JPanel } /** - * Reset the visible channel configs list + * Reset the visible channels list */ mVisibleChannels.clear(); - - long minimum = getMinFrequency(); - long maximum = getMaxFrequency(); - - for( Channel channel: mChannelManager.getChannels() ) - { - if( channel.isWithin( minimum, maximum ) ) - { - mVisibleChannels.add( channel ); - } - } + mVisibleChannels.addAll( + mChannelModel.getChannelsInFrequencyRange( getMinFrequency(), + getMaxFrequency() ) ); } /** @@ -716,27 +706,20 @@ public class OverlayPanel extends JPanel switch( event.getEvent() ) { -// case CHANNEL_ADDED: - case CHANNEL_ENABLED: -// if( !mChannels.contains( channel ) ) -// { -// mChannels.add( channel ); -// } - - if( channel.isWithin( getMinFrequency(), getMaxFrequency() ) && - !mVisibleChannels.contains( channel ) ) + case NOTIFICATION_ADD: + case NOTIFICATION_PROCESSING_START: + if( !mVisibleChannels.contains( channel ) && + channel.isWithin( getMinFrequency(), getMaxFrequency() ) ) { mVisibleChannels.add( channel ); } break; - case CHANNEL_DELETED: -// mChannels.remove( channel ); + case NOTIFICATION_DELETE: mVisibleChannels.remove( channel ); break; - case CHANNEL_PROCESSING_STOPPED: + case NOTIFICATION_PROCESSING_STOP: if( channel.getChannelType() == ChannelType.TRAFFIC ) { -// mChannels.remove( channel ); mVisibleChannels.remove( channel ); } break; diff --git a/src/spectrum/SpectralDisplayPanel.java b/src/spectrum/SpectralDisplayPanel.java index d335f2a8..e03d27e9 100644 --- a/src/spectrum/SpectralDisplayPanel.java +++ b/src/spectrum/SpectralDisplayPanel.java @@ -28,7 +28,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import java.text.DecimalFormat; import java.util.ArrayList; -import java.util.Arrays; import java.util.Hashtable; import javax.swing.JCheckBoxMenuItem; @@ -82,7 +81,7 @@ import com.jidesoft.swing.JideSplitPane; import controller.ConfigurationControllerModel; import controller.channel.Channel; -import controller.channel.ChannelManager; +import controller.channel.ChannelModel; import controller.channel.ChannelUtils; import dsp.filter.Window.WindowType; import dsp.filter.smoothing.SmoothingFilter.SmoothingType; @@ -133,7 +132,7 @@ public class SpectralDisplayPanel extends JPanel * the DFT is translated to decibels for display in the spectrum and * waterfall components. */ - public SpectralDisplayPanel( ChannelManager channelManager, + public SpectralDisplayPanel( ChannelModel channelModel, ConfigurationControllerModel controller, PlaylistManager playlistManager, SettingsManager settingsManager ) @@ -143,7 +142,7 @@ public class SpectralDisplayPanel extends JPanel mSettingsManager = settingsManager; mSpectrumPanel = new SpectrumPanel( mSettingsManager ); - mOverlayPanel = new OverlayPanel( mSettingsManager, channelManager ); + mOverlayPanel = new OverlayPanel( mSettingsManager, channelModel ); mWaterfallPanel = new WaterfallPanel( mSettingsManager ); //Register to receive tuner selection events diff --git a/src/spectrum/SpectrumFrame.java b/src/spectrum/SpectrumFrame.java index 2305721c..aa39a2f2 100644 --- a/src/spectrum/SpectrumFrame.java +++ b/src/spectrum/SpectrumFrame.java @@ -23,13 +23,13 @@ import java.awt.event.WindowListener; import javax.swing.JFrame; -import playlist.PlaylistManager; import net.miginfocom.swing.MigLayout; +import playlist.PlaylistManager; import settings.SettingsManager; import source.tuner.Tuner; import controller.ConfigurationControllerModel; import controller.ResourceManager; -import controller.channel.ChannelManager; +import controller.channel.ChannelModel; public class SpectrumFrame extends JFrame implements WindowListener { @@ -38,7 +38,7 @@ public class SpectrumFrame extends JFrame implements WindowListener private ResourceManager mResourceManager; private SpectralDisplayPanel mSpectralDisplayPanel; - public SpectrumFrame( ChannelManager channelManager, + public SpectrumFrame( ChannelModel channelModel, ConfigurationControllerModel controller, PlaylistManager playlistManager, SettingsManager settingsManager, @@ -50,7 +50,7 @@ public class SpectrumFrame extends JFrame implements WindowListener setLayout( new MigLayout( "insets 0 0 0 0", "[grow]", "[grow]") ); - mSpectralDisplayPanel = new SpectralDisplayPanel( channelManager, + mSpectralDisplayPanel = new SpectralDisplayPanel( channelModel, controller, playlistManager, settingsManager ); mSpectralDisplayPanel.tunerSelected( tuner );