OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::DeviceManager Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DeviceCore/DevManager.h>

Collaboration diagram for Slic3r::DeviceManager:

Public Member Functions

 DeviceManager (NetworkAgent *agent=nullptr, bool enable_refresher=true, AppConfig *app_config=nullptr)
 ~DeviceManager ()
NetworkAgent * get_agent () const
AppConfig * get_app_config () const
void set_agent (NetworkAgent *agent)
void start_refresher ()
void stop_refresher ()
MachineObject * get_selected_machine ()
bool set_selected_machine (std::string dev_id)
void OnSelectedMachineLost ()
void record_user_last_machine (const std::string &dev_id)
std::string get_user_last_machine () const
void set_local_selected_machine (std::string dev_id)
MachineObject * get_local_selected_machine () const
void erase_local_machine (std::string dev_id)
std::map< std::string, MachineObject * > get_local_machinelist () const
MachineObject * get_local_machine (std::string dev_id) const
std::map< std::string, MachineObject * > get_user_machinelist () const
std::string get_first_online_user_machine () const
void erase_user_machine (std::string dev_id)
void clean_user_info (bool keep_local_selection=false)
void clear_other_devices ()
void load_last_machine ()
void update_user_machine_list_info (const std::string &provider)
void parse_user_print_info (std::string body)
void reload_printer_settings ()
MachineObject * get_user_machine (std::string dev_id, const std::string &provider)
void add_user_subscribe ()
void del_user_subscribe ()
void subscribe_device_list (std::vector< std::string > dev_list)
MachineObject * get_my_machine (std::string dev_id)
std::map< std::string, MachineObject * > get_my_machine_list (const std::string &agent_id="")
std::map< std::string, MachineObject * > get_my_cloud_machine_list (const std::string &agent_id="")
void modify_device_name (std::string dev_id, std::string dev_name, const std::string &provider)
std::string get_current_printer_agent_id () const
void on_machine_alive (std::string json_str)
int query_bind_status (std::string &msg, const std::string &provider)
void EnableMultiMachine (bool enable=true)
bool IsMultiMachineEnabled () const
MachineObject * insert_local_device (const BBLocalMachine &machine, std::string connection_type, std::string bind_state, std::string version, std::string access_code)

Static Public Member Functions

static void update_local_machine (const MachineObject &m)
static void update_local_machine (const MachineObject &m, AppConfig *config)

Public Attributes

std::vector< std::string > subscribe_list_cache
std::map< std::string, std::vector< std::string > > device_subseries

Private Member Functions

void load_local_machines_from_config ()
void keep_alive ()
void check_pushing ()
std::string get_current_cloud_provider () const
void OnMachineBindStateChanged (MachineObject *obj, const std::string &new_state)
void OnSelectedMachineChanged (const std::string &pre_dev_id, const std::string &new_dev_id)

Private Attributes

NetworkAgent * m_agent { nullptr }
AppConfig * m_app_config { nullptr }
DeviceManagerRefresher * m_refresher { nullptr }
bool m_enable_mutil_machine = false
std::mutex listMutex
std::string selected_machine
std::string local_selected_machine
std::map< std::string, MachineObject * > localMachineList
std::map< std::string, MachineObject * > userMachineList

Friends

class GUI::GUI_App
class DeviceManagerRefresher

Detailed Description

Constructor & Destructor Documentation

◆ DeviceManager()

Slic3r::DeviceManager::DeviceManager ( NetworkAgent * agent = nullptr,
bool enable_refresher = true,
AppConfig * app_config = nullptr )
69 {
70 m_agent = agent;
71 m_app_config = app_config;
72 if (enable_refresher)
74
76
77 // Load saved local machines (needs an agent; when built without one the load is
78 // deferred to set_agent()).
79 if (agent) {
81 }
82 }
static void InitFilePath(const std::string &res_file_path)
Definition DevConfigUtil.h:61
AppConfig * m_app_config
Definition DevManager.h:31
DeviceManagerRefresher * m_refresher
Definition DevManager.h:32
void load_local_machines_from_config()
Definition DevManager.cpp:89
friend class DeviceManagerRefresher
Definition DevManager.h:28
NetworkAgent * m_agent
Definition DevManager.h:30
const std::string & resources_dir()
Definition utils.cpp:296

References DeviceManagerRefresher, Slic3r::DevPrinterConfigUtil::InitFilePath(), load_local_machines_from_config(), m_agent, m_app_config, m_refresher, and Slic3r::resources_dir().

Here is the call graph for this function:

◆ ~DeviceManager()

Slic3r::DeviceManager::~DeviceManager ( )
138 {
139 if (m_refresher)
140 delete m_refresher;
141
142 for (auto it = localMachineList.begin(); it != localMachineList.end(); it++)
143 {
144 if (it->second)
145 {
146 delete it->second;
147 it->second = nullptr;
148 }
149 }
150 localMachineList.clear();
151
152 for (auto it = userMachineList.begin(); it != userMachineList.end(); it++)
153 {
154 if (it->second)
155 {
156 delete it->second;
157 it->second = nullptr;
158 }
159 }
160 userMachineList.clear();
161 }
std::map< std::string, MachineObject * > userMachineList
Definition DevManager.h:40
std::map< std::string, MachineObject * > localMachineList
Definition DevManager.h:39

References localMachineList, m_refresher, and userMachineList.

Member Function Documentation

◆ add_user_subscribe()

void Slic3r::DeviceManager::add_user_subscribe ( )
766 {
767 /* user machine */
768 std::vector<std::string> dev_list;
769 for (auto it = userMachineList.begin(); it != userMachineList.end(); it++)
770 {
771 dev_list.push_back(it->first);
772 BOOST_LOG_TRIVIAL(trace) << "add_user_subscribe: " << it->first;
773 }
774 const int result = m_agent->add_subscribe(dev_list);
775 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: add_user_subscribe count=" << dev_list.size()
776 << " result=" << result;
777 }
void trace(unsigned int level, const char *message)
Definition utils.cpp:247

References m_agent, Slic3r::trace(), and userMachineList.

Here is the call graph for this function:

◆ check_pushing()

void Slic3r::DeviceManager::check_pushing ( )
private
246 {
247 keep_alive();
248 MachineObject* obj = this->get_selected_machine();
249 if (!obj) {
250 BOOST_LOG_TRIVIAL(warning) << "DeviceManager::check_pushing selected machine not found";
251 return;
252 }
253
254 std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
255 auto internal = std::chrono::duration_cast<std::chrono::milliseconds>(start - obj->last_update_time);
256
257 if (!obj->is_support_mqtt_alive)
258 {
259 if (internal.count() > TIMEOUT_FOR_STRAT && internal.count() < 1000 * 60 * 60 * 300)
260 {
261 BOOST_LOG_TRIVIAL(info) << "command_pushing: diff = " << internal.count();
262 obj->command_pushing("start");
263 }
264 }
265 }
#define TIMEOUT_FOR_STRAT
Definition DeviceManager.hpp:44
void keep_alive()
Definition DevManager.cpp:218
MachineObject * get_selected_machine()
Definition DevManager.cpp:747

References Slic3r::MachineObject::command_pushing(), get_selected_machine(), Slic3r::MachineObject::is_support_mqtt_alive, keep_alive(), Slic3r::MachineObject::last_update_time, and TIMEOUT_FOR_STRAT.

Here is the call graph for this function:

◆ clean_user_info()

void Slic3r::DeviceManager::clean_user_info ( bool keep_local_selection = false)
589 {
590 BOOST_LOG_TRIVIAL(trace) << "DeviceManager::clean_user_info";
591 const std::string previous_selected_machine = selected_machine;
592 const bool keep_selected_machine = keep_local_selection &&
593 !selected_machine.empty() &&
595
596 // clean user list
597 for (auto it = userMachineList.begin(); it != userMachineList.end(); it++)
598 {
599 if (it->second)
600 {
601 it->second->set_access_code("");
602 delete it->second;
603 it->second = nullptr;
604 }
605 }
606 userMachineList.clear();
607
608 if (!keep_selected_machine) {
609 selected_machine = "";
611 }
612
613 OnSelectedMachineChanged(previous_selected_machine, selected_machine);
614 }
std::string local_selected_machine
Definition DevManager.h:38
std::string selected_machine
Definition DevManager.h:37
void OnSelectedMachineChanged(const std::string &pre_dev_id, const std::string &new_dev_id)
Definition DevManager.cpp:1111

References local_selected_machine, localMachineList, OnSelectedMachineChanged(), selected_machine, Slic3r::trace(), and userMachineList.

Here is the call graph for this function:

◆ clear_other_devices()

