OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{ElegooLink.cpp} Namespace Reference

Enumerations

enum class  ElegooPrinterType { Other , CC , CC2 }

Functions

std::string sn_cache_key (const std::string &host_ip, const std::string &token)
void cache_sn (const std::string &host_ip, const std::string &token, const std::string &sn)
std::string lookup_sn (const std::string &host_ip, const std::string &token)
std::string load_sn_from_config (const std::string &host_ip)
void persist_sn (const std::string &host_ip, const std::string &token, const std::string &sn)
ElegooPrinterType classify_printer_model (const std::string &printer_model)
std::string get_cc2_token (const std::string &apikey)
bool parse_cc2_response (const std::string &body, std::string &error_message, std::string *serial_number=nullptr)
std::string lookup_cc2_serial_impl (const std::string &printer_model, const std::string &print_host, const std::string &apikey)
std::string lookup_cc2_serial (DynamicPrintConfig *config)
std::string escape_string (const std::string &unescaped)
std::string escape_path_by_element (const boost::filesystem::path &path)
std::string path_to_utf8 (const boost::filesystem::path &path)
std::string filename_to_utf8 (const boost::filesystem::path &path)

Variables

constexpr const char * ELEGOO_CC2_DEFAULT_TOKEN = "123456"
constexpr const char * ELEGOO_DEV_SN_SECTION = "dev_sn"
static std::mutex s_sn_cache_mutex
static std::map< std::string, std::string > s_sn_cache

Enumeration Type Documentation

◆ ElegooPrinterType

enum class Slic3r::anonymous_namespace{ElegooLink.cpp}::ElegooPrinterType
strong
Enumerator
Other 
CC 
CC2 
130 {
131 Other,
132 CC,
133 CC2,
134 };
@ Other
Definition ExclusionVolumePathCheck.hpp:19

Function Documentation

◆ cache_sn()

void Slic3r::anonymous_namespace{ElegooLink.cpp}::cache_sn ( const std::string & host_ip,
const std::string & token,
const std::string & sn )
95 {
96 if (host_ip.empty() || token.empty() || sn.empty())
97 return;
98 std::lock_guard<std::mutex> lock(s_sn_cache_mutex);
99 s_sn_cache[sn_cache_key(host_ip, token)] = sn;
100 }

References cache_sn(), s_sn_cache, s_sn_cache_mutex, and sn_cache_key().

Referenced by cache_sn(), and persist_sn().

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

◆ classify_printer_model()

ElegooPrinterType Slic3r::anonymous_namespace{ElegooLink.cpp}::classify_printer_model ( const std::string & printer_model)
137 {
138 if (!boost::algorithm::starts_with(printer_model, "Elegoo Centauri"))
140
141 const auto last_char = printer_model.find_last_not_of(" \t\r\n");
142 if (last_char != std::string::npos && printer_model[last_char] == '2')
144
146 }

References CC, CC2, classify_printer_model(), and Other.

Referenced by classify_printer_model(), and lookup_cc2_serial_impl().

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

◆ escape_path_by_element()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::escape_path_by_element ( const boost::filesystem::path & path)
301 {
302 std::string ret_val = escape_string(path.filename().string());
303 boost::filesystem::path parent(path.parent_path());
304 while (!parent.empty() && parent.string() != "/") // "/" check is for case "/file.gcode" was inserted. Then boost takes "/" as parent_path.
305 {
306 ret_val = escape_string(parent.filename().string()) + "/" + ret_val;
307 parent = parent.parent_path();
308 }
309 return ret_val;
310 }

References escape_path_by_element(), and escape_string().

Referenced by escape_path_by_element().

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

◆ escape_string()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::escape_string ( const std::string & unescaped)
287 {
288 std::string ret_val;
289 CURL* curl = curl_easy_init();
290 if (curl) {
291 char* decoded = curl_easy_escape(curl, unescaped.c_str(), unescaped.size());
292 if (decoded) {
293 ret_val = std::string(decoded);
294 curl_free(decoded);
295 }
296 curl_easy_cleanup(curl);
297 }
298 return ret_val;
299 }

References escape_string().

Referenced by escape_path_by_element(), and escape_string().

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

◆ filename_to_utf8()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::filename_to_utf8 ( const boost::filesystem::path & path)
322 {
323 #ifdef WIN32
324 return boost::nowide::narrow(path.filename().wstring());
325 #else
326 return path.filename().string();
327 #endif
328 }

References filename_to_utf8().

Referenced by filename_to_utf8().

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

◆ get_cc2_token()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::get_cc2_token ( const std::string & apikey)
149 {
150 return apikey.empty() ? ELEGOO_CC2_DEFAULT_TOKEN : apikey;
151 }

References ELEGOO_CC2_DEFAULT_TOKEN, and get_cc2_token().

Referenced by get_cc2_token(), and lookup_cc2_serial_impl().

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

◆ load_sn_from_config()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::load_sn_from_config ( const std::string & host_ip)
110 {
111 if (host_ip.empty())
112 return {};
113 AppConfig* app_cfg = GUI::get_app_config();
114 if (app_cfg == nullptr)
115 return {};
116 return app_cfg->get(ELEGOO_DEV_SN_SECTION, host_ip);
117 }
Definition AppConfig.hpp:100
bool get(const std::string &section, const std::string &key, std::string &value) const
Definition AppConfig.hpp:147
AppConfig * get_app_config()
Definition GUI.cpp:539

References ELEGOO_DEV_SN_SECTION, Slic3r::AppConfig::get(), Slic3r::GUI::get_app_config(), and load_sn_from_config().

Referenced by load_sn_from_config(), and lookup_cc2_serial_impl().

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

◆ lookup_cc2_serial()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::lookup_cc2_serial ( DynamicPrintConfig * config)
213 {
214 if (config == nullptr)
215 return {};
216 return lookup_cc2_serial_impl(config->opt_string("printer_model"),
217 config->opt_string("print_host"),
218 config->opt_string("printhost_apikey"));
219 }
std::string & opt_string(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:3042

References lookup_cc2_serial(), lookup_cc2_serial_impl(), and Slic3r::DynamicConfig::opt_string().

Referenced by lookup_cc2_serial().

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

◆ lookup_cc2_serial_impl()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::lookup_cc2_serial_impl ( const std::string & printer_model,
const std::string & print_host,
const std::string & apikey )
200 {
202 return {};
203
204 const std::string host_ip = Http::get_host_header_value(print_host);
205 const std::string token = get_cc2_token(apikey);
206 std::string sn = lookup_sn(host_ip, token);
207 if (sn.empty())
208 sn = load_sn_from_config(host_ip);
209 return sn;
210 }
static std::string get_host_header_value(const std::string &url)
Definition Http.cpp:1044

References CC2, classify_printer_model(), get_cc2_token(), Slic3r::Http::get_host_header_value(), load_sn_from_config(), lookup_cc2_serial_impl(), and lookup_sn().

Referenced by lookup_cc2_serial(), and lookup_cc2_serial_impl().

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

◆ lookup_sn()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::lookup_sn ( const std::string & host_ip,
const std::string & token )
103 {
104 std::lock_guard<std::mutex> lock(s_sn_cache_mutex);
105 auto it = s_sn_cache.find(sn_cache_key(host_ip, token));
106 return it != s_sn_cache.end() ? it->second : std::string{};
107 }

References lookup_sn(), s_sn_cache, s_sn_cache_mutex, and sn_cache_key().

Referenced by lookup_cc2_serial_impl(), and lookup_sn().

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

◆ parse_cc2_response()

bool Slic3r::anonymous_namespace{ElegooLink.cpp}::parse_cc2_response ( const std::string & body,
std::string & error_message,
std::string * serial_number = nullptr )
154 {
155 try {
156 pt::ptree root;
157 std::istringstream is(body);
158 pt::read_json(is, root);
159
160 const int error_code = root.get<int>("error_code", -1);
161 if (error_code != 0) {
162 error_message = root.get<std::string>("message", _u8L("Printer returned an error"));
163 if (error_message.empty())
164 error_message = _u8L("Printer returned an error");
165 error_message += " (" + std::to_string(error_code) + ")";
166 return false;
167 }
168
169 if (serial_number != nullptr) {
170 const auto system_info = root.get_child_optional("system_info");
171 if (!system_info) {
172 error_message = _u8L("Missing system_info in response");
173 return false;
174 }
175
176 const auto sn = system_info->get_optional<std::string>("sn");
177 if (!sn || sn->empty()) {
178 error_message = _u8L("Missing printer serial number in response");
179 return false;
180 }
181 *serial_number = *sn;
182 }
183
184 return true;
185 } catch (const std::exception&) {
186 error_message = _u8L("Error parsing response");
187 return false;
188 }
189 }
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, and parse_cc2_response().

Referenced by parse_cc2_response().

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

◆ path_to_utf8()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::path_to_utf8 ( const boost::filesystem::path & path)
313 {
314 #ifdef WIN32
315 return boost::nowide::narrow(path.wstring());
316 #else
317 return path.string();
318 #endif
319 }

References path_to_utf8().

Referenced by path_to_utf8().

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

◆ persist_sn()

void Slic3r::anonymous_namespace{ElegooLink.cpp}::persist_sn ( const std::string & host_ip,
const std::string & token,
const std::string & sn )
120 {
121 if (host_ip.empty() || sn.empty())
122 return;
123 cache_sn(host_ip, token, sn);
124 AppConfig* app_cfg = GUI::get_app_config();
125 if (app_cfg == nullptr)
126 return;
127 app_cfg->set_str(ELEGOO_DEV_SN_SECTION, host_ip, sn);
128 }
void set_str(const std::string &section, const std::string &key, const std::string &value)
Definition AppConfig.hpp:184

References cache_sn(), ELEGOO_DEV_SN_SECTION, Slic3r::GUI::get_app_config(), persist_sn(), and Slic3r::AppConfig::set_str().

Referenced by persist_sn().

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

◆ sn_cache_key()

std::string Slic3r::anonymous_namespace{ElegooLink.cpp}::sn_cache_key ( const std::string & host_ip,
const std::string & token )
90 {
91 return host_ip + ":" + token;
92 }

References sn_cache_key().

Referenced by cache_sn(), lookup_sn(), and sn_cache_key().

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

Variable Documentation

◆ ELEGOO_CC2_DEFAULT_TOKEN

const char* Slic3r::anonymous_namespace{ElegooLink.cpp}::ELEGOO_CC2_DEFAULT_TOKEN = "123456"
constexpr

Referenced by get_cc2_token().

◆ ELEGOO_DEV_SN_SECTION

const char* Slic3r::anonymous_namespace{ElegooLink.cpp}::ELEGOO_DEV_SN_SECTION = "dev_sn"
constexpr

Referenced by load_sn_from_config(), and persist_sn().

◆ s_sn_cache

std::map<std::string, std::string> Slic3r::anonymous_namespace{ElegooLink.cpp}::s_sn_cache
static

Referenced by cache_sn(), and lookup_sn().

◆ s_sn_cache_mutex

std::mutex Slic3r::anonymous_namespace{ElegooLink.cpp}::s_sn_cache_mutex
static

Referenced by cache_sn(), and lookup_sn().