forked from ClusterM/open-bamboo-networking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabi_cloud.cpp
More file actions
99 lines (86 loc) · 3.53 KB
/
abi_cloud.cpp
File metadata and controls
99 lines (86 loc) · 3.53 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
#include <string>
#include <vector>
#include "obn/abi_export.hpp"
#include "obn/agent.hpp"
#include "obn/bambu_networking.hpp"
#include "obn/log.hpp"
using obn::as_agent;
// Server connectivity -------------------------------------------------------
OBN_ABI int bambu_network_connect_server(void* agent)
{
auto* a = as_agent(agent);
if (!a) return BAMBU_NETWORK_ERR_INVALID_HANDLE;
int rc = a->connect_cloud();
OBN_INFO("bambu_network_connect_server -> %d", rc);
return rc;
}
OBN_ABI bool bambu_network_is_server_connected(void* agent)
{
auto* a = as_agent(agent);
if (!a) return false;
return a->cloud_connected();
}
OBN_ABI int bambu_network_refresh_connection(void* agent)
{
auto* a = as_agent(agent);
if (!a) return BAMBU_NETWORK_ERR_INVALID_HANDLE;
// Called on Studio's ~1Hz device refresh timer - keep it quiet in
// the log and let the agent decide whether a real reconnect is
// needed.
OBN_DEBUG("bambu_network_refresh_connection");
return a->cloud_refresh();
}
// Topic subscriptions -------------------------------------------------------
// Studio calls start_subscribe("app") / stop_subscribe("app") from its
// IDLE hook to tell the cloud "the Studio window is focused / blurred".
// On Bambu's side this is a keepalive-ish hint that influences how
// aggressively the broker streams pushes; it's not tied to any
// specific MQTT topic. We just log it and move on.
OBN_ABI int bambu_network_start_subscribe(void* /*agent*/, std::string module)
{
OBN_DEBUG("bambu_network_start_subscribe(%s) [no-op]", module.c_str());
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_stop_subscribe(void* /*agent*/, std::string module)
{
OBN_DEBUG("bambu_network_stop_subscribe(%s) [no-op]", module.c_str());
return BAMBU_NETWORK_SUCCESS;
}
OBN_ABI int bambu_network_add_subscribe(void* agent, std::vector<std::string> dev_list)
{
auto* a = as_agent(agent);
if (!a) return BAMBU_NETWORK_ERR_INVALID_HANDLE;
OBN_INFO("bambu_network_add_subscribe(%zu devs)", dev_list.size());
return a->cloud_add_subscribe(dev_list);
}
OBN_ABI int bambu_network_del_subscribe(void* agent, std::vector<std::string> dev_list)
{
auto* a = as_agent(agent);
if (!a) return BAMBU_NETWORK_ERR_INVALID_HANDLE;
OBN_INFO("bambu_network_del_subscribe(%zu devs)", dev_list.size());
return a->cloud_del_subscribe(dev_list);
}
OBN_ABI void bambu_network_enable_multi_machine(void* /*agent*/, bool /*enable*/)
{
// Multi-machine mode only controls whether Studio shows the multi-
// device UI. No extra state on the plugin side.
}
// Send a command to a specific device. Studio invokes this from the
// device control path without knowing which transport is live (LAN
// direct vs cloud tunnel). Prefer the LAN session when it matches the
// target dev_id; otherwise route through cloud MQTT.
OBN_ABI int bambu_network_send_message(void* agent,
std::string dev_id,
std::string json_str,
int qos,
int /*flag*/)
{
auto* a = as_agent(agent);
if (!a) return BAMBU_NETWORK_ERR_INVALID_HANDLE;
// Try LAN first: send_message_to_printer returns INVALID_HANDLE
// when no LAN session matches the dev_id, in which case we fall
// through to cloud.
int rc = a->send_message_to_printer(dev_id, json_str, qos);
if (rc != BAMBU_NETWORK_ERR_INVALID_HANDLE) return rc;
return a->cloud_send_message(dev_id, json_str, qos);
}