void Slic3r::DeviceManager::clear_other_devices ( )
617 {
618 // Device entries are now scoped by printer_agent_id when they are presented. Keep
619 // agent-owned discoveries across a switch so agents without automatic discovery (and
620 // plugins whose devices have not received an access code yet) do not lose their list.
621 // Entries without an owner are legacy/unscoped and cannot safely be shown.
622 for (auto it = localMachineList.begin(); it != localMachineList.end();)
623 {
624 if (!it->second || it->second->printer_agent_id.empty())
625 {
626 delete it->second;
627 it = localMachineList.erase(it);
628 }
629 else
630 {
631 ++it;
632 }
633 }
634 }

References localMachineList.

◆ del_user_subscribe()

void Slic3r::DeviceManager::del_user_subscribe ( )
781 {
782 /* user machine */
783 std::vector<std::string> dev_list;
784 for (auto it = userMachineList.begin(); it != userMachineList.end(); it++)
785 {
786 dev_list.push_back(it->first);
787 BOOST_LOG_TRIVIAL(trace) << "del_user_subscribe: " << it->first;
788 }
789 const int result = m_agent->del_subscribe(dev_list);
790 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: del_user_subscribe count=" << dev_list.size()
791 << " result=" << result;
792 }

References m_agent, Slic3r::trace(), and userMachineList.

Here is the call graph for this function:

◆ EnableMultiMachine()

void Slic3r::DeviceManager::EnableMultiMachine ( bool enable = true)
209 {
210 m_agent->enable_multi_machine(enable);
211 m_enable_mutil_machine = enable;
212 }
bool m_enable_mutil_machine
Definition DevManager.h:34

References m_agent, and m_enable_mutil_machine.

◆ erase_local_machine()

void Slic3r::DeviceManager::erase_local_machine ( std::string dev_id)
inline
70{ localMachineList.erase(dev_id); }

References localMachineList.

◆ erase_user_machine()

void Slic3r::DeviceManager::erase_user_machine ( std::string dev_id)
inline
81{ userMachineList.erase(dev_id); }

References userMachineList.

Referenced by Slic3r::GUI::UnBindMachineDialog::on_unbind_printer().

Here is the caller graph for this function:

◆ get_agent()

NetworkAgent * Slic3r::DeviceManager::get_agent ( ) const
inline
48{ return m_agent; }

References m_agent.

◆ get_app_config()

AppConfig * Slic3r::DeviceManager::get_app_config ( ) const
85 {
86 return m_app_config ? m_app_config : GUI::wxGetApp().app_config;
87 }

References m_app_config.

Referenced by get_user_last_machine(), insert_local_device(), load_local_machines_from_config(), on_machine_alive(), parse_user_print_info(), and record_user_last_machine().

Here is the caller graph for this function:

◆ get_current_cloud_provider()

std::string Slic3r::DeviceManager::get_current_cloud_provider ( ) const
private
201 {
202 const std::string agent_id = get_current_printer_agent_id();
203 if (!agent_id.empty())
205 return GUI::wxGetApp().get_printer_cloud_provider();
206 }
std::string get_current_printer_agent_id() const
Definition DevManager.cpp:192
static const std::string ORCA_CLOUD_PROVIDER("orca")
static const std::string BBL_CLOUD_PROVIDER("bbl")
static constexpr char BBL_PRINTER_AGENT_ID[]
Definition NetworkAgentFactory.hpp:20

References Slic3r::BBL_CLOUD_PROVIDER(), Slic3r::BBL_PRINTER_AGENT_ID, get_current_printer_agent_id(), and Slic3r::ORCA_CLOUD_PROVIDER().

Referenced by parse_user_print_info().

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

◆ get_current_printer_agent_id()

std::string Slic3r::DeviceManager::get_current_printer_agent_id ( ) const

◆ get_first_online_user_machine()

std::string Slic3r::DeviceManager::get_first_online_user_machine ( ) const
870 {
871 for (auto it = userMachineList.begin(); it != userMachineList.end(); it++)
872 {
873 if (it->second && it->second->is_online())
874 {
875 return it->second->get_dev_id();
876 }
877 }
878 return "";
879 }

References userMachineList.

◆ get_local_machine()

MachineObject * Slic3r::DeviceManager::get_local_machine ( std::string dev_id) const
inline
73 {
74 auto it = localMachineList.find(dev_id);
75 return (it != localMachineList.end()) ? it->second : nullptr;
76 }

References localMachineList.

Referenced by get_local_selected_machine(), and Slic3r::GUI::UnBindMachineDialog::on_unbind_printer().

Here is the caller graph for this function:

◆ get_local_machinelist()

std::map< std::string, MachineObject * > Slic3r::DeviceManager::get_local_machinelist ( ) const
inline
71{ return localMachineList; }

References localMachineList.

Referenced by Slic3r::GUI::SyncAmsInfoDialog::update_lan_machine_list(), Slic3r::GUI::SelectMachinePopup::update_other_devices(), and Slic3r::GUI::SyncAmsInfoDialog::update_user_printer().

Here is the caller graph for this function:

◆ get_local_selected_machine()

MachineObject * Slic3r::DeviceManager::get_local_selected_machine ( ) const
inline
MachineObject * get_local_machine(std::string dev_id) const
Definition DevManager.h:72

References get_local_machine(), and local_selected_machine.

Here is the call graph for this function:

◆ get_my_cloud_machine_list()

std::map< std::string, MachineObject * > Slic3r::DeviceManager::get_my_cloud_machine_list ( const std::string & agent_id = "")
857 {
858 std::map<std::string, MachineObject*> result;
859 for (auto it = userMachineList.begin(); it != userMachineList.end(); it++)
860 {
861 if (!it->second || (!agent_id.empty() && it->second->printer_agent_id != agent_id))
862 continue;
863
864 if (!it->second->is_lan_mode_printer()) { result.emplace(*it); }
865 }
866 return result;
867 }

References userMachineList.

Referenced by Slic3r::GUI::CloudTaskManagerPage::refresh_user_device(), Slic3r::GUI::LocalTaskManagerPage::refresh_user_device(), Slic3r::GUI::MultiMachineManagerPage::refresh_user_device(), Slic3r::GUI::MultiMachinePickPage::refresh_user_device(), and Slic3r::GUI::SendMultiMachinePage::refresh_user_device().

Here is the caller graph for this function:

◆ get_my_machine()

MachineObject * Slic3r::DeviceManager::get_my_machine ( std::string dev_id)
578 {
580 auto it = list.find(dev_id);
581 if (it != list.end())
582 {
583 return it->second;
584 }
585 return nullptr;
586 }
std::map< std::string, MachineObject * > get_my_machine_list(const std::string &agent_id="")
Definition DevManager.cpp:824

References get_current_printer_agent_id(), and get_my_machine_list().

Referenced by Slic3r::GUI::SendToPrinterDialog::ChangeConnectMethod(), Slic3r::GUI::SelectMachineDialog::on_timer(), Slic3r::GUI::ThermalPreconditioningDialog::on_timer(), Slic3r::GUI::SelectMachineDialog::save_option_vals(), Slic3r::GUI::CalibrationPanel::update_all(), Slic3r::GUI::SendToPrinterDialog::update_show_status(), and Slic3r::GUI::ThermalPreconditioningDialog::update_thermal_remaining_time().

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

◆ get_my_machine_list()

std::map< std::string, MachineObject * > Slic3r::DeviceManager::get_my_machine_list ( const std::string & agent_id = "")
825 {
826 std::map<std::string, MachineObject*> result;
827
828 for (auto it = userMachineList.begin(); it != userMachineList.end(); it++)
829 {
830 if (!it->second || (!agent_id.empty() && it->second->printer_agent_id != agent_id))
831 continue;
832
833 if (!it->second->is_lan_mode_printer())
834 {
835 result.insert(std::make_pair(it->first, it->second));
836 }
837 }
838
839 for (auto it = localMachineList.begin(); it != localMachineList.end(); it++)
840 {
841 if (!it->second || (!agent_id.empty() && it->second->printer_agent_id != agent_id))
842 continue;
843
844 if (it->second->has_access_right() && it->second->is_avaliable() && it->second->is_lan_mode_printer())
845 {
846 // remove redundant in userMachineList
847 if (result.find(it->first) == result.end())
848 {
849 result.emplace(std::make_pair(it->first, it->second));
850 }
851 }
852 }
853 return result;
854 }

References localMachineList, and userMachineList.

Referenced by Slic3r::GUI::_collect_sorted_machines(), Slic3r::GUI::PresetComboBox::add_connected_printers(), get_my_machine(), Slic3r::GUI::PresetComboBox::get_preset_item_name(), set_selected_machine(), Slic3r::GUI::SelectMachinePopup::update_user_devices(), Slic3r::GUI::SelectMObjectPopup::update_user_devices(), Slic3r::GUI::SendToPrinterDialog::update_user_printer(), and Slic3r::GUI::SyncAmsInfoDialog::update_user_printer().

