Lots of changes/fixes inc rewrite rigctld and move more commands.

This commit is contained in:
Phil Taylor 2023-05-24 19:50:01 +01:00
parent bbcf733537
commit 001065e8a5
23 changed files with 1555 additions and 2036 deletions

View file

@ -70,16 +70,19 @@ void cachingQueue::run()
prio = priorityLowest;
}
counter++;
QMutableMultiMapIterator<queuePriority,queueItem> itt(queue);
auto it = queue.find(prio);
if (it != queue.end())
{
auto item = it.value();
emit haveCommand(item.type, item.command,item.param);
it=queue.erase(it);
while (it.key()==prio)
it++;
it = queue.erase(it);
it = queue.end();
//if (it != queue.end()) {
// while (it != queue.end() && it.key()==prio)
// it++;
//}
// Add it back into the queue
if (item.recurring) {
queue.insert(it,prio,item);
@ -125,6 +128,7 @@ void cachingQueue::add(queuePriority prio ,queueItem item)
} else {
queue.insert(prio, item);
updateCache(false,item.command,item.param);
// Update cache with sent data (will be replaced if found to be invalid.)
if (item.recurring) qInfo() << "adding" << funcString[item.command] << "recurring" << item.recurring << "priority" << prio;
}
}
@ -218,15 +222,24 @@ void cachingQueue::receiveValue(funcs func, QVariant value)
void cachingQueue::updateCache(bool reply, funcs func, QVariant value)
{
/* if (func == funcFreqGet || func == funcFreqTR || func == funcSelectedFreq || func == funcUnselectedFreq)
func = funcVFOFrequency; // This is a composite function.
if (func == funcModeGet || func == funcModeTR || func == funcSelectedMode || func == funcUnselectedMode)
func = funcVFOMode; // This is a composite function. */
// Mutex MUST be locked by the calling function.
auto cv = cache.find(func);
if (cv != cache.end()) {
if (reply) {
cv->reply = QDateTime::currentDateTime();
cv->value = value;
} else {
cv->req = QDateTime::currentDateTime();
}
// If we are sending an actual value, update the cache with it
// Value will be replaced if invalid on next get()
if (value.isValid())
cv->value = value;
return;
}
@ -234,23 +247,33 @@ void cachingQueue::updateCache(bool reply, funcs func, QVariant value)
c.command = func;
if (reply) {
c.reply = QDateTime::currentDateTime();
c.value = value;
} else {
c.req = QDateTime::currentDateTime();
}
// If we are sending an actual value, update the cache with it
// Value will be replaced if invalid on next get()
if (value.isValid())
c.value = value;
cache.insert(func,c);
}
cacheItem cachingQueue::getCache(funcs func)
{
QMutexLocker locker(&mutex);
auto it = cache.find(func);
if (it != cache.end())
{
return it.value();
cacheItem ret;
if (func != funcNone) {
QMutexLocker locker(&mutex);
auto it = cache.find(func);
if (it != cache.end())
ret = cacheItem(*it);
}
return cacheItem();
// If the cache is more than 5-20 seconds old, re-request it as it may be stale (maybe make this a config option?)
// Using priorityhighest WILL slow down the S-Meter when a command intensive client is connected to rigctl
if (func != funcNone && (!ret.value.isValid() || ret.reply.addSecs(QRandomGenerator::global()->bounded(5,20)) <= QDateTime::currentDateTime())) {
//qInfo() << "No (or expired) cache found for" << funcString[func] << "requesting";
add(priorityHighest,func);
}
return ret;
}
//Calling function MUST call unlockMutex() once finished with data