diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-19 20:26:31 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2009-12-19 20:26:31 +0000 |
commit | aae367b63c9b619db1e40f27dc334c6987219481 (patch) | |
tree | 142f6ffed6bb749e24a06343587cad6b966888bd /libs/pbd/pbd | |
parent | 67460c2af45d0455e64623572480c064445c2e5b (diff) |
use new syntax for connecting to backend signals that enforces explicit connection scope, plus a few other related matters
git-svn-id: svn://localhost/ardour2/branches/3.0@6376 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/pbd')
-rw-r--r-- | libs/pbd/pbd/controllable.h | 16 | ||||
-rw-r--r-- | libs/pbd/pbd/destructible.h | 4 | ||||
-rw-r--r-- | libs/pbd/pbd/memento_command.h | 4 | ||||
-rw-r--r-- | libs/pbd/pbd/scoped_connections.h | 72 | ||||
-rw-r--r-- | libs/pbd/pbd/signals.h | 171 | ||||
-rw-r--r-- | libs/pbd/pbd/undo.h | 4 |
6 files changed, 185 insertions, 86 deletions
diff --git a/libs/pbd/pbd/controllable.h b/libs/pbd/pbd/controllable.h index dbec03b396..d94c58d54f 100644 --- a/libs/pbd/pbd/controllable.h +++ b/libs/pbd/pbd/controllable.h @@ -24,7 +24,7 @@ v it under the terms of the GNU General Public License as published by #include <set> #include <map> -#include <boost/signals2.hpp> +#include "pbd/signals.h" #include <glibmm/thread.h> #include "pbd/statefuldestructible.h" @@ -44,16 +44,16 @@ class Controllable : public PBD::StatefulDestructible { virtual void set_value (float) = 0; virtual float get_value (void) const = 0; - boost::signals2::signal<void()> LearningFinished; - static boost::signals2::signal<void(PBD::Controllable*,int,int)> CreateBinding; - static boost::signals2::signal<void(PBD::Controllable*)> DeleteBinding; + PBD::Signal0<void> LearningFinished; + static PBD::Signal3<void,PBD::Controllable*,int,int> CreateBinding; + static PBD::Signal1<void,PBD::Controllable*> DeleteBinding; - static boost::signals2::signal<bool(PBD::Controllable*)> StartLearning; - static boost::signals2::signal<void(PBD::Controllable*)> StopLearning; + static PBD::Signal1<bool,PBD::Controllable*> StartLearning; + static PBD::Signal1<void,PBD::Controllable*> StopLearning; - static boost::signals2::signal<void(Controllable*)> Destroyed; + static PBD::Signal1<void,Controllable*> Destroyed; - boost::signals2::signal<void()> Changed; + PBD::Signal0<void> Changed; int set_state (const XMLNode&, int version); XMLNode& get_state (); diff --git a/libs/pbd/pbd/destructible.h b/libs/pbd/pbd/destructible.h index 241d847aff..8cc0113ff7 100644 --- a/libs/pbd/pbd/destructible.h +++ b/libs/pbd/pbd/destructible.h @@ -20,7 +20,7 @@ #ifndef __pbd_destructible_h__ #define __pbd_destructible_h__ -#include <boost/signals2.hpp> +#include "pbd/signals.h" namespace PBD { @@ -29,7 +29,7 @@ class Destructible { Destructible() : refs_dropped (false){} virtual ~Destructible () {} - boost::signals2::signal<void ()> GoingAway; + PBD::Signal0<void> GoingAway; void drop_references () { if (!refs_dropped) { GoingAway(); } refs_dropped = true; } private: diff --git a/libs/pbd/pbd/memento_command.h b/libs/pbd/pbd/memento_command.h index c5e8b19272..b87f784334 100644 --- a/libs/pbd/pbd/memento_command.h +++ b/libs/pbd/pbd/memento_command.h @@ -42,7 +42,7 @@ public: : obj(a_object), before(a_before), after(a_after) { /* if the object dies, make sure that we die and that everyone knows about it */ - obj_death_connection = obj.GoingAway.connect (boost::bind (&MementoCommand::object_died, this)); + obj.GoingAway.connect (obj_death_connection, boost::bind (&MementoCommand::object_died, this)); } ~MementoCommand () { @@ -97,7 +97,7 @@ protected: obj_T& obj; XMLNode* before; XMLNode* after; - boost::signals2::scoped_connection obj_death_connection; + PBD::ScopedConnection obj_death_connection; }; #endif // __lib_pbd_memento_h__ diff --git a/libs/pbd/pbd/scoped_connections.h b/libs/pbd/pbd/scoped_connections.h deleted file mode 100644 index bb992e4f78..0000000000 --- a/libs/pbd/pbd/scoped_connections.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - Copyright (C) 2009 Paul Davis - - 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 __pbd_scoped_connections_h__ -#define __pbd_scoped_connections_h__ - -#include <list> -#include <glibmm/thread.h> -#include <boost/signals2.hpp> - -#include "pbd/destructible.h" - -namespace PBD { - -class ScopedConnectionList -{ - public: - ScopedConnectionList(); - ~ScopedConnectionList (); - - void add_connection (const boost::signals2::connection& c); - void drop_connections (); - - template<typename S> void scoped_connect (S& sig, const typename S::slot_function_type& sf) { - add_connection (sig.connect (sf)); - } - - private: - /* this class is not copyable */ - ScopedConnectionList(const ScopedConnectionList&) {} - - /* this lock is shared by all instances of a ScopedConnectionList. - We do not want one mutex per list, and since we only need the lock - when adding or dropping connections, which are generally occuring - in object creation and UI operations, the contention on this - lock is low and not of significant consequence. Even though - boost::signals2 is thread-safe, this additional list of - scoped connections needs to be protected in 2 cases: - - (1) (unlikely) we make a connection involving a callback on the - same object from 2 threads. (wouldn't that just be appalling - programming style?) - - (2) where we are dropping connections in one thread and adding - one from another. - */ - - static Glib::StaticMutex _lock; - - typedef std::list<boost::signals2::scoped_connection*> ConnectionList; - ConnectionList _list; -}; - -} /* namespace */ - -#endif /* __pbd_scoped_connections_h__ */ diff --git a/libs/pbd/pbd/signals.h b/libs/pbd/pbd/signals.h new file mode 100644 index 0000000000..4ddd72eba8 --- /dev/null +++ b/libs/pbd/pbd/signals.h @@ -0,0 +1,171 @@ +/* + Copyright (C) 2009 Paul Davis + + 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 __pbd_signals_h__ +#define __pbd_signals_h__ + +#include <list> +#include <glibmm/thread.h> +#include <boost/signals2.hpp> +#include <boost/noncopyable.hpp> + +namespace PBD { + +typedef boost::signals2::connection UnscopedConnection; +typedef boost::signals2::connection Connection; +typedef boost::signals2::scoped_connection ScopedConnection; + +class ScopedConnectionList : public boost::noncopyable +{ + public: + ScopedConnectionList(); + ~ScopedConnectionList (); + + void add_connection (const UnscopedConnection& c); + void drop_connections (); + + template<typename S> void scoped_connect (S& sig, const typename S::slot_function_type& sf) { + add_connection (sig.connect (sf)); + } + + private: + /* this class is not copyable */ + ScopedConnectionList(const ScopedConnectionList&) {} + + /* this lock is shared by all instances of a ScopedConnectionList. + We do not want one mutex per list, and since we only need the lock + when adding or dropping connections, which are generally occuring + in object creation and UI operations, the contention on this + lock is low and not of significant consequence. Even though + boost::signals2 is thread-safe, this additional list of + scoped connections needs to be protected in 2 cases: + + (1) (unlikely) we make a connection involving a callback on the + same object from 2 threads. (wouldn't that just be appalling + programming style?) + + (2) where we are dropping connections in one thread and adding + one from another. + */ + + static Glib::StaticMutex _lock; + + typedef std::list<ScopedConnection*> ConnectionList; + ConnectionList _list; +}; + +template<typename R> +class Signal0 { +public: + Signal0 () {} + typedef boost::signals2::signal<R()> SignalType; + + void connect (ScopedConnectionList& clist, + const typename SignalType::slot_function_type& slot) { + clist.add_connection (_signal.connect (slot)); + } + + void connect (Connection& c, + const typename SignalType::slot_function_type& slot) { + c = _signal.connect (slot); + } + + typename SignalType::result_type operator()() { + return _signal (); + } + +private: + SignalType _signal; +}; + +template<typename R, typename A> +class Signal1 { +public: + Signal1 () {} + typedef boost::signals2::signal<R(A)> SignalType; + + void connect (ScopedConnectionList& clist, + const typename SignalType::slot_function_type& slot) { + clist.add_connection (_signal.connect (slot)); + } + + void connect (Connection& c, + const typename SignalType::slot_function_type& slot) { + c = _signal.connect (slot); + } + + typename SignalType::result_type operator()(A arg1) { + return _signal (arg1); + } + +private: + SignalType _signal; +}; + +template<typename R, typename A1, typename A2> +class Signal2 { +public: + Signal2 () {} + typedef boost::signals2::signal<R(A1, A2)> SignalType; + + void connect (ScopedConnectionList& clist, + const typename SignalType::slot_function_type& slot) { + clist.add_connection (_signal.connect (slot)); + } + + void connect (Connection& c, + const typename SignalType::slot_function_type& slot) { + c = _signal.connect (slot); + } + + typename SignalType::result_type operator()(A1 arg1, A2 arg2) { + return _signal (arg1, arg2); + } + +private: + SignalType _signal; +}; + +template<typename R, typename A1, typename A2, typename A3> +class Signal3 { +public: + Signal3 () {} + typedef boost::signals2::signal<R(A1,A2,A3)> SignalType; + + void connect (ScopedConnectionList& clist, + const typename SignalType::slot_function_type& slot) { + clist.add_connection (_signal.connect (slot)); + } + + void connect (Connection& c, + const typename SignalType::slot_function_type& slot) { + c = _signal.connect (slot); + } + + typename SignalType::result_type operator()(A1 arg1, A2 arg2, A3 arg3) { + return _signal (arg1, arg2, arg3); + } + +private: + SignalType _signal; +}; + +} /* namespace */ + +#endif /* __pbd_signals_h__ */ diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h index 6340ef04b9..bb910252c3 100644 --- a/libs/pbd/pbd/undo.h +++ b/libs/pbd/pbd/undo.h @@ -27,7 +27,7 @@ #include <sigc++/bind.h> #include <sys/time.h> -#include "pbd/scoped_connections.h" +#include "pbd/signals.h" #include "pbd/command.h" typedef sigc::slot<void> UndoAction; @@ -106,7 +106,7 @@ class UndoHistory : public PBD::ScopedConnectionList void set_depth (uint32_t); - boost::signals2::signal<void()> Changed; + PBD::Signal0<void> Changed; private: bool _clearing; |