Here is the caller graph for this function:

◆ get_selected_machine()

MachineObject * Slic3r::DeviceManager::get_selected_machine ( )
748 {
749 if (selected_machine.empty()) return nullptr;
750
751 MachineObject* obj = get_user_machine(selected_machine, GUI::wxGetApp().get_printer_cloud_provider());
752 if (obj)
753 return obj;
754
755 // return local machine has access code
756 auto it = localMachineList.find(selected_machine);
757 if (it != localMachineList.end())
758 {
759 if (it->second->has_access_right())
760 return it->second;
761 }
762 return nullptr;
763 }
MachineObject * get_user_machine(std::string dev_id, const std::string &provider)
Definition DevManager.cpp:565

References get_user_machine(), localMachineList, and selected_machine.

Referenced by Slic3r::GUI::AMSControl::AMSControl(), Slic3r::GUI::NewCalibrationHistoryDialog::NewCalibrationHistoryDialog(), Slic3r::GUI::StatusBasePanel::StatusBasePanel(), Slic3r::GUI::_collect_sorted_machines(), Slic3r::_get_filament_name_from_ams(), Slic3r::GUI::_get_used_nozzle_idxes(), Slic3r::GUI::anonymous_namespace{NativeCommands.cpp}::build_command_catalog(), Slic3r::GUI::CalibUtils::calib_flowrate(), Slic3r::GUI::CalibUtils::calib_flowrate_X1C(), Slic3r::GUI::CalibUtils::calib_generic_auto_pa_cali(), Slic3r::GUI::CalibUtils::calib_generic_PA(), Slic3r::GUI::CalibUtils::calib_PA(), Slic3r::GUI::SelectMachineDialog::can_support_pa_auto_cali(), Slic3r::GUI::Plater::priv::check_ams_status_impl(), Slic3r::check_filaments_printable(), Slic3r::GUI::CameraPopup::check_func_supported(), Slic3r::GUI::check_nozzle_diameter_and_type(), check_pushing(), Slic3r::GUI::SelectMachineDialog::clear_nozzle_mapping(), Slic3r::GUI::CalibUtils::delete_PA_calib_result(), Slic3r::GUI::CalibUtils::emit_get_flow_ratio_calib_results(), Slic3r::GUI::CalibUtils::emit_get_PA_calib_infos(), Slic3r::GUI::CalibUtils::emit_get_PA_calib_results(), Slic3r::GUI::PartSkipDialog::fetchUrl(), Slic3r::GUI::Plater::priv::get_extruder_filament_info(), Slic3r::GUI::CalibUtils::get_flow_ratio_calib_results(), Slic3r::GUI::get_hms_wiki_url(), Slic3r::GUI::Plater::priv::get_machine_sync_status(), Slic3r::GUI::SelectMachineDialog::get_mapped_nozzle_str(), Slic3r::GUI::SelectMachineDialog::get_mapped_nozzles(), Slic3r::GUI::CalibUtils::get_PA_calib_results(), Slic3r::GUI::CalibUtils::get_PA_calib_tab(), Slic3r::GUI::SendToPrinterDialog::GetConnection(), Slic3r::GUI::SyncAmsInfoDialog::has_selector(), Slic3r::GUI::SelectMachineDialog::init_bind(), Slic3r::GUI::SyncAmsInfoDialog::init_bind(), Slic3r::GUI::GUI_App::is_blocking_printing(), Slic3r::GUI::SyncAmsInfoDialog::is_same_nozzle_type(), Slic3r::GUI::SelectMachineDialog::is_same_printer_model(), Slic3r::GUI::SyncAmsInfoDialog::is_same_printer_model(), Slic3r::GUI::AMSControl::isFilaSwitchReady(), keep_alive(), Slic3r::GUI::SelectMachineDialog::on_flow_cali_option_changed(), Slic3r::GUI::SendToPrinterDialog::on_ok(), Slic3r::GUI::SelectMachineDialog::on_ok_btn(), Slic3r::GUI::SelectMachineDialog::on_pa_value_option_changed(), Slic3r::GUI::SelectMachineDialog::on_reselect_dialog_btn_clicked(), Slic3r::GUI::MonitorPanel::on_select_printer(), Slic3r::GUI::SelectMachineDialog::on_selection_changed(), Slic3r::GUI::SendToPrinterDialog::on_selection_changed(), Slic3r::GUI::SelectMachineDialog::on_send_print(), Slic3r::GUI::GUI_App::on_start_subscribe_again(), Slic3r::GUI::CalibrationCaliPage::on_subtask_abort(), Slic3r::GUI::CalibrationCaliPage::on_subtask_pause_resume(), Slic3r::GUI::SelectMachineDialog::on_timelapse_storage_check_result(), Slic3r::GUI::SelectMachineDialog::on_timelapse_storage_check_timer(), Slic3r::GUI::SyncAmsInfoDialog::on_timer(), OnSelectedMachineChanged(), Slic3r::GUI::SelectMachineDialog::popup_filament_backup(), Slic3r::GUI::SyncAmsInfoDialog::popup_filament_backup(), Slic3r::GUI::Plater::print_job_finished(), Slic3r::GUI::PrintJob::process(), Slic3r::GUI::CalibUtils::process_and_store_3mf(), Slic3r::GUI::GUI_App::process_network_msg(), Slic3r::GUI::SelectMachineDialog::reset_and_sync_ams_list(), Slic3r::GUI::SyncAmsInfoDialog::reset_and_sync_ams_list(), Slic3r::GUI::CalibUtils::select_PA_calib_result(), Slic3r::anonymous_namespace{PluginHostApp.cpp}::selected_printer(), Slic3r::GUI::CalibUtils::send_to_print(), Slic3r::GUI::CalibUtils::send_to_print(), Slic3r::GUI::SelectMachineDialog::set_default_from_sdcard(), Slic3r::GUI::SelectMachineDialog::set_default_normal(), Slic3r::GUI::CalibUtils::set_PA_calib_result(), Slic3r::GUI::CalibrationPanel::Show(), Slic3r::GUI::MonitorPanel::Show(), Slic3r::GUI::UpgradePanel::Show(), Slic3r::GUI::GUI_App::show_modal_ip_address_enter_dialog(), Slic3r::GUI::SelectMachineDialog::show_status(), Slic3r::GUI::SyncAmsInfoDialog::show_status(), Slic3r::GUI::SelectMachineDialog::show_timelapse_folder_popup(), Slic3r::GUI::SelectMachineDialog::sync_ams_mapping_result(), Slic3r::GUI::CalibrationPanel::update_all(), Slic3r::GUI::MonitorPanel::update_all(), Slic3r::GUI::SelectMachineDialog::update_best_pos_dialog(), Slic3r::GUI::SelectMachineDialog::update_filament_change_count(), Slic3r::GUI::CalibrationPresetPage::update_show_status(), Slic3r::GUI::SelectMachineDialog::update_show_status(), Slic3r::GUI::SyncAmsInfoDialog::update_show_status(), Slic3r::GUI::SendToPrinterDialog::update_user_printer(), and Slic3r::GUI::AMSLib::UpdateInfo().

Here is the call graph for this function:

◆ get_user_last_machine()

std::string Slic3r::DeviceManager::get_user_last_machine ( ) const
1070 {
1071 if (AppConfig* config = get_app_config()) {
1072 const auto& user_last_machine = config->get("user_last_selected_machine");
1073 if (!user_last_machine.empty()) {
1074 return user_last_machine;
1075 } else if (m_agent) {
1076 return m_agent->get_user_selected_machine();
1077 }
1078 }
1079
1080 return "";
1081 }
AppConfig * get_app_config() const
Definition DevManager.cpp:84

References get_app_config(), and m_agent.

Referenced by load_last_machine().

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

◆ get_user_machine()

MachineObject * Slic3r::DeviceManager::get_user_machine ( std::string dev_id,
const std::string & provider )
566 {
567 if (!m_agent || !m_agent->is_user_login(provider))
568 {
569 return nullptr;
570 }
571
572 std::map<std::string, MachineObject*>::iterator it = userMachineList.find(dev_id);
573 if (it == userMachineList.end()) return nullptr;
574 return it->second;
575 }

References m_agent, and userMachineList.

Referenced by get_selected_machine().

Here is the caller graph for this function:

◆ get_user_machinelist()

std::map< std::string, MachineObject * > Slic3r::DeviceManager::get_user_machinelist ( ) const
inline
79{ return userMachineList; }

References userMachineList.

◆ insert_local_device()

