/* * SignalBase.h * * Copyright (C) 2009 Matthias Schiffer * * 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 3 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, see . */ #ifndef MAD_SIGNALS_SIGNALBASE_H_ #define MAD_SIGNALS_SIGNALBASE_H_ #include "Connection.h" #include #include #include #include namespace Mad { namespace Net { namespace Signals { template class SignalBase : private boost::noncopyable { public: typedef boost::slot slot_type; protected: typedef SignalType signal_type; std::set connections; boost::mutex mutex; signal_type signal; SignalBase() {} ~SignalBase() { // Wait for other threads boost::lock_guard lock(mutex); } public: Connection connect(const slot_type &slot) { boost::lock_guard lock(mutex); boost::signals::connection con(signal.connect(slot)); connections.insert(con); return con; } void disconnect(const Connection &connection) { boost::lock_guard lock(mutex); std::set::iterator it = connections.find(connection.connection); if(it == connections.end()) return; it->disconnect(); connections.erase(it); } }; } } } #endif /* MAD_SIGNALS_SIGNALBASE_H_ */