Basic cleanup / mutex additions / bulk demod add

This commit is contained in:
Charles J. Cliffe 2016-05-31 19:58:37 -04:00
parent a75faaf4f2
commit c1863d9319
8 changed files with 65 additions and 13 deletions

View File

@ -1627,6 +1627,7 @@ bool AppFrame::loadSession(std::string fileName) {
int numDemodulators = 0;
DemodulatorInstance *loadedDemod = NULL;
DemodulatorInstance *newDemod = NULL;
std::vector<DemodulatorInstance *> demodsLoaded;
while (demodulators->hasAnother("demodulator")) {
DataNode *demod = demodulators->getNext("demodulator");
@ -1727,8 +1728,9 @@ bool AppFrame::loadSession(std::string fileName) {
}
newDemod->run();
newDemod->setActive(false);
wxGetApp().bindDemodulator(newDemod);
newDemod->setActive(true);
demodsLoaded.push_back(newDemod);
// wxGetApp().bindDemodulator(newDemod);
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
@ -1740,9 +1742,7 @@ bool AppFrame::loadSession(std::string fileName) {
DemodulatorInstance *focusDemod = loadedDemod?loadedDemod:newDemod;
if (focusDemod) {
focusDemod->setActive(true);
focusDemod->setFollow(true);
focusDemod->setTracking(true);
wxGetApp().bindDemodulators(&demodsLoaded);
wxGetApp().getDemodMgr().setActiveDemodulator(focusDemod, false);
}
} catch (DataInvalidChildException &e) {

View File

@ -632,6 +632,13 @@ void CubicSDR::bindDemodulator(DemodulatorInstance *demod) {
sdrPostThread->bindDemodulator(demod);
}
void CubicSDR::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
if (!demods) {
return;
}
sdrPostThread->bindDemodulators(demods);
}
long long CubicSDR::getSampleRate() {
return sampleRate;
}

View File

@ -115,6 +115,7 @@ public:
SDRThread *getSDRThread();
void bindDemodulator(DemodulatorInstance *demod);
void bindDemodulators(std::vector<DemodulatorInstance *> *demods);
void removeDemodulator(DemodulatorInstance *demod);
void setFrequencySnap(int snap);

View File

@ -13,9 +13,17 @@
bool demodFreqCompare (DemodulatorInstance *i, DemodulatorInstance *j) { return (i->getFrequency()<j->getFrequency()); }
bool inactiveCompare (DemodulatorInstance *i, DemodulatorInstance *j) { return (i->isActive()<j->isActive()); }
DemodulatorMgr::DemodulatorMgr() :
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL), lastBandwidth(DEFAULT_DEMOD_BW), lastDemodType(
DEFAULT_DEMOD_TYPE), lastSquelchEnabled(false), lastSquelch(-100), lastGain(1.0), lastMuted(false), lastDeltaLock(false) {
DemodulatorMgr::DemodulatorMgr() {
activeDemodulator = NULL;
lastActiveDemodulator = NULL;
activeVisualDemodulator = NULL;
lastBandwidth = DEFAULT_DEMOD_BW;
lastDemodType = DEFAULT_DEMOD_TYPE;
lastSquelchEnabled = false;
lastSquelch = -100;
lastGain = 1.0;
lastMuted = false;
lastDeltaLock = false;
}
DemodulatorMgr::~DemodulatorMgr() {
@ -23,26 +31,35 @@ DemodulatorMgr::~DemodulatorMgr() {
}
DemodulatorInstance *DemodulatorMgr::newThread() {
garbageCollect();
demods_busy.lock();
DemodulatorInstance *newDemod = new DemodulatorInstance;
demods.push_back(newDemod);
std::stringstream label;
label << demods.size();
newDemod->setLabel(label.str());
demods.push_back(newDemod);
demods_busy.unlock();
return newDemod;
}
void DemodulatorMgr::terminateAll() {
while (demods.size()) {
demods_busy.lock();
DemodulatorInstance *d = demods.back();
demods.pop_back();
demods_busy.unlock();
wxGetApp().removeDemodulator(d);
deleteThread(d);
}
}
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
demods_busy.lock();
demods_busy.unlock();
return demods;
}
@ -110,6 +127,8 @@ DemodulatorInstance *DemodulatorMgr::getFirstDemodulator() {
}
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
demods_busy.lock();
std::vector<DemodulatorInstance *>::iterator i;
i = std::find(demods.begin(), demods.end(), demod);
@ -131,10 +150,13 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
demods_deleted.push_back(demod);
demods_busy.unlock();
garbageCollect();
}
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long freq, int bandwidth) {
demods_busy.lock();
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
@ -150,12 +172,13 @@ std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long
foundDemods->push_back(testDemod);
}
}
demods_busy.unlock();
return foundDemods;
}
bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
demods_busy.lock();
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
DemodulatorInstance *testDemod = demods[i];
@ -166,10 +189,12 @@ bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
long long halfBuffer = bandwidth / 2;
if ((freq <= (freqTest + ((testDemod->getDemodulatorType() != "LSB")?halfBandwidthTest:0) + halfBuffer)) && (freq >= (freqTest - ((testDemod->getDemodulatorType() != "USB")?halfBandwidthTest:0) - halfBuffer))) {
demods_busy.unlock();
return true;
}
}
demods_busy.unlock();
return false;
}
@ -206,7 +231,7 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
activeDemodulator = demod;
garbageCollect();
// garbageCollect();
}
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
@ -222,6 +247,7 @@ DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
void DemodulatorMgr::garbageCollect() {
if (demods_deleted.size()) {
demods_busy.lock();
std::vector<DemodulatorInstance *>::iterator i;
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
@ -232,9 +258,12 @@ void DemodulatorMgr::garbageCollect() {
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
delete deleted;
demods_busy.unlock();
return;
}
}
demods_busy.unlock();
}
}

View File

@ -72,5 +72,7 @@ private:
bool lastMuted;
bool lastDeltaLock;
std::mutex demods_busy;
std::map<std::string, ModemSettings> lastModemSettings;
};

View File

@ -33,6 +33,18 @@ void SDRPostThread::bindDemodulator(DemodulatorInstance *demod) {
busy_demod.unlock();
}
void SDRPostThread::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
if (!demods) {
return;
}
busy_demod.lock();
for (std::vector<DemodulatorInstance *>::iterator di = demods->begin(); di != demods->end(); di++) {
demodulators.push_back(*di);
doRefresh.store(true);
}
busy_demod.unlock();
}
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
if (!demod) {
return;

View File

@ -13,6 +13,7 @@ public:
~SDRPostThread();
void bindDemodulator(DemodulatorInstance *demod);
void bindDemodulators(std::vector<DemodulatorInstance *> *demods);
void removeDemodulator(DemodulatorInstance *demod);
void run();

View File

@ -1554,7 +1554,7 @@ bool DataTree::SaveToFileXML(const std::string& filename) {
*/
bool DataTree::SaveToFile(const std::string& filename, bool compress, int /* compress_level */) {
long dataSize, compressedSize, headerSize;
long dataSize, compressedSize = 0, headerSize;
char *serialized = nullptr, *hdr_serialized = nullptr, *compressed = nullptr;
DataTree dtHeader;