OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
PrinterFileSystem Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Printer/PrinterFileSystem.h>

Inheritance diagram for PrinterFileSystem:
Collaboration diagram for PrinterFileSystem:

Classes

struct  Progress
struct  File
struct  UploadFile
struct  Void
struct  Session
struct  Download
struct  Upload

Public Types

enum  {
  SUCCESS = 0 , CONTINUE = 1 , ERROR_JSON = 2 , ERROR_PIPE = 3 ,
  ERROR_CANCEL = 4 , ERROR_RES_BUSY = 5 , ERROR_TIME_OUT = 6 , FILE_NO_EXIST = 10 ,
  FILE_NAME_INVALID = 11 , FILE_SIZE_ERR = 12 , FILE_OPEN_ERR = 13 , FILE_READ_WRITE_ERR = 14 ,
  FILE_CHECK_ERR = 15 , FILE_TYPE_ERR = 16 , STORAGE_UNAVAILABLE = 17 , API_VERSION_UNSUPPORT = 18 ,
  FILE_EXIST = 19 , STORAGE_SPACE_NOT_ENOUGH = 20 , FILE_CREATE_ERR = 21 , FILE_WRITE_ERR = 22 ,
  MD5_COMPARE_ERR = 23 , FILE_RENAME_ERR = 24 , SEND_ERR = 25
}
enum  FileType { F_TIMELAPSE , F_VIDEO , F_MODEL , F_INVALID_TYPE }
enum  GroupMode { G_NONE , G_MONTH , G_YEAR }
enum  Flags {
  FF_SELECT = 1 , FF_THUMNAIL = 2 , FF_DOWNLOAD = 4 , FF_DELETED = 8 ,
  FF_FETCH_MODEL = 16 , FF_UPLOADING = 1 << 5 , FF_UPLOADDONE = 1 << 6 , FF_UPLOADCANCEL = 1 << 7 ,
  FF_THUMNAIL_RETRY = 0x100
}
enum  UploadStatus { Uploading = 1 << 0 , UploadDone = 1 << 1 , UploadCancel = 1 << 2 }
enum  RequestMediaAbilityStatus { S_SUCCESS , S_FAILED }
enum  Status {
  Initializing , Connecting , ListSyncing , ListReady ,
  Failed , Reconnecting
}
template<typename T>
using Callback = std::function<void(int, T)>
typedef std::vector< File > FileList
typedef std::vector< std::string > MediaAbilityList

Public Member Functions

 PrinterFileSystem ()
 ~PrinterFileSystem ()
void SetFileType (FileType type, std::string const &storage={})
void SetGroupMode (GroupMode mode)
size_t EnterSubGroup (size_t index)
FileType GetFileType () const
GroupMode GetGroupMode () const
void ListAllFiles ()
void DeleteFiles (size_t index)
void DownloadFiles (size_t index, std::string const &path)
void GetPickImage (int id, const std::string &local_path, const std::string &path)
void GetPickImages (const std::vector< std::string > &local_paths, const std::vector< std::string > &targetpaths)
void DownloadRamFile (int index, const std::string &local_path, const std::string &param)
void SendExistedFile ()
void SendConnectFail ()
void DownloadCheckFiles (std::string const &path)
bool DownloadCheckFile (size_t index)
void DownloadCancel (size_t index)
void FetchModel (size_t index, std::function< void(int, std::string const &)> callback)
void FetchModelCancel ()
size_t GetCount () const
size_t GetIndexAtTime (boost::uint32_t time)
void ToggleSelect (size_t index)
void SelectAll (bool select)
size_t GetSelectCount () const
void SetFocusRange (size_t start, size_t count)
File const & GetFile (size_t index)
File const & GetFile (size_t index, bool &select)
Status GetStatus () const
int GetLastError () const
void Attached ()
void Start ()
void Retry ()
void SetUrl (std::string const &url)
void Stop (bool quit=false)
boost::uint32_t RequestMediaAbility (int api_version)
void RequestUploadFile ()
MediaAbilityList GetMediaAbilityList () const
void SetUploadFile (const std::string &path, const std::string &name, const std::string &select_storage)
void CancelUploadTask (bool send_cancel_req=true)

Protected Attributes

FileType m_file_type = F_INVALID_TYPE
std::string m_file_storage
GroupMode m_group_mode = G_NONE
FileList m_file_list
std::map< std::pair< FileType, std::string >, FileList > m_file_list_cache
std::vector< size_t > m_group_year
std::vector< size_t > m_group_month
std::vector< int > m_group_flags
std::shared_ptr< UploadFile > m_upload_file

Private Types

enum  {
  LIST_INFO = 0x0001 , SUB_FILE = 0x0002 , FILE_DEL = 0x0003 , FILE_DOWNLOAD = 0x0004 ,
  FILE_UPLOAD = 0x0005 , REQUEST_MEDIA_ABILITY = 0x0007 , NOTIFY_FIRST = 0x0100 , LIST_CHANGE_NOTIFY = 0x0100 ,
  LIST_RESYNC_NOTIFY = 0x0101 , TASK_CANCEL = 0x1000
}
template<typename T>
using Translator = std::function<int(nlohmann::json const &, T &, unsigned char const *)>
typedef std::function< void(int, nlohmann::json const &resp)> callback_t
typedef std::function< int(int, nlohmann::json const &resp, unsigned char const *data)> callback_t2
typedef std::function< int(std::string &msg)> callback_t3
template<typename T>
using Applier = std::function<void(T const &)>

Private Member Functions

void BuildGroups ()
void UpdateGroupSelect ()
void DeleteFilesContinue ()
void DownloadNextFile ()
void UpdateFocusThumbnail ()
void UpdateFocusThumbnail2 (std::shared_ptr< std::vector< File > > files, int type)
void FileRemoved (std::pair< FileType, std::string > type, size_t index, std::string const &name, bool by_path)
std::pair< FileList &, size_t > FindFile (std::pair< FileType, std::string > type, size_t index, std::string const &name, bool by_path)
void SendChangedEvent (wxEventType type, size_t index=(size_t) -1, std::string const &str={}, long extra=0)
template<typename T>
boost::uint32_t SendRequest (int type, nlohmann::json const &req, Translator< T > const &translator, Callback< T > const &callback, const std::string &param="")
template<typename T>
void InstallNotify (int type, Translator< T > const &translator, Applier< T > const &applier)
boost::uint32_t SendRequest (int type, nlohmann::json const &req, callback_t2 const &callback, const std::string &param="")
void InstallNotify (int type, callback_t2 const &callback)
void CancelRequest (boost::uint32_t seq)
void CancelRequests (std::vector< boost::uint32_t > const &seqs)
void CancelRequests2 (std::vector< boost::uint32_t > const &seqs)
void RecvMessageThread ()
void HandleResponse (boost::unique_lock< boost::mutex > &l, Bambu_Sample const &sample)
void Reconnect (boost::unique_lock< boost::mutex > &l, int result)
template<typename T>
void PostCallback (Callback< T > const &callback, int result, T const &resp)
void PostCallback (std::function< void(void)> const &callback)
int UploadFileTask (std::shared_ptr< UploadFile > upload_file, boost::uint64_t seq, std::string &msg)

Static Private Member Functions

static bool ParseThumbnail (File &file)
static bool ParseThumbnail (File &file, std::istream &is)
static void DumpLog (void *context, int level, tchar const *msg)

Private Attributes

size_t m_select_count = 0
size_t m_lock_start = 0
size_t m_lock_end = 0
int m_task_flags = 0
std::vector< bool > m_download_states
Session m_session
boost::uint32_t m_sequence = 0
boost::uint32_t m_download_seq = 0
boost::uint32_t m_fetch_model_seq = 0
boost::uint32_t m_upload_seq = 0
std::deque< std::string > m_messages
std::deque< callback_t2 > m_callbacks
std::deque< callback_t2 > m_notifies
bool m_stopped = true
boost::mutex m_mutex
boost::condition_variable m_cond
boost::thread m_recv_thread
Status m_status
int m_last_error = 0
MediaAbilityList m_media_ability_list
std::map< boost::uint32_t, callback_t3 > m_produce_message_cb_map

Static Private Attributes

static const int CTRL_TYPE = 0x3001

Detailed Description


Class Documentation

◆ PrinterFileSystem::Void

struct PrinterFileSystem::Void

◆ PrinterFileSystem::Session

struct PrinterFileSystem::Session
Collaboration diagram for PrinterFileSystem::Session:
Class Members
PrinterFileSystem * owner
Bambu_Tunnel tunnel = nullptr

Member Typedef Documentation

◆ Applier

template<typename T>
using PrinterFileSystem::Applier = std::function<void(T const &)>
private

◆ Callback

template<typename T>
using PrinterFileSystem::Callback = std::function<void(int, T)>

◆ callback_t

typedef std::function<void(int, nlohmann::json const & resp)> PrinterFileSystem::callback_t
private

◆ callback_t2

typedef std::function<int(int, nlohmann::json const &resp, unsigned char const *data)> PrinterFileSystem::callback_t2
private

◆ callback_t3

typedef std::function<int(std::string &msg)> PrinterFileSystem::callback_t3
private

◆ FileList

typedef std::vector<File> PrinterFileSystem::FileList

◆ MediaAbilityList

typedef std::vector<std::string> PrinterFileSystem::MediaAbilityList

◆ Translator

template<typename T>
using PrinterFileSystem::Translator = std::function<int(nlohmann::json const &, T &, unsigned char const *)>
private

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
LIST_INFO 
SUB_FILE 
FILE_DEL 
FILE_DOWNLOAD 
FILE_UPLOAD 
REQUEST_MEDIA_ABILITY 
NOTIFY_FIRST 
LIST_CHANGE_NOTIFY 
LIST_RESYNC_NOTIFY 
TASK_CANCEL 
44 {
45 LIST_INFO = 0x0001,
46 SUB_FILE = 0x0002,
47 FILE_DEL = 0x0003,
48 FILE_DOWNLOAD = 0x0004,
49 FILE_UPLOAD = 0x0005,
50 REQUEST_MEDIA_ABILITY = 0x0007,
51 NOTIFY_FIRST = 0x0100,
52 LIST_CHANGE_NOTIFY = 0x0100,
53 LIST_RESYNC_NOTIFY = 0x0101,
54 TASK_CANCEL = 0x1000
55 };
@ LIST_CHANGE_NOTIFY
Definition PrinterFileSystem.h:52
@ LIST_RESYNC_NOTIFY
Definition PrinterFileSystem.h:53
@ REQUEST_MEDIA_ABILITY
Definition PrinterFileSystem.h:50
@ LIST_INFO
Definition PrinterFileSystem.h:45
@ FILE_DOWNLOAD
Definition PrinterFileSystem.h:48
@ FILE_UPLOAD
Definition PrinterFileSystem.h:49
@ FILE_DEL
Definition PrinterFileSystem.h:47
@ SUB_FILE
Definition PrinterFileSystem.h:46
@ NOTIFY_FIRST
Definition PrinterFileSystem.h:51
@ TASK_CANCEL
Definition PrinterFileSystem.h:54

◆ anonymous enum

anonymous enum
Enumerator
SUCCESS 
CONTINUE 
ERROR_JSON 
ERROR_PIPE 
ERROR_CANCEL 
ERROR_RES_BUSY 
ERROR_TIME_OUT 
FILE_NO_EXIST 
FILE_NAME_INVALID 
FILE_SIZE_ERR 
FILE_OPEN_ERR 
FILE_READ_WRITE_ERR 
FILE_CHECK_ERR 
FILE_TYPE_ERR 
STORAGE_UNAVAILABLE 
API_VERSION_UNSUPPORT 
FILE_EXIST 
STORAGE_SPACE_NOT_ENOUGH 
FILE_CREATE_ERR 
FILE_WRITE_ERR 
MD5_COMPARE_ERR 
FILE_RENAME_ERR 
SEND_ERR 
58 {
59 SUCCESS = 0,
60 CONTINUE = 1,
61 ERROR_JSON = 2,
62 ERROR_PIPE = 3,
63 ERROR_CANCEL = 4,
66 FILE_NO_EXIST = 10,
68 FILE_SIZE_ERR = 12,
69 FILE_OPEN_ERR = 13,
71 FILE_CHECK_ERR = 15,
72 FILE_TYPE_ERR = 16,
75 FILE_EXIST = 19,
77 FILE_CREATE_ERR = 21,
78 FILE_WRITE_ERR = 22,
79 MD5_COMPARE_ERR = 23,
80 FILE_RENAME_ERR = 24,
81 SEND_ERR = 25,
82 };
@ ERROR_PIPE
Definition PrinterFileSystem.h:62
@ FILE_NO_EXIST
Definition PrinterFileSystem.h:66
@ ERROR_CANCEL
Definition PrinterFileSystem.h:63
@ ERROR_RES_BUSY
Definition PrinterFileSystem.h:64
@ FILE_WRITE_ERR
Definition PrinterFileSystem.h:78
@ FILE_SIZE_ERR
Definition PrinterFileSystem.h:68
@ FILE_OPEN_ERR
Definition PrinterFileSystem.h:69
@ FILE_READ_WRITE_ERR
Definition PrinterFileSystem.h:70
@ API_VERSION_UNSUPPORT
Definition PrinterFileSystem.h:74
@ CONTINUE
Definition PrinterFileSystem.h:60
@ FILE_CHECK_ERR
Definition PrinterFileSystem.h:71
@ FILE_TYPE_ERR
Definition PrinterFileSystem.h:72
@ FILE_EXIST
Definition PrinterFileSystem.h:75
@ ERROR_JSON
Definition PrinterFileSystem.h:61
@ STORAGE_UNAVAILABLE
Definition PrinterFileSystem.h:73
@ FILE_NAME_INVALID
Definition PrinterFileSystem.h:67
@ SUCCESS
Definition PrinterFileSystem.h:59
@ ERROR_TIME_OUT
Definition PrinterFileSystem.h:65
@ STORAGE_SPACE_NOT_ENOUGH
Definition PrinterFileSystem.h:76
@ SEND_ERR
Definition PrinterFileSystem.h:81
@ FILE_RENAME_ERR
Definition PrinterFileSystem.h:80
@ FILE_CREATE_ERR
Definition PrinterFileSystem.h:77
@ MD5_COMPARE_ERR
Definition PrinterFileSystem.h:79

