Reputation:
I have a c++ program on a raspberry pi (headless setup) that records data from an ADC every minute over a period of days and stores them in a file. I want to add an web interface to it that launches possibly many instances of the program, keeps track of how far along they are till completion, view the data possibly in a chart and download the recorded data after completion. Once launched, I want the instances to be running even after the client closes the web interface. What is the best way of doing this? The most troubling part of this for me seems to be maintaining a long running task in the background within a webserver which is conceptually short-lived (a session ends when the client closes the tab in the browser)
Is there any other way of doing this? Or some kind of solution that is employed in this scenario? Any other libraries/frameworks/solutions to consider?
Upvotes: -1
Views: 160
Reputation: 11072
This is perfectly doable with Wt; see the Server Push example.
In it simplest form, you can just start a new background thread as follows:
std::thread([](){
... // your background task.
}).detach();
Have a look at the Server Push example, if you want some interaction between the worker thread and your GUI.
Upvotes: -1