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

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

Collaboration diagram for Slic3r::FileTransferTunnel:

Public Types

using ConnectionCb = std::function<void(bool is_success, int err_code, std::string error_msg)>
using TunnelStatusCb = std::function<void(int old_status, int new_status, int err_code, std::string error_msg)>

Public Member Functions

 FileTransferTunnel (FileTransferModule &m, const std::string &url)
 ~FileTransferTunnel ()
 FileTransferTunnel (const FileTransferTunnel &)=delete
FileTransferTunnel & operator= (const FileTransferTunnel &)=delete
 FileTransferTunnel (FileTransferTunnel &&)=delete
FileTransferTunnel & operator= (FileTransferTunnel &&)=delete
void start_connect ()
bool sync_start_connect ()
void on_connection (ConnectionCb cb)
void on_status (TunnelStatusCb cb)
void shutdown ()
int get_status () const
bool check_valid () const
FT_TunnelHandle * native () const noexcept

Private Member Functions

void reset () noexcept

Private Attributes

int status_ {}
FileTransferModule * m_ {}
FT_TunnelHandle * h_ {}
ConnectionCb conn_cb_ {}
TunnelStatusCb status_cb_ {}

Detailed Description

Member Typedef Documentation

◆ ConnectionCb

using Slic3r::FileTransferTunnel::ConnectionCb = std::function<void(bool is_success, int err_code, std::string error_msg)>

◆ TunnelStatusCb

using Slic3r::FileTransferTunnel::TunnelStatusCb = std::function<void(int old_status, int new_status, int err_code, std::string error_msg)>

Constructor & Destructor Documentation

◆ FileTransferTunnel() [1/3]

Slic3r::FileTransferTunnel::FileTransferTunnel ( FileTransferModule & m,
const std::string & url )
explicit
44 : m_(&m)
45{
46 // Guard against missing symbols in older Bambu networking plugins.
47 // These symbols were added in a newer plugin ABI; if the installed
48 // plugin predates them, ft_tunnel_create/ft_tunnel_set_status_cb
49 // will be null and calling them crashes.
50 if (!m_->ft_tunnel_create || !m_->ft_tunnel_set_status_cb) {
51 throw std::runtime_error("Bambu networking plugin is too old: missing ft_tunnel_* symbols. "
52 "Please update the networking plugin.");
53 }
54 FT_TunnelHandle *h{};
55 if (m_->ft_tunnel_create(url.c_str(), &h) != 0 || !h) {
56 throw std::runtime_error("ft_tunnel_create failed");
57 }
58 h_ = h;
59
60 // C API: ft_status_cb(void* user, int old_status, int new_status, int err, const char* msg)
61 auto tramp = [](void *user, int old_status, int new_status, int err_code, const char *msg) noexcept {
62 auto *self = reinterpret_cast<FileTransferTunnel *>(user);
63 self->status_ = new_status;
64 if (!self->status_cb_) return;
65 try {
66 self->status_cb_(old_status, new_status, err_code, std::string(msg ? msg : ""));
67 } catch (...) {}
68 };
69 if (m_->ft_tunnel_set_status_cb(h_, tramp, this) == ft_err::FT_EXCEPTION) { throw std::runtime_error("ft_tunnel_set_status_cb failed"); }
70}
FileTransferModule * m_
Definition FileTransferUtils.hpp:171
FileTransferTunnel(FileTransferModule &m, const std::string &url)
Definition FileTransferUtils.cpp:44
FT_TunnelHandle * h_
Definition FileTransferUtils.hpp:172
@ FT_EXCEPTION
Definition FileTransferUtils.hpp:45

References h_, and m_.

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

Here is the caller graph for this function:

◆ ~FileTransferTunnel()

Slic3r::FileTransferTunnel::~FileTransferTunnel ( )
inline
143{ reset(); }
void reset() noexcept
Definition FileTransferUtils.hpp:162

References reset().

Here is the call graph for this function:

◆ FileTransferTunnel() [2/3]

Slic3r::FileTransferTunnel::FileTransferTunnel ( const FileTransferTunnel & )
delete

References FileTransferTunnel().

Here is the call graph for this function:

◆ FileTransferTunnel() [3/3]

Slic3r::FileTransferTunnel::FileTransferTunnel ( FileTransferTunnel && )
delete

