diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-24 19:49:14 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-24 19:49:14 +0100 |
| commit | 17830349b580b5933589f2b739671828b5cfc208 (patch) | |
| tree | 9b81623c16cf4d899458a87d32337c4b7b7b0e39 /src | |
| parent | bd8fa9a370f1739952c83107352baa08c79d095e (diff) | |
Cross-thread UI signalling.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/film.cc | 3 | ||||
| -rw-r--r-- | src/lib/ui_signaller.cc | 23 | ||||
| -rw-r--r-- | src/lib/ui_signaller.h | 51 | ||||
| -rw-r--r-- | src/lib/wscript | 1 | ||||
| -rw-r--r-- | src/tools/dvdomatic.cc | 11 | ||||
| -rw-r--r-- | src/wx/wscript | 1 | ||||
| -rw-r--r-- | src/wx/wx_ui_signaller.cc | 34 | ||||
| -rw-r--r-- | src/wx/wx_ui_signaller.h | 32 |
8 files changed, 155 insertions, 1 deletions
diff --git a/src/lib/film.cc b/src/lib/film.cc index 7ce56138a..b76f9df71 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -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 index 000000000..4f39a6187 --- /dev/null +++ b/src/lib/ui_signaller.cc @@ -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 index 000000000..6b0e73c60 --- /dev/null +++ b/src/lib/ui_signaller.h @@ -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 diff --git a/src/lib/wscript b/src/lib/wscript index af8b4b7d3..4f1fa0636 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -48,6 +48,7 @@ def build(bld): timer.cc transcode_job.cc transcoder.cc + ui_signaller.cc util.cc version.cc """ diff --git a/src/tools/dvdomatic.cc b/src/tools/dvdomatic.cc index 5bc8b93fb..4e3006c57 100644 --- a/src/tools/dvdomatic.cc +++ b/src/tools/dvdomatic.cc @@ -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) diff --git a/src/wx/wscript b/src/wx/wscript index df2edbde1..41514c5b1 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -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 index 000000000..2e926edc6 --- /dev/null +++ b/src/wx/wx_ui_signaller.cc @@ -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 index 000000000..d134d2b6d --- /dev/null +++ b/src/wx/wx_ui_signaller.h @@ -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; +}; |
