Implement download interfcae api.

This commit is contained in:
Gerhard Hoffmann 2023-12-08 13:00:48 +01:00
parent 1155b83ca9
commit 4efbbcbb5a

View File

@ -4415,63 +4415,196 @@ bool hwapi::dcDownloadResetRequest() const {
if (data) {
data->m_downLoadDC.m_requested = false;
}
}
bool hwapi::dcDownloadFinished() {
return true;
}
void hwapi::dcDownloadReportStart() {
SharedMem const *data = SharedMem::getData();
bool hwapi::dcDownloadRequestAck() const {
SharedMem *data = SharedMem::getData();
if (data) {
if (data->m_downLoadDC.m_requested) {
m_reportingThread = new ReportingThread(this);
m_reportingThread->start();
data->m_downLoadDC.m_requested = false;
data->m_downLoadDC.m_running = true;
data->m_downLoadDC.m_finished = false;
}
}
}
bool hwapi::dcDownloadReportRunning() {
if (m_reportingThread) {
return m_reportingThread->isRunning();
}
return false;
}
bool hwapi::dcDownloadReportFinished() {
if (m_reportingThread) {
bool hwapi::dcDownloadRunning() const {
SharedMem const *data = SharedMem::getDataConst();
if (data) {
int cnt = 10;
while (--cnt > 0 && !m_reportingThread->isFinished()) {
while (--cnt > 0) {
bool running = data->m_downLoadDC.m_running.load();
bool finished = data->m_downLoadDC.m_finished.load();
if (!running || finished) {
if (cnt < 3) {
qCritical() << "DOWNLOAD THREAD NOT RUNNING" << running << finished;
}
QThread::msleep(500);
} else break;
}
// qCritical() << "DOWNLOAD RUNNING" << cnt << (cnt > 0);
return (cnt > 0);
}
return false;
}
void hwapi::dcDownloadThreadFinalize(DownloadThread *dthread) {
delete dthread;
m_downloadThread = nullptr;
}
bool hwapi::dcDownloadFinished() {
SharedMem const *data = SharedMem::getDataConst();
if (data) {
int cnt = 10;
while ((--cnt > 0) &&
((data->m_downLoadDC.m_running.load() == true) &&
(data->m_downLoadDC.m_finished.load() == false))) {
QThread::sleep(1);
}
if (!m_reportingThread->isFinished()) {
return false;
//if (cnt > 0) {
// delete m_downloadThread;
// m_downloadThread = nullptr;
// return true;
//}
}
return false;
}
// download thread
bool hwapi::dcDownloadThreadStart() {
m_downloadThread = new DownloadThread(this);
if (m_downloadThread) {
m_downloadThread->start();
int cnt = 10;
while (--cnt > 0 && !dcDownloadThreadRunning()) {
QThread::msleep(200);
}
return (cnt > 0);
}
return false;
}
bool hwapi::dcDownloadThreadRunning() const {
return (dcDownloadGetRunning() == true)
&& (dcDownloadGetFinished() == false);
}
bool hwapi::dcDownloadThreadFinished() const {
return (dcDownloadThreadRunning() == false);
}
// report thread
bool hwapi::dcDownloadReportThreadStart() { // only start reporting thread
int cnt = 10; // if download thread is running
while (--cnt > 0 && !dcDownloadRunning()) {
QThread::msleep(500);
}
if (cnt > 0) {
m_reportingThread = new ReportingThread(this);
if (m_reportingThread) {
m_reportingThread->start();
cnt = 10;
while (--cnt > 0 && !dcDownloadReportThreadRunning()) {
QThread::msleep(200);
}
return (cnt > 0);
}
}
return false;
}
bool hwapi::dcDownloadReportThreadRunning() const {
return m_reportingThread ? m_reportingThread->isRunning() : false;
}
void hwapi::dcDownloadReportThreadFinalize() {
if (m_reportingThread) {
if (m_reportingThread->isFinished()) {
delete m_reportingThread;
m_reportingThread = nullptr;
}
}
}
void hwapi::dcDownloadReportThreadQuit() {
if (m_reportingThread) {
m_reportingThread->quit();
}
}
bool hwapi::dcDownloadReportThreadFinished() const {
return m_reportingThread ? m_reportingThread->isFinished() : false;
}
bool hwapi::dcDownloadReportStart() const {
int cnt = 10;
while (--cnt > 0 && !dcDownloadRunning()) {
QThread::msleep(200);
}
return (cnt == 0);
}
bool hwapi::dcDownloadReportRunning() const {
return dcDownloadReportThreadRunning();
}
bool hwapi::dcDownloadReportFinished() {
int cnt = 10;
while (--cnt > 0 && !dcDownloadReportThreadFinished()) {
QThread::sleep(1);
}
if (cnt == 0 && !dcDownloadReportThreadFinished()) {
return false;
}
if (dcDownloadReportThreadFinished()) {
delete m_reportingThread;
m_reportingThread = nullptr;
}
return true;
}
bool hwapi::dcDownloadRequested() const {
SharedMem const *data = SharedMem::getData();
// should be false at entry
return data ? data->m_downLoadDC.m_requested.load() : false;
}
bool hwapi::dcDownloadResetRequest() {
SharedMem *data = SharedMem::getData();
if (data) {
data->m_downLoadDC.m_requested = false;
}
return true;
}
QString hwapi::dcDownloadFileName() const {
SharedMem const *data = SharedMem::getDataConst();
return data ? data->m_downLoadDC.m_filename : "";
}
bool hwapi::dcDownloadSetRequested(bool requested) {
SharedMem *data = SharedMem::getData();
if (data) {
data->m_downLoadDC.m_requested = requested;
return true;
}
return false;
}
bool hwapi::dcDownloadSetRunning(bool running) {
SharedMem *data = SharedMem::getData();
if (data) {
data->m_downLoadDC.m_running = running;
return true;
}
return false;
}
bool hwapi::dcDownloadSetFinished(bool finished) {
SharedMem *data = SharedMem::getData();
if (data) {
data->m_downLoadDC.m_finished = finished;
return true;
}
return false;
}
void hwapi::dcDownloadSetTotalBlockNumber(uint16_t totalBlockNumber) {
SharedMem::getData()->m_downLoadDC.m_totalBlocks = totalBlockNumber;
}
@ -4490,13 +4623,17 @@ uint16_t hwapi::dcDownloadGetCurrentBlockNumber() const {
return data ? data->m_downLoadDC.m_currentblockNumber.load() : 0;
}
bool hwapi::dcDownloadRunning() const {
SharedMem const *data = SharedMem::getData();
return data ? data->m_downLoadDC.m_running.load() : false;
bool hwapi::dcDownloadGetRequested() const {
SharedMem const *data = SharedMem::getDataConst();
return data ? data->m_downLoadDC.m_requested.load() : 0;
}
bool hwapi::dcDownloadFinished() const {
SharedMem const *data = SharedMem::getData();
return data ? data->m_downLoadDC.m_finished.load() : false;
bool hwapi::dcDownloadGetRunning() const {
SharedMem const *data = SharedMem::getDataConst();
return data ? data->m_downLoadDC.m_running.load() : 0;
}
bool hwapi::dcDownloadGetFinished() const {
SharedMem const *data = SharedMem::getDataConst();
return data ? data->m_downLoadDC.m_running.load() : 0;
}