MachineObject * Slic3r::DeviceManager::insert_local_device ( const BBLocalMachine & machine,
std::string connection_type,
std::string bind_state,
std::string version,
std::string access_code )
474 {
475 MachineObject* obj;
476 auto it = localMachineList.find(machine.dev_id);
477 if (it != localMachineList.end()) {
478 obj = it->second;
479 // insert_local_device is called by the active agent, so a reused entry must follow
480 // that agent as well; otherwise the agent-scoped printer list hides it.
481 obj->printer_agent_id = get_current_printer_agent_id();
482 } else {
483 obj = new MachineObject(this, m_agent, machine.dev_name, machine.dev_id, machine.dev_ip);
484 obj->printer_agent_id = get_current_printer_agent_id();
485 localMachineList.insert(std::make_pair(machine.dev_id, obj));
486 }
487 if (machine.printer_type.empty())
488 obj->printer_type = _parse_printer_type("C11");
489 else
490 obj->printer_type = _parse_printer_type(machine.printer_type);
491 obj->dev_connection_type = connection_type == "farm" ? "lan":connection_type;
492 obj->bind_state = connection_type == "farm" ? "free":bind_state;
493 obj->bind_sec_link = "secure";
494 obj->bind_ssdp_version = version;
495 obj->m_is_online = true;
496 obj->last_alive = Slic3r::Utils::get_current_time_utc();
497 obj->set_access_code(access_code, false);
498
500
501 return obj;
502 }
static void update_local_machine(const MachineObject &m)
Definition DevManager.cpp:504
time_t get_current_time_utc()
Definition Time.cpp:183
static std::string _parse_printer_type(const std::string &type_str)
Definition DevConfigUtil.h:217

References Slic3r::_parse_printer_type(), Slic3r::MachineObject::bind_sec_link, Slic3r::MachineObject::bind_ssdp_version, Slic3r::MachineObject::bind_state, Slic3r::MachineObject::dev_connection_type, Slic3r::BBLocalMachine::dev_id, Slic3r::BBLocalMachine::dev_ip, Slic3r::BBLocalMachine::dev_name, get_app_config(), get_current_printer_agent_id(), Slic3r::Utils::get_current_time_utc(), Slic3r::MachineObject::last_alive, localMachineList, m_agent, Slic3r::MachineObject::m_is_online, Slic3r::MachineObject::printer_agent_id, Slic3r::BBLocalMachine::printer_type, Slic3r::MachineObject::printer_type, Slic3r::MachineObject::set_access_code(), and update_local_machine().

Referenced by Slic3r::GUI::InputIpAddressDialog::workerThreadFunc().

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

◆ IsMultiMachineEnabled()

bool Slic3r::DeviceManager::IsMultiMachineEnabled ( ) const
inline
117{ return m_enable_mutil_machine; }

References m_enable_mutil_machine.

◆ keep_alive()

void Slic3r::DeviceManager::keep_alive ( )
private
219 {
220 MachineObject* obj = this->get_selected_machine();
221 if (obj)
222 {
223 if (obj->keep_alive_count == 0)
224 {
225 obj->last_keep_alive = std::chrono::system_clock::now();
226 }
227 obj->keep_alive_count++;
228 std::chrono::system_clock::time_point start = std::chrono::system_clock::now();
229 auto internal = std::chrono::duration_cast<std::chrono::milliseconds>(start - obj->last_keep_alive);
230 if (internal.count() > TIMEOUT_FOR_KEEPALIVE && (internal.count() < 1000 * 60 * 60 * 300))
231 {
232 BOOST_LOG_TRIVIAL(info) << "keep alive = " << internal.count() << ", count = " << obj->keep_alive_count;
233 obj->command_request_push_all();
234 obj->last_keep_alive = start;
235 }
236 else if (obj->m_push_count == 0)
237 {
238 BOOST_LOG_TRIVIAL(info) << "keep alive = " << internal.count() << ", push_count = 0, count = " << obj->keep_alive_count;
239 obj->command_request_push_all();
240 obj->last_keep_alive = start;
241 }
242 }
243 }
#define TIMEOUT_FOR_KEEPALIVE
Definition DeviceManager.hpp:45

References Slic3r::MachineObject::command_request_push_all(), get_selected_machine(), Slic3r::MachineObject::keep_alive_count, Slic3r::MachineObject::last_keep_alive, Slic3r::MachineObject::m_push_count, and TIMEOUT_FOR_KEEPALIVE.

Referenced by check_pushing().

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

◆ load_last_machine()

void Slic3r::DeviceManager::load_last_machine ( )
1084 {
1085 // Only reconnect the remembered cloud machine. Do not select an arbitrary
1086 // first machine: agent swaps intentionally leave the selection empty until
1087 // the new agent explicitly selects its configured printer.
1088 if (userMachineList.empty())
1089 return;
1090
1091 const auto& last_monitor_machine = get_user_last_machine();
1092 if (userMachineList.find(last_monitor_machine) != userMachineList.end())
1093 set_selected_machine(last_monitor_machine);
1094 }
bool set_selected_machine(std::string dev_id)
Definition DevManager.cpp:636
std::string get_user_last_machine() const
Definition DevManager.cpp:1069

References get_user_last_machine(), set_selected_machine(), and userMachineList.

Referenced by Slic3r::GUI::CalibrationPanel::Show(), Slic3r::GUI::MonitorPanel::Show(), and Slic3r::GUI::SendToPrinterDialog::update_user_printer().

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

◆ load_local_machines_from_config()

void Slic3r::DeviceManager::load_local_machines_from_config ( )
private
90 {
91 AppConfig* config = get_app_config();
92 if (!config)
93 return;
94 const auto local_machines = config->get_local_machines();
95 for (auto& it : local_machines) {
96 const auto& m = it.second;
97 if (localMachineList.count(m.dev_id))
98 continue;
99 MachineObject* obj = new MachineObject(this, m_agent, m.dev_name, m.dev_id, m.dev_ip);
100 obj->printer_type = m.printer_type;
101 obj->printer_agent_id = m.printer_agent_id;
102 obj->dev_connection_type = "lan";
103 obj->bind_state = "free";
104 obj->bind_sec_link = "secure";
105 obj->m_is_online = true;
106 obj->last_alive = Slic3r::Utils::get_current_time_utc();
107 obj->set_access_code(get_access_code_with_legacy_fallback(config, m.dev_id, obj->printer_agent_id), false);
108 if (obj->has_access_right()) {
109 localMachineList.insert(std::make_pair(m.dev_id, obj));
110 } else {
111 config->erase_local_machine(m.dev_id);
112 delete obj;
113 }
114 }
115 }
std::string get_access_code_with_legacy_fallback(Slic3r::AppConfig *config, const std::string &dev_id, const std::string &agent_id)
Definition DevManager.cpp:49

References Slic3r::MachineObject::bind_sec_link, Slic3r::MachineObject::bind_state, Slic3r::MachineObject::dev_connection_type, Slic3r::AppConfig::erase_local_machine(), get_app_config(), Slic3r::Utils::get_current_time_utc(), Slic3r::AppConfig::get_local_machines(), Slic3r::MachineObject::has_access_right(), Slic3r::MachineObject::last_alive, localMachineList, m_agent, Slic3r::MachineObject::m_is_online, Slic3r::MachineObject::printer_agent_id, Slic3r::MachineObject::printer_type, and Slic3r::MachineObject::set_access_code().

Referenced by DeviceManager(), and set_agent().

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

◆ modify_device_name()

void Slic3r::DeviceManager::modify_device_name ( std::string dev_id,
std::string dev_name,
const std::string & provider )
882 {
883 BOOST_LOG_TRIVIAL(trace) << "modify_device_name";
884 if (m_agent)
885 {
886 int result = m_agent->modify_printer_name(dev_id, dev_name, provider);
887 if (result == 0)
888 {
890 }
891 }
892 }
void update_user_machine_list_info(const std::string &provider)
Definition DevManager.cpp:1042

References m_agent, Slic3r::trace(), and update_user_machine_list_info().

Referenced by Slic3r::GUI::EditDevNameDialog::on_edit_name().

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

◆ on_machine_alive()

