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

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

Collaboration diagram for Slic3r::FileTransferJob:

Public Types

using ResultCb = std::function<void(int res, int resp_ec, std::string json_res, std::vector<std::byte> bin_res)>
using MsgCb = std::function<void(int kind, std::string json)>

Public Member Functions

 FileTransferJob (FileTransferModule &m, const std::string &params_json)
 ~FileTransferJob ()
 FileTransferJob (const FileTransferJob &)=delete
FileTransferJob & operator= (const FileTransferJob &)=delete
 FileTransferJob (FileTransferJob &&)=delete
FileTransferJob & operator= (FileTransferJob &&)=delete
void on_result (ResultCb cb)
bool get_result (int &ec, int &resp_ec, std::string &json, std::vector< std::byte > &bin, uint32_t timeout_ms)
void start_on (FileTransferTunnel &t)
void on_msg (MsgCb cb)
bool try_get_msg (int &kind, std::string &json)
bool get_msg (uint32_t timeout_ms, int &kind, std::string &json)
FT_JobHandle * native () const noexcept
bool check_valid () const
bool finished () const
void cancel ()

Private Member Functions

void reset () noexcept
void solve_result (ft_job_result result)

Private Attributes

FileTransferModule * m_ {}
FT_JobHandle * h_ {}
ResultCb result_cb_ {}
MsgCb msg_cb_ {}
bool finished_ = false
int res_ = 0
int resp_ec_ = 0
std::string res_json_
std::vector< std::byte > res_bin_

Detailed Description

Member Typedef Documentation

◆ MsgCb

using Slic3r::FileTransferJob::MsgCb = std::function<void(int kind, std::string json)>

◆ ResultCb

using Slic3r::FileTransferJob::ResultCb = std::function<void(int res, int resp_ec, std::string json_res, std::vector<std::byte> bin_res)>

Constructor & Destructor Documentation

◆ FileTransferJob() [1/3]

Slic3r::FileTransferJob::FileTransferJob ( FileTransferModule & m,
const std::string & params_json )
explicit
98 : m_(&m)
99{
100 FT_JobHandle *h{};
101 if (m_->ft_job_create(params_json.c_str(), &h) != 0 || !h) {
102
103 }
104 h_ = h;
105
106 // C API: ft_job_result_cb(void* user, int tunnel_err, ft_job_result result)
107 auto tramp = [](void *user, ft_job_result r) noexcept {
108 auto *self = reinterpret_cast<FileTransferJob *>(user);
109 if (!self) return;
110
111 try {
112 self->finished_ = true;
113 self->solve_result(r);
114
115 if (self->result_cb_) self->result_cb_(self->res_, self->resp_ec_, self->res_json_, self->res_bin_);
116 self->m_->ft_job_result_destroy(&r);
117 } catch (...) {
118 // swallow
119 }
120
121 try {
122 if (auto *mod = self ? self->m_ : nullptr) {
123 if (mod->ft_job_result_destroy)
124 mod->ft_job_result_destroy(&r);
125 else if (mod->ft_free) {
126 if (r.json) mod->ft_free((void *) r.json);
127 if (r.bin) mod->ft_free((void *) r.bin);
128 }
129 }
130 } catch (...) {}
131 };
132
133 if (m_->ft_job_set_result_cb(h_, tramp, this) == ft_err::FT_EXCEPTION) { throw std::runtime_error("ft_job_set_result_cb failed"); }
134}
FileTransferJob(FileTransferModule &m, const std::string &params_json)
Definition FileTransferUtils.cpp:98
FT_JobHandle * h_
Definition FileTransferUtils.hpp:224
FileTransferModule * m_
Definition FileTransferUtils.hpp:223
@ FT_EXCEPTION
Definition FileTransferUtils.hpp:45

References FileTransferJob(), Slic3r::ft_job_result::bin, h_, Slic3r::ft_job_result::json, and m_.

Referenced by FileTransferJob(), FileTransferJob(), FileTransferJob(), on_msg(), operator=(), and operator=().

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

◆ ~FileTransferJob()

