Files
OrcaSlicer/src/slic3r/GUI/DeviceCore/DevUpgrade.h
T
HanifKoh 73d32d4791 Stop Leaking json Through Headers and Drop Includes Kept Only for the Name (#16221)
* Stop Leaking json Through Headers and Drop Includes Kept Only for the Name

AppConfig.hpp, DeviceManager.hpp and UserManager.hpp carried a global
"using namespace nlohmann;", json_diff.hpp a global "using json =
nlohmann::json;" and PrinterFileSystem.h a global "using nlohmann::json;".
Every file that included one of them, directly or not, could write a
bare json, and 63 did without declaring it.

The last two also made the include checker treat json_diff.hpp and
PrinterFileSystem.h as the headers that provide json, so they were
included from files that use nothing else from them: 57 of the 59
includers of json_diff.hpp never name json_diff.

The five statements are removed. Headers that use the type now spell
nlohmann::json, source files declare their own "using json =
nlohmann::json;", and the includes that only supplied the name are
dropped or replaced by <nlohmann/json.hpp>.

Eight files reached json_diff.hpp only through an include that is now
gone and with it lost that header's "using namespace std;". The std
names they used unqualified are qualified.

* Declare json in OrcaSlicer.cpp on Every Platform

OrcaSlicer.cpp had its "using namespace nlohmann;" and the json include
inside the Linux-only include block, so on Windows and macOS it took
json from AppConfig.hpp's global directive, which is gone. The include
and a "using json = nlohmann::json;" now sit outside the block.
2026-10-07 14:22:16 +08:00

111 lines
4.3 KiB
C++

#pragma once
#include <memory>
#include <map>
#include <nlohmann/json.hpp>
#include <string>
#include <wx/string.h>
#include "DevDefs.h"
#include "DevFirmware.h"
namespace Slic3r {
class MachineObject;
class DevUpgrade
{
public:
static std::shared_ptr<DevUpgrade> Create(MachineObject *owner) { return std::shared_ptr<DevUpgrade>(new DevUpgrade(owner)); }
public:
// upgrade status
bool IsUpgrading() const { return m_upgrade_display_state == DevFirmwareUpgradeState::UpgradingInProgress; }
bool IsUpgradeAvaliable() const { return m_upgrade_display_state == DevFirmwareUpgradeState::UpgradingAvaliable; }
DevFirmwareUpgradeState GetUpgradeState() const { return m_upgrade_display_state; }
std::string GetUpgradeStatusStr() const { return m_upgrade_status; }
// upgrade request
bool IsUpgradeConsistencyRequest() const { return m_upgrade_consistency_request; }
bool IsUpgradeForceUpgrade() const { return m_upgrade_force_upgrade; }
bool HasNewVersion() const { return m_upgrade_new_version_state == 1; }
std::string GetOtaNewVersion() const { return m_ota_new_version_number; }
std::map<std::string, DevFirmwareVersionInfo> GetNewVersionList() const { return m_new_ver_list; }
// upgrading
std::string GetUpgradeModuleStr() const { return m_upgrade_module; }
std::string GetUpgradeProgressStr() const { return m_upgrade_progress; }
int GetUpgradeProgressInt() const;
std::string GetUpgradeMessageStr() const { return m_upgrade_message; }
wxString GetUpgradeErrCodeStr() const;
public:
// ctrls
int CtrlUpgradeConfirm();
int CtrlUpgradeConsistencyConfirm();
int CtrlUpgradeFirmware(FirmwareInfo info);
int CtrlUpgradeModule(std::string url, std::string module_type, std::string version);
// parser
void ParseUpgrade_V1_0(const nlohmann::json &print_jj);
void ParseUpgradeDisplayState(const nlohmann::json &upgrade_state_jj);
protected:
DevUpgrade(MachineObject *owner) : m_owner(owner) {}
private:
MachineObject *m_owner = nullptr;
int m_upgrade_new_version_state = 0; // 0: invalid version, 1: new version available, 2: no new version
bool m_upgrade_consistency_request = false;
bool m_upgrade_force_upgrade = false;
std::string m_ota_new_version_number;
std::map<std::string, DevFirmwareVersionInfo> m_new_ver_list; // some protcols have version list
DevFirmwareUpgradeState m_upgrade_display_state = DevFirmwareUpgradeState::DC;
int m_upgrade_err_code = 0;
std::string m_upgrade_status;
std::string m_upgrade_progress;
std::string m_upgrade_message;
std::string m_upgrade_module;
};
#if 0 /*TODO*/
class DevUpgradeGetVersionInfo
{
public:
DevUpgradeGetVersionInfo(MachineObject* obj) : m_owner(obj) {} ;
public:
bool IsEmpty() const { m_module_version_map.empty();}
DevFirmwareVersionInfo GetAirPumpVersionInfo() const { return m_air_pump_version_info; }
DevFirmwareVersionInfo GetLaserVersionInfo() const { return m_laser_version_info; }
DevFirmwareVersionInfo GetCuttingModuleVersionInfo() const { return m_cutting_module_version_info; }
DevFirmwareVersionInfo GetExtinguishVersionInfo() const { return m_extinguish_version_info; }
DevFirmwareVersionInfo GetRotaryVersionInfo() const { return m_rotary_version_info; }
std::map<std::string, DevFirmwareVersionInfo> GetModuleVersionInfoMap() const { return m_module_version_map; }
public:
int CtrlGetVersion(bool with_retry = true);
void ParseGetVersion(const nlohmann::json &print_jj);
private:
MachineObject *m_owner;
// some version info
DevFirmwareVersionInfo m_air_pump_version_info;
DevFirmwareVersionInfo m_laser_version_info;
DevFirmwareVersionInfo m_cutting_module_version_info;
DevFirmwareVersionInfo m_extinguish_version_info;
DevFirmwareVersionInfo m_rotary_version_info;
std::map<std::string, DevFirmwareVersionInfo> m_module_version_map;
// ctrl retry
int m_retry_count = 0;
int m_max_retry = 3;
};
#endif
} // namespace Slic3r