Handle exceptions thrown from ServerFinder.
authorCarl Hetherington <cth@carlh.net>
Mon, 30 Dec 2013 23:10:49 +0000 (23:10 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 30 Dec 2013 23:10:49 +0000 (23:10 +0000)
src/lib/server_finder.cc
src/lib/server_finder.h
src/tools/dcpomatic.cc

index de90e0d5c1380ee85d6429bf8c591f94c9f95dc6..5b67d8048dc197a98d91213c4c0070de61f75d02 100644 (file)
@@ -47,6 +47,7 @@ ServerFinder::ServerFinder ()
 
 void
 ServerFinder::broadcast_thread ()
+try
 {
        boost::system::error_code error;
        boost::asio::io_service io_service;
@@ -88,9 +89,14 @@ ServerFinder::broadcast_thread ()
                dcpomatic_sleep (10);
        }
 }
+catch (...)
+{
+       store_current ();
+}
 
 void
 ServerFinder::listen_thread ()
+try
 {
        while (1) {
                shared_ptr<Socket> sock (new Socket (10));
@@ -117,6 +123,10 @@ ServerFinder::listen_thread ()
                }
        }
 }
+catch (...)
+{
+       store_current ();
+}
 
 bool
 ServerFinder::server_found (string ip) const
index 01e26f7dfee1aa3a7c432d8ba9c68c9d4e777057..202bee8f920d9610bd82c50b6951ea701199ed25 100644 (file)
@@ -20,7 +20,7 @@
 #include <boost/signals2.hpp>
 #include "server.h"
 
-class ServerFinder
+class ServerFinder : public ExceptionStore
 {
 public:
        void connect (boost::function<void (ServerDescription)>);
index 66f795ddf4a10de1d38edc6e771809e301650045..891c4623ca9b6e1ea1ac995d41108d119468e72f 100644 (file)
@@ -54,6 +54,7 @@
 #include "lib/cinema.h"
 #include "lib/kdm.h"
 #include "lib/send_kdm_email_job.h"
+#include "lib/server_finder.h"
 
 using std::cout;
 using std::string;
@@ -632,8 +633,12 @@ class App : public wxApp
                f->Show ();
 
                ui_signaller = new wxUISignaller (this);
-               this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
+               Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
 
+               Bind (wxEVT_TIMER, boost::bind (&App::check, this));
+               _timer.reset (new wxTimer (this));
+               _timer->Start (1000);
+               
                return true;
        }
        catch (exception& e)
@@ -670,6 +675,17 @@ class App : public wxApp
        {
                ui_signaller->ui_idle ();
        }
+
+       void check ()
+       {
+               try {
+                       ServerFinder::instance()->rethrow ();
+               } catch (exception& e) {
+                       error_dialog (0, std_to_wx (e.what ()));
+               }
+       }
+
+       shared_ptr<wxTimer> _timer;
 };
 
 IMPLEMENT_APP (App)