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

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/Utils/NetworkAgentFactory.hpp>

Static Public Member Functions

static void register_all_agents ()
static bool register_printer_agent (const std::string &id, const std::string &display_name, PrinterAgentFactory factory)
static bool is_printer_agent_registered (const std::string &id)
static const PrinterAgentInfo * get_printer_agent_info (const std::string &id)
static std::string get_printer_agent_plugin_identifier (const std::string &id)
static std::vector< PrinterAgentInfo > get_registered_printer_agents ()
static std::shared_ptr< IPrinterAgent > create_printer_agent_by_id (const std::string &id, std::shared_ptr< ICloudServiceAgent > cloud_agent, const std::string &log_dir)
static void clear_printer_agent_cache ()
static std::shared_ptr< ICloudServiceAgent > create_cloud_agent (const std::string &provider, const std::string &log_dir)
static void register_python_plugin (const std::string &plugin_key)
static void deregister_python_plugin (const std::string &plugin_key)
static void register_python_printer_agent (const std::string &plugin_key, const std::string &capability_name)
static void deregister_python_printer_agent (const std::string &plugin_key, const std::string &capability_name)

Private Member Functions

 NetworkAgentFactory ()=delete
 ~NetworkAgentFactory ()=delete
 NetworkAgentFactory (const NetworkAgentFactory &)=delete
NetworkAgentFactory & operator= (const NetworkAgentFactory &)=delete

Detailed Description

NetworkAgentFactory - Factory for creating network agent instances

This factory creates cloud agents and printer agents for the networking subsystem. The architecture separates cloud services (authentication, project sync) from printer communication (device discovery, print jobs).

Startup flow:

  1. Call register_all_agents() during app initialization
  2. Cloud agent created at startup via create_agent_from_config()
  3. Printer agent created on-demand when a printer is selected

Usage: // At app startup (before any agent creation) NetworkAgentFactory::register_all_agents();

// Create NetworkAgent with cloud agent only auto agent = create_agent_from_config(log_dir, app_config);

// When printer is selected - create printer agent from registry auto printer = NetworkAgentFactory::create_printer_agent_by_id("orca", cloud, log_dir);

Constructor & Destructor Documentation

◆ NetworkAgentFactory() [1/2]

Slic3r::NetworkAgentFactory::NetworkAgentFactory ( )
privatedelete

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

Here is the caller graph for this function:

◆ ~NetworkAgentFactory()

Slic3r::NetworkAgentFactory::~NetworkAgentFactory ( )
privatedelete

◆ NetworkAgentFactory() [2/2]

Slic3r::NetworkAgentFactory::NetworkAgentFactory ( const NetworkAgentFactory & )
privatedelete

References NetworkAgentFactory().

Here is the call graph for this function:

Member Function Documentation

◆ clear_printer_agent_cache()

void Slic3r::NetworkAgentFactory::clear_printer_agent_cache ( )
static

Clear the printer agent cache. Calls disconnect_printer() on each cached agent and releases all shared_ptrs. Should be called during application shutdown before destroying the NetworkAgent.

168{
169 // Disconnects and destroys the agents outside the lock, since a destructor waits for its agent's threads
170 std::map<std::string, std::shared_ptr<IPrinterAgent>> cache;
171 {
172 std::lock_guard<std::mutex> lock(s_registry_mutex);
173 cache.swap(get_printer_agent_cache());
174 }
175 for (auto& pair : cache) {
176 if (pair.second)
177 pair.second->disconnect_printer();
178 }
179 cache.clear();
180 BOOST_LOG_TRIVIAL(info) << "Printer agent cache cleared";
181}
std::map< std::string, std::shared_ptr< IPrinterAgent > > & get_printer_agent_cache()
Definition NetworkAgentFactory.cpp:48
@ lock
Definition GLGizmoEmboss.cpp:209

Referenced by Slic3r::GUI::GUI_App::~GUI_App(), Slic3r::GUI::GUI_App::OnExit(), and Slic3r::GUI::GUI_App::shutdown().

Here is the caller graph for this function:

◆ create_cloud_agent()

std::shared_ptr< ICloudServiceAgent > Slic3r::NetworkAgentFactory::create_cloud_agent ( const std::string & provider,
const std::string & log_dir )
inlinestatic

Create a cloud service agent based on provider type. Handles authentication, project sync, and other cloud services.

Parameters
providerWhich implementation to use (Orca or BBL)
log_dirDirectory for log files
Returns
Shared pointer to ICloudServiceAgent implementation
146 {
147 if (provider == ORCA_CLOUD_PROVIDER) {
148 return std::make_shared<OrcaCloudServiceAgent>(log_dir);
149 } else if (provider == BBL_CLOUD_PROVIDER) {
150 auto& plugin = BBLNetworkPlugin::instance();
151 if (!plugin.is_loaded()) {
152 return nullptr;
153 }
154 if (!plugin.has_agent()) {
155 plugin.create_agent(log_dir);
156 }
157 if (!plugin.has_agent()) {
158 return nullptr;
159 }
160 return std::make_shared<BBLCloudServiceAgent>();
161 }
162 return nullptr;
163 }
static BBLNetworkPlugin & instance()
Definition BBLNetworkPlugin.cpp:56
static const std::string ORCA_CLOUD_PROVIDER("orca")
static const std::string BBL_CLOUD_PROVIDER("bbl")

References Slic3r::BBL_CLOUD_PROVIDER(), Slic3r::BBLNetworkPlugin::instance(), and Slic3r::ORCA_CLOUD_PROVIDER().

Referenced by Slic3r::create_agent_from_config().

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

◆ create_printer_agent_by_id()

std::shared_ptr< IPrinterAgent > Slic3r::NetworkAgentFactory::create_printer_agent_by_id ( const std::string & id,
std::shared_ptr< ICloudServiceAgent > cloud_agent,
const std::string & log_dir )
static

Create a printer agent by registry/config key

Returns a cached instance if one exists for the given key, otherwise creates a new agent via the registered factory and caches it.

Parameters
idAgent registry/config key to create
cloud_agentCloud agent for token access
log_dirDirectory for log files
Returns
Shared pointer to IPrinterAgent, or nullptr if ID not found
137{
138 std::lock_guard<std::mutex> lock(s_registry_mutex);
139
140 // Check cache first
141 auto& cache = get_printer_agent_cache();
142 auto cache_it = cache.find(id);
143 if (cache_it != cache.end()) {
144 BOOST_LOG_TRIVIAL(info) << "Reusing cached printer agent: " << id;
145 if (cloud_agent)
146 cache_it->second->set_cloud_agent(cloud_agent);
147 return cache_it->second;
148 }
149
150 // Not cached — create via factory
151 auto& agents = get_printer_agents();
152 auto it = agents.find(id);
153
154 if (it == agents.end()) {
155 BOOST_LOG_TRIVIAL(warning) << "Unknown printer agent ID: " << id;
156 return nullptr;
157 }
158
159 auto agent = it->second.factory(cloud_agent, log_dir);
160 if (agent) {
161 BOOST_LOG_TRIVIAL(info) << "Created and cached printer agent: " << id;
162 cache[id] = agent;
163 }
164 return agent;
165}
std::map< std::string, PrinterAgentInfo > & get_printer_agents()
Definition NetworkAgentFactory.cpp:42

Referenced by Slic3r::GUI::GUI_App::switch_printer_agent().

Here is the caller graph for this function:

◆ deregister_python_plugin()

void Slic3r::NetworkAgentFactory::deregister_python_plugin ( const std::string & plugin_key)
static
426{
427 std::vector<std::string> capability_names;
428
429 {
430 std::lock_guard<std::mutex> lock(s_registry_mutex);
431 for (const auto& [capability_key, token] : s_python_printer_agent_registration_tokens) {
432 (void) token;
433 if (capability_key.first == plugin_key)
434 capability_names.push_back(capability_key.second);
435 }
436 for (const auto& [capability_key, agent_id] : get_python_printer_agent_ids()) {
437 (void) agent_id;
438 if (capability_key.first == plugin_key &&
439 std::find(capability_names.begin(), capability_names.end(), capability_key.second) == capability_names.end())
440 capability_names.push_back(capability_key.second);
441 }
442 }
443
444 for (const std::string& capability_name : capability_names)
445 deregister_python_printer_agent(plugin_key, capability_name);
446
447 if (capability_names.empty())
448 BOOST_LOG_TRIVIAL(debug) << "Python printer-agent plugin '" << plugin_key << "' has no registered capabilities";
449}
static void deregister_python_printer_agent(const std::string &plugin_key, const std::string &capability_name)
Definition NetworkAgentFactory.cpp:451
std::map< std::pair< std::string, std::string >, std::string > & get_python_printer_agent_ids()
Definition NetworkAgentFactory.cpp:54

References deregister_python_printer_agent().

Referenced by Slic3r::GUI::GUI_App::init_plugin_gui_wiring().

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

◆ deregister_python_printer_agent()

void Slic3r::NetworkAgentFactory::deregister_python_printer_agent ( const std::string & plugin_key,
const std::string & capability_name )
static
452{
453 std::string agent_id;
454 std::shared_ptr<IPrinterAgent> cached_agent;
455
456 {
457 std::lock_guard<std::mutex> lock(s_registry_mutex);
458
459 auto token_it = std::find_if(s_python_printer_agent_registration_tokens.begin(),
461 [&plugin_key, &capability_name](const auto& entry) {
462 return entry.first.first == plugin_key &&
463 entry.first.second == capability_name;
464 });
465 if (token_it != s_python_printer_agent_registration_tokens.end())
467
468 auto& python_agent_ids = get_python_printer_agent_ids();
469 auto id_it = std::find_if(python_agent_ids.begin(), python_agent_ids.end(),
470 [&plugin_key, &capability_name](const auto& entry) {
471 return entry.first.first == plugin_key &&
472 entry.first.second == capability_name;
473 });
474 if (id_it == python_agent_ids.end()) {
475 BOOST_LOG_TRIVIAL(debug) << "Python printer-agent capability '" << capability_name << "' from plugin '"
476 << plugin_key << "' is not registered";
477 return;
478 }
479
480 agent_id = id_it->second;
481 python_agent_ids.erase(id_it);
482
483 auto& cache = get_printer_agent_cache();
484 auto cache_it = cache.find(agent_id);
485 if (cache_it != cache.end()) {
486 cached_agent = std::move(cache_it->second);
487 cache.erase(cache_it);
488 }
489
490 get_printer_agents().erase(agent_id);
491 }
492
493 if (cached_agent)
494 cached_agent->disconnect_printer();
495
496 // The GUI may still own the active capability separately from the factory cache. Clear that
497 // handle before the plugin module is torn down, otherwise NetworkAgent can retain a Python
498 // object whose implementation is about to be unloaded.
499 if (!agent_id.empty() && wxTheApp) {
500 NetworkAgent* network_agent = GUI::wxGetApp().getAgent();
501 if (network_agent) {
502 const auto active_agent = network_agent->get_printer_agent();
503 if (active_agent && active_agent->get_agent_info().id == agent_id)
504 network_agent->set_printer_agent(nullptr);
505 }
506 }
507
508 BOOST_LOG_TRIVIAL(info) << "Deregistered Python printer-agent capability '" << capability_name << "' from plugin '"
509 << plugin_key << "' with agent ID '" << agent_id << "'";
510}
static std::map< std::pair< std::string, std::string >, std::shared_ptr< PythonPrinterAgentRegistrationToken > > s_python_printer_agent_registration_tokens
Definition NetworkAgentFactory.cpp:40

References Slic3r::NetworkAgent::get_printer_agent(), and Slic3r::NetworkAgent::set_printer_agent().

Referenced by deregister_python_plugin(), and Slic3r::GUI::GUI_App::init_plugin_gui_wiring().

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

◆ get_printer_agent_info()

const PrinterAgentInfo * Slic3r::NetworkAgentFactory::get_printer_agent_info ( const std::string & id)
static

Get info about a registered agent by registry/config key

99{
100 std::lock_guard<std::mutex> lock(s_registry_mutex);
101 auto& agents = get_printer_agents();
102 auto it = agents.find(id);
103 return (it != agents.end()) ? &it->second : nullptr;
104}

Referenced by Slic3r::GUI::GUI_App::switch_printer_agent(), and Slic3r::GUI::GUI_App::switch_printer_agent_if_pending().

Here is the caller graph for this function:

◆ get_printer_agent_plugin_identifier()

std::string Slic3r::NetworkAgentFactory::get_printer_agent_plugin_identifier ( const std::string & id)
static

Return the full plugin reference for a plugin-backed printer agent ID, or empty for built-ins.

107{
108 std::lock_guard<std::mutex> lock(s_registry_mutex);
109 auto& agents = get_printer_agents();
110 auto it = agents.find(id);
111 return (it != agents.end() && it->second.is_plugin()) ? it->second.plugin_identifier : std::string();
112}

◆ get_registered_printer_agents()

std::vector< PrinterAgentInfo > Slic3r::NetworkAgentFactory::get_registered_printer_agents ( )
static

Get all registered printer agents (for UI population)

115{
116 std::lock_guard<std::mutex> lock(s_registry_mutex);
117 auto& agents = get_printer_agents();
118 std::vector<PrinterAgentInfo> result;
119 result.reserve(agents.size());
120
121 for (const auto& pair : agents) {
122 if (!pair.second.is_plugin())
123 result.push_back(pair.second);
124 }
125
126 for (const auto& pair : agents) {
127 if (pair.second.is_plugin())
128 result.push_back(pair.second);
129 }
130
131 return result;
132}

Referenced by Slic3r::GUI::TabPrinter::build_fff(), Slic3r::GUI::TabPrinter::refresh_printer_agent_dropdown(), and Slic3r::GUI::PrinterAgentChoice::reload_rows().

Here is the caller graph for this function:

◆ is_printer_agent_registered()

bool Slic3r::NetworkAgentFactory::is_printer_agent_registered ( const std::string & id)
static

Check if an agent registry/config key is registered

92{
93 std::lock_guard<std::mutex> lock(s_registry_mutex);
94 auto& agents = get_printer_agents();
95 return agents.find(id) != agents.end();
96}

◆ operator=()

NetworkAgentFactory & Slic3r::NetworkAgentFactory::operator= ( const NetworkAgentFactory & )
privatedelete

References NetworkAgentFactory().

Here is the call graph for this function:

◆ register_all_agents()

void Slic3r::NetworkAgentFactory::register_all_agents ( )
static

Register all built-in printer agents. Must be called once during application initialization, before any calls to get_registered_printer_agents() or create_printer_agent_by_id().

184{
185 register_agent<OrcaPrinterAgent>();
186 register_agent<QidiPrinterAgent>();
187 register_agent<SnapmakerPrinterAgent>();
188 register_agent<CrealityPrintAgent>(); // Must come BEFORE MoonrakerPrinterAgent —
189 // CrealityPrintAgent extends Moonraker behaviour
190 // for K-series boards with CFS support.
191 register_agent<MoonrakerPrinterAgent>();
192
193 // Keep BBL as a built-in option. Python printer-agent plugins with the
194 // same AgentInfo ID are listed separately under the plugin registry key.
195 {
197 register_printer_agent(info.id, info.name,
198 [](std::shared_ptr<ICloudServiceAgent> cloud_agent,
199 const std::string& /*log_dir*/) -> std::shared_ptr<IPrinterAgent> {
200 auto agent = std::make_shared<BBLPrinterAgent>();
201 if (cloud_agent)
202 agent->set_cloud_agent(cloud_agent);
203 return agent;
204 });
205 }
206}
static AgentInfo get_agent_info_static()
Definition BBLPrinterAgent.cpp:549
static bool register_printer_agent(const std::string &id, const std::string &display_name, PrinterAgentFactory factory)
Definition NetworkAgentFactory.cpp:84

