From 245d3fc91d4d3e30de57b81351e98088500bf865 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 30 Dec 2013 22:49:08 +0000 Subject: [PATCH] Improve exception handling in dcpomatic_server. --- run/dcpomatic_server | 10 ++++++++++ run/dcpomatic_server_gui | 10 ---------- src/tools/dcpomatic_server.cc | 25 +++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100755 run/dcpomatic_server delete mode 100755 run/dcpomatic_server_gui diff --git a/run/dcpomatic_server b/run/dcpomatic_server new file mode 100755 index 000000000..5856221b3 --- /dev/null +++ b/run/dcpomatic_server @@ -0,0 +1,10 @@ +#!/bin/bash + +export LD_LIBRARY_PATH=build/src/lib:$LD_LIBRARY_PATH +if [ "$1" == "--debug" ]; then + gdb --args build/src/tools/dcpomatic_server +elif [ "$1" == "--valgrind" ]; then + valgrind --tool="memcheck" build/src/tools/dcpomatic_server +else + build/src/tools/dcpomatic_server +fi diff --git a/run/dcpomatic_server_gui b/run/dcpomatic_server_gui deleted file mode 100755 index b7b122e67..000000000 --- a/run/dcpomatic_server_gui +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -export LD_LIBRARY_PATH=build/src/lib:$LD_LIBRARY_PATH -if [ "$1" == "--debug" ]; then - gdb --args build/src/tools/dcpomatic_server_gui -elif [ "$1" == "--valgrind" ]; then - valgrind --tool="memcheck" build/src/tools/dcpomatic_server_gui -else - build/src/tools/dcpomatic_server_gui -fi diff --git a/src/tools/dcpomatic_server.cc b/src/tools/dcpomatic_server.cc index 8c6a29461..a82478dfd 100644 --- a/src/tools/dcpomatic_server.cc +++ b/src/tools/dcpomatic_server.cc @@ -27,6 +27,7 @@ using std::cout; using std::string; +using std::exception; using boost::shared_ptr; using boost::thread; using boost::bind; @@ -133,7 +134,7 @@ private: } }; -class App : public wxApp +class App : public wxApp, public ExceptionStore { public: App () @@ -154,6 +155,10 @@ private: _icon = new TaskBarIcon; _thread = new thread (bind (&App::main_thread, this)); + + Bind (wxEVT_TIMER, boost::bind (&App::check, this)); + _timer.reset (new wxTimer (this)); + _timer->Start (1000); return true; } @@ -165,13 +170,29 @@ private: } void main_thread () - { + try { Server server (memory_log, false); server.run (Config::instance()->num_local_encoding_threads ()); + } catch (...) { + store_current (); + } + + void check () + { + try { + rethrow (); + } catch (exception& e) { + error_dialog (0, std_to_wx (e.what ())); + wxTheApp->ExitMainLoop (); + } catch (...) { + error_dialog (0, _("An unknown error has occurred with the DCP-o-matic server.")); + wxTheApp->ExitMainLoop (); + } } boost::thread* _thread; TaskBarIcon* _icon; + shared_ptr _timer; }; IMPLEMENT_APP (App) -- 2.30.2