Work in progress - program compiles and runs

This commit is contained in:
denny
2016-01-02 12:29:40 -05:00
parent d8a20b5adb
commit c405ddad96
36 changed files with 374 additions and 694 deletions

View File

@@ -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<ChannelEventListener> mChannelListeners =
new CopyOnWriteArrayList<ChannelEventListener>();
private CopyOnWriteArrayList<Listener<Message>> mMessageListeners =
new CopyOnWriteArrayList<Listener<Message>>();
private Map<String,Channel> 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<ChannelEventListener> 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<Message> listener )
{
mMessageListeners.add( listener );
if( isProcessing() )
{
mProcessingChain.addMessageListener( listener );
}
}
public void removeListener( Listener<Message> 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<Channel> getTrafficChannels()
{
return Collections.unmodifiableCollection( mTrafficChannels.values() );
}
public boolean hasTrafficChannel( String name )
{
return mTrafficChannels.containsKey( name );
}
}

View File

@@ -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() );
}

View File

@@ -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 <http://www.gnu.org/licenses/>
******************************************************************************/
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;
}
}

View File

@@ -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

View File

@@ -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 <http://www.gnu.org/licenses/>
******************************************************************************/
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<Channel> mChannels = new ArrayList<>();
private List<ChannelEventListener> mChannelListeners = new ArrayList<>();
private List<Listener<Message>> 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<Channel> 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<ChannelEventListener> 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<Listener<Message>> getMessageListeners()
{
return mMessageListeners;
}
/**
* Adds a message listener that will be added to all channels to receive
* any messages.
*/
public void addListener( Listener<Message> listener )
{
mMessageListeners.add( listener );
}
/**
* Removes a message listener.
*/
public void removeListener( Listener<Message> listener )
{
mMessageListeners.remove( listener );
}
}

View File

@@ -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:

View File

@@ -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 )
{