Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::PrintHostJobQueue::priv Struct Reference
+ Collaboration diagram for Slic3r::PrintHostJobQueue::priv:

Public Member Functions

 priv (PrintHostJobQueue *q)
 
void emit_progress (int progress)
 
void emit_error (wxString error)
 
void emit_cancel (size_t id)
 
void emit_info (wxString tag, wxString status)
 
void start_bg_thread ()
 
void stop_bg_thread ()
 
void bg_thread_main ()
 
void progress_fn (Http::Progress progress, bool &cancel)
 
void error_fn (wxString error)
 
void info_fn (wxString tag, wxString status)
 
void remove_source (const fs::path &path)
 
void remove_source ()
 
void perform_job (PrintHostJob the_job)
 

Public Attributes

PrintHostJobQueueq
 
Channel< PrintHostJobchannel_jobs
 
Channel< size_t > channel_cancels
 
size_t job_id = 0
 
int prev_progress = -1
 
fs::path source_to_remove
 
std::thread bg_thread
 
bool bg_exit = false
 
PrintHostQueueDialogqueue_dialog
 

Detailed Description

Constructor & Destructor Documentation

◆ priv()

Slic3r::PrintHostJobQueue::priv::priv ( PrintHostJobQueue q)
inline
94: q(q) {}
PrintHostJobQueue * q
Definition PrintHost.cpp:81

Member Function Documentation

◆ bg_thread_main()

void Slic3r::PrintHostJobQueue::priv::bg_thread_main ( )
166{
167 // bg thread entry point
168
169 try {
170 // Pick up jobs from the job channel:
171 while (! bg_exit) {
172 auto job = channel_jobs.pop(); // Sleeps in a cond var if there are no jobs
173 if (job.empty()) {
174 // This happens when the thread is being stopped
175 break;
176 }
177
178 source_to_remove = job.upload_data.source_path;
179
180 BOOST_LOG_TRIVIAL(debug) << boost::format("PrintHostJobQueue/bg_thread: Received job: [%1%]: `%2%` -> `%3%`, cancelled: %4%")
181 % job_id
182 % job.upload_data.upload_path
183 % job.printhost->get_host()
184 % job.cancelled;
185
186 if (! job.cancelled) {
187 perform_job(std::move(job));
188 }
189
191 job_id++;
192 }
193 } catch (const std::exception &e) {
194 emit_error(e.what());
195 }
196
197 // Cleanup leftover files, if any
199 auto jobs = channel_jobs.lock_rw();
200 for (const PrintHostJob &job : *jobs) {
201 remove_source(job.upload_data.source_path);
202 }
203}
bool bg_exit
Definition PrintHost.cpp:90
void emit_error(wxString error)
Definition PrintHost.cpp:128
void perform_job(PrintHostJob the_job)
Definition PrintHost.cpp:299
fs::path source_to_remove
Definition PrintHost.cpp:87
Channel< PrintHostJob > channel_jobs
Definition PrintHost.cpp:83
size_t job_id
Definition PrintHost.cpp:85
void remove_source()
Definition PrintHost.cpp:293

◆ emit_cancel()

void Slic3r::PrintHostJobQueue::priv::emit_cancel ( size_t  id)
141{
142 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_CANCEL, queue_dialog->GetId(), id);
143 wxQueueEvent(queue_dialog, evt);
144}
PrintHostQueueDialog * queue_dialog
Definition PrintHost.cpp:92

◆ emit_error()

void Slic3r::PrintHostJobQueue::priv::emit_error ( wxString  error)
129{
130 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_ERROR, queue_dialog->GetId(), job_id, std::move(error));
131 wxQueueEvent(queue_dialog, evt);
132}
static char error[256]
Definition tga.cpp:50

References error.

◆ emit_info()

void Slic3r::PrintHostJobQueue::priv::emit_info ( wxString  tag,
wxString  status 
)
135{
136 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_INFO, queue_dialog->GetId(), job_id, std::move(tag), std::move(status));
137 wxQueueEvent(queue_dialog, evt);
138}

◆ emit_progress()

void Slic3r::PrintHostJobQueue::priv::emit_progress ( int  progress)
123{
124 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_PROGRESS, queue_dialog->GetId(), job_id, progress);
125 wxQueueEvent(queue_dialog, evt);
126}

References job_id, and queue_dialog.

◆ error_fn()

void Slic3r::PrintHostJobQueue::priv::error_fn ( wxString  error)
249{
250 // check if transfer was not canceled before error occured - than do not show the error
251 bool do_emit_err = true;
252 if (channel_cancels.size_hint() > 0) {
253 // Lock both queues
254 auto cancels = channel_cancels.lock_rw();
255 auto jobs = channel_jobs.lock_rw();
256
257 for (size_t cancel_id : *cancels) {
258 if (cancel_id == job_id) {
259 do_emit_err = false;
261 }
262 else if (cancel_id > job_id) {
263 const size_t idx = cancel_id - job_id - 1;
264 if (idx < jobs->size()) {
265 jobs->at(idx).cancelled = true;
266 BOOST_LOG_TRIVIAL(debug) << boost::format("PrintHostJobQueue: Job id %1% cancelled") % cancel_id;
267 emit_cancel(cancel_id);
268 }
269 }
270 }
271 cancels->clear();
272 }
273 if (do_emit_err)
274 emit_error(std::move(error));
275}
size_t size_hint() const noexcept
Definition Channel.hpp:81
LockedPtr lock_rw()
Definition Channel.hpp:88
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183
void emit_cancel(size_t id)
Definition PrintHost.cpp:140
Channel< size_t > channel_cancels
Definition PrintHost.cpp:84

