Skip to content

Commit a7a1775

Browse files
dimonomidcesantabot
authored andcommitted
Get rid of mgos_hook in favor of mgos_event
PUBLISHED_FROM=906c4c550d5ac223c6495d5063d4f84739b22961
1 parent 99d8a7a commit a7a1775

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/mgos_mqtt.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include "common/mg_str.h"
1313
#include "common/platform.h"
1414
#include "common/queue.h"
15-
#include "mgos_hooks.h"
15+
#include "mgos_debug.h"
16+
#include "mgos_event.h"
1617
#include "mgos_mdns.h"
1718
#include "mgos_mongoose.h"
1819
#include "mgos_net.h"
@@ -229,31 +230,29 @@ static void mgos_mqtt_net_ev(enum mgos_net_event ev,
229230
(void) arg;
230231
}
231232

232-
static void s_debug_write_hook(enum mgos_hook_type type,
233-
const struct mgos_hook_arg *arg,
234-
void *userdata) {
233+
static void s_debug_write_cb(int ev, void *ev_data, void *userdata) {
234+
struct mgos_debug_hook_arg *arg = (struct mgos_debug_hook_arg *) ev_data;
235235
const char *topic =
236-
(arg->debug.fd == 1
236+
(arg->fd == 1
237237
? mgos_sys_config_get_debug_stdout_topic()
238-
: arg->debug.fd == 2 ? mgos_sys_config_get_debug_stderr_topic()
239-
: NULL);
238+
: arg->fd == 2 ? mgos_sys_config_get_debug_stderr_topic() : NULL);
240239
if (topic != NULL &&
241240
mgos_mqtt_num_unsent_bytes() < MGOS_MQTT_LOG_PUSHBACK_THRESHOLD) {
242241
static uint32_t s_seq = 0;
243-
char *msg = arg->debug.buf;
242+
char *msg = arg->buf;
244243
int msg_len = mg_asprintf(
245244
&msg, MGOS_DEBUG_TMP_BUF_SIZE, "%s %u %.3lf %d|%.*s",
246245
(mgos_sys_config_get_device_id() ? mgos_sys_config_get_device_id()
247246
: "-"),
248-
s_seq, mg_time(), arg->debug.fd, (int) arg->debug.len, arg->debug.data);
249-
if (arg->debug.len > 0) {
247+
s_seq, mg_time(), arg->fd, (int) arg->len, arg->data);
248+
if (arg->len > 0) {
250249
mgos_mqtt_pub(topic, msg, msg_len, 0 /* qos */, false);
251250
s_seq++;
252251
}
253-
if (msg != arg->debug.buf) free(msg);
252+
if (msg != arg->buf) free(msg);
254253
}
255254

256-
(void) type;
255+
(void) ev;
257256
(void) userdata;
258257
}
259258

@@ -280,7 +279,7 @@ bool mgos_mqtt_init(void) {
280279

281280
mgos_mqtt_set_max_qos(mgos_sys_config_get_mqtt_max_qos());
282281

283-
mgos_hook_register(MGOS_HOOK_DEBUG_WRITE, s_debug_write_hook, NULL);
282+
mgos_event_add_handler(MGOS_EVENT_LOG, s_debug_write_cb, NULL);
284283

285284
return true;
286285
}

0 commit comments

Comments
 (0)