Slic3r::FileTransferJob::~FileTransferJob ( )
inline
184{ reset(); }
void reset() noexcept
Definition FileTransferUtils.hpp:213

References reset().

Here is the call graph for this function:

◆ FileTransferJob() [2/3]

Slic3r::FileTransferJob::FileTransferJob ( const FileTransferJob & )
delete

References FileTransferJob().

Here is the call graph for this function:

◆ FileTransferJob() [3/3]

Slic3r::FileTransferJob::FileTransferJob ( FileTransferJob && )
delete

References FileTransferJob().

Here is the call graph for this function:

Member Function Documentation

◆ cancel()

void Slic3r::FileTransferJob::cancel ( )
inline
208 {
209 if (m_->ft_job_cancel && h_) m_->ft_job_cancel(h_);
210 }

References h_, and m_.

◆ check_valid()

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

References h_.

◆ finished()

bool Slic3r::FileTransferJob::finished ( ) const
inline
205{ return finished_; }
bool finished_
Definition FileTransferUtils.hpp:227

References finished_.

◆ get_msg()

bool Slic3r::FileTransferJob::get_msg ( uint32_t timeout_ms,
int & kind,
std::string & json )
203{
204 if (!h_) return false;
205 ft_job_msg m{};
206 int rc = m_->ft_job_get_msg(h_, timeout_ms, &m);
207 if (rc != 0) return false;
208
209 kind = m.kind;
210 json.assign(m.json ? m.json : "");
211
212 if (m_->ft_job_msg_destroy)
213 m_->ft_job_msg_destroy(&m);
214 else if (m_->ft_free && m.json)
215 m_->ft_free((void *) m.json);
216
217 return true;
218}
nlohmann::json json
Definition AssembleList.cpp:42

References h_, Slic3r::ft_job_msg::json, Slic3r::ft_job_msg::kind, and m_.

◆ get_result()

bool Slic3r::FileTransferJob::get_result ( int & ec,
int & resp_ec,
std::string & json,
std::vector< std::byte > & bin,
uint32_t timeout_ms )
139{
140 if (!h_) throw std::runtime_error("job handle invalid");
141 ft_job_result result;
142 if (m_->ft_job_get_result(h_, timeout_ms, &result) == ft_err::FT_EXCEPTION) return false;
143 solve_result(result);
144 m_->ft_job_result_destroy(&result);
145 ec = res_;
146 resp_ec = res_;
147 json = res_json_;
148 bin = res_bin_;
149 return true;
150}
std::vector< std::byte > res_bin_
Definition FileTransferUtils.hpp:231
std::string res_json_
Definition FileTransferUtils.hpp:230
void solve_result(ft_job_result result)
Definition FileTransferUtils.cpp:220
int res_
Definition FileTransferUtils.hpp:228

References Slic3r::FT_EXCEPTION, h_, m_, res_, res_bin_, res_json_, and solve_result().

Here is the call graph for this function:

◆ native()

FT_JobHandle * Slic3r::FileTransferJob::native ( ) const
inlinenoexcept
203{ return h_; }

References h_.

◆ on_msg()

void Slic3r::FileTransferJob::on_msg ( MsgCb cb)
159{
160 msg_cb_ = std::move(cb);
161 if (!h_) return;
162
163 // C API: ft_job_msg_cb(void* user, ft_job_msg msg)
164 auto tramp = [](void *user, ft_job_msg m) noexcept {
165 auto *self = reinterpret_cast<FileTransferJob *>(user);
166 if (!self) return;
167 try {
168 if (self->msg_cb_) { self->msg_cb_(m.kind, std::string(m.json ? m.json : "")); }
169 } catch (...) {}
170
171 try {
172 if (auto *mod = self->m_) {
173 if (mod->ft_job_msg_destroy)
174 mod->ft_job_msg_destroy(&m);
175 else if (mod->ft_free && m.json)
176 mod->ft_free((void *) m.json);
177 }
178 } catch (...) {}
179 };
180
181 if (m_->ft_job_set_msg_cb(h_, tramp, this) == ft_err::FT_EXCEPTION) { throw std::runtime_error("ft_job_set_msg_cb failed"); }
182}
MsgCb msg_cb_
Definition FileTransferUtils.hpp:226

