Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: don't exit too early #2478

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions examples/start_stop_server/start_stop_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

#include <mavsdk/mavsdk.h>
#include <mavsdk/mavsdk_server/mavsdk_server_api.h>
#include <atomic>
#include <iostream>
#include <chrono>
#include <csignal>
#include <thread>

using namespace mavsdk;

static struct MavsdkServer* mavsdk_server;
static std::atomic<bool> _should_stop{false};

void signal_handler(int sig)
{
std::cout << "Received signal " << sig << std::endl;

mavsdk_server_stop(mavsdk_server);
_should_stop.store(true);
}

int main(int argc, char* argv[])
Expand All @@ -27,9 +29,18 @@ int main(int argc, char* argv[])

signal(SIGINT, signal_handler);

MavsdkServer* mavsdk_server;

mavsdk_server_init(&mavsdk_server);

// This returns when a system has been discovered.
mavsdk_server_run(mavsdk_server, argv[1], 50051);

while (!_should_stop.load()) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}

mavsdk_server_stop(mavsdk_server);
mavsdk_server_destroy(mavsdk_server);

return 0;
Expand Down
Loading