◆ FileType

Enumerator
F_TIMELAPSE 
F_VIDEO 
F_MODEL 
F_INVALID_TYPE 
91 {
93 F_VIDEO,
94 F_MODEL,
96 };
@ F_INVALID_TYPE
Definition PrinterFileSystem.h:95
@ F_TIMELAPSE
Definition PrinterFileSystem.h:92
@ F_VIDEO
Definition PrinterFileSystem.h:93
@ F_MODEL
Definition PrinterFileSystem.h:94

◆ Flags

Enumerator
FF_SELECT 
FF_THUMNAIL 
FF_DOWNLOAD 
FF_DELETED 
FF_FETCH_MODEL 
FF_UPLOADING 
FF_UPLOADDONE 
FF_UPLOADCANCEL 
FF_THUMNAIL_RETRY 
116 {
117 FF_SELECT = 1,
118 FF_THUMNAIL = 2, // Thumbnail ready
119 FF_DOWNLOAD = 4, // Request download
120 FF_DELETED = 8, // Request delete
121 FF_FETCH_MODEL = 16, // Request model
122 FF_UPLOADING = 1 << 5, // File uploading
123 FF_UPLOADDONE = 1 << 6, // File upload done
124 FF_UPLOADCANCEL = 1 << 7, // File upload cancel
125 FF_THUMNAIL_RETRY = 0x100, // Thumbnail need retry
126 };
@ FF_UPLOADCANCEL
Definition PrinterFileSystem.h:124
@ FF_THUMNAIL
Definition PrinterFileSystem.h:118
@ FF_THUMNAIL_RETRY
Definition PrinterFileSystem.h:125
@ FF_UPLOADDONE
Definition PrinterFileSystem.h:123
@ FF_FETCH_MODEL
Definition PrinterFileSystem.h:121
@ FF_DOWNLOAD
Definition PrinterFileSystem.h:119
@ FF_UPLOADING
Definition PrinterFileSystem.h:122
@ FF_SELECT
Definition PrinterFileSystem.h:117
@ FF_DELETED
Definition PrinterFileSystem.h:120

◆ GroupMode

Enumerator
G_NONE 
G_MONTH 
G_YEAR 
98 {
99 G_NONE,
100 G_MONTH,
101 G_YEAR,
102 };
@ G_MONTH
Definition PrinterFileSystem.h:100
@ G_YEAR
Definition PrinterFileSystem.h:101
@ G_NONE
Definition PrinterFileSystem.h:99

◆ RequestMediaAbilityStatus

Enumerator
S_SUCCESS 
S_FAILED 
136 {
137 S_SUCCESS,
139 };
@ S_FAILED
Definition PrinterFileSystem.h:138
@ S_SUCCESS
Definition PrinterFileSystem.h:137

◆ Status

Enumerator
Initializing 
Connecting 
ListSyncing 
ListReady 
Failed 
Reconnecting 
234 {
238 ListReady,
239 Failed,
241 };
@ Initializing
Definition PrinterFileSystem.h:235
@ ListSyncing
Definition PrinterFileSystem.h:237
@ Connecting
Definition PrinterFileSystem.h:236
@ ListReady
Definition PrinterFileSystem.h:238
@ Reconnecting
Definition PrinterFileSystem.h:240
@ Failed
Definition PrinterFileSystem.h:239

◆ UploadStatus

Enumerator
Uploading 
UploadDone 
UploadCancel 
129 {
130 Uploading = 1 << 0,
131 UploadDone = 1 << 1,
132 UploadCancel = 1 << 2,
133 };
@ UploadCancel
Definition PrinterFileSystem.h:132
@ Uploading
Definition PrinterFileSystem.h:130
@ UploadDone
Definition PrinterFileSystem.h:131

Constructor & Destructor Documentation

◆ PrinterFileSystem()

PrinterFileSystem::PrinterFileSystem ( )
116 : BambuLib(StaticBambuLib::get(this))
117{
118 if (!default_thumbnail.IsOk()) {
119 default_thumbnail = *Slic3r::GUI::BitmapCache().load_svg("printer_file", 0, 0);
120#ifdef __APPLE__
121 default_thumbnail = wxBitmap(default_thumbnail.ConvertToImage(), -1, 1);
122#endif
123 }
124 m_session.owner = this;
125#ifdef PRINTER_FILE_SYSTEM_TEST
126 auto time = wxDateTime::Now();
127 wxString path = "D:\\work\\pic\\";
128 for (int i = 0; i < 10; ++i) {
129 auto name = wxString::Format(L"gcode-%02d.3mf", i + 1);
130 m_file_list.push_back({name.ToUTF8().data(), "", time.GetTicks(), 26937, i < 5 ? FF_DOWNLOAD : 0, default_thumbnail});
131 std::ifstream ifs((path + name).ToUTF8().data(), std::ios::binary);
132 if (ifs)
133 ParseThumbnail(m_file_list.back(), ifs);
134 time.Add(wxDateSpan::Days(-1));
135 }
137 time = wxDateTime::Now();
138 for (int i = 0; i < 100; ++i) {
139 auto name = wxString::Format(L"img-%03d.jpg", i + 1);
140 wxImage im(path + name);
141 m_file_list.push_back({name.ToUTF8().data(), "", time.GetTicks(), 26937, i < 20 ? FF_DOWNLOAD : 0, i > 3 ? im : default_thumbnail});
142 time.Add(wxDateSpan::Days(-1));
143 }
144 m_file_list[0].thumbnail = default_thumbnail;
146#endif
147}
#define L(s)
Definition ExtrusionEntity.cpp:25
static wxBitmap default_thumbnail
Definition PrinterFileSystem.cpp:86
Session m_session
Definition PrinterFileSystem.h:398
FileList m_file_list
Definition PrinterFileSystem.h:377
static bool ParseThumbnail(File &file)
Definition PrinterFileSystem.cpp:987
std::map< std::pair< FileType, std::string >, FileList > m_file_list_cache
Definition PrinterFileSystem.h:378
static StaticBambuLib & get(BambuLib *copy=nullptr)
Definition PrinterFileSystem.cpp:1857

References default_thumbnail, F_MODEL, F_TIMELAPSE, FF_DOWNLOAD, L, m_file_list, m_file_list_cache, m_session, and ParseThumbnail().

Referenced by DumpLog().

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

◆ ~PrinterFileSystem()

PrinterFileSystem::~PrinterFileSystem ( )
150{
151 m_recv_thread.detach();
152}
boost::thread m_recv_thread
Definition PrinterFileSystem.h:409

References m_recv_thread.

Member Function Documentation

◆ Attached()

void PrinterFileSystem::Attached ( )
700{
701 boost::unique_lock lock(m_mutex);
702 m_recv_thread = boost::thread([w = weak_from_this()] {
703 boost::shared_ptr<PrinterFileSystem> s = w.lock();
704 if (s) s->RecvMessageThread();
705 });
706}
boost::mutex m_mutex
Definition PrinterFileSystem.h:407
@ lock
Definition GLGizmoEmboss.cpp:209

References m_mutex, and m_recv_thread.

◆ BuildGroups()

void PrinterFileSystem::BuildGroups ( )
private
754{
755 m_group_year.clear();
756 m_group_month.clear();
757 if (m_file_list.empty())
758 return;
759 wxDateTime t = wxDateTime((time_t) m_file_list.front().time);
760 m_group_year.push_back(0);
761 m_group_month.push_back(0);
762 for (size_t i = 0; i < m_file_list.size(); ++i) {
763 wxDateTime s = wxDateTime((time_t) m_file_list[i].time);
764 if (s.GetYear() != t.GetYear()) {
765 m_group_year.push_back(m_group_month.size());
766 m_group_month.push_back(i);
767 } else if (s.GetMonth() != t.GetMonth()) {
768 m_group_month.push_back(i);
769 }
770 t = s;
771 }
772}
std::vector< size_t > m_group_year
Definition PrinterFileSystem.h:379
std::vector< size_t > m_group_month
Definition PrinterFileSystem.h:380

References m_file_list, m_group_month, and m_group_year.

Referenced by ListAllFiles(), and SetFileType().

Here is the caller graph for this function:

◆ CancelRequest()

void PrinterFileSystem::CancelRequest ( boost::uint32_t seq)
private
1504{ CancelRequests({seq}); }
void CancelRequests(std::vector< boost::uint32_t > const &seqs)
Definition PrinterFileSystem.cpp:1506

References CancelRequests().

Referenced by CancelUploadTask(), DownloadCancel(), and HandleResponse().

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

◆ CancelRequests()

void PrinterFileSystem::CancelRequests ( std::vector< boost::uint32_t > const & seqs)
private
1507{
1508 json req;
1509 json arr;
1510 for (auto seq : seqs)
1511 arr.push_back(seq);
1512 req["tasks"] = arr;
1513 SendRequest(TASK_CANCEL, req, [this](int result, json const &resp, unsigned char const *) -> int {
1514 if (result != 0) return result;
1515 json tasks = resp["tasks"];
1516 std::vector<boost::uint32_t> seqs;
1517 for (auto &f : tasks) seqs.push_back(f);
1518 CancelRequests2(seqs);
1519 return 0;
1520 });
1521}
void CancelRequests2(std::vector< boost::uint32_t > const &seqs)
Definition PrinterFileSystem.cpp:1523
boost::uint32_t SendRequest(int type, nlohmann::json const &req, Translator< T > const &translator, Callback< T > const &callback, const std::string &param="")
Definition PrinterFileSystem.h:300
nlohmann::json json
Definition AssembleList.cpp:42

References CancelRequests2(), SendRequest(), and TASK_CANCEL.

Referenced by CancelRequest().

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

◆ CancelRequests2()

void PrinterFileSystem::CancelRequests2 ( std::vector< boost::uint32_t > const & seqs)
private
1524{
1525 std::vector<std::pair<boost::uint32_t, callback_t2>> callbacks;
1526 boost::unique_lock l(m_mutex);
1527 for (auto &f : seqs) {
1528 boost::uint32_t seq = f;
1529 seq -= m_sequence;
1530 if (size_t(seq) >= m_callbacks.size()) continue;
1531 auto &c = m_callbacks[seq];
1532 if (c == nullptr) continue;
1533 callbacks.emplace_back(f, c);
1534 c = nullptr;
1535
1536 // erase m_produce_message_cb
1538 m_produce_message_cb_map.erase(seq);
1539 }
1540 while (!m_callbacks.empty() && m_callbacks.front() == nullptr) {
1541 m_callbacks.pop_front();
1542 ++m_sequence;
1543 }
1544 l.unlock();
1545 for (auto &c : callbacks) {
1546 wxLogInfo("PrinterFileSystem::CancelRequests2: %u\n", c.first);
1547 c.second(ERROR_CANCEL, json(), nullptr);
1548 }
1549}
std::map< boost::uint32_t, callback_t3 > m_produce_message_cb_map
Definition PrinterFileSystem.h:414
std::deque< callback_t2 > m_callbacks
Definition PrinterFileSystem.h:404
boost::uint32_t m_sequence
Definition PrinterFileSystem.h:399

References ERROR_CANCEL, m_callbacks, m_mutex, m_produce_message_cb_map, and m_sequence.

Referenced by CancelRequests(), CancelUploadTask(), and FetchModelCancel().

Here is the caller graph for this function:

◆ CancelUploadTask()

void PrinterFileSystem::CancelUploadTask ( bool send_cancel_req = true)
1447{
1448 if (!m_upload_file)
1449 return;
1450
1451 {
1452 boost::unique_lock l(m_mutex);
1455 if (m_upload_file->upload->ifs.is_open()) {
1456 m_upload_file->upload->ifs.close();
1457 }
1458 m_upload_file.reset();
1459 }
1460
1461 if (send_cancel_req) {
1463 } else {
1465 }
1466}
boost::uint32_t m_upload_seq
Definition PrinterFileSystem.h:402
void CancelRequest(boost::uint32_t seq)
Definition PrinterFileSystem.cpp:1504
std::shared_ptr< UploadFile > m_upload_file
Definition PrinterFileSystem.h:382

References CancelRequest(), CancelRequests2(), m_mutex, m_produce_message_cb_map, m_upload_file, and m_upload_seq.

Here is the call graph for this function:

◆ DeleteFiles()

void PrinterFileSystem::DeleteFiles ( size_t index)
270{
271 if (index == size_t(-1)) {
272 size_t n = 0;
273 for (size_t i = 0; i < m_file_list.size(); ++i) {
274 auto &file = m_file_list[i];
275 if ((file.flags & FF_SELECT) != 0 && (file.flags & FF_DELETED) == 0) {
276 file.flags |= FF_DELETED;
277 ++n;
278 }
279 }
280 if (n == 0) return;
281 } else {
282 if (index >= m_file_list.size())
283 return;
284 auto &file = m_file_list[index];
285 if ((file.flags & FF_DELETED) != 0)
286 return;
287 file.flags |= FF_DELETED;
288 }
289 if ((m_task_flags & FF_DELETED) == 0)
291}
int m_task_flags
Definition PrinterFileSystem.h:388
void DeleteFilesContinue()
Definition PrinterFileSystem.cpp:794