References FileTransferTunnel().

Here is the call graph for this function:

Member Function Documentation

◆ check_valid()

bool Slic3r::FileTransferTunnel::check_valid ( ) const
inline
158{ return h_ != nullptr; }

References h_.

◆ get_status()

int Slic3r::FileTransferTunnel::get_status ( ) const
inline
157{ return status_; }
int status_
Definition FileTransferUtils.hpp:170

References status_.

◆ native()

FT_TunnelHandle * Slic3r::FileTransferTunnel::native ( ) const
inlinenoexcept
159{ return h_; }

References h_.

Referenced by Slic3r::FileTransferJob::start_on().

Here is the caller graph for this function:

◆ on_connection()

void Slic3r::FileTransferTunnel::on_connection ( ConnectionCb cb)
90{ conn_cb_ = std::move(cb); }
ConnectionCb conn_cb_
Definition FileTransferUtils.hpp:173

References conn_cb_, and on_connection().

Referenced by on_connection().

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

◆ on_status()

void Slic3r::FileTransferTunnel::on_status ( TunnelStatusCb cb)
91{ status_cb_ = std::move(cb); }
TunnelStatusCb status_cb_
Definition FileTransferUtils.hpp:174

References on_status(), and status_cb_.

Referenced by on_status().

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

◆ operator=() [1/2]

FileTransferTunnel & Slic3r::FileTransferTunnel::operator= ( const FileTransferTunnel & )
delete

References FileTransferTunnel().

Here is the call graph for this function:

◆ operator=() [2/2]

FileTransferTunnel & Slic3r::FileTransferTunnel::operator= ( FileTransferTunnel && )
delete

References FileTransferTunnel().

Here is the call graph for this function:

◆ reset()

void Slic3r::FileTransferTunnel::reset ( )
inlineprivatenoexcept
163 {
164 if (h_) {
165 m_->ft_tunnel_release(h_);
166 h_ = nullptr;
167 }
168 }

References h_, and m_.

Referenced by ~FileTransferTunnel().

Here is the caller graph for this function:

◆ shutdown()

void Slic3r::FileTransferTunnel::shutdown ( )
94{
95 if (m_->ft_tunnel_shutdown) (void) m_->ft_tunnel_shutdown(h_);
96}

References h_, m_, and shutdown().

Referenced by shutdown().

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

◆ start_connect()

void Slic3r::FileTransferTunnel::start_connect ( )
73{
74 // C API: ft_conn_cb(void* user, int ok, int err, const char* msg)
75 auto tramp = [](void *user, int ok, int ec, const char *msg) noexcept {
76 auto *pcb = reinterpret_cast<ConnectionCb *>(user);
77 if (!pcb) return;
78 try {
79 (*pcb)(ok == 0, ec, std::string(msg ? msg : ""));
80 } catch (...) {}
81 };
82 if (m_->ft_tunnel_start_connect(h_, tramp, &conn_cb_) == ft_err::FT_EXCEPTION) { throw std::runtime_error("ft_tunnel_start_connect failed"); }
83}
std::function< void(bool is_success, int err_code, std::string error_msg)> ConnectionCb
Definition FileTransferUtils.hpp:139

References conn_cb_, Slic3r::FT_EXCEPTION, h_, m_, and start_connect().

Referenced by start_connect().

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

◆ sync_start_connect()

bool Slic3r::FileTransferTunnel::sync_start_connect ( )
86{
87 return m_->ft_tunnel_sync_connect(h_) == FT_OK;
88}
@ FT_OK
Definition FileTransferUtils.hpp:45

References Slic3r::FT_OK, h_, m_, and sync_start_connect().

Referenced by sync_start_connect().

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

Member Data Documentation

◆ conn_cb_

ConnectionCb Slic3r::FileTransferTunnel::conn_cb_ {}
private
173{};

Referenced by on_connection(), and start_connect().

◆ h_

FT_TunnelHandle* Slic3r::FileTransferTunnel::h_ {}
private

◆ m_

FileTransferModule* Slic3r::FileTransferTunnel::m_ {}
private

◆ status_

int Slic3r::FileTransferTunnel::status_ {}
private
170{};

Referenced by get_status().

◆ status_cb_

TunnelStatusCb Slic3r::FileTransferTunnel::status_cb_ {}
private
174{};

Referenced by on_status().


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