void Slic3r::DeviceManager::on_machine_alive ( std::string json_str)
268 {
269 try {
270 json j = json::parse(json_str);
271 std::string dev_name = j["dev_name"].get<std::string>();
272 std::string dev_id = j["dev_id"].get<std::string>();
273 std::string dev_ip = j["dev_ip"].get<std::string>();
274 std::string printer_type_str= j["dev_type"].get<std::string>();
275 std::string printer_signal = j["dev_signal"].get<std::string>();
276 std::string connect_type = j["connect_type"].get<std::string>();
277 std::string bind_state = j["bind_state"].get<std::string>();
278
279 // Passive discovery must not replace another agent's saved binding.
281 if (AppConfig* config = get_app_config()) {
282 const auto& machines = config->get_local_machines();
283 auto it = machines.find(dev_id);
284 if (it != machines.end() && it->second.printer_agent_id != MOONRAKER_PRINTER_AGENT_ID) {
285 BOOST_LOG_TRIVIAL(warning) << "Ignoring Moonraker discovery for a device owned by another agent: " << dev_id;
286 return;
287 }
288 }
289 }
290
291 if (connect_type == "farm") {
292 connect_type ="lan";
293 bind_state = "free";
294 }
295
296 std::string sec_link = "";
297 std::string ssdp_version = "";
298 if (j.contains("sec_link")) {
299 sec_link = j["sec_link"].get<std::string>();
300 }
301 if (j.contains("ssdp_version")) {
302 ssdp_version = j["ssdp_version"].get<std::string>();
303 }
304 std::string connection_name = "";
305 if (j.contains("connection_name")) {
306 connection_name = j["connection_name"].get<std::string>();
307 }
308
309 MachineObject* obj;
310
311 /* update userMachineList info */
312 auto it = userMachineList.find(dev_id);
313 if (it != userMachineList.end()) {
314 // A reused entry may have been created while another printer agent was active.
315 // The response was obtained through the current agent, so move ownership with
316 // the entry; otherwise agent-scoped lists hide it after a preset switch.
317 it->second->printer_agent_id = get_current_printer_agent_id();
318 if (it->second->get_dev_ip() != dev_ip ||
319 it->second->bind_state != bind_state ||
320 it->second->bind_sec_link != sec_link ||
321 it->second->dev_connection_type != connect_type ||
322 it->second->bind_ssdp_version != ssdp_version)
323 {
324 if (it->second->bind_state != bind_state) {
325 OnMachineBindStateChanged(it->second, bind_state);
326 }
327
328 it->second->set_dev_ip(dev_ip);
329 it->second->bind_state = bind_state;
330 it->second->bind_sec_link = sec_link;
331 it->second->dev_connection_type = connect_type;
332 it->second->bind_ssdp_version = ssdp_version;
333 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " UpdateUserMachineInfo"
334 << ", dev_id= " << dev_id
335 << ", ip = " <<dev_ip
336 << ", printer_name= " << dev_name
337 << ", con_type= " << connect_type << ", signal= " << printer_signal
338 << ", bind_state= " << bind_state;
339 }
340 }
341
342 /* update localMachineList */
343 it = localMachineList.find(dev_id);
344 AppConfig* config = get_app_config();
345
346 if (it != localMachineList.end()) {
347 // update properties
348 /* ip changed */
349 obj = it->second;
350 // A reused LAN entry may have been discovered while another printer agent was
351 // active. The current discovery message establishes ownership for this agent.
352 obj->printer_agent_id = get_current_printer_agent_id();
353
354 if (obj->get_dev_ip().compare(dev_ip) != 0) {
355 if ( connection_name.empty() ) {
356 BOOST_LOG_TRIVIAL(info) << "MachineObject IP changed from " << obj->get_dev_ip()
357 << " to " << dev_ip;
358 obj->set_dev_ip(dev_ip);
359 }
360 else {
361 if ( obj->dev_connection_name.empty() || obj->dev_connection_name.compare(connection_name) == 0) {
362 BOOST_LOG_TRIVIAL(info) << "MachineObject IP changed from " << obj->get_dev_ip()
363 << " to " << dev_ip << " connection_name is " << connection_name;
364 if(obj->dev_connection_name.empty()){obj->dev_connection_name = connection_name;}
365 obj->set_dev_ip(dev_ip);
366 }
367 }
368 /* ip changed reconnect mqtt */
369 }
370
371 if (obj->wifi_signal != printer_signal ||
372 obj->dev_connection_type != connect_type ||
373 obj->bind_state != bind_state ||
374 obj->bind_sec_link != sec_link ||
375 obj->bind_ssdp_version != ssdp_version ||
376 obj->printer_type != _parse_printer_type(printer_type_str))
377 {
378 if (obj->dev_connection_type != connect_type ||
379 obj->bind_state != bind_state ||
380 obj->bind_sec_link != sec_link ||
381 obj->bind_ssdp_version != ssdp_version ||
382 obj->printer_type != _parse_printer_type(printer_type_str))
383 {
384 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " UpdateLocalMachineInfo"
385 << ", dev_id= " << dev_id
386 << ", ip = " << dev_ip
387 << ", printer_name= " << dev_name
388 << ", con_type= " << connect_type << ", signal= " << printer_signal
389 << ", bind_state= " << bind_state;
390 }
391 else
392 {
393 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " UpdateLocalMachineInfo_WIFI"
394 << ", dev_id= " << dev_id
395 << ", ip = " << dev_ip
396 << ", printer_name= " << dev_name
397 << ", con_type= " << connect_type << ", signal= " << printer_signal
398 << ", bind_state= " << bind_state;
399 }
400
401 obj->wifi_signal = printer_signal;
402 obj->dev_connection_type = connect_type;
403 obj->bind_state = bind_state;
404 obj->bind_sec_link = sec_link;
405 obj->bind_ssdp_version = ssdp_version;
406 obj->printer_type = _parse_printer_type(printer_type_str);
407 }
408
409 // U0 firmware
410 if (obj->dev_connection_type.empty() && obj->bind_state.empty())
411 obj->bind_state = "free";
412
413 obj->last_alive = Slic3r::Utils::get_current_time_utc();
414 // Route through set_online_state() (rather than writing m_is_online directly) so the
415 // DeviceOnline lifecycle event fires consistently; same effective value/behavior
416 // here since the object was already online in the common case.
417 obj->set_online_state(true);
418 obj->set_dev_name(dev_name);
419 /* if (!obj->dev_ip.empty()) {
420 Slic3r::GUI::wxGetApp().app_config->set_str("ip_address", obj->dev_id, obj->dev_ip);
421 Slic3r::GUI::wxGetApp().app_config->save();
422 }*/
423 }
424 else {
425 /* insert a new machine */
426 obj = new MachineObject(this, m_agent, dev_name, dev_id, dev_ip);
427 obj->printer_type = _parse_printer_type(printer_type_str);
428 obj->printer_agent_id = get_current_printer_agent_id();
429 obj->wifi_signal = printer_signal;
430 obj->dev_connection_type = connect_type;
431 obj->bind_state = bind_state;
432 obj->bind_sec_link = sec_link;
433 obj->dev_connection_name = connection_name;
434 obj->bind_ssdp_version = ssdp_version;
435 // Discovery establishes the initial reachability state. Do not report it as an
436 // online transition; DeviceDiscovered below is the lifecycle event for a new
437 // device. Subsequent updates route through set_online_state(), so a known device
438 // still emits DeviceOnline/DeviceOffline when its reachability actually changes.
439 obj->m_is_online = true;
440
441 //load access code
442 if (config) {
443 obj->set_access_code(get_access_code_with_legacy_fallback(config, dev_id, obj->printer_agent_id), false);
444 }
445 localMachineList.insert(std::make_pair(dev_id, obj));
446
447 /* if (!obj->dev_ip.empty()) {
448 Slic3r::GUI::wxGetApp().app_config->set_str("ip_address", obj->dev_id, obj->dev_ip);
449 Slic3r::GUI::wxGetApp().app_config->save();
450 }*/
451 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " New Machine, dev_id= " << dev_id
452 << ", ip = " << dev_ip <<", printer_name = " << dev_name
453 << ", con_type= " << connect_type <<", signal= " << printer_signal << ", bind_state= " << bind_state;
454
455 // First discovery of a genuinely new device (not a periodic SSDP/heartbeat update to
456 // an already-known one, which is handled in the branch above).
457 {
458 LifecycleEventContext ctx;
459 ctx.name = dev_id;
460 ctx.code = LifecycleEvtCode::Ok;
462 }
463 }
464 update_local_machine(*obj, config);
465 }
466 catch (...) {
467 ;
468 }
469 }
void OnMachineBindStateChanged(MachineObject *obj, const std::string &new_state)
Definition DevManager.cpp:1096
nlohmann::json json
Definition AssembleList.cpp:42
static constexpr char MOONRAKER_PRINTER_AGENT_ID[]
Definition NetworkAgentFactory.hpp:21
@ DeviceDiscovered
Definition LifecycleEvents.hpp:54
@ Ok
Definition LifecycleEvents.hpp:68
void fire_lifecycle_event(LifecycleEvent event, const LifecycleEventContext &ctx)
Definition LifecycleEvents.hpp:234