References DeleteFilesContinue(), FF_DELETED, FF_SELECT, m_file_list, and m_task_flags.

Here is the call graph for this function:

◆ DeleteFilesContinue()

void PrinterFileSystem::DeleteFilesContinue ( )
private
795{
796 std::vector<size_t> indexes;
797 std::vector<std::string> names;
798 std::vector<std::string> paths;
799 for (size_t i = 0; i < m_file_list.size(); ++i)
800 if ((m_file_list[i].flags & FF_DELETED) && !m_file_list[i].name.empty()) {
801 indexes.push_back(i);
802 auto &file = m_file_list[i];
803 if (file.path.empty())
804 names.push_back(file.name);
805 else
806 paths.push_back(file.path);
807 if (names.size() >= 64 || paths.size() >= 64)
808 break;
809 }
811 if (names.empty() && paths.empty())
812 return;
813 json req;
814 json arr;
815 if (paths.empty()) {
816 for (auto &name : names) arr.push_back(name);
817 req["delete"] = arr;
818 } else {
819 for (auto &path : paths) arr.push_back(path);
820 req["paths"] = arr;
821 }
823 auto type = std::make_pair(m_file_type, m_file_storage);
825 FILE_DEL, req, nullptr,
826 [indexes, type, names = paths.empty() ? names : paths, bypath = !paths.empty(), this](int, Void const &) {
827 // TODO:
828 for (size_t i = indexes.size() - 1; i != size_t(-1); --i)
829 FileRemoved(type, indexes[i], names[i], bypath);
830 SendChangedEvent(EVT_FILE_CHANGED, indexes.size());
831 DeleteFilesContinue();
832 });
833}
std::string m_file_storage
Definition PrinterFileSystem.h:375
FileType m_file_type
Definition PrinterFileSystem.h:374
Definition PrinterFileSystem.h:186

References FF_DELETED, FILE_DEL, m_file_list, m_file_storage, m_file_type, m_task_flags, and SendRequest().

Referenced by DeleteFiles().

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

◆ DownloadCancel()

void PrinterFileSystem::DownloadCancel ( size_t index)
522{
523 if (index == (size_t) -1) return;
524 if (index >= m_file_list.size()) return;
525 auto &file = m_file_list[index];
526 if ((file.flags & FF_DOWNLOAD) == 0 || !file.download) return;
527 if (file.DownloadProgress() >= 0)
529 else
530 file.flags &= ~FF_DOWNLOAD, file.download.reset();
531}
boost::uint32_t m_download_seq
Definition PrinterFileSystem.h:400

References CancelRequest(), FF_DOWNLOAD, m_download_seq, and m_file_list.

Here is the call graph for this function:

◆ DownloadCheckFile()

bool PrinterFileSystem::DownloadCheckFile ( size_t index)
507{
508 if (index >= m_file_list.size()) return false;
509 auto &file = m_file_list[index];
510 if ((file.flags & FF_DOWNLOAD) == 0 || file.local_path.empty())
511 return false;
512 if (!boost::filesystem::exists(file.local_path)) {
513 file.flags &= ~FF_DOWNLOAD;
514 file.local_path.clear();
515 SendChangedEvent(EVT_DOWNLOAD, index, file.local_path);
516 return false;
517 }
518 return true;
519}
void SendChangedEvent(wxEventType type, size_t index=(size_t) -1, std::string const &str={}, long extra=0)
Definition PrinterFileSystem.cpp:1235

References FF_DOWNLOAD, m_file_list, and SendChangedEvent().

Here is the call graph for this function:

◆ DownloadCheckFiles()

void PrinterFileSystem::DownloadCheckFiles ( std::string const & path)
493{
494 for (size_t i = 0; i < m_file_list.size(); ++i) {
495 auto &file = m_file_list[i];
496 if ((file.flags & FF_DOWNLOAD) != 0 && file.download) continue;
497 auto path2 = boost::filesystem::path(path) / file.name;
498 boost::system::error_code ec;
499 if (boost::filesystem::file_size(path2, ec) == file.size) {
500 file.flags |= FF_DOWNLOAD;
501 file.local_path = path2.string();
502 }
503 }
504}

References FF_DOWNLOAD, and m_file_list.

◆ DownloadFiles()

void PrinterFileSystem::DownloadFiles ( size_t index,
std::string const & path )
456{
457 if (index == (size_t) -1) {
458 size_t n = 0;
459 for (size_t i = 0; i < m_file_list.size(); ++i) {
460 auto &file = m_file_list[i];
461 if ((file.flags & FF_SELECT) == 0) continue;
462 if ((file.flags & FF_DOWNLOAD) != 0 && file.DownloadProgress() >= -1) continue;
463 file.flags |= FF_DOWNLOAD;
464 std::shared_ptr<Download> download(new Download);
465 download->progress = -1;
466 download->local_path = (boost::filesystem::path(path) / file.name).string();
467 file.download = download;
468 ++n;
469 }
470 if (n == 0) return;
471 } else {
472 if (index >= m_file_list.size())
473 return;
474 auto &file = m_file_list[index];
475 if ((file.flags & FF_DOWNLOAD) != 0 && file.DownloadProgress() >= -1)
476 return;
477 file.flags |= FF_DOWNLOAD;
478 std::shared_ptr<Download> download(new Download);
479 download->progress = -1;
480 download->local_path = (boost::filesystem::path(path) / file.name).string();
481 file.download = download;
482 }
483 boost::filesystem::create_directories(path);
484 if ((m_task_flags & FF_DOWNLOAD) == 0)
486}
void DownloadNextFile()
Definition PrinterFileSystem.cpp:835
Definition PrinterFileSystem.cpp:294

References DownloadNextFile(), FF_DOWNLOAD, FF_SELECT, m_file_list, and m_task_flags.

Here is the call graph for this function:

◆ DownloadNextFile()

void PrinterFileSystem::DownloadNextFile ( )
private
836{
837 size_t index = size_t(-1);
838 for (size_t i = 0; i < m_file_list.size(); ++i) {
839 if (m_file_list[i].IsDownload() && m_file_list[i].DownloadProgress() == -1) {
840 index = i;
841 break;
842 }
843 }
845 if (index >= m_file_list.size())
846 return;
847 auto &file = m_file_list[index];
848 json req;
849 if (file.path.empty())
850 req["file"] = file.name;
851 else
852 req["path"] = file.path;
853 SendChangedEvent(EVT_DOWNLOAD, index, m_file_list[index].name);
854 std::shared_ptr<Download> download(m_file_list[index].download);
855 download->index = index;
856 download->name = file.name;
857 download->path = file.path;
860 FILE_DOWNLOAD, req,
861 [download](json const &resp, Progress &prog, unsigned char const *data) -> int {
862 // in work thread, continue recv
863 size_t size = resp.value("size", 0);
864 prog.size = resp["offset"];
865 prog.total = resp["total"];
866 if (prog.size == 0) {
867 download->ofs.open(download->local_path, std::ios::binary);
868 if (!download->ofs) {
869 download->error = last_system_error();
870 wxLogWarning("PrinterFileSystem::DownloadNextFile open error: %s\n", wxString::FromUTF8(download->error));
871 return FILE_OPEN_ERR;
872 }
873 }
874 if (download->total && (download->size != prog.size || download->total != prog.total)) {
875 wxLogWarning("PrinterFileSystem::DownloadNextFile data error: %d != %d\n", download->size, prog.size);
876 }
877 // receive data
878 download->ofs.write((char const *) data, size);
879 if (!download->ofs) {
880 download->error = last_system_error();
881 wxLogWarning("PrinterFileSystem::DownloadNextFile write error: %s\n", wxString::FromUTF8(download->error));
882 return FILE_READ_WRITE_ERR;
883 }
884 download->boost_md5.process_bytes(data, size);
885 prog.size += size;
886 download->total = prog.total;
887 download->size = prog.size;
888 if (prog.size < prog.total) { return 0; }
889 download->ofs.close();
890 int result = 0;
891 std::string md5 = resp["file_md5"];
892 // check size and md5
893 if (prog.size == prog.total) {
894 boost::uuids::detail::md5::digest_type digest;
895 download->boost_md5.get_digest(digest);
896 for (int i = 0; i < 4; ++i) digest[i] = boost::endian::endian_reverse(digest[i]);
897 std::string str_md5;
898 const auto char_digest = reinterpret_cast<const char *>(&digest[0]);
899 boost::algorithm::hex(char_digest, char_digest + sizeof(digest), std::back_inserter(str_md5));
900 if (!boost::iequals(str_md5, md5)) {
901 wxLogWarning("PrinterFileSystem::DownloadNextFile checksum error: %s != %s\n", str_md5, md5);
902 boost::system::error_code ec;
903 boost::filesystem::rename(download->local_path, download->local_path + ".tmp", ec);
904 result = FILE_CHECK_ERR;
905 }
906 } else {
907 result = FILE_SIZE_ERR;
908 }
909 if (result != 0) {
910 boost::system::error_code ec;
911 boost::filesystem::remove(download->local_path, ec);
912 }
913 return result;
914 },
915 [this, download, type = std::make_pair(m_file_type, m_file_storage)](int result, Progress const &data) {
916 int progress = data.total ? data.size * 100 / data.total : 0;
917 if (result == CONTINUE) {
918 if (download->progress == progress)
919 return;
920 }
921 download->progress = progress;
922 if (download->index != size_t(-1)) {
923 auto file_index = FindFile(type, download->index, download->path.empty() ? download->name : download->path, !download->path.empty());
924 download->index = file_index.second;
925 if (download->index != size_t(-1)) {
926 auto &file = file_index.first[download->index];
927 if (result == CONTINUE)
928 ;
929 else if (result == SUCCESS)
930 file.download.reset(), file.local_path = download->local_path;
931 else if (result == ERROR_CANCEL)
932 file.download.reset(), file.flags &= ~FF_DOWNLOAD;
933 else // FAILED
934 file.download.reset();
935 if (&file_index.first == &m_file_list)
936 SendChangedEvent(EVT_DOWNLOAD, download->index, result ? download->error : file.local_path, result);
937 }
938 }
939 if (result != CONTINUE) DownloadNextFile();
940 });
941}
std::string last_system_error()
Definition PrinterFileSystem.cpp:63
std::pair< FileList &, size_t > FindFile(std::pair< FileType, std::string > type, size_t index, std::string const &name, bool by_path)
Definition PrinterFileSystem.cpp:1167
Definition PrinterFileSystem.h:142

References CONTINUE, DownloadNextFile(), ERROR_CANCEL, FF_DOWNLOAD, FILE_CHECK_ERR, FILE_DOWNLOAD, FILE_OPEN_ERR, FILE_READ_WRITE_ERR, FILE_SIZE_ERR, FindFile(), last_system_error(), m_download_seq, m_file_list, m_file_storage, m_file_type, m_task_flags, SendChangedEvent(), SendRequest(), PrinterFileSystem::Progress::size, SUCCESS, and PrinterFileSystem::Progress::total.

Referenced by DownloadFiles(), DownloadNextFile(), and ListAllFiles().

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

◆ DownloadRamFile()

