Cross-thread UI signalling.
authorCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 18:49:14 +0000 (19:49 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 24 Oct 2012 18:49:14 +0000 (19:49 +0100)
src/lib/film.cc
src/lib/ui_signaller.cc [new file with mode: 0644]
src/lib/ui_signaller.h [new file with mode: 0644]
src/lib/wscript
src/tools/dvdomatic.cc
src/wx/wscript
src/wx/wx_ui_signaller.cc [new file with mode: 0644]
src/wx/wx_ui_signaller.h [new file with mode: 0644]

index 7ce56138aabb6a05c75abfd41f15de7809b770c9..b76f9df7174f84d8fe8da13da9302c1e05eecdac 100644 (file)
@@ -51,6 +51,7 @@
 #include "config.h"
 #include "check_hashes_job.h"
 #include "version.h"
+#include "ui_signaller.h"
 
 using namespace std;
 using namespace boost;
@@ -1190,7 +1191,7 @@ void
 Film::signal_changed (Property p)
 {
        _dirty = true;
-       Changed (p);
+       ui_signaller->emit (boost::bind (boost::ref (Changed), p));
 }
 
 int
diff --git a/src/lib/ui_signaller.cc b/src/lib/ui_signaller.cc
new file mode 100644 (file)
index 0000000..4f39a61
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "ui_signaller.h"
+
+UISignaller* ui_signaller = 0;
+
diff --git a/src/lib/ui_signaller.h b/src/lib/ui_signaller.h
new file mode 100644 (file)
index 0000000..6b0e73c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef DVDOMATIC_UI_SIGNALLER_H
+#define DVDOMATIC_UI_SIGNALLER_H
+
+#include <boost/bind.hpp>
+#include <boost/asio.hpp>
+
+class UISignaller
+{
+public:
+       UISignaller ()
+               : _work (_service)
+       {}
+       
+       template <class S>
+       void emit (S signal) {
+               _service.post (boost::bind (boost::ref (signal)));
+       }
+
+       void ui_idle () {
+               _service.poll ();
+       }
+
+       virtual void wake_ui () = 0;
+
+private:
+       boost::asio::io_service _service;
+       boost::asio::io_service::work _work;
+};
+
+extern UISignaller* ui_signaller;
+
+#endif
index af8b4b7d39e9f4c4306a8a4a73e86d68efc890af..4f1fa06364a3d9896576beee0ed5770082deb08d 100644 (file)
@@ -48,6 +48,7 @@ def build(bld):
                  timer.cc
                 transcode_job.cc
                 transcoder.cc
+                 ui_signaller.cc
                 util.cc
                 version.cc
                 """
index 5bc8b93fbfd21a37d624a9d48aa0cc210c390356..4e3006c57cd74d7a7d64fbf0c34e4cddc17ba748 100644 (file)
@@ -31,6 +31,7 @@
 #include "wx/wx_util.h"
 #include "wx/new_film_dialog.h"
 #include "wx/properties_dialog.h"
+#include "wx/wx_ui_signaller.h"
 #include "lib/film.h"
 #include "lib/format.h"
 #include "lib/config.h"
@@ -39,6 +40,7 @@
 #include "lib/scaler.h"
 #include "lib/exceptions.h"
 #include "lib/version.h"
+#include "lib/ui_signaller.h"
 
 using namespace std;
 using namespace boost;
@@ -381,8 +383,17 @@ class App : public wxApp
                SetTopWindow (f);
                f->Maximize ();
                f->Show ();
+
+               ui_signaller = new wxUISignaller (this);
+               this->Connect (-1, wxEVT_IDLE, wxIdleEventHandler (App::idle));
+
                return true;
        }
+
+       void idle (wxIdleEvent &)
+       {
+               ui_signaller->ui_idle ();
+       }
 };
 
 IMPLEMENT_APP (App)
index df2edbde1b31a14196735de7bdf030051dca67df..41514c5b1ba22433c6eee0c3734fdd67463c9cdf 100644 (file)
@@ -24,6 +24,7 @@ def build(bld):
                  properties_dialog.cc
                  server_dialog.cc
                  wx_util.cc
+                 wx_ui_signaller.cc
                  """
 
 #                 alignment.cc
diff --git a/src/wx/wx_ui_signaller.cc b/src/wx/wx_ui_signaller.cc
new file mode 100644 (file)
index 0000000..2e926ed
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <wx/wx.h>
+#include "wx_ui_signaller.h"
+
+wxUISignaller::wxUISignaller (wxEvtHandler* h)
+       : _handler (h)
+{
+
+}
+
+void
+wxUISignaller::wake_ui ()
+{
+        wxCommandEvent event (-1, -1);
+        _handler->AddPendingEvent (event);
+}
diff --git a/src/wx/wx_ui_signaller.h b/src/wx/wx_ui_signaller.h
new file mode 100644 (file)
index 0000000..d134d2b
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "ui_signaller.h"
+
+class wxEvtHandler;
+
+class wxUISignaller : public UISignaller
+{
+public:
+       wxUISignaller (wxEvtHandler *);
+       void wake_ui ();
+
+private:
+       wxEvtHandler* _handler;
+};