forked from ClusterM/open-bamboo-networking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabi_makerworld.cpp
More file actions
202 lines (181 loc) · 8.42 KB
/
abi_makerworld.cpp
File metadata and controls
202 lines (181 loc) · 8.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include <functional>
#include <string>
#include <vector>
#include "obn/abi_export.hpp"
#include "obn/agent.hpp"
#include "obn/bambu_networking.hpp"
#include "obn/log.hpp"
// Forward declaration only: BBLModelTask is defined in Bambu Studio's
// DeviceManager.hpp. We never dereference the pointer; we just need the type
// name to match Studio's std::function<void(BBLModelTask*)> template
// instantiation exactly. Getting the template parameter wrong is NOT merely
// a style issue - std::function's type-erased invoker expects arguments at
// specific offsets/layouts, and a mismatched instantiation silently
// reinterprets (e.g.) an int as a pointer, which is how PID 459153 died
// with SIGBUS inside StatusPanel::update_model_info.
class BBLModelTask;
using obn::as_agent;
// MakerWorld / model mall / OSS: no open specification exists. These all
// return success with empty payloads so Studio's UI degrades gracefully
// instead of crashing.
OBN_ABI int bambu_network_get_design_staffpick(void* /*agent*/,
int /*offset*/, int /*limit*/,
std::function<void(std::string)> cb)
{
if (cb) cb("{\"list\":[],\"total\":0}");
return BAMBU_NETWORK_SUCCESS;
}
// The real plugin spells this `start_publish` when resolved (NetworkAgent.cpp
// uses the typo `start_pubilsh` only on the Studio side for the function
// pointer name), so we export the canonical name.
OBN_ABI int bambu_network_start_publish(void* /*agent*/,
BBL::PublishParams /*params*/,
BBL::OnUpdateStatusFn /*update_fn*/,
BBL::WasCancelledFn /*cancel_fn*/,
std::string* out)
{
if (out) out->clear();
return BAMBU_NETWORK_ERR_INVALID_RESULT;
}
OBN_ABI int bambu_network_get_model_publish_url(void* /*agent*/, std::string* url)
{
if (url) *url = "https://makerworld.com/";
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_get_subtask(void* /*agent*/,
BBLModelTask* task,
std::function<void(BBLModelTask*)> cb)
{
// Cloud-only endpoint: in LAN mode there is no subtask/model-task record
// to fetch. Do NOT invoke the callback with a fake pointer - the caller
// (StatusPanel::update_model_info) dereferences subtask->task_id
// unconditionally and would SIGBUS/SIGSEGV on any non-mappable address.
OBN_DEBUG("get_subtask task=%p cb=%d (stub: no callback)", (void*)task, cb ? 1 : 0);
(void)cb;
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_get_model_mall_home_url(void* /*agent*/, std::string* url)
{
if (url) *url = "https://makerworld.com/";
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_get_model_mall_detail_url(void* /*agent*/,
std::string* url,
std::string id)
{
if (url) *url = std::string("https://makerworld.com/models/") + id;
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_put_model_mall_rating(void* /*agent*/,
int /*rating_id*/, int /*score*/,
std::string /*content*/,
std::vector<std::string> /*images*/,
unsigned int& http_code,
std::string& http_error)
{
http_code = 0;
http_error.clear();
return BAMBU_NETWORK_ERR_INVALID_RESULT;
}
OBN_ABI int bambu_network_get_oss_config(void* /*agent*/,
std::string& config,
std::string /*country_code*/,
unsigned int& http_code,
std::string& http_error)
{
config.clear();
http_code = 0;
http_error.clear();
return BAMBU_NETWORK_ERR_INVALID_RESULT;
}
OBN_ABI int bambu_network_put_rating_picture_oss(void* /*agent*/,
std::string& /*config*/,
std::string& pic_oss_path,
std::string /*model_id*/,
int /*profile_id*/,
unsigned int& http_code,
std::string& http_error)
{
pic_oss_path.clear();
http_code = 0;
http_error.clear();
return BAMBU_NETWORK_ERR_INVALID_RESULT;
}
OBN_ABI int bambu_network_get_model_mall_rating(void* /*agent*/,
int /*job_id*/,
std::string& rating_result,
unsigned int& http_code,
std::string& http_error)
{
rating_result.clear();
http_code = 0;
http_error.clear();
return BAMBU_NETWORK_ERR_INVALID_RESULT;
}
OBN_ABI int bambu_network_get_mw_user_preference(void* /*agent*/,
std::function<void(std::string)> cb)
{
// CRITICAL: Studio expects a JSON with a numeric `recommendStatus`
// field. It reads it as `int nRecommendStatus = jPrefer["recommendStatus"]`
// inside a CallAfter lambda (WebViewDialog.cpp, SendDesignStaffpick).
// If the field is missing, nlohmann::json converts null -> int and
// throws type_error, which propagates out of the queued lambda
// (past Studio's outer try/catch) and aborts the whole process via
// wxApp::OnUnhandledException. We answer with 0 so Studio takes the
// "default staff pick" branch and never looks at a null.
if (cb) cb("{\"recommendStatus\":0}");
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_get_mw_user_4ulist(void* /*agent*/,
int /*seed*/, int /*limit*/,
std::function<void(std::string)> cb)
{
if (cb) cb("{\"list\":[],\"total\":0}");
return BAMBU_NETWORK_SUCCESS;
}
// -----------------------------------------------------------------------
// Additional symbols exported by the real plugin. Bambu Studio's current
// NetworkAgent.cpp does not resolve them, but newer Studio builds might; we
// export them as no-ops to stay binary-compatible.
// -----------------------------------------------------------------------
OBN_ABI int bambu_network_check_user_report(void* /*agent*/, int* /*id*/, bool* printable)
{
if (printable) *printable = false;
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_del_rating_picture_oss(void* /*agent*/,
std::string& /*config*/,
std::string& pic_oss_path,
std::string /*model_id*/,
int /*profile_id*/,
unsigned int& http_code,
std::string& http_error)
{
pic_oss_path.clear();
http_code = 0;
http_error.clear();
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_get_model_instance_id(void* /*agent*/,
std::string /*model_id*/,
std::string* instance_id,
unsigned int& http_code,
std::string& http_error)
{
if (instance_id) instance_id->clear();
http_code = 0;
http_error.clear();
return BAMBU_NETWORK_ERR_GET_INSTANCE_ID_FAILED;
}
OBN_ABI int bambu_network_get_model_rating_id(void* /*agent*/,
std::string /*model_id*/,
int /*profile_id*/,
int* rating_id,
unsigned int& http_code,
std::string& http_error)
{
if (rating_id) *rating_id = 0;
http_code = 0;
http_error.clear();
return BAMBU_NETWORK_ERR_GET_RATING_ID_FAILED;
}