void PrinterFileSystem::DownloadRamFile ( int index,
const std::string & local_path,
const std::string & param )
340{
341 std::shared_ptr<Download> download(new Download);
342 download->local_path = local_path;
343
344 json req;
345 req["path"] = "mem:/" + std::to_string(index);
346 req["offset"] = 0;
347 req["mem_dl_param_size"] = param.size();
348
350 FILE_DOWNLOAD, req,
351 [download](json const &resp, Progress &prog, unsigned char const *data) -> int {
352 size_t size = resp.value("size", 0);
353 prog.size = resp["offset"];
354 prog.total = resp["total"];
355
356 if (resp.contains("mem_dl_param_size")) {
357 size_t s = resp["mem_dl_param_size"].get<size_t>();
358 std::string json_str(reinterpret_cast<const char *>(data), s);
359 // OutputDebugStringA(json_str.c_str());
360 // OutputDebugStringA("\n");
361 json mem_dl_json = json::parse(json_str);
362 // download->mem_dl_param_size = size;
363 if (!mem_dl_json.contains("result") || mem_dl_json["result"] == 1 ) {
364 wxLogWarning("Download failed: result = 1");
365 return ERROR_JSON;
366 }
367 if(mem_dl_json.contains("size") && mem_dl_json["size"] == 0 )
368 return FILE_SIZE_ERR;
369
370 return CONTINUE;
371 }
372
373 if (prog.size == 0 ) {
374 download->ofs.open(download->local_path, std::ios::binary);
375 if (!download->ofs) {
376 download->error = last_system_error();
377 wxLogWarning("DownloadImageFromRam open error: %s\n", wxString::FromUTF8(download->error));
378 return FILE_OPEN_ERR;
379 }
380 }
381
382 download->ofs.write(reinterpret_cast<const char *>(data), size);
383 if (!download->ofs) {
384 download->error = last_system_error();
385 wxLogWarning("DownloadImageFromRam write error: %s\n", wxString::FromUTF8(download->error));
386 return FILE_READ_WRITE_ERR;
387 }
388
389 download->boost_md5.process_bytes(data, size);
390
391 prog.size += size;
392 download->total = prog.total;
393 download->size = prog.size;
394
395 if (prog.size < prog.total) {
396 return 0;
397 }
398 download->ofs.close();
399
400 std::string md5 = resp["file_md5"];
401 boost::uuids::detail::md5::digest_type digest;
402 download->boost_md5.get_digest(digest);
403 for (int i = 0; i < 4; ++i) digest[i] = boost::endian::endian_reverse(digest[i]);
404 std::string str_md5;
405 const auto char_digest = reinterpret_cast<const char *>(&digest[0]);
406 boost::algorithm::hex(char_digest, char_digest + sizeof(digest), std::back_inserter(str_md5));
407 if (!boost::iequals(str_md5, md5)) {
408 wxLogWarning("DownloadImageFromRam checksum error: %s != %s\n", str_md5, md5);
409 boost::system::error_code ec;
410 boost::filesystem::rename(download->local_path, download->local_path + ".tmp", ec);
411 return FILE_CHECK_ERR;
412 }
413 return SUCCESS;
414 },
415
416 [this, download](int result, Progress const &data) {
417 //OutputDebugStringA(std::to_string(result).c_str());
418 //OutputDebugStringA("\n");
419 if (result == CONTINUE) { return; }
420 std::string msg;
421 if (result == SUCCESS) {
422 if (std::filesystem::exists(download->local_path)) {
423 m_download_states.emplace_back(true);
424 BOOST_LOG_TRIVIAL(info) <<"DownloadImageFromRam finished: " << download->local_path << "result = " << result;
425 }else{
426 m_download_states.emplace_back(false);
427 BOOST_LOG_TRIVIAL(warning) <<"DownloadImageFromRam finished, but file not exist: " << download->local_path << "result = " << result;
428 }
429 } else if (result != CONTINUE) {
430 m_download_states.emplace_back(false);
431 BOOST_LOG_TRIVIAL(warning) << "DownloadImageFromRam failed: " << download->error << "result = " << result;
432 }
433
434 if(m_download_states.size() == 3){
436 SendChangedEvent(EVT_RAMDOWNLOAD, SUCCESS);
437 }else{
438 // FILE_NO_EXIST is not really error_code
439 SendChangedEvent(EVT_RAMDOWNLOAD, FILE_NO_EXIST);
440 }
441 }else{
442 BOOST_LOG_TRIVIAL(warning) << "m_download_states current size is : " << m_download_states.size();
443 }
444 },param);
445}
std::vector< bool > m_download_states
Definition PrinterFileSystem.h:390

References CONTINUE, ERROR_JSON, FILE_CHECK_ERR, FILE_DOWNLOAD, FILE_NO_EXIST, FILE_OPEN_ERR, FILE_READ_WRITE_ERR, FILE_SIZE_ERR, last_system_error(), m_download_seq, m_download_states, SendChangedEvent(), SendRequest(), PrinterFileSystem::Progress::size, SUCCESS, and PrinterFileSystem::Progress::total.

Referenced by GetPickImage().

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

◆ DumpLog()

void PrinterFileSystem::DumpLog ( void * context,
int level,
tchar const * msg )
staticprivate
1254{
1255
1256#if !BBL_RELEASE_TO_PUBLIC
1257 BOOST_LOG_TRIVIAL(info) << "PrinterFileSystem: " << wxString(msg).ToUTF8().data();
1258#endif
1259
1260 static_cast<PrinterFileSystem*>(thiz)->Bambu_FreeLogMsg(msg);
1261}
BAMBU_EXPORT void BAMBU_FUNC Bambu_FreeLogMsg(tchar const *msg)
PrinterFileSystem()
Definition PrinterFileSystem.cpp:115

References PrinterFileSystem(), and Bambu_FreeLogMsg().

Referenced by Reconnect().

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

◆ EnterSubGroup()

size_t PrinterFileSystem::EnterSubGroup ( size_t index)
187{
188 if (m_group_mode == G_NONE)
189 return index;
190 index = m_group_mode == G_YEAR ? m_group_year[index] : m_group_month[index];
192 return index;
193}
GroupMode m_group_mode
Definition PrinterFileSystem.h:376
void SetGroupMode(GroupMode mode)
Definition PrinterFileSystem.cpp:176
GroupMode
Definition PrinterFileSystem.h:98

References G_NONE, G_YEAR, m_group_mode, m_group_month, m_group_year, and SetGroupMode().

Here is the call graph for this function:

◆ FetchModel()

void PrinterFileSystem::FetchModel ( size_t index,
std::function< void(int, std::string const &)> callback )
534{
536 return;
537 json req;
538 json arr;
539 if (index == (size_t) -1) return;
540 if (index >= m_file_list.size()) return;
541 auto &file = m_file_list[index];
542 arr.push_back(file.path + "#_rels/.rels");
543 arr.push_back(file.path + "#3D/3dmodel.model");
544 arr.push_back(file.path + "#Metadata/model_settings.config");
545 arr.push_back(file.path + "#Metadata/slice_info.config");
546 arr.push_back(file.path + "#Metadata/project_settings.config");
547 for (auto & meta : file.metadata) {
548 if (boost::algorithm::starts_with(meta.first, "plate_thumbnail_"))
549 arr.push_back(file.path + "#" + meta.second);
550 }
551 req["paths"] = arr;
552 req["zip"] = true;
554 std::shared_ptr<std::string> file_data(new std::string());
556 SUB_FILE, req,
557 [file_data](json const &resp, Void &, unsigned char const *data) -> int {
558 // in work thread, continue recv
559 // receive data
560 boost::uint32_t size = resp["size"];
561 if (size > 0) {
562 *file_data += std::string((char *) data, size);
563 }
564 return 0;
565 },
566 [this, file_data, callback](int result, Void const &) {
567 if (result == CONTINUE) return;
569 if (result != 0) {
570 auto iter = error_messages.find(result);
571 if (iter != error_messages.end())
572 *file_data = _u8L(iter->second.c_str());
573 else
574 file_data->clear();
575 }
576 callback(result, *file_data);
577 });
578}
static std::map< int, std::string > error_messages
Definition MediaPlayCtrl.cpp:74
boost::uint32_t m_fetch_model_seq
Definition PrinterFileSystem.h:401
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, CONTINUE, error_messages, FF_FETCH_MODEL, m_fetch_model_seq, m_file_list, m_task_flags, SendRequest(), and SUB_FILE.

Here is the call graph for this function:

◆ FetchModelCancel()

void PrinterFileSystem::FetchModelCancel ( )
581{
582 if ((m_task_flags & FF_FETCH_MODEL) == 0) return;
584}

References CancelRequests2(), FF_FETCH_MODEL, m_fetch_model_seq, and m_task_flags.

Here is the call graph for this function:

◆ FileRemoved()

void PrinterFileSystem::FileRemoved ( std::pair< FileType, std::string > type,
size_t index,
std::string const & name,
bool by_path )
private
1182{
1183 auto file_index = FindFile(type, index, name, by_path);
1184 if (file_index.second == size_t(-1))
1185 return;
1186 if (&file_index.first == &m_file_list) {
1187 auto removeFromGroup = [](std::vector<size_t> &group, size_t index, size_t total) {
1188 for (auto iter = group.begin(); iter != group.end(); ++iter) {
1189 size_t index2 = -1;
1190 if (*iter < index) continue;
1191 if (*iter == index) {
1192 auto iter2 = iter + 1;
1193 if (index + 1 == (iter2 == group.end() ? total : *iter2)) {
1194 index2 = std::distance(group.begin(), iter);
1195 }
1196 ++iter;
1197 }
1198 for (; iter != group.end(); ++iter) {
1199 --*iter;
1200 }
1201 return index2;
1202 }
1203 return size_t(-1);
1204 };
1205 size_t index2 = removeFromGroup(m_group_month, index, m_file_list.size());
1206 if (index2 < m_group_month.size()) {
1207 int index3 = removeFromGroup(m_group_year, index2, m_group_month.size());
1208 if (index3 < m_group_year.size()) {
1209 m_group_year.erase(m_group_year.begin() + index3);
1210 if (m_group_mode == G_YEAR)
1211 m_group_flags.erase(m_group_flags.begin() + index3);
1212 }
1213 m_group_month.erase(m_group_month.begin() + index2);
1214 if (m_group_mode == G_MONTH)
1215 m_group_flags.erase(m_group_flags.begin() + index2);
1216 }
1217 }
1218 file_index.first.erase(file_index.first.begin() + index);
1219}
std::vector< int > m_group_flags
Definition PrinterFileSystem.h:381

References FindFile(), G_MONTH, G_YEAR, m_file_list, m_group_flags, m_group_mode, m_group_month, and m_group_year.

Here is the call graph for this function:

◆ FindFile()

std::pair< PrinterFileSystem::FileList &, size_t > PrinterFileSystem::FindFile ( std::pair< FileType, std::string > type,
size_t index,
std::string const & name,
bool by_path )
private
1168{
1169 FileList & file_list = type == std::make_pair(m_file_type, m_file_storage) ?
1170 m_file_list :
1171 m_file_list_cache[type];
1172 if (index >= file_list.size() || (by_path ? file_list[index].path : file_list[index].name) != name) {
1173 auto iter = std::find_if(m_file_list.begin(), file_list.end(),
1174 [name, by_path](File &f) { return (by_path ? f.path : f.name) == name; });
1175 if (iter == m_file_list.end()) return {file_list, -1};
1176 index = std::distance(m_file_list.begin(), iter);
1177 }
1178 return {file_list, index};
1179}
std::vector< File > FileList
Definition PrinterFileSystem.h:188
Definition PrinterFileSystem.h:152

References m_file_list, m_file_list_cache, m_file_storage, and m_file_type.

Referenced by DownloadNextFile(), and FileRemoved().

Here is the caller graph for this function:

◆ GetCount()

size_t PrinterFileSystem::GetCount ( ) const
587{
588 if (m_group_mode == G_NONE)
589 return m_file_list.size();
590 return m_group_mode == G_YEAR ? m_group_year.size() : m_group_month.size();
591}

References G_NONE, G_YEAR, m_file_list, m_group_mode, m_group_month, and m_group_year.

Referenced by UpdateFocusThumbnail().

Here is the caller graph for this function:

◆ GetFile() [1/2]

PrinterFileSystem::File const & PrinterFileSystem::GetFile ( size_t index)
680{
681 if (m_group_mode == G_NONE)
682 return m_file_list[index];
683 if (m_group_mode == G_YEAR) index = m_group_year[index];
684 return m_file_list[m_group_month[index]];
685}

References G_NONE, G_YEAR, m_file_list, m_group_mode, m_group_month, and m_group_year.

Referenced by UpdateFocusThumbnail().

Here is the caller graph for this function:

◆ GetFile() [2/2]

PrinterFileSystem::File const & PrinterFileSystem::GetFile ( size_t index,
bool & select )
688{
689 if (m_group_mode == G_NONE) {
690 select = m_file_list[index].IsSelect();
691 return m_file_list[index];
692 }
693 select = m_group_flags[index] & FF_SELECT;
694 if (m_group_mode == G_YEAR)
695 index = m_group_year[index];
696 return m_file_list[m_group_month[index]];
697}

References FF_SELECT, G_NONE, G_YEAR, m_file_list, m_group_flags, m_group_mode, m_group_month, and m_group_year.

◆ GetFileType()

FileType PrinterFileSystem::GetFileType ( ) const
inline
110{ return m_file_type; }

References m_file_type.

◆ GetGroupMode()

GroupMode PrinterFileSystem::GetGroupMode ( ) const
inline
112{ return m_group_mode; }

References m_group_mode.

◆ GetIndexAtTime()

size_t PrinterFileSystem::GetIndexAtTime ( boost::uint32_t time)
611{
612 auto iter = std::upper_bound(m_file_list.begin(), m_file_list.end(), File{"", "", time});
613 size_t n = std::distance(m_file_list.begin(), iter) - 1;
614 if (m_group_mode == G_NONE) {
615 return n;
616 }
617 auto & group = m_group_mode == G_YEAR ? m_group_year : m_group_month;
618 auto iter2 = std::upper_bound(group.begin(), group.end(), n);
619 return std::distance(group.begin(), iter2) - 1;
620}

References G_NONE, G_YEAR, m_file_list, m_group_mode, m_group_month, and m_group_year.

◆ GetLastError()

int PrinterFileSystem::GetLastError ( ) const
inline
244{ return m_last_error; }
int m_last_error
Definition PrinterFileSystem.h:411

References m_last_error.

◆ GetMediaAbilityList()

PrinterFileSystem::MediaAbilityList PrinterFileSystem::GetMediaAbilityList ( ) const
1442{
1443 return m_media_ability_list;
1444}
MediaAbilityList m_media_ability_list
Definition PrinterFileSystem.h:413

References m_media_ability_list.

◆ GetPickImage()

void PrinterFileSystem::GetPickImage ( int id,
const std::string & local_path,
const std::string & path )
324{
325 json j;
326
327 j["sequence_id"] = id;
328 j["version"] = 1;
329 j["peer_host"] = "studio";
330 j["command"] = "get_project_file";
331 j["file_rel_path"] = targetpath;
332
333 std::string param = j.dump();
334
335 DownloadRamFile(16, local_path, param);
336}
void DownloadRamFile(int index, const std::string &local_path, const std::string &param)
Definition PrinterFileSystem.cpp:339

References DownloadRamFile().

Referenced by GetPickImages().

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

◆ GetPickImages()

