OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::OtherInstanceMessageHandler Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/InstanceCheck.hpp>

Public Member Functions

 OtherInstanceMessageHandler ()=default
 OtherInstanceMessageHandler (OtherInstanceMessageHandler const &)=delete
void operator= (OtherInstanceMessageHandler const &)=delete
 ~OtherInstanceMessageHandler ()
void init (wxEvtHandler *callback_evt_handler)
void shutdown (MainFrame *main_frame)
void handle_message (const std::string &message)

Private Attributes

bool m_initialized { false }
wxEvtHandler * m_callback_evt_handler { nullptr }

Detailed Description

Constructor & Destructor Documentation

◆ OtherInstanceMessageHandler() [1/2]

Slic3r::GUI::OtherInstanceMessageHandler::OtherInstanceMessageHandler ( )
default

Referenced by OtherInstanceMessageHandler(), and operator=().

Here is the caller graph for this function:

◆ OtherInstanceMessageHandler() [2/2]

Slic3r::GUI::OtherInstanceMessageHandler::OtherInstanceMessageHandler ( OtherInstanceMessageHandler const & )
delete

References OtherInstanceMessageHandler().

Here is the call graph for this function:

◆ ~OtherInstanceMessageHandler()

Slic3r::GUI::OtherInstanceMessageHandler::~OtherInstanceMessageHandler ( )
inline
64{ assert(!m_initialized); }
bool m_initialized
Definition InstanceCheck.hpp:86

References m_initialized.

Member Function Documentation

◆ handle_message()

void Slic3r::GUI::OtherInstanceMessageHandler::handle_message ( const std::string & message)
504{
505 BOOST_LOG_TRIVIAL(info) << "message from other instance: " << message;
506
507 std::vector<std::string> args;
508 bool parsed = unescape_strings_cstyle(message, args);
509 assert(parsed);
510 if (! parsed) {
511 BOOST_LOG_TRIVIAL(error) << "message from other instance is incorrectly formatted: " << message;
512 return;
513 }
514
515 std::vector<boost::filesystem::path> paths;
516 std::vector<std::string> downloads;
517 boost::regex re(R"(^(orcaslicer|prusaslicer|cura|bambustudio):\/\/open[\/]?\?file=)", boost::regbase::icase);
518 boost::regex re2(R"(^(bambustudioopen):\/\/)", boost::regex::icase);
519 boost::smatch results;
520
521 // Skip the first argument, it is the path to the slicer executable.
522 auto it = args.begin();
523 for (++ it; it != args.end(); ++ it) {
524 boost::filesystem::path p = MessageHandlerInternal::get_path(*it);
525 if (! p.string().empty())
526 paths.emplace_back(p);
527 else if (boost::regex_search(*it, results, re) || boost::regex_search(*it, results, re2))
528 downloads.emplace_back(*it);
529 }
530 if (! paths.empty()) {
531 //wxEvtHandler* evt_handler = wxGetApp().plater(); //assert here?
532 //if (evt_handler) {
533 wxPostEvent(m_callback_evt_handler, LoadFromOtherInstanceEvent(GUI::EVT_LOAD_MODEL_OTHER_INSTANCE, std::vector<boost::filesystem::path>(std::move(paths))));
534 //}
535 }
536 if (!downloads.empty())
537 {
538 wxPostEvent(m_callback_evt_handler, StartDownloadOtherInstanceEvent(GUI::EVT_START_DOWNLOAD_OTHER_INSTANCE, std::vector<std::string>(std::move(downloads))));
539 }
540}
wxEvtHandler * m_callback_evt_handler
Definition InstanceCheck.hpp:87
static boost::filesystem::path get_path(const std::string &possible_path)
Definition InstanceCheck.cpp:481
Event< std::vector< std::string > > StartDownloadOtherInstanceEvent
Definition InstanceCheck.hpp:51
Event< std::vector< boost::filesystem::path > > LoadFromOtherInstanceEvent
Definition InstanceCheck.hpp:50
bool unescape_strings_cstyle(const std::string &str, std::vector< std::string > &out)
Definition Config.cpp:173

References Slic3r::GUI::MessageHandlerInternal::get_path(), m_callback_evt_handler, and Slic3r::unescape_strings_cstyle().

Here is the call graph for this function:

◆ init()

void Slic3r::GUI::OtherInstanceMessageHandler::init ( wxEvtHandler * callback_evt_handler)
391{
392 assert(!m_initialized);
393 assert(m_callback_evt_handler == nullptr);
394 if (m_initialized)
395 return;
396
397 m_initialized = true;
398 m_callback_evt_handler = callback_evt_handler;
399
400#if defined(__APPLE__)
401 this->register_for_messages(wxGetApp().get_instance_hash_string());
402#endif //__APPLE__
403
404#ifdef BACKGROUND_MESSAGE_LISTENER
405 m_thread = boost::thread((boost::bind(&OtherInstanceMessageHandler::listen, this)));
406#endif //BACKGROUND_MESSAGE_LISTENER
407}

References m_callback_evt_handler, and m_initialized.

◆ operator=()

void Slic3r::GUI::OtherInstanceMessageHandler::operator= ( OtherInstanceMessageHandler const & )
delete

References OtherInstanceMessageHandler().

Here is the call graph for this function:

◆ shutdown()

void Slic3r::GUI::OtherInstanceMessageHandler::shutdown ( MainFrame * main_frame)

_WIN32

409{
410 BOOST_LOG_TRIVIAL(debug) << "message handler shutdown().";
411#ifndef _WIN32
413#endif
414 assert(m_initialized);
415 if (m_initialized) {
416#ifdef _WIN32
417 HWND hwnd = main_frame->GetHandle();
418 RemoveProp(hwnd, L"Instance_Hash_Minor");
419 RemoveProp(hwnd, L"Instance_Hash_Major");
420#endif //_WIN32
421#if __APPLE__
422 //delete macos implementation
423 this->unregister_for_messages();
424#endif //__APPLE__
425#ifdef BACKGROUND_MESSAGE_LISTENER
426 if (m_thread.joinable()) {
427 // Stop the worker thread, if running.
428 {
429 // Notify the worker thread to cancel wait on detection polling.
430 std::lock_guard<std::mutex> lck(m_thread_stop_mutex);
431 m_stop = true;
432 }
433 m_thread_stop_condition.notify_all();
434 // Wait for the worker thread to stop.
435 m_thread.join();
436 m_stop = false;
437 }
438#endif //BACKGROUND_MESSAGE_LISTENER
439 m_callback_evt_handler = nullptr;
440 m_initialized = false;
441 }
442}
#define L(s)
Definition ExtrusionEntity.cpp:25
static void delete_lockfile()
Definition InstanceCheck.cpp:207

References Slic3r::instance_check_internal::delete_lockfile(), L, m_callback_evt_handler, and m_initialized.

Here is the call graph for this function:

Member Data Documentation

◆ m_callback_evt_handler

wxEvtHandler* Slic3r::GUI::OtherInstanceMessageHandler::m_callback_evt_handler { nullptr }
private
87{ nullptr };

Referenced by handle_message(), init(), and shutdown().

◆ m_initialized

bool Slic3r::GUI::OtherInstanceMessageHandler::m_initialized { false }
private
86{ false };

Referenced by ~OtherInstanceMessageHandler(), init(), and shutdown().


The documentation for this class was generated from the following files: