mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 02:41:58 +08:00
New connect endpoint slicer/status replacing slicer/printers
move enum value to if 0
This commit is contained in:
parent
9619999c70
commit
7ad9431e3a
@ -192,41 +192,54 @@ bool UserAccount::on_connect_printers_success(const std::string& data, AppConfig
|
||||
return false;
|
||||
}
|
||||
// fill m_printer_map with data from ptree
|
||||
// tree string is in format {"printers": [{..}, {..}]}
|
||||
// tree string is in format {"result": [{"printer_type": "1.2.3", "states": [{"printer_state": "OFFLINE", "count": 1}, ...]}, {..}]}
|
||||
|
||||
ConnectPrinterStateMap new_printer_map;
|
||||
|
||||
assert(ptree.front().first == "printers");
|
||||
assert(ptree.front().first == "result");
|
||||
for (const auto& printer_tree : ptree.front().second) {
|
||||
// printer_tree is {"printer_type": "1.2.3", "states": [..]}
|
||||
std::string name;
|
||||
ConnectPrinterState state;
|
||||
std::string type_string = parse_tree_for_param(printer_tree.second, "printer_type");
|
||||
std::string state_string = parse_tree_for_param(printer_tree.second, "connect_state");
|
||||
|
||||
assert(!type_string.empty());
|
||||
assert(!state_string.empty());
|
||||
if (type_string.empty() || state_string.empty())
|
||||
const auto type_opt = printer_tree.second.get_optional<std::string>("printer_type");
|
||||
if (!type_opt) {
|
||||
continue;
|
||||
// name of printer needs to be taken from translate table, if missing
|
||||
if (auto pair = printer_type_and_name_table.find(type_string); pair != printer_type_and_name_table.end()) {
|
||||
}
|
||||
|
||||
if (auto pair = printer_type_and_name_table.find(*type_opt); pair != printer_type_and_name_table.end()) {
|
||||
name = pair->second;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
assert(true); // On this assert, printer_type_and_name_table needs to be updated with type_string and correct printer name
|
||||
continue;
|
||||
}
|
||||
// translate state string to enum value
|
||||
if (auto pair = printer_state_table.find(state_string); pair != printer_state_table.end()) {
|
||||
state = pair->second;
|
||||
} else {
|
||||
assert(true); // On this assert, printer_state_table and ConnectPrinterState needs to be updated
|
||||
continue;
|
||||
// printer should not appear twice
|
||||
assert(new_printer_map.find(name) == new_printer_map.end());
|
||||
// prepare all states on 0
|
||||
new_printer_map[name].reserve(static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT));
|
||||
for (size_t i = 0; i < static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT); i++) {
|
||||
new_printer_map[name].push_back(0);
|
||||
}
|
||||
if (auto counter = new_printer_map.find(name); counter != new_printer_map.end()) {
|
||||
new_printer_map[name][static_cast<size_t>(state)]++;
|
||||
} else {
|
||||
new_printer_map[name].reserve(static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT));
|
||||
for (size_t i = 0; i < static_cast<size_t>(ConnectPrinterState::CONNECT_PRINTER_STATE_COUNT); i++) {
|
||||
new_printer_map[name].push_back(i == static_cast<size_t>(state) ? 1 : 0);
|
||||
|
||||
for (const auto& section : printer_tree.second) {
|
||||
// section is "printer_type": "1.2.3" OR "states": [..]}
|
||||
if (section.first == "states") {
|
||||
for (const auto& subsection : section.second) {
|
||||
// subsection is {"printer_state": "OFFLINE", "count": 1}
|
||||
const auto state_opt = subsection.second.get_optional<std::string>("printer_state");
|
||||
const auto count_opt = subsection.second.get_optional<int>("count");
|
||||
if (!state_opt || ! count_opt) {
|
||||
continue;
|
||||
}
|
||||
if (auto pair = printer_state_table.find(*state_opt); pair != printer_state_table.end()) {
|
||||
state = pair->second;
|
||||
} else {
|
||||
assert(true); // On this assert, printer_state_table needs to be updated with *state_opt and correct ConnectPrinterState
|
||||
continue;
|
||||
}
|
||||
new_printer_map[name][static_cast<size_t>(state)] = *count_opt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ void UserAccountCommunication::enqueue_connect_printers_action()
|
||||
BOOST_LOG_TRIVIAL(error) << "Connect Printers endpoint connection failed - Not Logged in.";
|
||||
return;
|
||||
}
|
||||
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS, nullptr, nullptr, {});
|
||||
m_session->enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS, nullptr, nullptr, {});
|
||||
}
|
||||
wakeup_session_thread();
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void UserAccountSession::process_action_queue()
|
||||
if (m_priority_action_queue.empty() && m_action_queue.empty()) {
|
||||
// update printers periodically
|
||||
if (m_polling_enabled) {
|
||||
enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS, nullptr, nullptr, {});
|
||||
enqueue_action(UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS, nullptr, nullptr, {});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -40,9 +40,10 @@ enum class UserAccountActionID {
|
||||
USER_ACCOUNT_ACTION_USER_ID,
|
||||
USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN,
|
||||
USER_ACCOUNT_ACTION_TEST_CONNECTION,
|
||||
USER_ACCOUNT_ACTION_CONNECT_PRINTERS,
|
||||
USER_ACCOUNT_ACTION_CONNECT_STATUS, // status of all printers
|
||||
USER_ACCOUNT_ACTION_AVATAR,
|
||||
#if 0
|
||||
USER_ACCOUNT_ACTION_CONNECT_PRINTERS, // all info about all printers
|
||||
USER_ACCOUNT_ACTION_CONNECT_USER_DATA,
|
||||
USER_ACCOUNT_ACTION_CONNECT_DUMMY,
|
||||
#endif // 0
|
||||
@ -117,11 +118,12 @@ public:
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID] = std::make_unique<UserActionGetWithEvent>("USER_ID", "https://test-account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN] = std::make_unique<UserActionGetWithEvent>("TEST_ACCESS_TOKEN", "https://test-account.prusa3d.com/api/v1/me/", EVT_UA_ID_USER_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION] = std::make_unique<UserActionGetWithEvent>("TEST_CONNECTION", "https://test-account.prusa3d.com/api/v1/me/", wxEVT_NULL, EVT_UA_RESET);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS] = std::make_unique<UserActionGetWithEvent>("CONNECT_PRINTERS", "https://dev.connect.prusa3d.com/slicer/printers", EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS] = std::make_unique<UserActionGetWithEvent>("CONNECT_STATUS", "https://dev.connect.prusa3d.com/slicer/status", EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR] = std::make_unique<UserActionGetWithEvent>("AVATAR", "https://test-media.printables.com/media/", EVT_UA_AVATAR_SUCCESS, EVT_UA_FAIL);
|
||||
#if 0
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_USER_DATA] = std::make_unique<UserActionGetWithEvent>("CONNECT_USER_DATA", "https://dev.connect.prusa3d.com/app/login", EVT_UA_CONNECT_USER_DATA_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DUMMY] = std::make_unique<UserActionGetWithEvent>("CONNECT_DUMMY", "https://dev.connect.prusa3d.com/slicer/dummy", EVT_UA_SUCCESS, EVT_UA_FAIL);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS] = std::make_unique<UserActionGetWithEvent>("CONNECT_PRINTERS", "https://dev.connect.prusa3d.com/slicer/printers", EVT_UA_PRUSACONNECT_PRINTERS_SUCCESS, EVT_UA_FAIL);
|
||||
#endif // 0
|
||||
|
||||
}
|
||||
@ -133,11 +135,13 @@ public:
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_USER_ID].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_ACCESS_TOKEN].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_TEST_CONNECTION].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_STATUS].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_AVATAR].reset(nullptr);
|
||||
#if 0
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_USER_DATA].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_DUMMY].reset(nullptr);
|
||||
m_actions[UserAccountActionID::USER_ACCOUNT_ACTION_CONNECT_PRINTERS].reset(nullptr);
|
||||
|
||||
#endif // 0
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user