void PrinterFileSystem::GetPickImages ( const std::vector< std::string > & local_paths,
const std::vector< std::string > & targetpaths )
314{
315 m_download_states.clear();
316
317 GetPickImage(1, local_paths[0], targetpaths[0]);
318 GetPickImage(2, local_paths[1], targetpaths[1]);
319 GetPickImage(3, local_paths[2], targetpaths[2]);
320
321}
void GetPickImage(int id, const std::string &local_path, const std::string &path)
Definition PrinterFileSystem.cpp:323

References GetPickImage(), and m_download_states.

Here is the call graph for this function:

◆ GetSelectCount()

size_t PrinterFileSystem::GetSelectCount ( ) const
669{ return m_select_count; }
size_t m_select_count
Definition PrinterFileSystem.h:385

References m_select_count.

◆ GetStatus()

Status PrinterFileSystem::GetStatus ( ) const
inline
243{ return m_status; }
Status m_status
Definition PrinterFileSystem.h:410

References m_status.

◆ HandleResponse()

void PrinterFileSystem::HandleResponse ( boost::unique_lock< boost::mutex > & l,
Bambu_Sample const & sample )
private
1636{
1637 unsigned char const *end = sample.buffer + sample.size;
1638 unsigned char const *json_end = (unsigned char const *) memchr(sample.buffer, '\n', sample.size);
1639 while (json_end && json_end + 3 < end && json_end[1] != '\n') json_end = (unsigned char const *) memchr(json_end + 2, '\n', end - json_end - 2);
1640 if (json_end)
1641 json_end += 2;
1642 else
1643 json_end = end;
1644 std::string msg((char const *) sample.buffer, json_end - sample.buffer);
1645 json root;
1646 // OutputDebugStringA(msg.c_str());
1647 // OutputDebugStringA("\n");
1648 wxLogInfo("PrinterFileSystem::HandleResponse <<<: \n%s\n", wxString::FromUTF8(msg));
1649 std::istringstream iss(msg);
1650 int cmd = 0;
1651 int seq = -1;
1652 int result = 0;
1653 json resp;
1654 try {
1655 iss >> root;
1656 if (!root["result"].is_null()) {
1657 result = root["result"];
1658 seq = root["sequence"];
1659 resp = root["reply"];
1660 } else {
1661 // maybe notify
1662 cmd = root["cmdtype"];
1663 seq = root["sequence"];
1664 resp = root["notify"];
1665 }
1666 } catch (...) {
1667 result = ERROR_JSON;
1668 return;
1669 }
1670 if (cmd > 0) {
1671 if (cmd < NOTIFY_FIRST) return;
1672 cmd -= NOTIFY_FIRST;
1673 if (size_t(cmd) >= m_notifies.size()) return;
1674 auto n = m_notifies[cmd];
1675 l.unlock();
1676 n(result, resp, json_end);
1677 l.lock();
1678 } else {
1679 int seq2 = seq - m_sequence;
1680 if (size_t(seq2) >= m_callbacks.size()) return;
1681 auto c = m_callbacks[seq2];
1682 if (c == nullptr) return;
1683 l.unlock();
1684 int result2 = c(result, resp, json_end);
1685 l.lock();
1686 if (result2 != CONTINUE) {
1687 int seq2 = seq - m_sequence;
1688 m_callbacks[seq2] = callback_t2();
1689 if (seq2 == 0) {
1690 while (!m_callbacks.empty() && m_callbacks.front() == nullptr) {
1691 m_callbacks.pop_front();
1692 ++m_sequence;
1693 }
1694 }
1695 if (result == CONTINUE) {
1696 l.unlock();
1697 CancelRequest(seq);
1698 l.lock();
1699 }
1700
1701 // error should erase m_produce_message_cb
1702 if (m_produce_message_cb_map.find(seq2) != m_produce_message_cb_map.end()) {
1703 m_produce_message_cb_map.erase(seq2);
1704 }
1705 }
1706 }
1707}
std::deque< callback_t2 > m_notifies
Definition PrinterFileSystem.h:405
std::function< int(int, nlohmann::json const &resp, unsigned char const *data)> callback_t2
Definition PrinterFileSystem.h:296
T * end(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:841

References __Bambu_Sample::buffer, CancelRequest(), CONTINUE, ERROR_JSON, m_callbacks, m_notifies, m_produce_message_cb_map, m_sequence, NOTIFY_FIRST, and __Bambu_Sample::size.

Referenced by RecvMessageThread().

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

◆ InstallNotify() [1/2]

void PrinterFileSystem::InstallNotify ( int type,
callback_t2 const & callback )
private
1498{
1499 type -= NOTIFY_FIRST;
1500 if (m_notifies.size() <= size_t(type)) m_notifies.resize(type + 1);
1501 m_notifies[type] = callback;
1502}

References m_notifies, and NOTIFY_FIRST.

◆ InstallNotify() [2/2]

template<typename T>
void PrinterFileSystem::InstallNotify ( int type,
Translator< T > const & translator,
Applier< T > const & applier )
inlineprivate
324 {
325 auto c = [translator, applier, this](int result, nlohmann::json const &resp, unsigned char const *data) -> int
326 {
327 T t;
328 if (result == 0 || result == CONTINUE) {
329 try {
330 int n = (translator != nullptr) ? translator(resp, t, data) : 0;
331 result = n == 0 ? result : n;
332 }
333 catch (...) {
334 result = ERROR_JSON;
335 }
336 }
337 if (result == 0 && applier) {
338 PostCallback<T>([applier](int, T const & t) {
339 applier(t);
340 }, 0, t);
341 }
342 return result;
343 };
344 InstallNotify(type, c);
345 }
void InstallNotify(int type, Translator< T > const &translator, Applier< T > const &applier)
Definition PrinterFileSystem.h:323
void PostCallback(Callback< T > const &callback, int result, T const &resp)
Definition PrinterFileSystem.h:364

References CONTINUE, ERROR_JSON, InstallNotify(), and PostCallback().

Referenced by InstallNotify().

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

◆ ListAllFiles()

void PrinterFileSystem::ListAllFiles ( )
196{
197 json req;
198 char const * types[] {"timelapse","video", "model" };
199 req["type"] = types[m_file_type];
200 if (!m_file_storage.empty())
201 req["storage"] = m_file_storage;
202 req["api_version"] = 2;
203 req["notify"] = "DETAIL";
204 SendRequest<FileList>(LIST_INFO, req, [type = m_file_type](json const& resp, FileList & list, auto) -> int {
205 json files = resp["file_lists"];
206 for (auto& f : files) {
207 std::string name = f["name"];
208 std::string path = f.value("path", "");
209 time_t time = f.value("time", 0);
210 boost::uint64_t size = f["size"];
211 if (type > F_TIMELAPSE && path.empty()) // Fix old printer that always return timelapses
212 return FILE_TYPE_ERR;
213 File ff = {name, path, time, size, 0};
214 list.push_back(ff);
215 }
216 return 0;
217 }, [this, type = m_file_type](int result, FileList list) {
218 if (result != 0) {
219 m_last_error = result;
221 m_file_list.clear();
222 BuildGroups();
224 SendChangedEvent(EVT_STATUS_CHANGED, m_status, "", result);
225 SendChangedEvent(EVT_FILE_CHANGED);
226 return 0;
227 }
228 if (type != m_file_type)
229 return 0;
230 m_file_list.swap(list);
231 for (auto & file : m_file_list)
232 file.thumbnail = default_thumbnail;
233 std::sort(m_file_list.begin(), m_file_list.end());
234 auto iter1 = m_file_list.begin();
235 auto end1 = m_file_list.end();
236 auto iter2 = list.begin();
237 auto end2 = list.end();
238 while (iter1 != end1 && iter2 != end2) {
239 if (*iter1 < *iter2) {
240 ++iter1;
241 } else if (*iter2 < *iter1) {
242 ++iter2;
243 } else {
244 if (iter1->path == iter2->path && iter1->name == iter2->name) {
245 iter1->thumbnail = iter2->thumbnail;
246 iter1->flags = iter2->flags;
247 if (!iter1->thumbnail.IsOk())
248 iter1->flags &= ~FF_THUMNAIL;
249 iter1->download = iter2->download;
250 iter1->local_path = iter2->local_path;
251 iter1->metadata = iter2->metadata;
252 }
253 ++iter1;
254 ++iter2;
255 }
256 }
257 BuildGroups();
259 m_last_error = 0;
261 SendChangedEvent(EVT_STATUS_CHANGED, m_status);
262 SendChangedEvent(EVT_FILE_CHANGED);
263 if ((m_task_flags & FF_DOWNLOAD) == 0)
265 return 0;
266 });
267}
void BuildGroups()
Definition PrinterFileSystem.cpp:753
void UpdateGroupSelect()
Definition PrinterFileSystem.cpp:774

References BuildGroups(), default_thumbnail, DownloadNextFile(), F_TIMELAPSE, Failed, FF_DOWNLOAD, FF_THUMNAIL, FILE_TYPE_ERR, LIST_INFO, ListReady, m_file_list, m_file_storage, m_file_type, m_last_error, m_status, m_task_flags, SendChangedEvent(), SendRequest(), and UpdateGroupSelect().

Here is the call graph for this function:

◆ ParseThumbnail() [1/2]

bool PrinterFileSystem::ParseThumbnail ( File & file)
staticprivate
988{
989 std::istringstream iss(file.local_path, std::ios::binary);
990 return ParseThumbnail(file, iss);
991}

References PrinterFileSystem::File::local_path, and ParseThumbnail().

Referenced by PrinterFileSystem(), ParseThumbnail(), and UpdateFocusThumbnail2().

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

◆ ParseThumbnail() [2/2]

bool PrinterFileSystem::ParseThumbnail ( File & file,
std::istream & is )
staticprivate
1001{
1002 Slic3r::DynamicPrintConfig config;
1003 Slic3r::Model model;
1004 Slic3r::PlateDataPtrs plate_data_list;
1005 Slic3r::Semver file_version;
1006 if (!Slic3r::load_gcode_3mf_from_stream(is, &config, &model, &plate_data_list, &file_version))
1007 return false;
1008 float time = 0.f;
1009 float weight = 0.f;
1010 for (auto &plate : plate_data_list) {
1011 time += atof(plate->gcode_prediction.c_str());
1012 weight += atof(plate->gcode_weight.c_str());
1013 if (!plate->gcode_file.empty() && !plate->thumbnail_file.empty())
1014 file.metadata.emplace("plate_thumbnail_" + std::to_string(plate->plate_index), plate->thumbnail_file);
1015 }
1016 file.metadata.emplace("Title", model.model_info->model_name);
1017 file.metadata.emplace("Time", durationString(round(time)));
1018 file.metadata.emplace("Weight", std::to_string(int(round(weight))) + 'g');
1019 auto thumbnail = model.model_info->metadata_items["Thumbnail"];
1020 if (thumbnail.empty() && !plate_data_list.empty()) {
1021 thumbnail = plate_data_list.front()->thumbnail_file;
1022 }
1023 file.metadata.emplace("Thumbnail", thumbnail);
1024 return true;
1025}
static std::string durationString(long duration)
Definition PrinterFileSystem.cpp:993
std::shared_ptr< ModelInfo > model_info
Definition Model.hpp:1713
std::vector< PlateData * > PlateDataPtrs
Definition bbs_3mf.hpp:278
bool load_gcode_3mf_from_stream(std::istream &data, DynamicPrintConfig *config, Model *model, PlateDataPtrs *plate_data_list, Semver *file_version)
Definition bbs_3mf.cpp:9714

References durationString(), Slic3r::load_gcode_3mf_from_stream(), PrinterFileSystem::File::metadata, and Slic3r::Model::model_info.

Here is the call graph for this function:

◆ PostCallback() [1/2]

template<typename T>
void PrinterFileSystem::PostCallback ( Callback< T > const & callback,
int result,
T const & resp )
inlineprivate
365 {
366 PostCallback([=] { callback(result, resp); });
367 }

References PostCallback().

Referenced by InstallNotify(), PostCallback(), Reconnect(), and SendRequest().

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

◆ PostCallback() [2/2]

void PrinterFileSystem::PostCallback ( std::function< void(void)> const & callback)
private
1230{
1231 wxCommandEvent *e = new CallbackEvent(callback, boost::weak_ptr(shared_from_this()));
1232 wxQueueEvent(this, e);
1233}

◆ Reconnect()

void PrinterFileSystem::Reconnect ( boost::unique_lock< boost::mutex > & l,
int result )
private
1710{
1711 if (m_session.tunnel) {
1712 auto tunnel = m_session.tunnel;
1713 m_session.tunnel = nullptr;
1714 wxLogMessage("PrinterFileSystem::Reconnect close %d", result);
1715 l.unlock();
1716 Bambu_Close(tunnel);
1717 Bambu_Destroy(tunnel);
1718 l.lock();
1719 }
1720 if (m_session.owner == nullptr)
1721 return;
1722 json r;
1723 while(!m_callbacks.empty()) {
1724 auto c = m_callbacks.front();
1725 m_callbacks.pop_front();
1726 ++m_sequence;
1727 if (c) c(result, r, nullptr);
1728 }
1729 m_messages.clear();
1730 if (result)
1731 m_cond.timed_wait(l, boost::posix_time::seconds(10));
1732
1733
1734 while (true) {
1735 while (m_stopped) {
1736 if (m_session.owner == nullptr)
1737 return;
1739 SendChangedEvent(EVT_STATUS_CHANGED, m_status);
1740 m_cond.wait(l);
1741 }
1742 wxLogMessage("PrinterFileSystem::Reconnect Initializing");
1744 m_last_error = 0;
1745 SendChangedEvent(EVT_STATUS_CHANGED, m_status);
1746 // wait for url
1747 while (!m_stopped && m_messages.empty())
1748 m_cond.wait(l);
1749 if (m_stopped || m_messages.empty()) continue;
1750 std::string url = m_messages.front();
1751 m_messages.clear();
1752 if (url.size() < 2) {
1753 wxLogMessage("PrinterFileSystem::Reconnect Initialize failed: %s", wxString::FromUTF8(url));
1754 m_last_error = atoi(url.c_str());
1755 if (m_last_error == 0)
1756 m_stopped = true;
1757 } else {
1758 wxLogInfo("PrinterFileSystem::Reconnect Initialized: %s", wxString::FromUTF8(url));
1759 l.unlock();
1761 wxLogMessage("PrinterFileSystem::Reconnect Connecting");
1762 SendChangedEvent(EVT_STATUS_CHANGED, m_status);
1763 Bambu_Tunnel tunnel = nullptr;
1764 int ret = Bambu_Create(&tunnel, url.c_str());
1765 if (ret == 0) {
1766
1767 Bambu_SetLogger(tunnel, DumpLog, this);
1768 ret = Bambu_Open(tunnel);
1769 }
1770
1771 if (ret == 0)
1772 {
1773 auto start_time = boost::posix_time::microsec_clock::universal_time();
1774 boost::posix_time::time_duration timeout = boost::posix_time::seconds(3);
1775 do{
1776 ret = Bambu_StartStreamEx ? Bambu_StartStreamEx(tunnel, CTRL_TYPE) : Bambu_StartStream(tunnel, false);
1777 if (ret == Bambu_would_block)
1778 boost::this_thread::sleep(boost::posix_time::milliseconds(100));
1779
1780 auto now = boost::posix_time::microsec_clock::universal_time();
1781 if (now - start_time > timeout) {
1782 BOOST_LOG_TRIVIAL(warning) << "StartStream timeout after 5 seconds.";
1783 break;
1784 }
1785
1786 } while (ret == Bambu_would_block && !m_stopped);
1787 }
1788 l.lock();
1789 if (ret == 0) {
1790 m_session.tunnel = tunnel;
1791 wxLogMessage("PrinterFileSystem::Reconnect Connected");
1792 break;
1793 } else if (ret == 1) {
1794 m_stopped = true;
1795 ret = ERROR_RES_BUSY;
1796 }
1797 if (tunnel) {
1798 Bambu_Close(tunnel);
1799 Bambu_Destroy(tunnel);
1800 }
1801 m_last_error = ret;
1802 }
1803 wxLogMessage("PrinterFileSystem::Reconnect Failed");
1805
1806 SendChangedEvent(EVT_STATUS_CHANGED, m_status, "", url.size() < 2 ? 1 : m_last_error);
1807 m_cond.timed_wait(l, boost::posix_time::seconds(10));
1808 }
1809
1810#ifdef PRINTER_FILE_SYSTEM_TEST
1811 PostCallback([this] { SendChangedEvent(EVT_FILE_CHANGED); });
1812#else
1813 PostCallback([this] {
1814 m_task_flags = 0;
1816 SendChangedEvent(EVT_STATUS_CHANGED, m_status);
1817 });
1818#endif
1819}
@ Bambu_would_block
Definition BambuTunnel.h:108
BAMBU_EXPORT int BAMBU_FUNC Bambu_StartStream(Bambu_Tunnel tunnel, bool video)
BAMBU_EXPORT void BAMBU_FUNC Bambu_Destroy(Bambu_Tunnel tunnel)
BAMBU_EXPORT void BAMBU_FUNC Bambu_Close(Bambu_Tunnel tunnel)
BAMBU_EXPORT int BAMBU_FUNC Bambu_Open(Bambu_Tunnel tunnel)
void * Bambu_Tunnel
Definition BambuTunnel.h:36
BAMBU_EXPORT int BAMBU_FUNC Bambu_StartStreamEx(Bambu_Tunnel tunnel, int type)
BAMBU_EXPORT void BAMBU_FUNC Bambu_SetLogger(Bambu_Tunnel tunnel, Logger logger, void *context)
BAMBU_EXPORT int BAMBU_FUNC Bambu_Create(Bambu_Tunnel *tunnel, char const *path)
std::deque< std::string > m_messages
Definition PrinterFileSystem.h:403
static const int CTRL_TYPE
Definition PrinterFileSystem.h:42
bool m_stopped
Definition PrinterFileSystem.h:406
boost::condition_variable m_cond
Definition PrinterFileSystem.h:408
static void DumpLog(void *context, int level, tchar const *msg)
Definition PrinterFileSystem.cpp:1253

References Bambu_Close(), Bambu_Create(), Bambu_Destroy(), Bambu_Open(), Bambu_SetLogger(), Bambu_StartStream(), Bambu_StartStreamEx(), Bambu_would_block, Connecting, CTRL_TYPE, DumpLog(), ERROR_RES_BUSY, Failed, Initializing, ListSyncing, m_callbacks, m_cond, m_last_error, m_messages, m_sequence, m_session, m_status, m_stopped, m_task_flags, PostCallback(), Reconnecting, and SendChangedEvent().

Referenced by RecvMessageThread().

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

◆ RecvMessageThread()

void PrinterFileSystem::RecvMessageThread ( )
private
1552{
1553 Bambu_Sample sample;
1554 boost::unique_lock l(m_mutex);
1555 Reconnect(l, 0);
1556 while (true) {
1557 if (m_stopped && (m_session.owner == nullptr || (m_messages.empty() && m_callbacks.empty()))) {
1558 Reconnect(l, 0); // Close and wait start again
1559 if (m_session.owner == nullptr) {
1560 // clear callbacks first
1561 auto callbacks(std::move(m_callbacks));
1562 break;
1563 }
1564 }
1565 if (m_messages.empty() && !m_produce_message_cb_map.empty()) {
1566 auto it = m_produce_message_cb_map.begin();
1567 while(it != m_produce_message_cb_map.end()) {
1568 std::string msg;
1569 auto prodeuce_message_cb = it->second;
1570 l.unlock();
1571 int res = prodeuce_message_cb(msg);
1572 l.lock();
1573 if (res == CONTINUE || res == SUCCESS) {
1574 m_messages.emplace_back(msg);
1575 if (res == SUCCESS) {
1576 it = m_produce_message_cb_map.erase(it);
1577 continue;
1578 }
1579 it++;
1580 } else {
1581 int seq2 = it->first - m_sequence;
1582 // erase it
1583 it = m_produce_message_cb_map.erase(it);
1584 if (size_t(seq2) >= m_callbacks.size())
1585 continue;
1586 auto c = m_callbacks[seq2];
1587 if (c == nullptr)
1588 continue;;
1589 m_callbacks[seq2] = nullptr;
1590 if (seq2 == 0) {
1591 // if produce message return error, erase callback and sequence should plus
1592 while (!m_callbacks.empty() && m_callbacks.front() == nullptr) {
1593 m_callbacks.pop_front();
1594 ++m_sequence;
1595 }
1596 }
1597
1598 l.unlock();
1599 c(res, json(), nullptr);
1600 l.lock();
1601 }
1602 }
1603 }
1604 if (!m_messages.empty()) {
1605 auto & msg = m_messages.front();
1606 // OutputDebugStringA(msg.c_str());
1607 // OutputDebugStringA("\n");
1608 wxLogInfo("PrinterFileSystem::SendRequest >>>: \n%s\n", wxString::FromUTF8(msg));
1609 l.unlock();
1610 int n = Bambu_SendMessage(m_session.tunnel, CTRL_TYPE, msg.c_str(), msg.length());
1611 l.lock();
1612 if (n == 0)
1613 m_messages.pop_front();
1614 else if (n != Bambu_would_block) {
1615 Reconnect(l, n);
1616 continue;
1617 }
1618 }
1619 l.unlock();
1620 int n = Bambu_ReadSample(m_session.tunnel, &sample);
1621 l.lock();
1622 if (n == 0) {
1623 HandleResponse(l, sample);
1624 } else if (n == Bambu_stream_end) {
1625 m_stopped = true;
1627 } else if (n == Bambu_would_block) {
1628 m_cond.timed_wait(l, boost::posix_time::milliseconds(m_messages.empty() && m_callbacks.empty() ? 1000 : 20));
1629 } else {
1630 Reconnect(l, n);
1631 }
1632 } // while
1633}
struct __Bambu_Sample Bambu_Sample
@ Bambu_stream_end
Definition BambuTunnel.h:107
BAMBU_EXPORT int BAMBU_FUNC Bambu_ReadSample(Bambu_Tunnel tunnel, Bambu_Sample *sample)
BAMBU_EXPORT int BAMBU_FUNC Bambu_SendMessage(Bambu_Tunnel tunnel, int ctrl, char const *data, int len)
void Reconnect(boost::unique_lock< boost::mutex > &l, int result)
Definition PrinterFileSystem.cpp:1709
void HandleResponse(boost::unique_lock< boost::mutex > &l, Bambu_Sample const &sample)
Definition PrinterFileSystem.cpp:1635

References Bambu_ReadSample(), Bambu_SendMessage(), Bambu_stream_end, Bambu_would_block, CONTINUE, CTRL_TYPE, ERROR_PIPE, ERROR_RES_BUSY, HandleResponse(), ListSyncing, m_callbacks, m_cond, m_messages, m_mutex, m_produce_message_cb_map, m_sequence, m_session, m_status, m_stopped, Reconnect(), and SUCCESS.

Here is the call graph for this function:

◆ RequestMediaAbility()

boost::uint32_t PrinterFileSystem::RequestMediaAbility ( int api_version)
1264{
1265 json req;
1266 req["peer"] = "studio";
1267 req["api_version"] = api_version;
1268
1270 REQUEST_MEDIA_ABILITY, req, [](const json &resp, MediaAbilityList &list, auto) -> int {
1271 json abliity_list = resp["storage"];
1272 list = abliity_list.get<MediaAbilityList>();
1273 return 0;
1274 },
1275 [this](int result, MediaAbilityList list){
1276 if (result != 0) {
1277 m_last_error = result;
1278 m_media_ability_list.clear();
1279 SendChangedEvent(EVT_MEDIA_ABILITY_CHANGED, RequestMediaAbilityStatus::S_FAILED, "", m_last_error);
1280 return result;
1281 }
1282
1283 m_media_ability_list.swap(list);
1284 SendChangedEvent(EVT_MEDIA_ABILITY_CHANGED, RequestMediaAbilityStatus::S_SUCCESS);
1285 return 0;
1286 });
1287}
std::vector< std::string > MediaAbilityList
Definition PrinterFileSystem.h:189

References m_last_error, m_media_ability_list, REQUEST_MEDIA_ABILITY, S_FAILED, S_SUCCESS, SendChangedEvent(), and SendRequest().

Here is the call graph for this function:

◆ RequestUploadFile()

void PrinterFileSystem::RequestUploadFile ( )
1290{
1291 if (!m_upload_file) {
1292 return;
1293 }
1294
1295 json req;
1296 req["type"] = "model";
1297 req["storage"] = m_upload_file->select_storage;
1298 req["path"] = m_upload_file->name;
1299
1300 m_upload_file->upload = std::make_unique<Upload>();
1301 boost::filesystem::path path = boost::filesystem::path(m_upload_file->path);
1302 boost::system::error_code ec;
1303 boost::uint32_t file_size = boost::filesystem::file_size(path, ec);
1304
1305 req["total"] = file_size;
1306 m_upload_file->size = file_size;
1307 m_upload_file->upload->total = file_size;
1308
1310 FILE_UPLOAD, req,
1311 [this](int result, const json& resp, auto) -> int{
1312 if (result != SUCCESS && result != CONTINUE && result != FILE_EXIST) {
1313 std::string error_msg = "";
1314 if (result == ERROR_CANCEL) {
1315 error_msg = _u8L("User cancels task.");
1316 } else if (result == FILE_READ_WRITE_ERR || result == FILE_OPEN_ERR) {
1317 error_msg = _u8L("Failed to read file, please try again.");
1318 }
1319 wxLogWarning("PrinterFileSystem::UploadFile error: %d\n", result);
1320 SendChangedEvent(EVT_UPLOAD_CHANGED, FF_UPLOADCANCEL, error_msg, result);
1321 } else if (result == SUCCESS) {
1322 SendChangedEvent(EVT_UPLOADING, 100);
1323 SendChangedEvent(EVT_UPLOAD_CHANGED, FF_UPLOADDONE);
1324 } else if (result == CONTINUE || result == FILE_EXIST) {
1325 if (m_upload_file) {
1326 m_upload_file->chunk_size = resp["chunk_size"];
1327 m_upload_file->upload->size = resp["offset"];
1328 m_upload_file->flags |= FF_UPLOADING;
1329 }
1330
1331 {
1332 boost::unique_lock l(m_mutex);
1333 auto cb = [this, upload_file = m_upload_file, seq = m_upload_seq](std::string &msg) -> int {
1334 return UploadFileTask(upload_file, seq, msg);
1335 };
1337 }
1338
1339 return CONTINUE;
1340 }
1341
1342 // reset m_upload_file
1343 if (m_upload_file) {
1344 if (m_upload_file->upload->ifs.is_open()) {
1345 m_upload_file->upload->ifs.close();
1346 }
1347 m_upload_file.reset();
1348 }
1349 return result;
1350 });
1351}
int UploadFileTask(std::shared_ptr< UploadFile > upload_file, boost::uint64_t seq, std::string &msg)
Definition PrinterFileSystem.cpp:1353