References Slic3r::BBLPrinterAgent::get_agent_info_static(), and register_printer_agent().

Referenced by Slic3r::GUI::GUI_App::on_init_network().

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

◆ register_printer_agent()

bool Slic3r::NetworkAgentFactory::register_printer_agent ( const std::string & id,
const std::string & display_name,
PrinterAgentFactory factory )
static

Register a printer agent type

Parameters
idUnique identifier for the agent (e.g., "orca", "bbl")
display_nameHuman-readable name for UI
factoryFactory function to create the agent
Returns
true if registration succeeded, false if already registered
85{
86 std::lock_guard<std::mutex> lock(s_registry_mutex);
87 auto& agents = get_printer_agents();
88 return agents.emplace(id, PrinterAgentInfo(id, display_name, std::move(factory))).second;
89}

Referenced by Slic3r::anonymous_namespace{NetworkAgentFactory.cpp}::register_agent(), and register_all_agents().

Here is the caller graph for this function:

◆ register_python_plugin()

void Slic3r::NetworkAgentFactory::register_python_plugin ( const std::string & plugin_key)
static
245{
246 for (const auto& capability : PluginManager::instance().get_plugin_capabilities(plugin_key, PluginCapabilityType::PrinterConnection,
247 /*only_enabled=*/true))
248 register_python_printer_agent(plugin_key, capability->name());
249}
static void register_python_printer_agent(const std::string &plugin_key, const std::string &capability_name)
Definition NetworkAgentFactory.cpp:251
static PluginManager & instance()
Definition PluginManager.cpp:74
@ PrinterConnection
Definition PythonPluginInterface.hpp:17

References Slic3r::PluginManager::instance(), Slic3r::PrinterConnection, and register_python_printer_agent().

Referenced by Slic3r::GUI::GUI_App::init_plugin_gui_wiring().

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

◆ register_python_printer_agent()

