OrcaSlicer latest
OrcaSlicer
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

PrintHostJobQueue * q
Channel< PrintHostJob > channel_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
PrintHostQueueDialog * queue_dialog

Detailed Description

Constructor & Destructor Documentation

◆ priv()

Slic3r::PrintHostJobQueue::priv::priv ( PrintHostJobQueue * q)
inline
245: q(q) {}
PrintHostJobQueue * q
Definition PrintHost.cpp:232

References Slic3r::PrintHostJobQueue::PrintHostJobQueue(), and q.

Here is the call graph for this function:

Member Function Documentation

◆ bg_thread_main()

void Slic3r::PrintHostJobQueue::priv::bg_thread_main ( )
317{
318 // bg thread entry point
319
320 try {
321 // Pick up jobs from the job channel:
322 while (! bg_exit) {
323 auto job = channel_jobs.pop(); // Sleeps in a cond var if there are no jobs
324 if (job.empty()) {
325 // This happens when the thread is being stopped
326 break;
327 }
328
329 source_to_remove = job.upload_data.source_path;
330
331 BOOST_LOG_TRIVIAL(debug) << boost::format("PrintHostJobQueue/bg_thread: Received job: [%1%]: `%2%` -> `%3%`, cancelled: %4%")
332 % job_id
333 % job.upload_data.upload_path
334 % job.printhost->get_host()
335 % job.cancelled;
336
337 if (! job.cancelled) {
338 perform_job(std::move(job));
339 }
340
342 job_id++;
343 }
344 } catch (const std::exception &e) {
345 emit_error(e.what());
346 }
347
348 // Cleanup leftover files, if any
350 auto jobs = channel_jobs.lock_rw();
351 for (const PrintHostJob &job : *jobs) {
352 remove_source(job.upload_data.source_path);
353 }
354}
bool bg_exit
Definition PrintHost.cpp:241
void emit_error(wxString error)
Definition PrintHost.cpp:279
void perform_job(PrintHostJob the_job)
Definition PrintHost.cpp:483
fs::path source_to_remove
Definition PrintHost.cpp:238
Channel< PrintHostJob > channel_jobs
Definition PrintHost.cpp:234
size_t job_id
Definition PrintHost.cpp:236
void remove_source()
Definition PrintHost.cpp:444

References bg_exit, channel_jobs, emit_error(), job_id, perform_job(), remove_source(), and source_to_remove.

Here is the call graph for this function:

◆ emit_cancel()

void Slic3r::PrintHostJobQueue::priv::emit_cancel ( size_t id)
292{
293 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_CANCEL, queue_dialog->GetId(), id);
294 wxQueueEvent(queue_dialog, evt);
295}
Definition PrintHostDialogs.hpp:73
PrintHostQueueDialog * queue_dialog
Definition PrintHost.cpp:243

References queue_dialog.

Referenced by error_fn(), and progress_fn().

Here is the caller graph for this function:

◆ emit_error()

void Slic3r::PrintHostJobQueue::priv::emit_error ( wxString error)
280{
281 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_ERROR, queue_dialog->GetId(), job_id, std::move(error));
282 wxQueueEvent(queue_dialog, evt);
283}

References job_id, and queue_dialog.

Referenced by bg_thread_main(), and error_fn().

Here is the caller graph for this function:

◆ emit_info()

void Slic3r::PrintHostJobQueue::priv::emit_info ( wxString tag,
wxString status )
286{
287 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_INFO, queue_dialog->GetId(), job_id, std::move(tag), std::move(status));
288 wxQueueEvent(queue_dialog, evt);
289}

References job_id, and queue_dialog.

Referenced by info_fn().

Here is the caller graph for this function:

◆ emit_progress()

void Slic3r::PrintHostJobQueue::priv::emit_progress ( int progress)
274{
275 auto evt = new PrintHostQueueDialog::Event(GUI::EVT_PRINTHOST_PROGRESS, queue_dialog->GetId(), job_id, progress);
276 wxQueueEvent(queue_dialog, evt);
277}

References job_id, and queue_dialog.

Referenced by perform_job(), and progress_fn().

Here is the caller graph for this function:

◆ error_fn()

void Slic3r::PrintHostJobQueue::priv::error_fn ( wxString error)
400{
401 // check if transfer was not canceled before error occured - than do not show the error
402 bool do_emit_err = true;
403 if (channel_cancels.size_hint() > 0) {
404 // Lock both queues
405 auto cancels = channel_cancels.lock_rw();
406 auto jobs = channel_jobs.lock_rw();
407
408 for (size_t cancel_id : *cancels) {
409 if (cancel_id == job_id) {
410 do_emit_err = false;
412 }
413 else if (cancel_id > job_id) {
414 const size_t idx = cancel_id - job_id - 1;
415 if (idx < jobs->size()) {
416 jobs->at(idx).cancelled = true;
417 BOOST_LOG_TRIVIAL(debug) << boost::format("PrintHostJobQueue: Job id %1% cancelled") % cancel_id;
418 emit_cancel(cancel_id);
419 }
420 }
421 }
422 cancels->clear();
423 }
424 if (do_emit_err)
425 emit_error(std::move(error));
426}
void emit_cancel(size_t id)
Definition PrintHost.cpp:291
Channel< size_t > channel_cancels
Definition PrintHost.cpp:235

References channel_cancels, channel_jobs, emit_cancel(), emit_error(), and job_id.

Referenced by perform_job().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ info_fn()

void Slic3r::PrintHostJobQueue::priv::info_fn ( wxString tag,
wxString status )
429{
430 emit_info(tag, status);
431}
void emit_info(wxString tag, wxString status)
Definition PrintHost.cpp:285

References emit_info().

