Skip to content

Commit

Permalink
fix Mobsya#811 by calling only once update_discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bonani committed Oct 13, 2020
1 parent 43189ea commit 689a1d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions aseba/thymio-device-manager/aseba_node_registery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ aseba_node_registery::node_map aseba_node_registery::nodes() const {

void aseba_node_registery::set_tcp_endpoint(const boost::asio::ip::tcp::endpoint& endpoint) {
m_nodes_service_desc.endpoint(endpoint);
update_discovery();
}

void aseba_node_registery::set_ws_endpoint(const boost::asio::ip::tcp::endpoint& endpoint) {
m_ws_endpoint = endpoint;
}

void aseba_node_registery::set_discovery() {
update_discovery();
}

Expand All @@ -134,10 +136,12 @@ void aseba_node_registery::update_discovery() {
void aseba_node_registery::on_update_discovery_complete(const boost::system::error_code& ec) {
if(ec) {
mLogError("Discovery : {}", ec.message());
m_discovery_needs_update = true;
} else {
mLogTrace("Discovery : update complete");
m_updating_discovery = false;
}
m_updating_discovery = false;
if(m_discovery_needs_update) {
boost::asio::post(boost::asio::get_associated_executor(this),
boost::bind(&aseba_node_registery::update_discovery, this));
Expand Down
1 change: 1 addition & 0 deletions aseba/thymio-device-manager/aseba_node_registery.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class aseba_node_registery : public boost::asio::detail::service_base<aseba_node

void set_tcp_endpoint(const boost::asio::ip::tcp::endpoint& endpoint);
void set_ws_endpoint(const boost::asio::ip::tcp::endpoint& endpoint);
void set_discovery();

node_map nodes() const;
std::shared_ptr<aseba_node> node_from_id(const node_id&) const;
Expand Down
6 changes: 5 additions & 1 deletion aseba/thymio-device-manager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ void run_service(boost::asio::io_context& ctx) {

// Create a server for websocket
mobsya::application_server<mobsya::websocket_t> websocket_server(ctx, 8597);
node_registery.set_ws_endpoint(websocket_server.endpoint());
websocket_server.accept();
node_registery.set_ws_endpoint(websocket_server.endpoint());

// Enable Bonjour, Zeroconf
node_registery.set_discovery();


#ifdef MOBSYA_TDM_ENABLE_USB
mobsya::usb_server usb_server(ctx, {mobsya::THYMIO2_DEVICE_ID, mobsya::THYMIO_WIRELESS_DEVICE_ID});
Expand Down

0 comments on commit 689a1d6

Please sign in to comment.