Skip to content

Commit

Permalink
* use a new api to catch SIGINT
Browse files Browse the repository at this point in the history
  • Loading branch information
lxowalle committed May 30, 2024
1 parent e527dbd commit 31cc350
Show file tree
Hide file tree
Showing 31 changed files with 66 additions and 63 deletions.
7 changes: 4 additions & 3 deletions components/basic/port/linux/maix_sys_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ namespace maix::sys
{
static void signal_handle(int signal)
{
const char *signal_msg = NULL;
switch (signal) {
case SIGINT:
maix::app::set_exit_flag(true);
#if CONFIG_BUILD_WITH_MAIXPY
raise(SIGINT);
#endif
break;
default: signal_msg = "UNKNOWN"; break;
default: break;
}
}

void register_default_signal_handle() {
signal(SIGILL, signal_handle);
signal(SIGINT, signal_handle);
}
}
7 changes: 4 additions & 3 deletions components/basic/port/maixcam/maix_sys_maixcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ namespace maix::sys
{
static void signal_handle(int signal)
{
const char *signal_msg = NULL;
switch (signal) {
case SIGINT:
maix::app::set_exit_flag(true);
#if CONFIG_BUILD_WITH_MAIXPY
raise(SIGINT);
#endif
break;
default: signal_msg = "UNKNOWN"; break;
default: break;
}
}

void register_default_signal_handle() {
signal(SIGILL, signal_handle);
signal(SIGINT, signal_handle);
}
}
3 changes: 2 additions & 1 deletion components/vision/port/linux/maix_rtmp_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "maix_rtmp.hpp"

namespace maix::rtmp {
Rtmp::Rtmp(std::string host, int port, std::string app, std::string stream) {
Rtmp::Rtmp(std::string host, int port, std::string app, std::string stream, int bitrate) {
_host = host;
_port = port;
_app = app;
_stream = stream;
_bitrate = bitrate;
}

Rtmp::~Rtmp() {
Expand Down
4 changes: 2 additions & 2 deletions examples/audio_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/camera_display/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ static int cmd_loop(camera::Camera *cam)

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/comm_protocol/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/comm_uart/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/gui_lvgl/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/gui_simple/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/hello_world/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/i18n/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/image_method/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5368,8 +5368,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/image_show/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/jpg_stream_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ std::string html =

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/key_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/nn_classifier/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/nn_runner/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/opencv_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ int _main(int argc, char *argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/peripheral_gpio/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/peripheral_i2c_eeprom/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/peripheral_pwm_servo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/rtmp_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/rtsp_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/video_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/video_record_mp4/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/websocket_client/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ int _main(int argc, char* argv[]) {

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/websocket_server/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ int _main(int argc, char* argv[]) {

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions examples/wifi_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions test/cvi_tpu_demo/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ int _main(int argc, char **argv) {

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions test/cvi_tpu_matmul/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ int _main(int argc, char **argv) {

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down
4 changes: 2 additions & 2 deletions tools/project_template/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ int _main(int argc, char* argv[])

int main(int argc, char* argv[])
{
// Catch SIGINT signal(e.g. Ctrl + C), and set exit flag to true.
signal(SIGINT, [](int sig){ app::set_exit_flag(true); });
// Catch signal and process
sys::register_default_signal_handle();

// Use CATCH_EXCEPTION_RUN_RETURN to catch exception,
// if we don't catch exception, when program throw exception, the objects will not be destructed.
Expand Down

0 comments on commit 31cc350

Please sign in to comment.