References FileTransferJob(), Slic3r::FT_EXCEPTION, h_, m_, and msg_cb_.

Here is the call graph for this function:

◆ on_result()

void Slic3r::FileTransferJob::on_result ( ResultCb cb)
136{ result_cb_ = std::move(cb); }
ResultCb result_cb_
Definition FileTransferUtils.hpp:225

References result_cb_.

◆ operator=() [1/2]

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

References FileTransferJob().

Here is the call graph for this function:

◆ operator=() [2/2]

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

References FileTransferJob().

Here is the call graph for this function:

◆ reset()

void Slic3r::FileTransferJob::reset ( )
inlineprivatenoexcept
214 {
215 if (h_) {
216 m_->ft_job_release(h_);
217 h_ = nullptr;
218 }
219 }

References h_, and m_.

Referenced by ~FileTransferJob().

Here is the caller graph for this function:

◆ solve_result()

void Slic3r::FileTransferJob::solve_result ( ft_job_result result)
private
221{
222 res_ = result.ec;
223 resp_ec_ = result.resp_ec;
224
225 res_bin_.clear();
226 if (result.bin && result.bin_size) res_bin_.assign(reinterpret_cast<const std::byte *>(result.bin),
227 reinterpret_cast<const std::byte *>(result.bin) + result.bin_size);
228 res_json_.assign(result.json ? result.json : "");
229}
int resp_ec_
Definition FileTransferUtils.hpp:229

References Slic3r::ft_job_result::bin, Slic3r::ft_job_result::bin_size, Slic3r::ft_job_result::ec, Slic3r::ft_job_result::json, res_, res_bin_, res_json_, Slic3r::ft_job_result::resp_ec, and resp_ec_.

Referenced by get_result().

Here is the caller graph for this function:

◆ start_on()

void Slic3r::FileTransferJob::start_on ( FileTransferTunnel & t)
153{
154 if (!h_) throw std::runtime_error("job handle invalid");
155 if (m_->ft_tunnel_start_job(t.native(), h_) == ft_err::FT_EXCEPTION) { throw std::runtime_error("ft_tunnel_start_job failed"); }
156}

References Slic3r::FT_EXCEPTION, h_, m_, and Slic3r::FileTransferTunnel::native().

Here is the call graph for this function:

◆ try_get_msg()

bool Slic3r::FileTransferJob::try_get_msg ( int & kind,
std::string & json )
185{
186 if (!h_) return false;
187 ft_job_msg m{};
188 int rc = m_->ft_job_try_get_msg(h_, &m);
189 if (rc != 0) return false;
190
191 kind = m.kind;
192 json.assign(m.json ? m.json : "");
193
194 if (m_->ft_job_msg_destroy)
195 m_->ft_job_msg_destroy(&m);
196 else if (m_->ft_free && m.json)
197 m_->ft_free((void *) m.json);
198
199 return true;
200}

References h_, Slic3r::ft_job_msg::json, Slic3r::ft_job_msg::kind, and m_.

Member Data Documentation

◆ finished_

bool Slic3r::FileTransferJob::finished_ = false
private

Referenced by finished().

◆ h_

FT_JobHandle* Slic3r::FileTransferJob::h_ {}
private

◆ m_

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

◆ msg_cb_

MsgCb Slic3r::FileTransferJob::msg_cb_ {}
private
226{};

Referenced by on_msg().

◆ res_

int Slic3r::FileTransferJob::res_ = 0
private

Referenced by get_result(), and solve_result().

◆ res_bin_

std::vector<std::byte> Slic3r::FileTransferJob::res_bin_
private

Referenced by get_result(), and solve_result().

◆ res_json_

std::string Slic3r::FileTransferJob::res_json_
private

Referenced by get_result(), and solve_result().

◆ resp_ec_

int Slic3r::FileTransferJob::resp_ec_ = 0
private

Referenced by solve_result().

◆ result_cb_

ResultCb Slic3r::FileTransferJob::result_cb_ {}
private
225{};

Referenced by on_result().


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