X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Ftools%2Fdcpomatic_server.cc;h=9158a897ee4aa8a1fd5bd0d10f887c263a6abaa5;hb=3155b285e8260329a835de8c057f4a4cc9a5dcbd;hp=152e063c1e59104b78d5f280bdfa0a3973e4b3df;hpb=237a0052c60af768f4d62b00321932918b7ba4d9;p=dcpomatic.git diff --git a/src/tools/dcpomatic_server.cc b/src/tools/dcpomatic_server.cc index 152e063c1..9158a897e 100644 --- a/src/tools/dcpomatic_server.cc +++ b/src/tools/dcpomatic_server.cc @@ -20,13 +20,14 @@ #include #include #include -#include "wx_util.h" +#include "wx/wx_util.h" #include "lib/util.h" #include "lib/server.h" #include "lib/config.h" using std::cout; using std::string; +using std::exception; using boost::shared_ptr; using boost::thread; using boost::bind; @@ -46,6 +47,14 @@ public: return _log; } + string head_and_tail (int amount = 1024) const { + if (int (_log.size ()) < (2 * amount)) { + return _log; + } + + return _log.substr (0, amount) + _log.substr (_log.size() - amount - 1, amount); + } + private: void do_log (string m) { @@ -73,12 +82,12 @@ public: SetSizer (_sizer); _sizer->Layout (); - Connect (ID_timer, wxEVT_TIMER, wxTimerEventHandler (StatusDialog::update)); + Bind (wxEVT_TIMER, boost::bind (&StatusDialog::update, this), ID_timer); _timer.Start (1000); } private: - void update (wxTimerEvent &) + void update () { _text->ChangeValue (std_to_wx (memory_log->get ())); _sizer->Layout (); @@ -102,11 +111,14 @@ public: wxBitmap bitmap (wxString::Format (wxT ("%s/taskbar_icon.png"), POSIX_ICON_PREFIX), wxBITMAP_TYPE_PNG); wxIcon icon; icon.CopyFromBitmap (bitmap); -#endif +#endif +#ifndef __WXOSX__ + /* XXX: fix this for OS X */ SetIcon (icon, std_to_wx ("DCP-o-matic encode server")); +#endif - Connect (ID_status, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (TaskBarIcon::status)); - Connect (ID_quit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler (TaskBarIcon::quit)); + Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&TaskBarIcon::status, this), ID_status); + Bind (wxEVT_COMMAND_MENU_SELECTED, boost::bind (&TaskBarIcon::quit, this), ID_quit); } wxMenu* CreatePopupMenu () @@ -118,19 +130,19 @@ public: } private: - void status (wxCommandEvent &) + void status () { StatusDialog* d = new StatusDialog; d->Show (); } - void quit (wxCommandEvent &) + void quit () { wxTheApp->ExitMainLoop (); } }; -class App : public wxApp +class App : public wxApp, public ExceptionStore { public: App () @@ -151,6 +163,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; } @@ -162,13 +178,29 @@ private: } void main_thread () - { - Server server (memory_log); + 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)