References Slic3r::_parse_printer_type(), Slic3r::MachineObject::bind_sec_link, Slic3r::MachineObject::bind_ssdp_version, Slic3r::MachineObject::bind_state, Slic3r::LifecycleEventContext::code, Slic3r::MachineObject::dev_connection_name, Slic3r::MachineObject::dev_connection_type, Slic3r::DeviceDiscovered, Slic3r::fire_lifecycle_event(), get_app_config(), get_current_printer_agent_id(), Slic3r::Utils::get_current_time_utc(), Slic3r::MachineObject::get_dev_ip(), Slic3r::MachineObject::last_alive, localMachineList, m_agent, Slic3r::MachineObject::m_is_online, Slic3r::MOONRAKER_PRINTER_AGENT_ID, Slic3r::LifecycleEventContext::name, Slic3r::Ok, OnMachineBindStateChanged(), Slic3r::MachineObject::printer_agent_id, Slic3r::MachineObject::printer_type, Slic3r::MachineObject::set_access_code(), Slic3r::MachineObject::set_dev_ip(), Slic3r::MachineObject::set_dev_name(), Slic3r::MachineObject::set_online_state(), update_local_machine(), userMachineList, and Slic3r::MachineObject::wifi_signal.

Here is the call graph for this function:

◆ OnMachineBindStateChanged()

void Slic3r::DeviceManager::OnMachineBindStateChanged ( MachineObject * obj,
const std::string & new_state )
private
1097 {
1098 if (!obj) { return; }
1099 if (obj->get_dev_id() == selected_machine)
1100 {
1101 if (new_state == "free") { OnSelectedMachineLost(); }
1102 }
1103 }
void OnSelectedMachineLost()
Definition DevManager.cpp:1105

References Slic3r::MachineObject::get_dev_id(), OnSelectedMachineLost(), and selected_machine.

Referenced by on_machine_alive().

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

◆ OnSelectedMachineChanged()

void Slic3r::DeviceManager::OnSelectedMachineChanged ( const std::string & pre_dev_id,
const std::string & new_dev_id )
private
1113 {
1114 {
1115 LifecycleEventContext ctx;
1116 ctx.name = new_dev_id; // empty string is a valid deselection
1117 ctx.code = LifecycleEvtCode::Ok;
1119 }
1120 if (MachineObject* obj_ = get_selected_machine()) {
1121 GUI::wxGetApp().sidebar().update_sync_status(obj_);
1122 if(m_agent->get_filament_sync_mode() == FilamentSyncMode::subscription)
1123 {
1124 GUI::wxGetApp().sidebar().load_ams_list(obj_);
1125 }
1126 };
1127 }
@ DeviceSelected
Definition LifecycleEvents.hpp:55
@ subscription
Real-time push updates via subscription (e.g., MQTT).
Definition IPrinterAgent.hpp:58

References Slic3r::LifecycleEventContext::code, Slic3r::DeviceSelected, Slic3r::fire_lifecycle_event(), get_selected_machine(), m_agent, Slic3r::LifecycleEventContext::name, Slic3r::Ok, and Slic3r::subscription.

Referenced by clean_user_info(), and set_selected_machine().

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

◆ OnSelectedMachineLost()

void Slic3r::DeviceManager::OnSelectedMachineLost ( )
1106 {
1107 GUI::wxGetApp().sidebar().update_sync_status(nullptr);
1108 GUI::wxGetApp().sidebar().load_ams_list(nullptr);
1109 }

Referenced by OnMachineBindStateChanged().

Here is the caller graph for this function:

◆ parse_user_print_info()

void Slic3r::DeviceManager::parse_user_print_info ( std::string body)
895 {
896 BOOST_LOG_TRIVIAL(trace) << "DeviceManager::parse_user_print_info";
897 std::lock_guard<std::mutex> lock(listMutex);
898
899 if (device_subseries.size() <= 0) {
901 if (device_subseries.size() <= 0) {
902 device_subseries.insert(std::pair<std::string, std::vector<std::string>>("", std::vector<std::string>()));
903 }
904 }
905
906 std::set<std::string> new_list;
907 try
908 {
909 json j = json::parse(body);
910
911 const bool has_request_context = j.contains("provider") && j.contains("agent_id") && j.contains("generation");
912 const std::string current_provider = get_current_cloud_provider();
913 const std::string provider = j.contains("provider") ? j["provider"].get<std::string>()
914 : current_provider;
915 const std::string agent_id = j.contains("agent_id") ? j["agent_id"].get<std::string>()
917 const std::uint64_t generation = j.value("generation", std::uint64_t(0));
918
919 if (has_request_context &&
920 (provider != current_provider ||
921 agent_id != get_current_printer_agent_id() ||
922 generation != (m_agent ? m_agent->get_user_machine_list_generation() : 0))) {
923 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": ignoring stale response provider="
924 << provider << " agent_id=" << agent_id
925 << " generation=" << generation;
926 return;
927 }
928
929#if !BBL_RELEASE_TO_PUBLIC
930 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": " << j;
931#endif
932
933 if (j.contains("devices") && !j["devices"].is_null())
934 {
935 for (auto& elem : j["devices"])
936 {
937 MachineObject* obj = nullptr;
938 std::string dev_id;
939 if (!elem["dev_id"].is_null())
940 {
941 dev_id = elem["dev_id"].get<std::string>();
942 new_list.insert(dev_id);
943 }
944 std::map<std::string, MachineObject*>::iterator iter = userMachineList.find(dev_id);
945 if (iter != userMachineList.end())
946 {
947 /* update field */
948 obj = iter->second;
949 obj->set_dev_id(dev_id);
950 // A device can be rediscovered by a different agent after a preset
951 // switch while retaining the same MachineObject instance.
952 obj->printer_agent_id = agent_id;
953 }
954 else
955 {
956 obj = new MachineObject(this, m_agent, "", "", "");
957 obj->printer_agent_id = agent_id;
958 if (m_agent)
959 {
960 obj->set_bind_status(m_agent->get_user_name(provider));
961 }
962
963 if (obj->get_dev_ip().empty())
964 {
965 if (AppConfig* config = get_app_config())
966 obj->get_dev_ip() = config->get("ip_address", dev_id);
967 }
968 userMachineList.insert(std::make_pair(dev_id, obj));
969 }
970
971 if (!obj) continue;
972
973 // Orca cloud printers are only ever delivered through this REST
974 // account list; tag them so DeviceManager's cloud/lan branches
975 // (subscribe + deselect in set_selected_machine) treat them right.
976 if (provider == ORCA_CLOUD_PROVIDER)
977 obj->dev_connection_type = "cloud";
978
979 if (!elem["dev_id"].is_null())
980 obj->set_dev_id(elem["dev_id"].get<std::string>());
981 if (!elem["dev_name"].is_null())
982 obj->set_dev_name(elem["dev_name"].get<std::string>());
983 if (!elem["dev_online"].is_null())
984 obj->m_is_online = elem["dev_online"].get<bool>();
985 if (elem.contains("dev_model_name") && !elem["dev_model_name"].is_null()) {
986 auto printer_type = elem["dev_model_name"].get<std::string>();
987 for (const auto &pair : device_subseries) {
988 auto it = std::find(pair.second.begin(), pair.second.end(), printer_type);
989 if (it != pair.second.end())
990 {
991 obj->printer_type = Slic3r::_parse_printer_type(pair.first);
992 break;
993 }
994 else
995 {
996 obj->printer_type = Slic3r::_parse_printer_type(printer_type);
997 }
998 }
999 }
1000 if (!elem["task_status"].is_null())
1001 obj->iot_print_status = elem["task_status"].get<std::string>();
1002 if (elem.contains("dev_product_name") && !elem["dev_product_name"].is_null())
1003 obj->dev_product_name = elem["dev_product_name"].get<std::string>();
1004 if (elem.contains("dev_access_code") && !elem["dev_access_code"].is_null())
1005 {
1006 std::string acc_code = elem["dev_access_code"].get<std::string>();
1007 acc_code.erase(std::remove(acc_code.begin(), acc_code.end(), '\n'), acc_code.end());
1008 obj->set_access_code(acc_code);
1009 }
1010
1011 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: parsed cloud machine dev_id=" << dev_id
1012 << " name=" << obj->get_dev_name()
1013 << " agent_id=" << obj->printer_agent_id
1014 << " connection_type=" << obj->connection_type()
1015 << " online=" << obj->m_is_online;
1016 }
1017
1018 //remove MachineObject from userMachineList
1019 std::map<std::string, MachineObject*>::iterator iterat;
1020 for (iterat = userMachineList.begin(); iterat != userMachineList.end(); )
1021 {
1022 if (new_list.find(iterat->first) == new_list.end())
1023 {
1024 iterat = userMachineList.erase(iterat);
1025 }
1026 else
1027 {
1028 iterat++;
1029 }
1030 }
1031 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: parse_user_print_info complete provider=" << provider
1032 << " parsed_count=" << new_list.size()
1033 << " stored_count=" << userMachineList.size();
1034 }
1035 }
1036 catch (std::exception& e)
1037 {
1038 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " exception=" << e.what();
1039 }
1040 }
static std::map< std::string, std::vector< std::string > > get_all_subseries(std::string type_str="")
Definition DevConfigUtil.cpp:289
std::map< std::string, std::vector< std::string > > device_subseries
Definition DevManager.h:119
std::string get_current_cloud_provider() const
Definition DevManager.cpp:200
std::mutex listMutex
Definition DevManager.h:36
@ lock
Definition GLGizmoEmboss.cpp:209