References _u8L, CONTINUE, ERROR_CANCEL, FF_UPLOADCANCEL, FF_UPLOADDONE, FF_UPLOADING, FILE_EXIST, FILE_OPEN_ERR, FILE_READ_WRITE_ERR, FILE_UPLOAD, m_mutex, m_produce_message_cb_map, m_upload_file, m_upload_seq, SendChangedEvent(), SendRequest(), SUCCESS, and UploadFileTask().

Here is the call graph for this function:

◆ Retry()

void PrinterFileSystem::Retry ( )
717{
718 boost::unique_lock l(m_mutex);
719 m_stopped = false;
720 m_cond.notify_all();
721}

References m_cond, m_mutex, and m_stopped.

◆ SelectAll()

void PrinterFileSystem::SelectAll ( bool select)
656{
657 if (select) {
658 for (auto &f : m_file_list) f.flags |= FF_SELECT;
660 for (auto &s : m_group_flags) s |= FF_SELECT;
661 } else {
662 for (auto &f : m_file_list) f.flags &= ~FF_SELECT;
663 m_select_count = 0;
664 for (auto &s : m_group_flags) s &= ~FF_SELECT;
665 }
666 SendChangedEvent(EVT_SELECT_CHANGED, m_select_count);
667}

References FF_SELECT, m_file_list, m_group_flags, m_select_count, and SendChangedEvent().

Referenced by SetFileType().

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

◆ SendChangedEvent()

void PrinterFileSystem::SendChangedEvent ( wxEventType type,
size_t index = (size_t)-1,
std::string const & str = {},
long extra = 0 )
private
1236{
1237 wxCommandEvent event(type);
1238 event.SetEventObject(this);
1239 event.SetInt(index);
1240 if (!str.empty())
1241 event.SetString(wxString::FromUTF8(str.c_str()));
1242 else if (auto iter = error_messages.find(extra); iter != error_messages.end())
1243 event.SetString(_L(iter->second.c_str()));
1244 else if (extra > CONTINUE && extra != ERROR_CANCEL)
1245 event.SetString(wxString::Format(_L("Error code: %d"), int(extra)));
1246 event.SetExtraLong(extra);
1247 if (wxThread::IsMain())
1248 ProcessEventLocally(event);
1249 else
1250 wxPostEvent(this, event);
1251}
#define _L(s)
Definition OBJ.cpp:34

References _L, CONTINUE, ERROR_CANCEL, and error_messages.

Referenced by DownloadCheckFile(), DownloadNextFile(), DownloadRamFile(), ListAllFiles(), Reconnect(), RequestMediaAbility(), RequestUploadFile(), SelectAll(), SendConnectFail(), SendExistedFile(), SetFileType(), SetGroupMode(), ToggleSelect(), UpdateFocusThumbnail2(), and UploadFileTask().

Here is the caller graph for this function:

◆ SendConnectFail()

void PrinterFileSystem::SendConnectFail ( )
450 {
451 SendChangedEvent(EVT_RAMDOWNLOAD, ERROR_PIPE);
452}

References ERROR_PIPE, and SendChangedEvent().

Here is the call graph for this function:

◆ SendExistedFile()

void PrinterFileSystem::SendExistedFile ( )
447 {
448 SendChangedEvent(EVT_RAMDOWNLOAD, SUCCESS);
449}

References SendChangedEvent(), and SUCCESS.

Here is the call graph for this function:

◆ SendRequest() [1/2]

boost::uint32_t PrinterFileSystem::SendRequest ( int type,
nlohmann::json const & req,
callback_t2 const & callback,
const std::string & param = "" )
private

◆ SendRequest() [2/2]

template<typename T>
boost::uint32_t PrinterFileSystem::SendRequest ( int type,
nlohmann::json const & req,
Translator< T > const & translator,
Callback< T > const & callback,
const std::string & param = "" )
inlineprivate
301 {
302 auto c = [translator, callback, this](int result, nlohmann::json const &resp, unsigned char const *data) -> int
303 {
304 T t;
305 if (result == 0 || result == CONTINUE || result == FILE_EXIST) {
306 try {
307 int n = (translator != nullptr) ? translator(resp, t, data) : 0;
308 result = n == 0 ? result : n;
309 }
310 catch (...) {
311 result = ERROR_JSON;
312 }
313 }
314 PostCallback<T>(callback, result, t);
315 return result;
316 };
317 return SendRequest(type, req, c, param);
318 }

References CONTINUE, ERROR_JSON, FILE_EXIST, PostCallback(), and SendRequest().

Referenced by CancelRequests(), DeleteFilesContinue(), DownloadNextFile(), DownloadRamFile(), FetchModel(), ListAllFiles(), RequestMediaAbility(), RequestUploadFile(), SendRequest(), and UpdateFocusThumbnail2().

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

◆ SetFileType()

void PrinterFileSystem::SetFileType ( FileType type,
std::string const & storage = {} )
155{
156 if (m_file_type == type && m_file_storage == storage)
157 return;
158 SelectAll(false);
159 assert(m_file_list_cache[std::make_pair(m_file_type, m_file_storage)].empty());
161 std::swap(m_file_type, type);
162 m_file_storage = storage;
165 BuildGroups();
167 SendChangedEvent(EVT_FILE_CHANGED);
168 if (type == F_INVALID_TYPE)
169 return;
170 if (m_session.tunnel == nullptr)
171 return;
173 SendChangedEvent(EVT_STATUS_CHANGED, m_status);
174}
void SelectAll(bool select)
Definition PrinterFileSystem.cpp:655
size_t m_lock_start
Definition PrinterFileSystem.h:386
size_t m_lock_end
Definition PrinterFileSystem.h:387
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273

References BuildGroups(), F_INVALID_TYPE, ListSyncing, m_file_list, m_file_list_cache, m_file_storage, m_file_type, m_lock_end, m_lock_start, m_session, m_status, SelectAll(), SendChangedEvent(), and UpdateGroupSelect().

Here is the call graph for this function:

◆ SetFocusRange()

void PrinterFileSystem::SetFocusRange ( size_t start,
size_t count )
672{
673 m_lock_start = start;
674 m_lock_end = start + count;
675 if (!m_stopped && (m_task_flags & FF_THUMNAIL) == 0)
677}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
void UpdateFocusThumbnail()
Definition PrinterFileSystem.cpp:952

References count, FF_THUMNAIL, m_lock_end, m_lock_start, m_stopped, m_task_flags, and UpdateFocusThumbnail().

Here is the call graph for this function:

◆ SetGroupMode()

void PrinterFileSystem::SetGroupMode ( GroupMode mode)
177{
178 if (this->m_group_mode == mode)
179 return;
180 this->m_group_mode = mode;
183 SendChangedEvent(EVT_MODE_CHANGED);
184}

References m_group_mode, m_lock_end, m_lock_start, SendChangedEvent(), and UpdateGroupSelect().

Referenced by EnterSubGroup().

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

◆ SetUploadFile()

void PrinterFileSystem::SetUploadFile ( const std::string & path,
const std::string & name,
const std::string & select_storage )
743{
744 boost::unique_lock l(m_mutex);
745 if (!m_upload_file) {
746 m_upload_file = std::make_unique<UploadFile>();
747 }
748 m_upload_file->path = path;
749 m_upload_file->name = name;
750 m_upload_file->select_storage = select_storage;
751}

References m_mutex, and m_upload_file.

◆ SetUrl()

void PrinterFileSystem::SetUrl ( std::string const & url)
724{
725 boost::unique_lock l(m_mutex);
726 m_messages.push_back(url);
727 m_cond.notify_all();
728}

References m_cond, m_messages, and m_mutex.

◆ Start()

void PrinterFileSystem::Start ( )
709{
710 boost::unique_lock l(m_mutex);
711 if (!m_stopped) return;
712 m_stopped = false;
713 m_cond.notify_all();
714}

References m_cond, m_mutex, and m_stopped.

◆ Stop()

void PrinterFileSystem::Stop ( bool quit = false)
731{
732 boost::unique_lock l(m_mutex);
733 if (quit) {
734 m_session.owner = nullptr;
735 } else if (m_stopped) {
736 return;
737 }
738 m_stopped = true;
739 m_cond.notify_all();
740}

References m_cond, m_mutex, m_session, and m_stopped.

◆ ToggleSelect()

void PrinterFileSystem::ToggleSelect ( size_t index)
623{
624 if (m_group_mode != G_NONE) {
625 size_t beg = m_group_mode == G_YEAR ? m_group_month[m_group_year[index]] : m_group_month[index];
626 size_t end_month = m_group_mode == G_YEAR ? ((index + 1) < m_group_year.size() ? m_group_year[index + 1] : m_group_month.size()) : index + 1;
627 size_t end = end_month < m_group_month.size() ? m_group_month[end_month] : m_file_list.size();
628 if ((m_group_flags[index] & FF_SELECT) == 0) {
629 for (int i = beg; i < end; ++i) {
630 if ((m_file_list[i].flags & FF_SELECT) == 0) {
631 m_file_list[i].flags |= FF_SELECT;
633 }
634 }
635 m_group_flags[index] |= FF_SELECT;
636 } else {
637 for (int i = beg; i < end; ++i) {
638 if (m_file_list[i].flags & FF_SELECT) {
639 m_file_list[i].flags &= ~FF_SELECT;
641 }
642 }
643 m_group_flags[index] &= ~FF_SELECT;
644 }
645 } else if (index < m_file_list.size()) {
646 m_file_list[index].flags ^= FF_SELECT;
647 if (m_file_list[index].flags & FF_SELECT)
649 else
651 }
652 SendChangedEvent(EVT_SELECT_CHANGED, m_select_count);
653}

References FF_SELECT, G_NONE, G_YEAR, m_file_list, m_group_flags, m_group_mode, m_group_month, m_group_year, m_select_count, and SendChangedEvent().

Here is the call graph for this function:

◆ UpdateFocusThumbnail()

