From 04bd447fd8960625bda5081cbac235b848d7631f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 13 May 2015 22:28:50 +0100 Subject: Rename UISignaller -> SignalManager. --- src/lib/content.cc | 1 - src/lib/job.cc | 1 - src/lib/job_manager.cc | 1 - src/lib/server_finder.cc | 1 - src/lib/signal_manager.cc | 23 ++++++++++ src/lib/signal_manager.h | 90 +++++++++++++++++++++++++++++++++++++ src/lib/signaller.h | 6 +-- src/lib/ui_signaller.cc | 24 ---------- src/lib/ui_signaller.h | 90 ------------------------------------- src/lib/update.cc | 1 - src/lib/wscript | 2 +- src/tools/dcpomatic.cc | 8 ++-- src/tools/dcpomatic_batch.cc | 6 +-- src/tools/dcpomatic_cli.cc | 4 +- src/tools/dcpomatic_create.cc | 10 ++--- src/wx/dolby_certificate_dialog.cc | 10 ++--- src/wx/doremi_certificate_dialog.cc | 4 +- src/wx/wscript | 2 +- src/wx/wx_signal_manager.cc | 34 ++++++++++++++ src/wx/wx_signal_manager.h | 36 +++++++++++++++ src/wx/wx_ui_signaller.cc | 34 -------------- src/wx/wx_ui_signaller.h | 36 --------------- 22 files changed, 209 insertions(+), 215 deletions(-) create mode 100644 src/lib/signal_manager.cc create mode 100644 src/lib/signal_manager.h delete mode 100644 src/lib/ui_signaller.cc delete mode 100644 src/lib/ui_signaller.h create mode 100644 src/wx/wx_signal_manager.cc create mode 100644 src/wx/wx_signal_manager.h delete mode 100644 src/wx/wx_ui_signaller.cc delete mode 100644 src/wx/wx_ui_signaller.h (limited to 'src') diff --git a/src/lib/content.cc b/src/lib/content.cc index b00ea3e57..b9e8367e1 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -24,7 +24,6 @@ #include "content.h" #include "util.h" #include "content_factory.h" -#include "ui_signaller.h" #include "exceptions.h" #include "film.h" #include "safe_stringstream.h" diff --git a/src/lib/job.cc b/src/lib/job.cc index f28146632..c4d93ddc1 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -27,7 +27,6 @@ #include "job.h" #include "util.h" #include "cross.h" -#include "ui_signaller.h" #include "exceptions.h" #include "film.h" #include "log.h" diff --git a/src/lib/job_manager.cc b/src/lib/job_manager.cc index 63db662d0..b5b64a77e 100644 --- a/src/lib/job_manager.cc +++ b/src/lib/job_manager.cc @@ -26,7 +26,6 @@ #include "job_manager.h" #include "job.h" #include "cross.h" -#include "ui_signaller.h" using std::string; using std::list; diff --git a/src/lib/server_finder.cc b/src/lib/server_finder.cc index 72a9a4ef5..b4b400b52 100644 --- a/src/lib/server_finder.cc +++ b/src/lib/server_finder.cc @@ -22,7 +22,6 @@ #include "util.h" #include "config.h" #include "cross.h" -#include "ui_signaller.h" #include "dcpomatic_socket.h" #include "raw_convert.h" #include diff --git a/src/lib/signal_manager.cc b/src/lib/signal_manager.cc new file mode 100644 index 000000000..7c2b3e11a --- /dev/null +++ b/src/lib/signal_manager.cc @@ -0,0 +1,23 @@ +/* + Copyright (C) 2012-2015 Carl Hetherington + + 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 "signal_manager.h" + +/** Global SignalManager instance */ +SignalManager* signal_manager = 0; diff --git a/src/lib/signal_manager.h b/src/lib/signal_manager.h new file mode 100644 index 000000000..ae4306e30 --- /dev/null +++ b/src/lib/signal_manager.h @@ -0,0 +1,90 @@ +/* + Copyright (C) 2012-2015 Carl Hetherington + + 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 DCPOMATIC_SIGNAL_MANAGER_H +#define DCPOMATIC_SIGNAL_MANAGER_H + +#include +#include +#include + +class Signaller; + +/** A class to allow signals to be emitted from non-UI threads and handled + * by a UI thread. + */ +class SignalManager : public boost::noncopyable +{ +public: + /** Create a SignalManager. Must be called from the UI thread */ + SignalManager () + : _work (_service) + { + _ui_thread = boost::this_thread::get_id (); + } + + /* Do something next time the UI is idle */ + template + void when_idle (T f) { + _service.post (f); + } + + /** Call this in the UI when it is idle */ + size_t ui_idle () { + /* This executes any functors that have been post()ed to _service */ + return _service.poll (); + } + + /** This should wake the UI and make it call ui_idle() */ + virtual void wake_ui () { + /* This is only a sensible implementation when there is no GUI */ + ui_idle (); + } + +private: + /** Emit a signal from any thread whose handlers will be called in the UI + * thread. Use something like: + * + * ui_signaller->emit (boost::bind (boost::ref (SomeSignal), parameter)); + */ + template + void emit (T f) { + if (boost::this_thread::get_id() == _ui_thread) { + /* already in the UI thread */ + f (); + } else { + /* non-UI thread; post to the service and wake up the UI */ + _service.post (f); + wake_ui (); + } + } + + friend class Signaller; + + /** A io_service which is used as the conduit for messages */ + boost::asio::io_service _service; + /** Object required to keep io_service from stopping when it has nothing to do */ + boost::asio::io_service::work _work; + /** The UI thread's ID */ + boost::thread::id _ui_thread; +}; + +extern SignalManager* signal_manager; + +#endif diff --git a/src/lib/signaller.h b/src/lib/signaller.h index 408cfcf5b..4ef9b38b3 100644 --- a/src/lib/signaller.h +++ b/src/lib/signaller.h @@ -20,7 +20,7 @@ #ifndef DCPOMATIC_SIGNALLER_H #define DCPOMATIC_SIGNALLER_H -#include "ui_signaller.h" +#include "signal_manager.h" #include #include @@ -100,8 +100,8 @@ public: void emit (T signal) { Wrapper* w = new Wrapper (signal); - if (ui_signaller) { - ui_signaller->emit (boost::bind (&Wrapper::signal, w)); + if (signal_manager) { + signal_manager->emit (boost::bind (&Wrapper::signal, w)); } boost::mutex::scoped_lock lm (_mutex); diff --git a/src/lib/ui_signaller.cc b/src/lib/ui_signaller.cc deleted file mode 100644 index 4cb34da51..000000000 --- a/src/lib/ui_signaller.cc +++ /dev/null @@ -1,24 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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" - -/** Global UISignaller instance */ -UISignaller* ui_signaller = 0; - diff --git a/src/lib/ui_signaller.h b/src/lib/ui_signaller.h deleted file mode 100644 index 9d4495cd1..000000000 --- a/src/lib/ui_signaller.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 DCPOMATIC_UI_SIGNALLER_H -#define DCPOMATIC_UI_SIGNALLER_H - -#include -#include -#include - -class Signaller; - -/** A class to allow signals to be emitted from non-UI threads and handled - * by a UI thread. - */ -class UISignaller : public boost::noncopyable -{ -public: - /** Create a UISignaller. Must be called from the UI thread */ - UISignaller () - : _work (_service) - { - _ui_thread = boost::this_thread::get_id (); - } - - /* Do something next time the UI is idle */ - template - void when_idle (T f) { - _service.post (f); - } - - /** Call this in the UI when it is idle */ - size_t ui_idle () { - /* This executes any functors that have been post()ed to _service */ - return _service.poll (); - } - - /** This should wake the UI and make it call ui_idle() */ - virtual void wake_ui () { - /* This is only a sensible implementation when there is no GUI... */ - ui_idle (); - } - -private: - /** Emit a signal from any thread whose handlers will be called in the UI - * thread. Use something like: - * - * ui_signaller->emit (boost::bind (boost::ref (SomeSignal), parameter)); - */ - template - void emit (T f) { - if (boost::this_thread::get_id() == _ui_thread) { - /* already in the UI thread */ - f (); - } else { - /* non-UI thread; post to the service and wake up the UI */ - _service.post (f); - wake_ui (); - } - } - - friend class Signaller; - - /** A io_service which is used as the conduit for messages */ - boost::asio::io_service _service; - /** Object required to keep io_service from stopping when it has nothing to do */ - boost::asio::io_service::work _work; - /** The UI thread's ID */ - boost::thread::id _ui_thread; -}; - -extern UISignaller* ui_signaller; - -#endif diff --git a/src/lib/update.cc b/src/lib/update.cc index 26944ecc3..f433ff991 100644 --- a/src/lib/update.cc +++ b/src/lib/update.cc @@ -19,7 +19,6 @@ #include "update.h" #include "version.h" -#include "ui_signaller.h" #include "safe_stringstream.h" #include "config.h" #include "util.h" diff --git a/src/lib/wscript b/src/lib/wscript index 68897a4c4..5956c73d6 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -109,7 +109,7 @@ sources = """ transcode_job.cc transcoder.cc types.cc - ui_signaller.cc + signal_manager.cc update.cc upmixer_a.cc util.cc diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index e59220785..904e39fda 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -21,7 +21,7 @@ #include "lib/config.h" #include "lib/util.h" #include "lib/version.h" -#include "lib/ui_signaller.h" +#include "lib/signal_manager.h" #include "lib/log.h" #include "lib/job_manager.h" #include "lib/transcode_job.h" @@ -39,7 +39,7 @@ #include "wx/wx_util.h" #include "wx/new_film_dialog.h" #include "wx/properties_dialog.h" -#include "wx/wx_ui_signaller.h" +#include "wx/wx_signal_manager.h" #include "wx/about_dialog.h" #include "wx/kdm_dialog.h" #include "wx/servers_list_dialog.h" @@ -841,7 +841,7 @@ private: } } - ui_signaller = new wxUISignaller (this); + signal_manager = new wxSignalManager (this); Bind (wxEVT_IDLE, boost::bind (&App::idle, this)); Bind (wxEVT_TIMER, boost::bind (&App::check, this)); @@ -909,7 +909,7 @@ private: void idle () { - ui_signaller->ui_idle (); + signal_manager->ui_idle (); } void check () diff --git a/src/tools/dcpomatic_batch.cc b/src/tools/dcpomatic_batch.cc index da8a61414..ae2f3a2c5 100644 --- a/src/tools/dcpomatic_batch.cc +++ b/src/tools/dcpomatic_batch.cc @@ -29,7 +29,7 @@ #include "lib/job_manager.h" #include "wx/wx_util.h" #include "wx/about_dialog.h" -#include "wx/wx_ui_signaller.h" +#include "wx/wx_signal_manager.h" #include "wx/job_manager_view.h" using std::exception; @@ -225,7 +225,7 @@ class App : public wxApp f->Maximize (); f->Show (); - ui_signaller = new wxUISignaller (this); + signal_manager = new wxSignalManager (this); this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this)); shared_ptr film; @@ -244,7 +244,7 @@ class App : public wxApp void idle () { - ui_signaller->ui_idle (); + signal_manager->ui_idle (); } void OnInitCmdLine (wxCmdLineParser& parser) diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc index 4facdd4d1..0307cac9c 100644 --- a/src/tools/dcpomatic_cli.cc +++ b/src/tools/dcpomatic_cli.cc @@ -30,7 +30,7 @@ #include "lib/cross.h" #include "lib/config.h" #include "lib/log.h" -#include "lib/ui_signaller.h" +#include "lib/signal_manager.h" #include "lib/server_finder.h" #include "lib/json_server.h" @@ -119,7 +119,7 @@ main (int argc, char* argv[]) film_dir = argv[optind]; dcpomatic_setup (); - ui_signaller = new UISignaller (); + signal_manager = new SignalManager (); if (no_remote) { ServerFinder::instance()->disable (); diff --git a/src/tools/dcpomatic_create.cc b/src/tools/dcpomatic_create.cc index 304f4f697..d121eb0cc 100644 --- a/src/tools/dcpomatic_create.cc +++ b/src/tools/dcpomatic_create.cc @@ -28,7 +28,7 @@ #include "lib/util.h" #include "lib/content_factory.h" #include "lib/job_manager.h" -#include "lib/ui_signaller.h" +#include "lib/signal_manager.h" #include "lib/job.h" #include "lib/dcp_content_type.h" #include "lib/ratio.h" @@ -59,11 +59,11 @@ help (string n) << " -o, --output output directory\n"; } -class SimpleUISignaller : public UISignaller +class SimpleSignalManager : public SignalManager { public: /* Do nothing in this method so that UI events happen in our thread - when we call UISignaller::ui_idle(). + when we call SignalManager::ui_idle(). */ void wake_ui () {} }; @@ -161,7 +161,7 @@ main (int argc, char* argv[]) exit (EXIT_FAILURE); } - ui_signaller = new SimpleUISignaller (); + signal_manager = new SimpleSignalManager (); try { shared_ptr film (new Film (output, false)); @@ -184,7 +184,7 @@ main (int argc, char* argv[]) JobManager* jm = JobManager::instance (); while (jm->work_to_do ()) {} - while (ui_signaller->ui_idle() > 0) {} + while (signal_manager->ui_idle() > 0) {} ContentList content = film->content (); for (ContentList::iterator i = content.begin(); i != content.end(); ++i) { diff --git a/src/wx/dolby_certificate_dialog.cc b/src/wx/dolby_certificate_dialog.cc index 15551a424..ad43f6479 100644 --- a/src/wx/dolby_certificate_dialog.cc +++ b/src/wx/dolby_certificate_dialog.cc @@ -21,7 +21,7 @@ #include #include "lib/compose.hpp" #include "lib/internet.h" -#include "lib/ui_signaller.h" +#include "lib/signal_manager.h" #include "dolby_certificate_dialog.h" #include "wx_util.h" @@ -80,7 +80,7 @@ DolbyCertificateDialog::setup_countries () /* See DoremiCertificateDialog for discussion about this daft delay */ wxMilliSleep (200); #endif - ui_signaller->when_idle (boost::bind (&DolbyCertificateDialog::finish_setup_countries, this)); + signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_setup_countries, this)); } void @@ -103,7 +103,7 @@ DolbyCertificateDialog::country_selected () #ifdef DCPOMATIC_OSX wxMilliSleep (200); #endif - ui_signaller->when_idle (boost::bind (&DolbyCertificateDialog::finish_country_selected, this)); + signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_country_selected, this)); } void @@ -126,7 +126,7 @@ DolbyCertificateDialog::cinema_selected () #ifdef DCPOMATIC_OSX wxMilliSleep (200); #endif - ui_signaller->when_idle (boost::bind (&DolbyCertificateDialog::finish_cinema_selected, this)); + signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_cinema_selected, this)); } void @@ -161,7 +161,7 @@ DolbyCertificateDialog::download () wxMilliSleep (200); #endif - ui_signaller->when_idle (boost::bind (&DolbyCertificateDialog::finish_download, this)); + signal_manager->when_idle (boost::bind (&DolbyCertificateDialog::finish_download, this)); } void diff --git a/src/wx/doremi_certificate_dialog.cc b/src/wx/doremi_certificate_dialog.cc index 105555da9..578a7a72d 100644 --- a/src/wx/doremi_certificate_dialog.cc +++ b/src/wx/doremi_certificate_dialog.cc @@ -21,7 +21,7 @@ #include #include "lib/compose.hpp" #include "lib/util.h" -#include "lib/ui_signaller.h" +#include "lib/signal_manager.h" #include "lib/internet.h" #include "doremi_certificate_dialog.h" #include "wx_util.h" @@ -59,7 +59,7 @@ DoremiCertificateDialog::download () wxMilliSleep (200); #endif - ui_signaller->when_idle (boost::bind (&DoremiCertificateDialog::finish_download, this, serial)); + signal_manager->when_idle (boost::bind (&DoremiCertificateDialog::finish_download, this, serial)); } void diff --git a/src/wx/wscript b/src/wx/wscript index a05774cd2..370f59c62 100644 --- a/src/wx/wscript +++ b/src/wx/wscript @@ -80,7 +80,7 @@ sources = """ update_dialog.cc video_panel.cc wx_util.cc - wx_ui_signaller.cc + wx_signal_manager.cc """ def configure(conf): diff --git a/src/wx/wx_signal_manager.cc b/src/wx/wx_signal_manager.cc new file mode 100644 index 000000000..3d8b9992a --- /dev/null +++ b/src/wx/wx_signal_manager.cc @@ -0,0 +1,34 @@ +/* + Copyright (C) 2012-2015 Carl Hetherington + + 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 +#include "wx_signal_manager.h" + +wxSignalManager::wxSignalManager (wxEvtHandler* h) + : _handler (h) +{ + +} + +void +wxSignalManager::wake_ui () +{ + wxCommandEvent event (-1, -1); + _handler->AddPendingEvent (event); +} diff --git a/src/wx/wx_signal_manager.h b/src/wx/wx_signal_manager.h new file mode 100644 index 000000000..ad18e6880 --- /dev/null +++ b/src/wx/wx_signal_manager.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2012-2015 Carl Hetherington + + 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 "lib/signal_manager.h" + +class wxEvtHandler; + +/** @class wxSignalManager + * @brief SignalManager for the wxWidgets event loop + */ + +class wxSignalManager : public SignalManager +{ +public: + wxSignalManager (wxEvtHandler *); + void wake_ui (); + +private: + wxEvtHandler* _handler; +}; diff --git a/src/wx/wx_ui_signaller.cc b/src/wx/wx_ui_signaller.cc deleted file mode 100644 index 8fc6670d6..000000000 --- a/src/wx/wx_ui_signaller.cc +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (C) 2012-2014 Carl Hetherington - - 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 -#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 deleted file mode 100644 index 63f2049cd..000000000 --- a/src/wx/wx_ui_signaller.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (C) 2012-2014 Carl Hetherington - - 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 "lib/ui_signaller.h" - -class wxEvtHandler; - -/** @class wxUISignaller - * @brief UISignaller for the wxWidgets event loop - */ - -class wxUISignaller : public UISignaller -{ -public: - wxUISignaller (wxEvtHandler *); - void wake_ui (); - -private: - wxEvtHandler* _handler; -}; -- cgit v1.2.3