References Slic3r::_parse_printer_type(), Slic3r::MachineObject::connection_type(), Slic3r::MachineObject::dev_connection_type, Slic3r::MachineObject::dev_product_name, device_subseries, Slic3r::DevPrinterConfigUtil::get_all_subseries(), get_app_config(), get_current_cloud_provider(), get_current_printer_agent_id(), Slic3r::MachineObject::get_dev_ip(), Slic3r::MachineObject::get_dev_name(), Slic3r::MachineObject::iot_print_status, listMutex, m_agent, Slic3r::MachineObject::m_is_online, Slic3r::ORCA_CLOUD_PROVIDER(), Slic3r::MachineObject::printer_agent_id, Slic3r::MachineObject::printer_type, Slic3r::MachineObject::set_access_code(), Slic3r::MachineObject::set_bind_status(), Slic3r::MachineObject::set_dev_id(), Slic3r::MachineObject::set_dev_name(), Slic3r::trace(), and userMachineList.

Referenced by Slic3r::GUI::SelectMachinePopup::update_user_devices(), Slic3r::GUI::SelectMObjectPopup::update_user_devices(), update_user_machine_list_info(), Slic3r::GUI::SelectMachineDialog::update_user_printer(), Slic3r::GUI::SendToPrinterDialog::update_user_printer(), and Slic3r::GUI::SyncAmsInfoDialog::update_user_printer().

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

◆ query_bind_status()

int Slic3r::DeviceManager::query_bind_status ( std::string & msg,
const std::string & provider )
510 {
511 if (!m_agent)
512 {
513 msg = "";
514 return -1;
515 }
516
517 BOOST_LOG_TRIVIAL(trace) << "DeviceManager::query_bind_status";
518 std::map<std::string, MachineObject*>::iterator it;
519 std::vector<std::string> query_list;
520 for (it = localMachineList.begin(); it != localMachineList.end(); it++)
521 {
522 query_list.push_back(it->first);
523 }
524
525 unsigned int http_code;
526 std::string http_body;
527 int result = m_agent->query_bind_status(query_list, &http_code, &http_body, provider);
528
529 if (result < 0)
530 {
531 msg = (boost::format("code=%1%,body=%2") % http_code % http_body).str();
532 }
533 else
534 {
535 msg = "";
536 try
537 {
538 json j = json::parse(http_body);
539 if (j.contains("bind_list"))
540 {
541
542 for (auto& item : j["bind_list"])
543 {
544 auto it = localMachineList.find(item["dev_id"].get<std::string>());
545 if (it != localMachineList.end())
546 {
547 if (!item["user_id"].is_null())
548 it->second->bind_user_id = item["user_id"].get<std::string>();
549 if (!item["user_name"].is_null())
550 it->second->bind_user_name = item["user_name"].get<std::string>();
551 else
552 it->second->bind_user_name = "Free";
553 }
554 }
555 }
556 }
557 catch (...)
558 {
559 ;
560 }
561 }
562 return result;
563 }

References localMachineList, m_agent, and Slic3r::trace().

Here is the call graph for this function:

◆ record_user_last_machine()

void Slic3r::DeviceManager::record_user_last_machine ( const std::string & dev_id)
1063 {
1064 if (AppConfig* config = get_app_config()) {
1065 config->set("user_last_selected_machine", dev_id);
1066 }
1067 }

References get_app_config().

Referenced by set_selected_machine().

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

◆ reload_printer_settings()

void Slic3r::DeviceManager::reload_printer_settings ( )
1130 {
1131 for (auto obj : this->userMachineList) { obj.second->reload_printer_settings(); };
1132 }

References userMachineList.

◆ set_agent()

void Slic3r::DeviceManager::set_agent ( NetworkAgent * agent)
164 {
165 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": updating agent for "
166 << localMachineList.size() << " local and "
167 << userMachineList.size() << " user machines";
168
169 // First real agent after an agent-less construction (network plugin wasn't ready at
170 // startup): run the persisted-LAN-printer load the constructor had to skip. See
171 // load_local_machines_from_config().
172 const bool first_real_agent = (m_agent == nullptr && agent != nullptr);
173 m_agent = agent;
174
175 std::lock_guard<std::mutex> lock(listMutex);
176 for (auto& it : localMachineList) {
177 if (it.second) {
178 it.second->set_agent(agent);
179 }
180 }
181 for (auto& it : userMachineList) {
182 if (it.second) {
183 it.second->set_agent(agent);
184 }
185 }
186
187 if (first_real_agent) {
189 }
190 }

References listMutex, load_local_machines_from_config(), localMachineList, m_agent, and userMachineList.

Here is the call graph for this function:

◆ set_local_selected_machine()

void Slic3r::DeviceManager::set_local_selected_machine ( std::string dev_id)
inline
66{ local_selected_machine = dev_id; };

References local_selected_machine.

◆ set_selected_machine()

bool Slic3r::DeviceManager::set_selected_machine ( std::string dev_id)
637 {
638 BOOST_LOG_TRIVIAL(info) << "set_selected_machine=" << dev_id
639 << " cur_selected=" << selected_machine;
640 auto my_machine_list = get_my_machine_list(get_current_printer_agent_id());
641 auto it = my_machine_list.find(dev_id);
642 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: set_selected_machine lookup dev_id=" << dev_id
643 << " found=" << (it != my_machine_list.end())
644 << " my_machine_count=" << my_machine_list.size()
645 << " current_agent=" << get_current_printer_agent_id()
646 << " provider=" << GUI::wxGetApp().get_printer_cloud_provider();
647 if (it != my_machine_list.end() && it->second) {
648 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: target machine dev_id=" << it->second->get_dev_id()
649 << " printer_agent_id=" << it->second->printer_agent_id
650 << " connection_type=" << it->second->connection_type()
651 << " dev_connection_type=" << it->second->dev_connection_type;
652 } else if (!dev_id.empty()) {
653 BOOST_LOG_TRIVIAL(warning) << "Orca diagnostic: target machine was not found in the current agent's machine list";
654 return false;
655 }
656
657 // disconnect last if dev_id difference from previous one
658 auto last_selected = my_machine_list.find(selected_machine);
659 if (last_selected != my_machine_list.end() && selected_machine != dev_id)
660 {
661 if (last_selected->second->connection_type() == "lan")
662 {
663 m_agent->disconnect_printer();
664 }
665 else if (last_selected->second->connection_type() == "cloud") {
666 const int result = m_agent->set_user_selected_machine("");
667 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: cleared previous cloud selection dev_id="
668 << selected_machine << " result=" << result;
669 }
670 }
671
672 // connect curr
673 if (it != my_machine_list.end())
674 {
675 if (selected_machine == dev_id)
676 {
677 // same dev_id, cloud => reset update time
678 if (it->second->connection_type() != "lan")
679 {
680 BOOST_LOG_TRIVIAL(info) << "set_selected_machine: same cloud machine, dev_id =" << dev_id
681 << ", just reset update time";
682
683 // only reset update time
684 it->second->reset_update_time();
685
686 // check subscribe state
687 Slic3r::GUI::wxGetApp().on_start_subscribe_again(dev_id);
688
689 return true;
690 }
691 // same dev_id, lan => disconnect and reconnect
692 else
693 {
694 BOOST_LOG_TRIVIAL(info) << "set_selected_machine: same lan machine, dev_id =" << dev_id
695 << ", disconnect and reconnect";
696
697 // lan mode printer reconnect printer
698 if (m_agent)
699 {
700 m_agent->disconnect_printer();
701 it->second->reset();
702
703 it->second->connect();
704 it->second->set_lan_mode_connection_state(true);
705 }
706 }
707 }
708 else
709 {
710 if (m_agent)
711 {
712 if (it->second->connection_type() != "lan" || it->second->connection_type().empty())
713 {
714 // diff dev_id, cloud => set_user_selected_machine(new)
715 BOOST_LOG_TRIVIAL(info) << "set_selected_machine: select new cloud machine, dev_id =" << dev_id;
716 const int result = m_agent->set_user_selected_machine(dev_id);
717 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: set new cloud selection dev_id="
718 << dev_id << " result=" << result;
719 it->second->reset();
720 }
721 else
722 {
723 BOOST_LOG_TRIVIAL(info) << "set_selected_machine: select new lan machine, dev_id =" << dev_id;
724 it->second->reset();
725 it->second->connect();
726 it->second->set_lan_mode_connection_state(true);
727 }
728 }
729 }
730 for (auto& data : it->second->m_nozzle_filament_data)
731 {
732 data.second.checked_filament.clear();
733 }
734 }
735
736 if (selected_machine != dev_id) {
738 }
739
740 selected_machine = dev_id;
742 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: DeviceManager selection complete selected_machine="
744 return true;
745 }
void record_user_last_machine(const std::string &dev_id)
Definition DevManager.cpp:1062