void Slic3r::NetworkAgentFactory::register_python_printer_agent ( const std::string & plugin_key,
const std::string & capability_name )
static
252{
253 PluginManager& plugin_manager = PluginManager::instance();
254
255 auto cap = plugin_manager.get_plugin_capability({PluginCapabilityType::PrinterConnection, capability_name, plugin_key},
256 /*only_enabled=*/false);
257 if (!cap) {
258 BOOST_LOG_TRIVIAL(warning) << "Printer-agent capability '" << capability_name << "' not found for plugin '" << plugin_key << "'";
259 return;
260 }
261
262 PluginDescriptor descriptor;
263 if (!plugin_manager.try_get_plugin_descriptor(plugin_key, descriptor)) {
264 BOOST_LOG_TRIVIAL(warning) << "Could not find descriptor for plugin key: '" << plugin_key;
265 return;
266 }
267 if (!cap->is_enabled()) {
268 BOOST_LOG_TRIVIAL(warning) << "Printer-agent capability '" << capability_name << "' is disabled for plugin '" << plugin_key << "'";
269 return;
270 }
271
272 auto plugin = std::dynamic_pointer_cast<PrinterAgentPluginCapability>(cap);
273
274 if (!plugin) {
275 BOOST_LOG_TRIVIAL(warning) << "Loaded plugin capability '" << capability_name << "' is not a printer-agent plugin";
276 return;
277 }
278
279 auto info = plugin->get_agent_info();
280
281 if (info.id.empty()) {
282 BOOST_LOG_TRIVIAL(warning) << "Printer-agent plugin '" << capability_name << "' returned an empty agent ID";
283 return;
284 }
285
286 const auto capability_key = std::make_pair(plugin_key, capability_name);
287 std::shared_ptr<PythonPrinterAgentRegistrationToken> registration_token;
288 {
289 std::lock_guard<std::mutex> lock(s_registry_mutex);
291 [&plugin_key, &capability_name](const auto& entry) {
292 return entry.first.first == plugin_key && entry.first.second == capability_name;
293 });
294 if (token_it == s_python_printer_agent_registration_tokens.end()) {
295 registration_token = std::make_shared<PythonPrinterAgentRegistrationToken>();
296 s_python_printer_agent_registration_tokens.emplace(capability_key, registration_token);
297 } else {
298 registration_token = token_it->second;
299 }
300 }
301
302 const std::string plugin_full_ref = plugin_printer_agent_full_ref(descriptor, capability_name);
303
304 std::weak_ptr<PrinterAgentPluginCapability> weak_plugin = plugin;
305 PrinterAgentFactory factory = [weak_plugin](std::shared_ptr<ICloudServiceAgent> cloud_agent,
306 const std::string& /*log_dir*/) -> std::shared_ptr<IPrinterAgent> {
307 // The capability implements IPrinterAgent directly, so it is handed out as the
308 // live agent (no adapter); the Python plugin services the calls.
309 auto plugin = weak_plugin.lock();
310 if (!plugin)
311 return nullptr;
312
313 if (cloud_agent)
314 plugin->set_cloud_agent(cloud_agent);
315 return plugin;
316 };
317
318 // Python work above may allow disable/unload/reload to replace this capability.
319 // Re-resolve without holding the registry mutex to avoid lock inversion and reentrancy.
320 // only_enabled defaults to true here, so a capability that changed identity (reload) or was
321 // merely disabled both surface the same way: current_cap no longer equals cap.
322 auto current_cap = plugin_manager.get_plugin_capability({PluginCapabilityType::PrinterConnection, capability_name, plugin_key});
323 if (current_cap != cap) {
324 BOOST_LOG_TRIVIAL(debug) << "Printer-agent capability '" << capability_name << "' from plugin '" << plugin_key
325 << "' changed or was disabled during registration";
326 return;
327 }
328
329 std::shared_ptr<IPrinterAgent> cached_agent;
330
331 auto reject_conflicting_capability = [plugin_key, capability_name](const std::string& error_message) {
332 if (!wxTheApp || GUI::wxGetApp().is_closing())
333 return;
334 GUI::wxGetApp().CallAfter([plugin_key, capability_name, error_message]() {
335 if (GUI::wxGetApp().is_closing())
336 return;
337 PluginManager& manager = PluginManager::instance();
338 manager.set_plugin_error(plugin_key, error_message);
339 // note: the unload callback triggered by disabling will call deregister,
340 // which will be a no-op since the printer agent is never registered
341 manager.set_capability_enabled({PluginCapabilityType::PrinterConnection, capability_name, plugin_key}, false);
342 wxMessageBox(wxString::FromUTF8(error_message.c_str()), _L("Plugins"), wxOK | wxICON_WARNING, GUI::wxGetApp().GetTopWindow());
343 });
344 };
345
346 {
347 std::lock_guard<std::mutex> lock(s_registry_mutex);
348
350 [&plugin_key, &capability_name](const auto& entry) {
351 return entry.first.first == plugin_key && entry.first.second == capability_name;
352 });
353 const bool cap_still_enabled = cap->is_enabled();
354 if (token_it == s_python_printer_agent_registration_tokens.end() || token_it->second != registration_token ||
355 !cap_still_enabled) {
356 BOOST_LOG_TRIVIAL(debug) << "Printer-agent capability '" << capability_name << "' from plugin '" << plugin_key
357 << "' was disabled before registry commit";
358 return;
359 }
360
361 auto& python_agent_ids = get_python_printer_agent_ids();
362 for (const auto& pair : python_agent_ids) {
363 if (pair.first != capability_key && pair.second == info.id) {
364 const std::string error_message = GUI::format(
365 // TRN %1% is the printer agent name, %2% its ID, %3% the capability and %4% the plugin already using that ID.
366 _u8L("Printer-agent '%1%' could not be enabled: agent ID '%2%' is already registered by capability '%3%' from plugin '%4%'."),
367 info.name, info.id, pair.first.second, pair.first.first);
368 BOOST_LOG_TRIVIAL(warning) << error_message;
369 reject_conflicting_capability(error_message);
370 return;
371 }
372 }
373
374 auto plugin_it = python_agent_ids.find(capability_key);
375 if (plugin_it != python_agent_ids.end() && plugin_it->second != info.id) {
376 const std::string old_agent_id = plugin_it->second;
377 get_printer_agents().erase(old_agent_id);
378
379 auto& cache = get_printer_agent_cache();
380 auto cache_it = cache.find(old_agent_id);
381 if (cache_it != cache.end()) {
382 cached_agent = std::move(cache_it->second);
383 cache.erase(cache_it);
384 }
385 }
386
387 auto& agents = get_printer_agents();
388 auto agent_it = agents.find(info.id);
389 // why: reject only when the ID is owned by SOMEONE ELSE - a built-in has an empty
390 // plugin_identifier, another plugin/capability has a different plugin_full_ref. When it
391 // IS the same plugin_full_ref, this capability is just re-registering itself, so fall
392 // through and refresh.
393 if (agent_it != agents.end() && agent_it->second.plugin_identifier != plugin_full_ref) {
394 const std::string error_message = GUI::format(
395 // TRN %1% is the printer agent name, %2% its ID and %3% the printer agent already using that ID.
396 _u8L("Printer-agent '%1%' could not be enabled: agent ID '%2%' is already registered by '%3%'."),
397 info.name, info.id, agent_it->second.display_name);
398 BOOST_LOG_TRIVIAL(warning) << error_message;
399 reject_conflicting_capability(error_message);
400 return;
401 }
402
403 // why: insert_or_assign, not emplace - reaching here means the ID is new, or the same
404 // capability is re-registering (same plugin_full_ref). In the re-register case we WANT to
405 // overwrite so the factory closure points at the current live capability instance; emplace
406 // would silently keep the stale entry.
407 agents.insert_or_assign(info.id, PrinterAgentInfo(info.id, info.name, plugin_full_ref, std::move(factory)));
408 python_agent_ids[capability_key] = info.id;
409
410 auto& cache = get_printer_agent_cache();
411 auto cache_it = cache.find(info.id);
412 if (cache_it != cache.end()) {
413 cached_agent = std::move(cache_it->second);
414 cache.erase(cache_it);
415 }
416 }
417
418 if (cached_agent)
419 cached_agent->disconnect_printer();
420
421 BOOST_LOG_TRIVIAL(info) << "Registered printer-agent plugin '" << capability_name << "' with agent ID '" << info.id
422 << "' and plugin ref '" << plugin_full_ref << "'";
423}
#define _L(s)
Definition OBJ.cpp:34
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
std::string plugin_printer_agent_full_ref(const PluginDescriptor &descriptor, const std::string &capability_name)
Definition NetworkAgentFactory.cpp:60
std::function< std::shared_ptr< IPrinterAgent >(std::shared_ptr< ICloudServiceAgent > cloud_agent, const std::string &log_dir)> PrinterAgentFactory
Definition NetworkAgentFactory.hpp:24
#define _u8L(s)
Definition I18N.hpp:11

References _L, _u8L, Slic3r::GUI::format(), Slic3r::PluginManager::get_plugin_capability(), Slic3r::PluginManager::instance(), Slic3r::PrinterConnection, Slic3r::PluginManager::set_capability_enabled(), Slic3r::PluginManager::set_plugin_error(), and Slic3r::PluginManager::try_get_plugin_descriptor().

Referenced by Slic3r::GUI::GUI_App::init_plugin_gui_wiring(), and register_python_plugin().

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

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