void PrinterFileSystem::UpdateFocusThumbnail ( )
private
953{
956 return;
957 size_t start = m_lock_start;
958 size_t end = std::min(m_lock_end, GetCount());
959 std::vector<File> names;
960 std::vector<File> paths;
961 for (; start < end; ++start) {
962 auto &file = GetFile(start);
963 if ((file.flags & FF_THUMNAIL) == 0) {
964 if (m_file_type == F_MODEL) {
965 const_cast<File &>(file).metadata.emplace("Time", "...");
966 const_cast<File &>(file).metadata.emplace("Weight", "...");
967 }
968 if (file.path.empty())
969 names.push_back({file.name, ""});
970 else
971 paths.push_back({file.name, file.path});
972 if (names.size() >= 2 || paths.size() >= 2)
973 break;
974 if ((file.flags & FF_THUMNAIL_RETRY) != 0) {
975 const_cast<File&>(file).flags &= ~FF_THUMNAIL_RETRY;
976 break;
977 }
978 }
979 }
980 if (names.empty() && paths.empty())
981 return;
983 UpdateFocusThumbnail2(std::make_shared<std::vector<File>>(paths.empty() ? names : paths),
985}
@ ModelMetadata
Definition PrinterFileSystem.cpp:947
@ VideoThumbnail
Definition PrinterFileSystem.cpp:946
@ OldThumbnail
Definition PrinterFileSystem.cpp:945
size_t GetCount() const
Definition PrinterFileSystem.cpp:586
File const & GetFile(size_t index)
Definition PrinterFileSystem.cpp:679
void UpdateFocusThumbnail2(std::shared_ptr< std::vector< File > > files, int type)
Definition PrinterFileSystem.cpp:1027

References F_MODEL, FF_THUMNAIL, FF_THUMNAIL_RETRY, GetCount(), GetFile(), m_file_list, m_file_type, m_lock_end, m_lock_start, m_task_flags, ModelMetadata, OldThumbnail, UpdateFocusThumbnail2(), and VideoThumbnail.

Referenced by SetFocusRange(), and UpdateFocusThumbnail2().

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

◆ UpdateFocusThumbnail2()

void PrinterFileSystem::UpdateFocusThumbnail2 ( std::shared_ptr< std::vector< File > > files,
int type )
private
1028{
1029 json req;
1030 json arr;
1031 if (type == OldThumbnail) {
1032 for (auto &file : *files) arr.push_back(file.name);
1033 req["files"] = arr;
1034 } else {
1035 if (type == VideoThumbnail) {
1036 for (auto &file : *files) arr.push_back(file.path + "#thumbnail");
1037 } else if (type == ModelMetadata) {
1038 for (auto &file : *files) {
1039 arr.push_back(file.path + "#_rels/.rels");
1040 arr.push_back(file.path + "#3D/3dmodel.model");
1041 arr.push_back(file.path + "#Metadata/model_settings.config");
1042 arr.push_back(file.path + "#Metadata/slice_info.config");
1043 arr.push_back(file.path + "#Metadata/project_settings.config");
1044 }
1045 req["zip"] = true;
1046 } else { // ModelThumbnail, FinishThumbnail
1047 std::vector<std::string> fails;
1048 for (auto &file : *files) {
1049 if ((file.flags & FF_THUMNAIL) == 0) {
1050 fails.push_back(file.path);
1051 file.flags |= FF_THUMNAIL;
1052 }
1053 }
1054 for (auto &path : fails) {
1055 auto iter = std::find_if(m_file_list.begin(), m_file_list.end(), [&path](auto &f) { return f.path == path; });
1056 if (iter != m_file_list.end()) {
1057 if (type == ModelThumbnail) iter->metadata.clear();
1058 iter->flags |= fails.size() == 1 ? FF_THUMNAIL : FF_THUMNAIL_RETRY;
1059 }
1060 }
1061 if (type == ModelThumbnail) {
1062 for (auto &file : *files) {
1063 auto thumbnail = file.metadata["Thumbnail"];
1064 if (!thumbnail.empty()) {
1065 arr.push_back(file.path + "#" + thumbnail);
1066 file.flags &= ~FF_THUMNAIL;
1067 file.local_path.clear();
1068 }
1069 }
1070 }
1071 if (arr.empty()) {
1073 return;
1074 }
1075 }
1076 req["paths"] = arr;
1077 }
1079 SUB_FILE, req, [type, files](json const &resp, File &file, unsigned char const *data) -> int {
1080 // in work thread, continue recv
1081 // receive data
1082 wxString mimetype = resp.value("mimetype", "");
1083 std::string thumbnail = resp.value("thumbnail", "");
1084 std::string path = resp.value("path", "");
1085 boost::uint32_t size = resp.value("size", 0);
1086 bool cont = resp.value("continue", false);
1087 if (size == 0) {
1088 file.name = thumbnail;
1089 file.path = path;
1090 return FILE_SIZE_ERR;
1091 }
1092 auto n = type == ModelMetadata ? std::string::npos : path.find_last_of('#'); // ModelMetadata is zipped without subpath
1093 auto path2 = n == std::string::npos ? path : path.substr(0, n);
1094 auto subpath = n == std::string::npos ? path : path.substr(n + 1);
1095 auto iter = std::find_if(files->begin(), files->end(), [&path2](auto &f) { return f.path == path2; });
1096 if (cont) {
1097 if (iter != files->end())
1098 iter->local_path += std::string((char *) data, size);
1099 return 0;
1100 }
1101 if (type == ModelMetadata) {
1102 if (iter != files->end())
1103 file.local_path = iter->local_path + std::string((char *) data, size);
1104 else
1105 file.local_path = std::string((char *) data, size);
1106 ParseThumbnail(file);
1107 } else {
1108 if (mimetype.empty()) {
1109 if (subpath.empty()) subpath = thumbnail;
1110 auto n = subpath.find_last_of('.');
1111 if (n != std::string::npos)
1112 mimetype = "image/" + subpath.substr(n + 1);
1113 else if (subpath == "thumbnail")
1114 mimetype = "image/jpeg"; // default jpg
1115 }
1116 if (iter != files->end() && !iter->local_path.empty()) {
1117 iter->local_path += std::string((char *) data, size);
1118 data = reinterpret_cast<unsigned char const *>(iter->local_path.c_str());
1119 size = iter->local_path.size();
1120 }
1121 wxMemoryInputStream mis(data, size);
1122 mimetype.Replace("jpg", "jpeg");
1123 file.thumbnail = wxImage(mis, mimetype);
1124 if (!file.thumbnail.IsOk()) {
1125 BOOST_LOG_TRIVIAL(info) << "PrinterFileSystem: parse thumbnail failed" << size << mimetype;
1126 }
1127 }
1128 file.name = thumbnail;
1129 file.path = path;
1130 return 0;
1131 },
1132 [this, files, type](int result, File const &file) {
1133 auto n = file.name.find_last_of('.');
1134 auto name = n == std::string::npos ? file.name : file.name.substr(0, n) + ".mp4";
1135 n = (type == ModelMetadata) ? std::string::npos : file.path.find_last_of('#');
1136 auto path = n == std::string::npos ? file.path : file.path.substr(0, n);
1137 auto iter = path.empty() ? std::find_if(m_file_list.begin(), m_file_list.end(), [&name](auto &f) { return f.name == name; }) :
1138 std::find_if(m_file_list.begin(), m_file_list.end(), [&path](auto &f) { return f.path == path; });
1139 auto iter2 = path.empty() ? std::find_if(files->begin(), files->end(), [&name](auto &f) { return f.name == name; }) :
1140 std::find_if(files->begin(), files->end(), [&path](auto &f) { return f.path == path; });
1141 if (iter != m_file_list.end()) {
1142 if (type == ModelMetadata) {
1143 iter->metadata = file.metadata;
1144 auto thumbnail = iter->metadata["Thumbnail"];
1145 if (thumbnail.empty())
1146 iter->flags |= FF_THUMNAIL; // DOTO: retry on fail
1147 int index = iter - m_file_list.begin();
1148 SendChangedEvent(EVT_THUMBNAIL, index, file.name);
1149 if (iter2 != files->end())
1150 iter2->metadata = file.metadata;
1151 } else {
1152 iter->flags |= FF_THUMNAIL; // DOTO: retry on fail
1153 if (file.thumbnail.IsOk()) {
1154 iter->thumbnail = file.thumbnail;
1155 int index = iter - m_file_list.begin();
1156 SendChangedEvent(EVT_THUMBNAIL, index, file.name);
1157 }
1158 }
1159 }
1160 if (iter2 != files->end())
1161 iter2->flags |= FF_THUMNAIL; // have received response
1162 if (result != CONTINUE)
1164 });
1165}
@ ModelThumbnail
Definition PrinterFileSystem.cpp:948
@ FinishThumbnail
Definition PrinterFileSystem.cpp:949

References CONTINUE, FF_THUMNAIL, FF_THUMNAIL_RETRY, FILE_SIZE_ERR, FinishThumbnail, PrinterFileSystem::File::local_path, m_file_list, PrinterFileSystem::File::metadata, ModelMetadata, ModelThumbnail, PrinterFileSystem::File::name, OldThumbnail, ParseThumbnail(), PrinterFileSystem::File::path, SendChangedEvent(), SendRequest(), SUB_FILE, PrinterFileSystem::File::thumbnail, UpdateFocusThumbnail(), UpdateFocusThumbnail2(), and VideoThumbnail.

Referenced by UpdateFocusThumbnail(), and UpdateFocusThumbnail2().

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

◆ UpdateGroupSelect()

void PrinterFileSystem::UpdateGroupSelect ( )
private
775{
776 m_group_flags.clear();
777 int beg = 0;
778 if (m_group_mode != G_NONE) {
779 auto group = m_group_mode == G_YEAR ? m_group_year : m_group_month;
780 if (m_group_mode == G_YEAR)
781 for (auto &g : group) g = m_group_month[g];
782 m_group_flags.resize(group.size(), FF_SELECT);
783 for (int i = 0; i < m_file_list.size(); ++i) {
784 if ((m_file_list[i].flags & FF_SELECT) == 0) {
785 auto iter = std::upper_bound(group.begin(), group.end(), i);
786 m_group_flags[iter - group.begin() - 1] &= ~FF_SELECT;
787 if (iter == group.end()) break;
788 i = *iter - 1; // start from next group
789 }
790 }
791 }
792}

References FF_SELECT, G_NONE, G_YEAR, m_file_list, m_group_flags, m_group_mode, m_group_month, and m_group_year.

Referenced by ListAllFiles(), SetFileType(), and SetGroupMode().

Here is the caller graph for this function:

◆ UploadFileTask()

int PrinterFileSystem::UploadFileTask ( std::shared_ptr< UploadFile > upload_file,
boost::uint64_t seq,
std::string & msg )
private
1354{
1355 if (!upload_file)
1356 return FILE_OPEN_ERR;
1357
1358 if (!(upload_file->flags & FF_UPLOADING))
1359 return FILE_OPEN_ERR;
1360
1361 auto &upload = upload_file->upload;
1362 if (!upload->ifs.is_open()) {
1363 upload->ifs.open(upload_file->path, std::ios::binary);
1364 if (!upload_file->upload->ifs) {
1365 wxLogWarning("PrinterFileSystem::UploadFile open error: %s\n", wxString::FromUTF8(upload_file->path));
1366 return FILE_OPEN_ERR;
1367 }
1368 MD5_Init(&upload->ctx);
1369 }
1370
1371 const boost::uint32_t buffer_size = upload_file->chunk_size * 1024;
1372 char *buffer = new char[buffer_size];
1373
1374 upload->ifs.seekg(upload->size, std::ios::beg);
1375 upload->ifs.read(buffer, buffer_size);
1376 boost::int32_t read_size = upload->ifs.gcount();
1377
1378 if (read_size <= 0) {
1379 wxLogWarning("PrinterFileSystem::Upload read error.\n");
1380 upload->ifs.close();
1381
1382 if (buffer) {
1383 delete[] buffer;
1384 buffer = nullptr;
1385 }
1386 return FILE_READ_WRITE_ERR;
1387 }
1388
1389 json req;
1390 req["frag_id"] = upload->frag_id;
1391 req["offset"] = upload->size;
1392 req["size"] = read_size;
1393
1394 MD5_Update(&upload->ctx, buffer, read_size);
1395 upload->size += read_size;
1396 if (upload->size == upload->total) {
1397 unsigned char digest[16];
1398 MD5_Final(digest, &upload->ctx);
1399 char md5_str[33];
1400 for (int j = 0; j < 16; j++) { sprintf(&md5_str[j * 2], "%02X", (unsigned int) digest[j]); }
1401 std::string md5_out = std::string(md5_str);
1402 std::transform(md5_out.begin(), md5_out.end(), md5_out.begin(), ::tolower);
1403
1404 req["file_md5"] = md5_out;
1405 // OutputDebugStringA(md5_out.c_str());
1406 // OutputDebugStringA("\n");
1407 }
1408
1409 if (m_upload_file && m_upload_file->flags & FF_UPLOADING) {
1410 upload->frag_id++;
1411 upload->progress = upload->size * 100 / upload->total;
1412 int progress = upload->progress == 100 ? 99 : upload->progress;
1413 SendChangedEvent(EVT_UPLOADING, progress);
1414 }
1415
1416 json root;
1417
1418 root["cmdtype"] = FILE_UPLOAD;
1419 root["sequence"] = seq;
1420 root["req"] = req;
1421
1422 std::ostringstream oss;
1423 oss << root;
1424 oss << "\n\n";
1425 oss << std::string(buffer, read_size);
1426 msg = oss.str();
1427
1428 if (buffer) {
1429 delete[] buffer;
1430 buffer = nullptr;
1431 }
1432
1433 if (upload->size == upload->total) {
1434 upload->ifs.close();
1435 return SUCCESS;
1436 }
1437
1438 return CONTINUE;
1439}

References CONTINUE, FF_UPLOADING, FILE_OPEN_ERR, FILE_READ_WRITE_ERR, FILE_UPLOAD, m_upload_file, SendChangedEvent(), and SUCCESS.

Referenced by RequestUploadFile().

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

Member Data Documentation

◆ CTRL_TYPE

const int PrinterFileSystem::CTRL_TYPE = 0x3001
staticprivate

Referenced by Reconnect(), and RecvMessageThread().

◆ m_callbacks

std::deque<callback_t2> PrinterFileSystem::m_callbacks
private

◆ m_cond

boost::condition_variable PrinterFileSystem::m_cond
private

◆ m_download_seq

boost::uint32_t PrinterFileSystem::m_download_seq = 0
private

◆ m_download_states

std::vector<bool> PrinterFileSystem::m_download_states
private

Referenced by DownloadRamFile(), and GetPickImages().

◆ m_fetch_model_seq

boost::uint32_t PrinterFileSystem::m_fetch_model_seq = 0
private

Referenced by FetchModel(), and FetchModelCancel().

◆ m_file_list

◆ m_file_list_cache

std::map<std::pair<FileType, std::string>, FileList> PrinterFileSystem::m_file_list_cache
protected

◆ m_file_storage

std::string PrinterFileSystem::m_file_storage
protected

◆ m_file_type

◆ m_group_flags

std::vector<int> PrinterFileSystem::m_group_flags
protected

◆ m_group_mode

◆ m_group_month

std::vector<size_t> PrinterFileSystem::m_group_month
protected

◆ m_group_year

std::vector<size_t> PrinterFileSystem::m_group_year
protected

◆ m_last_error

int PrinterFileSystem::m_last_error = 0
private

◆ m_lock_end

size_t PrinterFileSystem::m_lock_end = 0
private

◆ m_lock_start

size_t PrinterFileSystem::m_lock_start = 0
private

◆ m_media_ability_list

MediaAbilityList PrinterFileSystem::m_media_ability_list
private

◆ m_messages

std::deque<std::string> PrinterFileSystem::m_messages
private

◆ m_mutex

boost::mutex PrinterFileSystem::m_mutex
private

◆ m_notifies

std::deque<callback_t2> PrinterFileSystem::m_notifies
private

Referenced by HandleResponse(), and InstallNotify().

◆ m_produce_message_cb_map

std::map<boost::uint32_t, callback_t3> PrinterFileSystem::m_produce_message_cb_map
private

◆ m_recv_thread

boost::thread PrinterFileSystem::m_recv_thread
private

Referenced by ~PrinterFileSystem(), and Attached().

◆ m_select_count

size_t PrinterFileSystem::m_select_count = 0
private

◆ m_sequence

boost::uint32_t PrinterFileSystem::m_sequence = 0
private

◆ m_session

Session PrinterFileSystem::m_session
private

◆ m_status

Status PrinterFileSystem::m_status
private

◆ m_stopped

bool PrinterFileSystem::m_stopped = true
private

◆ m_task_flags

◆ m_upload_file

std::shared_ptr<UploadFile> PrinterFileSystem::m_upload_file
protected

◆ m_upload_seq

boost::uint32_t PrinterFileSystem::m_upload_seq = 0
private

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