mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-13 00:57:31 -05:00
#1221 resolves null pointer exception in tuner editor when attempting to restart an error tuner. (#1222)
Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
@@ -60,11 +60,28 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
* Sets the status of the discovered tuner and notifies registered listeners of the status change.
|
||||
* @param tunerStatus to set
|
||||
*/
|
||||
protected void setTunerStatus(TunerStatus tunerStatus)
|
||||
private void setTunerStatus(TunerStatus tunerStatus)
|
||||
{
|
||||
TunerStatus previous = mTunerStatus;
|
||||
mTunerStatus = tunerStatus;
|
||||
broadcast(this, previous, mTunerStatus);
|
||||
setTunerStatus(tunerStatus, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of the discovered tuner and optionally notifies registered listeners of the status change.
|
||||
* @param tunerStatus to set
|
||||
* @param notifyListeners true to notify and false to not notify
|
||||
*/
|
||||
private void setTunerStatus(TunerStatus tunerStatus, boolean notifyListeners)
|
||||
{
|
||||
if(mTunerStatus != tunerStatus)
|
||||
{
|
||||
TunerStatus previous = mTunerStatus;
|
||||
mTunerStatus = tunerStatus;
|
||||
|
||||
if(notifyListeners)
|
||||
{
|
||||
broadcast(this, previous, mTunerStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,8 +232,9 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
public void setErrorMessage(String errorMessage)
|
||||
{
|
||||
mErrorMessage = errorMessage;
|
||||
setTunerStatus(TunerStatus.ERROR);
|
||||
mLog.info("Tuner Error - Stopping - " + getId() + " Error: " + errorMessage);
|
||||
stop();
|
||||
setTunerStatus(TunerStatus.ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,7 +264,7 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
/**
|
||||
* Attempts to restart a tuner that's currently in an error state
|
||||
*/
|
||||
public void reset()
|
||||
public void restart()
|
||||
{
|
||||
if(getTunerStatus() == TunerStatus.ERROR)
|
||||
{
|
||||
@@ -254,7 +272,9 @@ public abstract class DiscoveredTuner implements ITunerErrorListener
|
||||
|
||||
if(isEnabled())
|
||||
{
|
||||
//Change status to enabled so that we can attempt to start, but don't notify listeners yet.
|
||||
setTunerStatus(TunerStatus.ENABLED);
|
||||
start();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -109,20 +109,9 @@ public class DiscoveredUSBTuner extends DiscoveredTuner
|
||||
}
|
||||
catch(SourceException se)
|
||||
{
|
||||
|
||||
//Set error message to flag this tuner with error status and invoke stop()
|
||||
setErrorMessage(se.getMessage());
|
||||
|
||||
mLog.error("Unable to start tuner [" + getTunerClass() + "] - error: " + getErrorMessage());
|
||||
|
||||
try
|
||||
{
|
||||
stop();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//No-op on attempted cleanup
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,9 +241,9 @@ public class TunerManager implements IDiscoveredTunerStatusListener
|
||||
* @param bus usb for the tuner
|
||||
* @param port usb for the tuner
|
||||
*/
|
||||
private void removeUsbTuner(int bus, int port)
|
||||
private DiscoveredTuner removeUsbTuner(int bus, int port)
|
||||
{
|
||||
mDiscoveredTunerModel.removeUsbTuner(bus, port);
|
||||
return mDiscoveredTunerModel.removeUsbTuner(bus, port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -489,12 +489,26 @@ public class TunerManager implements IDiscoveredTunerStatusListener
|
||||
|
||||
if(tunerClass.isSupportedUsbTuner())
|
||||
{
|
||||
addUsbTuner(bus, port, tunerClass);
|
||||
if(tunerClass.isFuncubeTuner())
|
||||
{
|
||||
//Funcube tuners take a few momements to setup the sound card interface. Delay adding
|
||||
//the tuner so that it can be started correctly.
|
||||
ThreadPool.SCHEDULED.schedule(() -> addUsbTuner(bus, port, tunerClass), 2, TimeUnit.SECONDS);
|
||||
}
|
||||
else
|
||||
{
|
||||
addUsbTuner(bus, port, tunerClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LibUsb.HOTPLUG_EVENT_DEVICE_LEFT:
|
||||
removeUsbTuner(bus, port);
|
||||
DiscoveredTuner removed = removeUsbTuner(bus, port);
|
||||
|
||||
if(removed != null)
|
||||
{
|
||||
mLog.info("Tuner Unplugged: " + removed.getId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user