Referenced by perform_job().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ perform_job()

void Slic3r::PrintHostJobQueue::priv::perform_job ( PrintHostJob the_job)
484{
485 emit_progress(0); // Indicate the upload is starting
486
487 bool success = PrintHostJobQueue::upload_job(the_job,
488 [this](Http::Progress progress, bool &cancel) { this->progress_fn(std::move(progress), cancel); },
489 [this](wxString error) { this->error_fn(std::move(error)); },
490 [this](wxString tag, wxString host) { this->info_fn(std::move(tag), std::move(host)); }
491 );
492
493 if (success) {
494 emit_progress(100);
495 if (the_job.switch_to_device_tab) {
496 const auto mainframe = GUI::wxGetApp().mainframe;
497 mainframe->request_select_tab(TAB_ID_MONITOR);
498 }
499 }
500}
#define TAB_ID_MONITOR
Definition MainFrame.hpp:62
static bool upload_job(PrintHostJob &job, PrintHost::ProgressFn progress_fn, PrintHost::ErrorFn error_fn, PrintHost::InfoFn info_fn)
Definition PrintHost.cpp:450
void cancel(size_t id)
Definition PrintHost.cpp:509
void progress_fn(Http::Progress progress, bool &cancel)
Definition PrintHost.cpp:356
void emit_progress(int progress)
Definition PrintHost.cpp:273
void info_fn(wxString tag, wxString status)
Definition PrintHost.cpp:428
void error_fn(wxString error)
Definition PrintHost.cpp:399

References Slic3r::PrintHostJobQueue::cancel(), emit_progress(), error_fn(), info_fn(), progress_fn(), Slic3r::PrintHostJob::switch_to_device_tab, TAB_ID_MONITOR, and Slic3r::PrintHostJobQueue::upload_job().

Referenced by bg_thread_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ progress_fn()

void Slic3r::PrintHostJobQueue::priv::progress_fn ( Http::Progress progress,
bool & cancel )
357{
358 if (cancel) {
359 // When cancel is true from the start, Http indicates request has been cancelled
361 return;
362 }
363
364 if (bg_exit) {
365 cancel = true;
366 return;
367 }
368
369 if (channel_cancels.size_hint() > 0) {
370 // Lock both queues
371 auto cancels = channel_cancels.lock_rw();
372 auto jobs = channel_jobs.lock_rw();
373
374 for (size_t cancel_id : *cancels) {
375 if (cancel_id == job_id) {
376 cancel = true;
377 } else if (cancel_id > job_id) {
378 const size_t idx = cancel_id - job_id - 1;
379 if (idx < jobs->size()) {
380 jobs->at(idx).cancelled = true;
381 BOOST_LOG_TRIVIAL(debug) << boost::format("PrintHostJobQueue: Job id %1% cancelled") % cancel_id;
382 emit_cancel(cancel_id);
383 }
384 }
385 }
386
387 cancels->clear();
388 }
389
390 if (! cancel) {
391 int gui_progress = progress.ultotal > 0 ? 100*progress.ulnow / progress.ultotal : 0;
392 if (gui_progress != prev_progress) {
393 emit_progress(gui_progress);
394 prev_progress = gui_progress;
395 }
396 }
397}
int prev_progress
Definition PrintHost.cpp:237

References bg_exit, Slic3r::PrintHostJobQueue::cancel(), channel_cancels, channel_jobs, emit_cancel(), emit_progress(), job_id, prev_progress, Slic3r::Http::Progress::ulnow, and Slic3r::Http::Progress::ultotal.

Referenced by perform_job().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_source() [1/2]

void Slic3r::PrintHostJobQueue::priv::remove_source ( )
445{
447 source_to_remove.clear();
448}

References remove_source(), and source_to_remove.

Here is the call graph for this function:

◆ remove_source() [2/2]

void Slic3r::PrintHostJobQueue::priv::remove_source ( const fs::path & path)
434{
435 if (! path.empty()) {
436 boost::system::error_code ec;
437 fs::remove(path, ec);
438 if (ec) {
439 BOOST_LOG_TRIVIAL(error) << boost::format("PrintHostJobQueue: Error removing file `%1%`: %2%") % path % ec;
440 }
441 }
442}

Referenced by bg_thread_main(), and remove_source().

Here is the caller graph for this function:

◆ start_bg_thread()

void Slic3r::PrintHostJobQueue::priv::start_bg_thread ( )
298{
299 if (bg_thread.joinable()) { return; }
300
301 std::shared_ptr<priv> p2 = q->p;
302 bg_thread = std::thread([p2]() {
303 p2->bg_thread_main();
304 });
305}
std::thread bg_thread
Definition PrintHost.cpp:240

References bg_thread, and q.

◆ stop_bg_thread()

void Slic3r::PrintHostJobQueue::priv::stop_bg_thread ( )
308{
309 if (bg_thread.joinable()) {
310 bg_exit = true;
311 channel_jobs.push(PrintHostJob()); // Push an empty job to wake up bg_thread in case it's sleeping
312 bg_thread.detach(); // Let the background thread go, it should exit on its own
313 }
314}

References bg_exit, bg_thread, and channel_jobs.

Member Data Documentation

◆ bg_exit

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

◆ bg_thread

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

Referenced by start_bg_thread(), and stop_bg_thread().

◆ channel_cancels

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

Referenced by error_fn(), and progress_fn().

◆ channel_jobs

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

◆ job_id

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

◆ prev_progress

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

Referenced by progress_fn().

◆ q

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

Referenced by priv(), and start_bg_thread().

◆ queue_dialog

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

◆ source_to_remove

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

Referenced by bg_thread_main(), and remove_source().


The documentation for this struct was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/PrintHost.cpp