Merges from master branch.

This commit is contained in:
Denny
2017-12-27 10:10:51 -05:00
parent 667c50174d
commit 236df8f3f4
262 changed files with 7701 additions and 49122 deletions

View File

@@ -25,62 +25,100 @@ import java.util.concurrent.CopyOnWriteArrayList;
*/
public class Broadcaster<T> implements Listener<T>
{
private List<Listener<T>> mListeners = new CopyOnWriteArrayList<>();
private List<Listener<T>> mListeners = new CopyOnWriteArrayList<>();
@Override
public void receive( T t )
/**
* Implements the Listener<T> interface to receive an element and broadcast that element to all registered
* listeners.
*
* @param t element to broadcast
*/
@Override
public void receive(T t)
{
broadcast( t );
broadcast(t);
}
/**
* Clear listeners to prepare for garbage collection
*/
public void dispose()
{
mListeners.clear();
}
public boolean hasListeners()
{
return !mListeners.isEmpty();
}
public int getListenerCount()
{
return mListeners.size();
}
public List<Listener<T>> getListeners()
{
return mListeners;
}
public void addListener( Listener<T> listener )
{
if(listener == null)
{
throw new IllegalArgumentException("Listener cannot be null");
}
mListeners.add( listener );
}
public void removeListener( Listener<T> listener )
{
mListeners.remove( listener );
}
public void clear()
{
mListeners.clear();
}
public void broadcast( T t )
/**
* Clear listeners to prepare for garbage collection
*/
public void dispose()
{
for( Listener<T> listener: mListeners )
{
listener.receive( t );
}
mListeners.clear();
}
/**
* Indicates if this broadcaster has any listeners registered
*/
public boolean hasListeners()
{
return !mListeners.isEmpty();
}
/**
* Indicates if the listener is currently registered with this broadcaster
*/
public boolean hasListener(Listener<T> listener)
{
return listener != null && mListeners.contains(listener);
}
/**
* The count of listeners currently registered with this broadcaster
*/
public int getListenerCount()
{
return mListeners.size();
}
/**
* The list of listeners currently registered with this broadcaster
*/
public List<Listener<T>> getListeners()
{
return mListeners;
}
/**
* Registers the listener to receive elements from this broadcaster
*
* @param listener
*/
public void addListener(Listener<T> listener)
{
if(listener != null && !mListeners.contains(listener))
{
mListeners.add(listener);
}
}
/**
* Deregisters the listener from receiving elements from this broadcaster
*/
public void removeListener(Listener<T> listener)
{
if(listener != null && mListeners.contains(listener))
{
mListeners.remove(listener);
}
}
/**
* Deregisters all listeners from this broadcaster
*/
public void clear()
{
mListeners.clear();
}
/**
* Broadcasts the element to all registered listeners
*/
public void broadcast(T t)
{
for(Listener<T> listener : mListeners)
{
listener.receive(t);
}
}
}

View File

@@ -19,6 +19,7 @@
package io.github.dsheirer.sample;
import io.github.dsheirer.sample.real.IOverflowListener;
import io.github.dsheirer.source.Source;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,6 +34,7 @@ public class OverflowableTransferQueue<E>
public enum State {NORMAL, OVERFLOW};
private IOverflowListener mOverflowListener;
private Source mSourceOverflowListener;
private LinkedTransferQueue<E> mQueue = new LinkedTransferQueue<E>();
private AtomicInteger mCounter = new AtomicInteger();
@@ -73,6 +75,14 @@ public class OverflowableTransferQueue<E>
}
}
/**
* Removes and returns a single element from the head of the queue or null if the queue is empty
*/
public E poll()
{
return mQueue.poll();
}
/**
* Retrieves elements from the queue into the collection up to the maximum number of elements specified
*/
@@ -91,13 +101,21 @@ public class OverflowableTransferQueue<E>
}
/**
* Sets a listener to receive overflow state change events
* Sets a listener to receive overflow state change events.
*/
public void setOverflowListener(IOverflowListener listener)
{
mOverflowListener = listener;
}
/**
* Sets the source to receive overflow state change events (in addition to an IOverflow listener)
*/
public void setSourceOverflowListener(Source source)
{
mSourceOverflowListener = source;
}
/**
* Toggles the overflow state and broadcast state change to listener
@@ -110,6 +128,11 @@ public class OverflowableTransferQueue<E>
{
mOverflowListener.sourceOverflow(overflow);
}
if(mSourceOverflowListener != null)
{
mSourceOverflowListener.broadcastOverflowState(overflow);
}
}
}
@@ -125,4 +148,4 @@ public class OverflowableTransferQueue<E>
mOverflow.set(false);
}
}
}
}

View File

@@ -2,7 +2,6 @@ package io.github.dsheirer.sample;
public enum SampleType
{
COMPLEX, //Baseband
REAL, //Demodulated
COMPLEX_AND_REAL; //Baseband and Demodulated
COMPLEX, // I/Q
REAL; // Real
}

View File

@@ -0,0 +1,39 @@
/*******************************************************************************
* sdrtrunk
* Copyright (C) 2014-2017 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 io.github.dsheirer.sample.complex;
import io.github.dsheirer.sample.Listener;
public interface IComplexBufferProvider
{
/**
* Adds the listener to receive complex buffer samples
*/
void addComplexBufferListener(Listener<ComplexBuffer> listener);
/**
* Removes the listener from receiving complex buffer samples
*/
void removeComplexBufferListener(Listener<ComplexBuffer> listener);
/**
* Indicates if there are any complex buffer listeners registered
*/
boolean hasComplexBufferListeners();
}