References get_current_printer_agent_id(), get_my_machine_list(), m_agent, OnSelectedMachineChanged(), record_user_last_machine(), selected_machine, and Slic3r::trace().

Referenced by load_last_machine(), Slic3r::GUI::MObjectPanel::on_mouse_left_up(), Slic3r::GUI::MonitorPanel::on_select_printer(), Slic3r::GUI::SelectMachineDialog::on_selection_changed(), Slic3r::GUI::SendToPrinterDialog::on_selection_changed(), Slic3r::UserManager::parse_json(), Slic3r::GUI::Plater::print_job_finished(), and Slic3r::GUI::CalibrationPanel::update_all().

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

◆ start_refresher()

void Slic3r::DeviceManager::start_refresher ( )
214{ if (m_refresher) m_refresher->Start(); }

References m_refresher.

◆ stop_refresher()

void Slic3r::DeviceManager::stop_refresher ( )
215{ if (m_refresher) m_refresher->Stop(); }

References m_refresher.

◆ subscribe_device_list()

void Slic3r::DeviceManager::subscribe_device_list ( std::vector< std::string > dev_list)
795 {
796 std::vector<std::string> unsub_list;
797 subscribe_list_cache.clear();
798 for (auto& it : subscribe_list_cache)
799 {
800 if (it != selected_machine)
801 {
802 unsub_list.push_back(it);
803 BOOST_LOG_TRIVIAL(trace) << "subscribe_device_list: unsub dev id = " << it;
804 }
805 }
806 BOOST_LOG_TRIVIAL(trace) << "subscribe_device_list: unsub_list size = " << unsub_list.size();
807
808 if (!selected_machine.empty())
809 {
811 }
812 for (auto& it : dev_list)
813 {
814 subscribe_list_cache.push_back(it);
815 BOOST_LOG_TRIVIAL(trace) << "subscribe_device_list: sub dev id = " << it;
816 }
817 BOOST_LOG_TRIVIAL(trace) << "subscribe_device_list: sub_list size = " << subscribe_list_cache.size();
818 if (!unsub_list.empty())
819 m_agent->del_subscribe(unsub_list);
820 if (!dev_list.empty())
821 m_agent->add_subscribe(subscribe_list_cache);
822 }
std::vector< std::string > subscribe_list_cache
Definition DevManager.h:118

References m_agent, selected_machine, subscribe_list_cache, and Slic3r::trace().

Referenced by Slic3r::GUI::CloudTaskManagerPage::refresh_user_device(), Slic3r::GUI::LocalTaskManagerPage::refresh_user_device(), Slic3r::GUI::MultiMachineManagerPage::refresh_user_device(), Slic3r::GUI::MultiMachinePickPage::refresh_user_device(), Slic3r::GUI::SendMultiMachinePage::refresh_user_device(), Slic3r::GUI::CloudTaskManagerPage::Show(), Slic3r::GUI::LocalTaskManagerPage::Show(), Slic3r::GUI::MultiMachineManagerPage::Show(), Slic3r::GUI::MultiMachinePickPage::Show(), and Slic3r::GUI::SendMultiMachinePage::Show().

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

◆ update_local_machine() [1/2]

void Slic3r::DeviceManager::update_local_machine ( const MachineObject & m)
static
505 {
506 update_local_machine(m, GUI::wxGetApp().app_config);
507 }

References update_local_machine().

Referenced by insert_local_device(), on_machine_alive(), Slic3r::MachineObject::parse_json(), Slic3r::MachineObject::set_access_code(), and update_local_machine().

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

◆ update_local_machine() [2/2]

void Slic3r::DeviceManager::update_local_machine ( const MachineObject & m,
AppConfig * config )
static
118 {
119 if (config) {
120 if (m.is_lan_mode_printer()) {
121 if (m.has_access_right()) {
122 BBLocalMachine local_machine;
123 local_machine.dev_id = m.get_dev_id();
124 local_machine.dev_name = m.get_dev_name();
125 local_machine.dev_ip = m.get_dev_ip();
126 local_machine.printer_type = m.printer_type;
127 local_machine.printer_agent_id = m.printer_agent_id;
128 local_machine.access_code = m.get_access_code();
129 config->update_local_machine(local_machine);
130 }
131 } else {
132 config->erase_local_machine(m.get_dev_id());
133 }
134 }
135 }

References Slic3r::BBLocalMachine::access_code, Slic3r::BBLocalMachine::dev_id, Slic3r::BBLocalMachine::dev_ip, Slic3r::BBLocalMachine::dev_name, Slic3r::AppConfig::erase_local_machine(), Slic3r::MachineObject::get_access_code(), Slic3r::MachineObject::get_dev_id(), Slic3r::MachineObject::get_dev_ip(), Slic3r::MachineObject::get_dev_name(), Slic3r::MachineObject::has_access_right(), Slic3r::MachineObject::is_lan_mode_printer(), Slic3r::BBLocalMachine::printer_agent_id, Slic3r::MachineObject::printer_agent_id, Slic3r::BBLocalMachine::printer_type, Slic3r::MachineObject::printer_type, and Slic3r::AppConfig::update_local_machine().

Here is the call graph for this function:

◆ update_user_machine_list_info()

void Slic3r::DeviceManager::update_user_machine_list_info ( const std::string & provider)
1043 {
1044 if (!m_agent) return;
1045
1046 BOOST_LOG_TRIVIAL(debug) << "update_user_machine_list_info";
1047 unsigned int http_code;
1048 std::string body;
1049 int result = m_agent->get_user_print_info(&http_code, &body, provider);
1050 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: get_user_print_info provider=" << provider
1051 << " result=" << result << " http_code=" << http_code
1052 << " body_bytes=" << body.size();
1053 if (result == 0)
1054 {
1055 // parse_user_print_info and on_machine_alive (SSDP for discovery) both mutate the same userMachineList map.
1056 // on_machine_alive mutates the map on the UI thread, do the same for parse_user_print_info.
1057 BOOST_LOG_TRIVIAL(trace) << "Orca diagnostic: queueing parse_user_print_info on UI thread";
1058 Slic3r::GUI::wxGetApp().CallAfter([this, body]() { parse_user_print_info(body); });
1059 }
1060 }
void parse_user_print_info(std::string body)
Definition DevManager.cpp:894

References m_agent, parse_user_print_info(), and Slic3r::trace().

Referenced by modify_device_name(), Slic3r::GUI::GUI_App::on_user_login_handle(), Slic3r::UserManager::parse_json(), and Slic3r::GUI::BindJob::process().

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

◆ DeviceManagerRefresher

friend class DeviceManagerRefresher
friend

◆ GUI::GUI_App

friend class GUI::GUI_App
friend

Member Data Documentation

◆ device_subseries

std::map<std::string, std::vector<std::string> > Slic3r::DeviceManager::device_subseries

Referenced by parse_user_print_info().

◆ listMutex

std::mutex Slic3r::DeviceManager::listMutex
private

Referenced by parse_user_print_info(), and set_agent().

◆ local_selected_machine

std::string Slic3r::DeviceManager::local_selected_machine
private

◆ localMachineList

◆ m_agent

◆ m_app_config

AppConfig* Slic3r::DeviceManager::m_app_config { nullptr }
private
31{ nullptr };

Referenced by DeviceManager(), and get_app_config().

◆ m_enable_mutil_machine

bool Slic3r::DeviceManager::m_enable_mutil_machine = false
private

◆ m_refresher

DeviceManagerRefresher* Slic3r::DeviceManager::m_refresher { nullptr }
private

◆ selected_machine

std::string Slic3r::DeviceManager::selected_machine
private

◆ subscribe_list_cache

std::vector<std::string> Slic3r::DeviceManager::subscribe_list_cache

Referenced by subscribe_device_list().

◆ userMachineList


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DeviceCore/DevManager.h
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/DeviceCore/DevManager.cpp