References error.

◆ info_fn()

void Slic3r::PrintHostJobQueue::priv::info_fn ( wxString  tag,
wxString  status 
)
278{
279 emit_info(tag, status);
280}
void emit_info(wxString tag, wxString status)
Definition PrintHost.cpp:134

◆ perform_job()

void Slic3r::PrintHostJobQueue::priv::perform_job ( PrintHostJob  the_job)
300{
301 emit_progress(0); // Indicate the upload is starting
302
303 bool success = the_job.printhost->upload(std::move(the_job.upload_data),
304 [this](Http::Progress progress, bool &cancel) { this->progress_fn(std::move(progress), cancel); },
305 [this](wxString error) { this->error_fn(std::move(error)); },
306 [this](wxString tag, wxString host) { this->info_fn(std::move(tag), std::move(host)); }
307 );
308
309 if (success) {
310 emit_progress(100);
311 }
312}
void cancel(size_t id)
Definition PrintHost.cpp:321
void emit_progress(int progress)
Definition PrintHost.cpp:122

References Slic3r::PrintHostJobQueue::cancel(), error, Slic3r::PrintHostJob::printhost, and Slic3r::PrintHostJob::upload_data.

+ Here is the call graph for this function:

◆ progress_fn()

void Slic3r::PrintHostJobQueue::priv::progress_fn ( Http::Progress  progress,
bool &  cancel 
)
206{
207 if (cancel) {
208 // When cancel is true from the start, Http indicates request has been cancelled
210 return;
211 }
212
213 if (bg_exit) {
214 cancel = true;
215 return;
216 }
217
218 if (channel_cancels.size_hint() > 0) {
219 // Lock both queues
220 auto cancels = channel_cancels.lock_rw();
221 auto jobs = channel_jobs.lock_rw();
222
223 for (size_t cancel_id : *cancels) {
224 if (cancel_id == job_id) {
225 cancel = true;
226 } else if (cancel_id > job_id) {
227 const size_t idx = cancel_id - job_id - 1;
228 if (idx < jobs->size()) {
229 jobs->at(idx).cancelled = true;
230 BOOST_LOG_TRIVIAL(debug) << boost::format("PrintHostJobQueue: Job id %1% cancelled") % cancel_id;
231 emit_cancel(cancel_id);
232 }
233 }
234 }
235
236 cancels->clear();
237 }
238
239 if (! cancel) {
240 int gui_progress = progress.ultotal > 0 ? 100*progress.ulnow / progress.ultotal : 0;
241 if (gui_progress != prev_progress) {
242 emit_progress(gui_progress);
243 prev_progress = gui_progress;
244 }
245 }
246}
int prev_progress
Definition PrintHost.cpp:86

References Slic3r::PrintHostJobQueue::cancel(), Slic3r::Http::Progress::ulnow, and Slic3r::Http::Progress::ultotal.

+ Here is the call graph for this function:

◆ remove_source() [1/2]

void Slic3r::PrintHostJobQueue::priv::remove_source ( )
294{
296 source_to_remove.clear();
297}

◆ remove_source() [2/2]

void Slic3r::PrintHostJobQueue::priv::remove_source ( const fs::path &  path)
283{
284 if (! path.empty()) {
285 boost::system::error_code ec;
286 fs::remove(path, ec);
287 if (ec) {
288 BOOST_LOG_TRIVIAL(error) << boost::format("PrintHostJobQueue: Error removing file `%1%`: %2%") % path % ec;
289 }
290 }
291}

References error.

◆ start_bg_thread()

void Slic3r::PrintHostJobQueue::priv::start_bg_thread ( )
147{
148 if (bg_thread.joinable()) { return; }
149
150 std::shared_ptr<priv> p2 = q->p;
151 bg_thread = std::thread([p2]() {
152 p2->bg_thread_main();
153 });
154}
std::shared_ptr< priv > p
Definition PrintHost.hpp:128
std::thread bg_thread
Definition PrintHost.cpp:89

◆ stop_bg_thread()

void Slic3r::PrintHostJobQueue::priv::stop_bg_thread ( )
157{
158 if (bg_thread.joinable()) {
159 bg_exit = true;
160 channel_jobs.push(PrintHostJob()); // Push an empty job to wake up bg_thread in case it's sleeping
161 bg_thread.detach(); // Let the background thread go, it should exit on its own
162 }
163}

Member Data Documentation

◆ bg_exit

bool Slic3r::PrintHostJobQueue::priv::bg_exit = false

◆ bg_thread

std::thread Slic3r::PrintHostJobQueue::priv::bg_thread

◆ channel_cancels

Channel<size_t> Slic3r::PrintHostJobQueue::priv::channel_cancels

◆ channel_jobs

Channel<PrintHostJob> Slic3r::PrintHostJobQueue::priv::channel_jobs

◆ job_id

size_t Slic3r::PrintHostJobQueue::priv::job_id = 0

Referenced by emit_progress().

◆ prev_progress

int Slic3r::PrintHostJobQueue::priv::prev_progress = -1

◆ q

PrintHostJobQueue* Slic3r::PrintHostJobQueue::priv::q

◆ queue_dialog

PrintHostQueueDialog* Slic3r::PrintHostJobQueue::priv::queue_dialog

Referenced by emit_progress().

◆ source_to_remove

fs::path Slic3r::PrintHostJobQueue::priv::source_to_remove

The documentation for this struct was generated from the following file: