#1511 Resolves issue with SDRPlay library crashes application when linux service is in stopped state. (#1514)

Co-authored-by: Dennis Sheirer <dsheirer@github.com>
This commit is contained in:
Denny Sheirer
2023-04-11 04:32:58 -04:00
committed by GitHub
parent 372d2ff870
commit 8d6b7c3ac8
3 changed files with 40 additions and 12 deletions

View File

@@ -185,9 +185,19 @@ public class TunerFactory
{
//API instance is retained across the lifecycle of the constructed device, so we only close it if we don't get
//a device from it.
SDRplay api = new SDRplay();
SDRplay api = null;
if(api.isAvailable())
try
{
api = new SDRplay();
}
catch(SDRPlayException se)
{
mLog.info("Caught the exception here ...", se);
api = null;
}
if(api != null && api.isAvailable())
{
Device device = api.getDevice(deviceInfo);

View File

@@ -299,9 +299,18 @@ public class TunerManager implements IDiscoveredTunerStatusListener
//Note: we have to keep this first API instance open while we use any RSP tuners, otherwise the additional API
//instance(s) used by the individual tuners become unresponsive. Note sure why.
mSDRplay = new SDRplay();
if(mSDRplay.isAvailable())
try
{
mSDRplay = new SDRplay();
}
catch(SDRPlayException se)
{
mLog.error("Couldn't load SDRPlay API");
mSDRplay = null;
}
if(mSDRplay != null && mSDRplay.isAvailable())
{
try
{
@@ -333,7 +342,11 @@ public class TunerManager implements IDiscoveredTunerStatusListener
}
else
{
mSDRplay.close();
if(mSDRplay != null)
{
mSDRplay.close();
}
mSDRplay = null;
}
}

View File

@@ -104,7 +104,7 @@ public class SDRplay
/**
* Constructs an instance of the SDRPLay API
*/
public SDRplay()
public SDRplay() throws SDRPlayException
{
mSdrplayLibraryLoaded = loadLibrary();
@@ -116,6 +116,11 @@ public class SDRplay
mLog.info("API library - open status: " + openStatus);
}
mAvailable = openStatus.success() && getVersion().isSupported();
if(openStatus == Status.FAIL)
{
throw new SDRPlayException("Service not available");
}
}
else
{
@@ -693,23 +698,23 @@ public class SDRplay
* Java will look there for the library, without having to specify it as a launcher
* option. This would allow for users that have installed the API to an alternate location.
*/
SDRplay sdrplay = new SDRplay();
Status status = sdrplay.open();
mLog.info("Open Status: " + status);
try
{
SDRplay sdrplay = new SDRplay();
Status status = sdrplay.open();
mLog.info("Open Status: " + status);
for(DeviceInfo deviceInfo: sdrplay.getDeviceInfos())
{
mLog.info("Found: " + deviceInfo);
}
Status closeStatus = sdrplay.close();
mLog.info("Close Status: " + closeStatus);
}
catch(SDRPlayException se)
{
mLog.info("Error", se);
}
Status closeStatus = sdrplay.close();
mLog.info("Close Status: " + closeStatus);
}
}