#ifndef __NETWORK_Agent_HPP__ #define __NETWORK_Agent_HPP__ #include "bambu_networking.hpp" #include "libslic3r/ProjectTask.hpp" #include "ICloudServiceAgent.hpp" #include "IPrinterAgent.hpp" #include #include #include #include namespace Slic3r { // Forward declaration class BBLNetworkPlugin; // The NetworkAgent class class NetworkAgent { public: // Static utility methods - delegate to BBLNetworkPlugin static std::string get_libpath_in_current_directory(std::string library_name); static std::string get_versioned_library_path(const std::string& version); static bool versioned_library_exists(const std::string& version); static bool legacy_library_exists(); static void remove_legacy_library(); static std::vector scan_plugin_versions(); static int initialize_network_module(bool using_backup = false, const std::string& version = ""); static int unload_network_module(); static bool is_network_module_loaded(); #if defined(_MSC_VER) || defined(_WIN32) static HMODULE get_bambu_source_entry(); #else static void* get_bambu_source_entry(); #endif static std::string get_version(); static void* get_network_function(const char* name); static bool use_legacy_network; static NetworkLibraryLoadError get_load_error(); static void clear_load_error(); static void set_load_error(const std::string& message, const std::string& technical_details, const std::string& attempted_path); // Sub-agent composition constructor (uses injected sub-agents) NetworkAgent(std::shared_ptr cloud_agent, std::shared_ptr printer_agent); ~NetworkAgent(); // Sub-agent accessors std::shared_ptr get_cloud_agent(const std::string& provider = ORCA_CLOUD_PROVIDER) const; std::shared_ptr get_printer_agent() const { return m_printer_agent; } // Shared agent management void add_cloud_agent(const std::string& provider, std::shared_ptr agent); void set_printer_agent(std::shared_ptr printer_agent); int set_queue_on_main_fn(QueueOnMainFn fn, const std::string& provider = ORCA_CLOUD_PROVIDER); // Get underlying agent handle from BBLNetworkPlugin void* get_network_agent(); // Cloud agent methods // These methods will be forwarded to all cloud agents int init_log(); int set_config_dir(std::string config_dir); int set_cert_file(std::string folder, std::string filename); int set_country_code(std::string country_code); int start(); int set_on_server_connected_fn(AppOnServerConnectedFn fn); int set_on_http_error_fn(AppOnHttpErrorFn fn); int set_get_country_code_fn(GetCountryCodeFn fn); int connect_server(); int refresh_connection(const std::string& provider = ""); int change_user(std::string user_info, const std::string& provider = ORCA_CLOUD_PROVIDER); bool is_user_login(const std::string& provider = ORCA_CLOUD_PROVIDER); int user_logout(bool request = false, const std::string& provider = ORCA_CLOUD_PROVIDER); std::string get_user_id(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string get_user_name(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string get_user_avatar(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string get_user_nickname(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string build_login_cmd(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string build_logout_cmd(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string build_login_info(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string get_cloud_service_host(const std::string& provider = ORCA_CLOUD_PROVIDER); std::string get_cloud_login_url(const std::string& language = "", const std::string& provider = ORCA_CLOUD_PROVIDER); bool is_server_connected(const std::string& provider = ORCA_CLOUD_PROVIDER); void enable_multi_machine(bool enable, const std::string& provider = ORCA_CLOUD_PROVIDER); // Profile synchronization methods // NOTE: this should always call only OrcaCloud int get_user_presets(std::map>* user_presets, const std::string& provider = ORCA_CLOUD_PROVIDER); std::string request_setting_id(std::string name, std::map* values_map, unsigned int* http_code, const std::string& provider = ORCA_CLOUD_PROVIDER); int put_setting(std::string setting_id, std::string name, std::map* values_map, unsigned int* http_code, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_setting_list(std::string bundle_version, ProgressFn pro_fn = nullptr, WasCancelledFn cancel_fn = nullptr, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_setting_list2(std::string bundle_version, CheckFn chk_fn, ProgressFn pro_fn = nullptr, WasCancelledFn cancel_fn = nullptr, const std::string& provider = ORCA_CLOUD_PROVIDER); int delete_setting(std::string setting_id, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_my_message(int type, int after, int limit, unsigned int* http_code, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); int check_user_task_report(int* task_id, bool* printable, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_user_print_info(unsigned int* http_code, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_user_tasks(TaskQueryParams params, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_printer_firmware(std::string dev_id, unsigned* http_code, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_task_plate_index(std::string task_id, int* plate_index, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_user_info(int* identifier, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_subtask_info(std::string subtask_id, std::string* task_json, unsigned int* http_code, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_slice_info(std::string project_id, std::string profile_id, int plate_index, std::string* slice_json, const std::string& provider = ORCA_CLOUD_PROVIDER); int query_bind_status(std::vector query_list, unsigned int* http_code, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); int modify_printer_name(std::string dev_id, std::string dev_name, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_camera_url(std::string dev_id, std::function callback, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_design_staffpick(int offset, int limit, std::function callback, const std::string& provider = ORCA_CLOUD_PROVIDER); int start_publish(PublishParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn, std::string* out, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_model_publish_url(std::string* url, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_subtask(BBLModelTask* task, OnGetSubTaskFn getsub_fn, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_model_mall_home_url(std::string* url, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_model_mall_detail_url(std::string* url, std::string id, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_my_profile(std::string token, unsigned int* http_code, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_my_token(std::string ticket, unsigned int* http_code, std::string* http_body, const std::string& provider = ORCA_CLOUD_PROVIDER); // Orca: telemetry only exists on the BBL cloud agent (Orca cloud has no track events). int track_enable(bool enable); int track_remove_files(); int track_event(std::string evt_key, std::string content, const std::string& provider = ORCA_CLOUD_PROVIDER); int track_header(std::string header, const std::string& provider = ORCA_CLOUD_PROVIDER); int track_update_property(std::string name, std::string value, std::string type = "string", const std::string& provider = ORCA_CLOUD_PROVIDER); int track_get_property(std::string name, std::string& value, std::string type = "string", const std::string& provider = ORCA_CLOUD_PROVIDER); int put_model_mall_rating(int design_id, int score, std::string content, std::vector images, unsigned int &http_code, std::string &http_error, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_oss_config(std::string &config, std::string country_code, unsigned int &http_code, std::string &http_error, const std::string& provider = ORCA_CLOUD_PROVIDER); int put_rating_picture_oss(std::string &config, std::string &pic_oss_path, std::string model_id, int profile_id, unsigned int &http_code, std::string &http_error, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_model_mall_rating_result(int job_id, std::string &rating_result, unsigned int &http_code, std::string &http_error, const std::string& provider = ORCA_CLOUD_PROVIDER); bool get_track_enable() { return enable_track; } int get_mw_user_preference(std::function callback, const std::string& provider = ORCA_CLOUD_PROVIDER); int get_mw_user_4ulist(int seed, int limit, std::function callback, const std::string& provider = ORCA_CLOUD_PROVIDER); // Printer agent methods int set_on_ssdp_msg_fn(OnMsgArrivedFn fn); int set_on_printer_connected_fn(OnPrinterConnectedFn fn); int set_on_subscribe_failure_fn(GetSubscribeFailureFn fn); int set_on_message_fn(OnMessageFn fn); int set_on_user_message_fn(OnMessageFn fn); int set_on_local_connect_fn(OnLocalConnectedFn fn); int set_on_local_message_fn(OnMessageFn fn); int set_server_callback(OnServerErrFn fn); int send_message(std::string dev_id, std::string json_str, int qos, int flag); int connect_printer(std::string dev_id, std::string dev_ip, std::string username, std::string password, bool use_ssl); int disconnect_printer(); int send_message_to_printer(std::string dev_id, std::string json_str, int qos, int flag); int check_cert(); void install_device_cert(std::string dev_id, bool lan_only); bool start_discovery(bool start, bool sending); int ping_bind(std::string ping_code); int bind_detect(std::string dev_ip, std::string sec_link, detectResult& detect); int bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn); int unbind(std::string dev_id); std::string get_user_selected_machine(); int set_user_selected_machine(std::string dev_id); int start_subscribe(std::string module); int stop_subscribe(std::string module); int add_subscribe(std::vector dev_list); int del_subscribe(std::vector dev_list); int start_print(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn, OnWaitFn wait_fn); int start_local_print_with_record(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn, OnWaitFn wait_fn); int start_send_gcode_to_sdcard(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn, OnWaitFn wait_fn); int start_local_print(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn); int start_sdcard_print(PrintParams params, OnUpdateStatusFn update_fn, WasCancelledFn cancel_fn); FilamentSyncMode get_filament_sync_mode() const; bool fetch_filament_info(std::string dev_id); int request_bind_ticket(std::string* ticket); private: struct PrinterCallbacks { OnMsgArrivedFn on_ssdp_msg_fn = nullptr; OnPrinterConnectedFn on_printer_connected_fn = nullptr; GetSubscribeFailureFn on_subscribe_failure_fn = nullptr; OnMessageFn on_message_fn = nullptr; OnMessageFn on_user_message_fn = nullptr; OnLocalConnectedFn on_local_connect_fn = nullptr; OnMessageFn on_local_message_fn = nullptr; QueueOnMainFn queue_on_main_fn = nullptr; OnServerErrFn on_server_err_fn = nullptr; }; void apply_printer_callbacks(const std::shared_ptr& printer_agent, const PrinterCallbacks& callbacks); PrinterCallbacks m_printer_callbacks; bool enable_track = false; // Sub-agent composition // We support dynamic switching of printer agents (e.g. for different printer types), but the cloud agent is fixed at construction since // it's tied to the user's cloud account OrcaCloudServiceAgent is designed to be the primary cloud agent, but we support the possibility // of adding third-party cloud agents (e.g. BBLCloudServiceAgent) and delegating calls to them as needed std::map> m_cloud_agents; std::shared_ptr m_printer_agent; std::string m_printer_agent_id; }; } #endif