Merge 1.0
[dcpomatic.git] / src / tools / dcpomatic_server.cc
index 1bfc23ff9fb166f7565d335d47140d46ffd9db10..a82478dfdbd47fc3a9e27985bff669eddd8c678f 100644 (file)
@@ -27,6 +27,7 @@
 
 using std::cout;
 using std::string;
+using std::exception;
 using boost::shared_ptr;
 using boost::thread;
 using boost::bind;
@@ -73,12 +74,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 ();
@@ -108,8 +109,8 @@ public:
                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 ()
@@ -121,19 +122,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 ()
@@ -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 ()
-       {
-               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<wxTimer> _timer;
 };
 
 IMPLEMENT_APP (App)