Share the web workflow MDNS object with the user

Fixes #7369
This commit is contained in:
Scott Shawcroft 2023-01-11 16:05:19 -08:00
parent 75241c466a
commit ca80f30348
No known key found for this signature in database
GPG Key ID: 0DFD512649C052DA
3 changed files with 24 additions and 0 deletions

View File

@ -33,6 +33,10 @@
#include "shared-bindings/mdns/Server.h" #include "shared-bindings/mdns/Server.h"
#include "shared-bindings/util.h" #include "shared-bindings/util.h"
#if CIRCUITPY_WEB_WORKFLOW
#include "supervisor/shared/web_workflow/web_workflow.h"
#endif
//| class Server: //| class Server:
//| """The MDNS Server responds to queries for this device's information and allows for querying //| """The MDNS Server responds to queries for this device's information and allows for querying
//| other devices.""" //| other devices."""
@ -53,6 +57,13 @@ STATIC mp_obj_t mdns_server_make_new(const mp_obj_type_t *type, size_t n_args, s
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
#if CIRCUITPY_WEB_WORKFLOW
mdns_server_obj_t *web_workflow_mdns = supervisor_web_workflow_mdns(args[ARG_network_interface].u_obj);
if (web_workflow_mdns != NULL) {
return web_workflow_mdns;
}
#endif
mdns_server_obj_t *self = m_new_obj(mdns_server_obj_t); mdns_server_obj_t *self = m_new_obj(mdns_server_obj_t);
self->base.type = &mdns_server_type; self->base.type = &mdns_server_type;
common_hal_mdns_server_construct(self, args[ARG_network_interface].u_obj); common_hal_mdns_server_construct(self, args[ARG_network_interface].u_obj);

View File

@ -200,6 +200,15 @@ STATIC void _update_encoded_ip(void) {
} }
} }
mdns_server_obj_t *supervisor_web_workflow_mdns(mp_obj_t network_interface) {
#if CIRCUITPY_MDNS
if (network_interface == &common_hal_wifi_radio_obj) {
return &mdns;
}
#endif
return NULL;
}
#if CIRCUITPY_STATUS_BAR #if CIRCUITPY_STATUS_BAR
bool supervisor_web_workflow_status_dirty(void) { bool supervisor_web_workflow_status_dirty(void) {
return common_hal_wifi_radio_get_enabled(&common_hal_wifi_radio_obj) != _last_enabled || return common_hal_wifi_radio_get_enabled(&common_hal_wifi_radio_obj) != _last_enabled ||

View File

@ -28,6 +28,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "shared-bindings/mdns/Server.h"
#include "shared-bindings/socketpool/Socket.h" #include "shared-bindings/socketpool/Socket.h"
// This background function should be called repeatedly. It cannot be done based // This background function should be called repeatedly. It cannot be done based
@ -38,5 +39,8 @@ void supervisor_web_workflow_status(void);
void supervisor_start_web_workflow(void); void supervisor_start_web_workflow(void);
void supervisor_stop_web_workflow(void); void supervisor_stop_web_workflow(void);
// Share the MDNS object with user code.
mdns_server_obj_t *supervisor_web_workflow_mdns(mp_obj_t network_interface);
// To share with websocket. // To share with websocket.
void web_workflow_send_raw(socketpool_socket_obj_t *socket, const uint8_t *buf, int len); void web_workflow_send_raw(socketpool_socket_obj_t *socket, const uint8_t *buf, int len);