Fix startup config access issues, init race

This commit is contained in:
Charles J. Cliffe 2015-07-08 18:54:52 -04:00
parent b762d4d118
commit f86950b334
5 changed files with 56 additions and 25 deletions

View File

@ -10,54 +10,65 @@ DeviceConfig::DeviceConfig(std::string deviceId) : ppm(0) {
}
void DeviceConfig::setPPM(int ppm) {
this->ppm = ppm;
this->ppm.store(ppm);
}
int DeviceConfig::getPPM() {
return ppm;
return ppm.load();
}
void DeviceConfig::setDirectSampling(int mode) {
directSampling = mode;
directSampling.store(mode);
}
int DeviceConfig::getDirectSampling() {
return directSampling;
return directSampling.load();
}
void DeviceConfig::setOffset(long long offset) {
this->offset = offset;
this->offset.store(offset);
}
long long DeviceConfig::getOffset() {
return offset;
return offset.load();
}
void DeviceConfig::setIQSwap(bool iqSwap) {
this->iqSwap = iqSwap;
this->iqSwap.store(iqSwap);
}
bool DeviceConfig::getIQSwap() {
return iqSwap;
return iqSwap.load();
}
void DeviceConfig::setDeviceId(std::string deviceId) {
busy_lock.lock();
this->deviceId = deviceId;
busy_lock.unlock();
}
std::string DeviceConfig::getDeviceId() {
return deviceId;
std::string tmp;
busy_lock.lock();
tmp = deviceId;
busy_lock.unlock();
return tmp;
}
void DeviceConfig::save(DataNode *node) {
busy_lock.lock();
*node->newChild("id") = deviceId;
*node->newChild("ppm") = (int)ppm;
*node->newChild("iq_swap") = iqSwap;
*node->newChild("direct_sampling") = directSampling;
*node->newChild("offset") = offset;
busy_lock.unlock();
}
void DeviceConfig::load(DataNode *node) {
busy_lock.lock();
if (node->hasAnother("ppm")) {
DataNode *ppm_node = node->getNext("ppm");
int ppmValue = 0;
@ -96,8 +107,9 @@ void DeviceConfig::load(DataNode *node) {
long long offsetValue = 0;
offset_node->element()->get(offsetValue);
setOffset(offsetValue);
std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "ppm" << std::endl;
std::cout << "Loaded offset for device '" << deviceId << "' at " << offsetValue << "Hz" << std::endl;
}
busy_lock.unlock();
}

View File

@ -3,10 +3,11 @@
#include <wx/stdpaths.h>
#include <wx/dir.h>
#include <wx/filename.h>
#include <atomic>
#include <mutex>
#include "DataTree.h"
class DeviceConfig {
public:
DeviceConfig();
@ -32,9 +33,11 @@ public:
private:
std::string deviceId;
int ppm, directSampling;
bool iqSwap;
long long offset;
std::mutex busy_lock;
std::atomic<int> ppm, directSampling;
std::atomic<bool> iqSwap;
std::atomic<long long> offset;
};
class AppConfig {

View File

@ -319,8 +319,18 @@ AppFrame::AppFrame() :
wxAcceleratorTable accel(3, entries);
SetAcceleratorTable(accel);
SDRDeviceInfo *dev = (*wxGetApp().getDevices())[wxGetApp().getDevice()];
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
// ShowFullScreen(true);
}
AppFrame::~AppFrame() {
}
void AppFrame::initDeviceParams(std::string deviceId) {
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(deviceId);
int dsMode = devConfig->getDirectSampling();
@ -331,16 +341,8 @@ AppFrame::AppFrame() :
if (devConfig->getIQSwap()) {
iqSwapMenuItem->Check();
}
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");
// ShowFullScreen(true);
}
AppFrame::~AppFrame() {
}
void AppFrame::OnMenu(wxCommandEvent& event) {
if (event.GetId() >= wxID_RT_AUDIO_DEVICE && event.GetId() < wxID_RT_AUDIO_DEVICE + devices.size()) {

View File

@ -58,6 +58,7 @@ public:
~AppFrame();
void OnThread(wxCommandEvent& event);
void OnEventInput(wxThreadEvent& event);
void initDeviceParams(std::string deviceId);
void saveSession(std::string fileName);
bool loadSession(std::string fileName);

View File

@ -67,6 +67,7 @@ bool CubicSDR::OnInit() {
std::vector<SDRDeviceInfo *>::iterator devs_i;
SDRThread::enumerate_rtl(&devs);
SDRDeviceInfo *dev = NULL;
if (devs.size() > 1) {
wxArrayString choices;
@ -78,6 +79,9 @@ bool CubicSDR::OnInit() {
devName.append(" [");
devName.append((*devs_i)->getSerial());
devName.append("]");
if (!dev) {
dev = (*devs_i);
}
} else {
devName.append(" (In Use?)");
}
@ -85,15 +89,24 @@ bool CubicSDR::OnInit() {
}
int devId = wxGetSingleChoiceIndex(wxT("Devices"), wxT("Choose Input Device"), choices);
dev = devs[devId];
std::cout << "Chosen: " << devId << std::endl;
sdrThread->setDeviceId(devId);
} else if (devs.size() == 1) {
dev = devs[0];
}
t_PostSDR = new std::thread(&SDRPostThread::threadMain, sdrPostThread);
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread);
appframe = new AppFrame();
if (dev != NULL) {
appframe->initDeviceParams(dev->getDeviceId());
DeviceConfig *devConfig = wxGetApp().getConfig()->getDevice(dev->getDeviceId());
ppm = devConfig->getPPM();
offset = devConfig->getOffset();
directSamplingMode = devConfig->getDirectSampling();
}
#ifdef __APPLE__
int main_policy;