Skip to content

Commit

Permalink
Refactor out uploadThread
Browse files Browse the repository at this point in the history
  • Loading branch information
UsualSpec committed Jul 3, 2024
1 parent 4aad7c2 commit 637b9f9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions client/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -535,18 +535,18 @@ void AutopowerClient::doPeriodicDataUpload() {
std::string excContent = e.what();
std::cerr << "Error: " << excContent << std::endl;
// also try to log error on server
// putStatusToServer(1, "Periodic upload got error: " + excContent); // (disabled for now as it makes re-connecting to server slower)
putStatusToServer(1, "Periodic upload got error: " + excContent);
}
measuringCv.wait_for(mm, std::chrono::minutes(this->periodicUploadMinutes));
mm.unlock();
}

std::cerr << "Error: Periodic upload thread exited" << std::endl;
std::cerr << "Error: Periodic upload thread exited." << std::endl;
putStatusToServer(1, "Error: Periodic upload thread exited. This points to a crash.");
}

void AutopowerClient::manageMsmt() {
// monitor thread creates the upload thread to do the periodic upload. This needs to be done on the same channel.
std::thread uploadThread(&AutopowerClient::doPeriodicDataUpload, this);
// monitor thread creates the upload thread to do the periodic upload.
while (true) {
// set uid
class autopapi::clientUid cluid;
Expand Down Expand Up @@ -714,9 +714,6 @@ void AutopowerClient::manageMsmt() {
}
std::cerr << "manageMsmt() exited..." << std::endl;
putStatusToServer(1, "manageMsmt() thread exited. This points to a crash.");
uploadThread.join();
std::cerr << "manageMsmt() and upload thread exited..." << std::endl;
putStatusToServer(1, "manageMsmt() and upload thread exited. This points to a crash.");
}

AutopowerClient::AutopowerClient(std::string _clientUid,
Expand All @@ -734,8 +731,10 @@ AutopowerClient::AutopowerClient(std::string _clientUid,
// start client running in multiple threads
std::thread managementThread(&AutopowerClient::manageMsmt, this); // thread to connect to server and for API
std::thread measurementThread(&AutopowerClient::getAndSavePpData, this);
std::thread uploadThread(&AutopowerClient::doPeriodicDataUpload, this);
startMeasurement();
measurementThread.join(); // should never get here
uploadThread.join(); // should never get here
measurementThread.join();
managementThread.join();
}

Expand Down

0 comments on commit 637b9f9

Please sign in to comment.