From d3a7b7c10b0ef7a3d8c8ea7f1aef2468702dd8f4 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 4 Jun 2009 22:32:56 +0200 Subject: Alte Signal-Implementierung entfernt --- src/Net/Signals/Connection.h | 22 +++++++++++------ src/Net/Signals/Connection2.h | 53 ----------------------------------------- src/Net/Signals/GenericSignal.h | 12 +++++----- src/Net/Signals/Signal0.h | 10 +++++--- src/Net/Signals/Signal1.h | 12 ++++++---- src/Net/Signals/Signal2.h | 12 ++++++---- src/Net/Signals/Signal20.h | 46 ----------------------------------- src/Net/Signals/Signal21.h | 47 ------------------------------------ src/Net/Signals/Signal22.h | 47 ------------------------------------ src/Net/Signals/SignalBase.h | 43 +++++++-------------------------- src/Net/Signals/SignalBase2.h | 53 ----------------------------------------- src/Net/Signals/Signals.h | 3 --- 12 files changed, 52 insertions(+), 308 deletions(-) delete mode 100644 src/Net/Signals/Connection2.h delete mode 100644 src/Net/Signals/Signal20.h delete mode 100644 src/Net/Signals/Signal21.h delete mode 100644 src/Net/Signals/Signal22.h delete mode 100644 src/Net/Signals/SignalBase2.h (limited to 'src/Net/Signals') diff --git a/src/Net/Signals/Connection.h b/src/Net/Signals/Connection.h index 0e66611..7730e13 100644 --- a/src/Net/Signals/Connection.h +++ b/src/Net/Signals/Connection.h @@ -20,22 +20,30 @@ #ifndef MAD_NET_SIGNALS_CONNECTION_H_ #define MAD_NET_SIGNALS_CONNECTION_H_ -#include - namespace Mad { namespace Net { namespace Signals { -template class SignalBase; +class SignalBase; class Connection { private: - template friend class SignalBase; + friend class SignalBase; + + SignalBase *signal; + unsigned long id; + + Connection(SignalBase *signal0, unsigned long id0) + : signal(signal0), id(id0) {} - boost::signals::connection connection; + public: + bool operator==(const Connection &o) const { + return (signal == o.signal && id == o.id); + } - Connection(const boost::signals::connection &connection0) - : connection(connection0) {} + bool operator<(const Connection &o) const { + return (signal != o.signal) ? (signal < o.signal) : (id < o.id); + } }; } diff --git a/src/Net/Signals/Connection2.h b/src/Net/Signals/Connection2.h deleted file mode 100644 index ab80a61..0000000 --- a/src/Net/Signals/Connection2.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Connection2.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_NET_SIGNALS_CONNECTION2_H_ -#define MAD_NET_SIGNALS_CONNECTION2_H_ - -namespace Mad { -namespace Net { -namespace Signals { - -class SignalBase2; - -class Connection2 { - private: - friend class SignalBase2; - - SignalBase2 *signal; - unsigned long id; - - Connection2(SignalBase2 *signal0, unsigned long id0) - : signal(signal0), id(id0) {} - - public: - bool operator==(const Connection2 &o) const { - return (signal == o.signal && id == o.id); - } - - bool operator<(const Connection2 &o) const { - return (signal != o.signal) ? (signal < o.signal) : (id < o.id); - } -}; - -} -} -} - -#endif /* MAD_NET_SIGNALS_CONNECTION2_H_ */ diff --git a/src/Net/Signals/GenericSignal.h b/src/Net/Signals/GenericSignal.h index d4fa8df..aa6cfa1 100644 --- a/src/Net/Signals/GenericSignal.h +++ b/src/Net/Signals/GenericSignal.h @@ -20,7 +20,7 @@ #ifndef MAD_NET_SIGNALS_GENERICSIGNAL_H_ #define MAD_NET_SIGNALS_GENERICSIGNAL_H_ -#include "SignalBase2.h" +#include "SignalBase.h" #include #include @@ -30,24 +30,24 @@ namespace Net { namespace Signals { template -class GenericSignal : protected SignalBase2 { +class GenericSignal : protected SignalBase { public: typedef FunctionType slot_type; protected: - std::map handlers; + std::map handlers; public: - Connection2 connect(const slot_type &slot) { + Connection connect(const slot_type &slot) { boost::lock_guard lock(mutex); - Connection2 con = getNewConnection(); + Connection con = getNewConnection(); handlers.insert(std::make_pair(con, slot)); return con; } - bool disconnect(const Connection2 &connection) { + bool disconnect(const Connection &connection) { boost::lock_guard lock(mutex); return handlers.erase(connection); diff --git a/src/Net/Signals/Signal0.h b/src/Net/Signals/Signal0.h index c468135..5c0a691 100644 --- a/src/Net/Signals/Signal0.h +++ b/src/Net/Signals/Signal0.h @@ -20,18 +20,22 @@ #ifndef MAD_NET_SIGNALS_SIGNAL0_H_ #define MAD_NET_SIGNALS_SIGNAL0_H_ -#include "SignalBase.h" +#include "GenericSignal.h" +#include + +#include namespace Mad { namespace Net { namespace Signals { -class Signal0 : public SignalBase, boost::function0 > { +class Signal0 : public GenericSignal > { public: void emit() { boost::lock_guard lock(mutex); - signal(); + for(std::map::iterator handler = handlers.begin(); handler != handlers.end(); ++handler) + Net::ThreadManager::get()->pushWork(handler->second); } }; diff --git a/src/Net/Signals/Signal1.h b/src/Net/Signals/Signal1.h index b9649be..331c5cb 100644 --- a/src/Net/Signals/Signal1.h +++ b/src/Net/Signals/Signal1.h @@ -20,19 +20,23 @@ #ifndef MAD_NET_SIGNALS_SIGNAL1_H_ #define MAD_NET_SIGNALS_SIGNAL1_H_ -#include "SignalBase.h" +#include "GenericSignal.h" +#include + +#include namespace Mad { namespace Net { namespace Signals { template -class Signal1 : public SignalBase, boost::function1 > { +class Signal1 : public GenericSignal > { public: void emit(T1 arg1) { - boost::lock_guard lock(SignalBase, boost::function1 >::mutex); + boost::lock_guard lock(this->mutex); - SignalBase, boost::function1 >::signal(arg1); + for(typename std::map >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler) + Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1)); } }; diff --git a/src/Net/Signals/Signal2.h b/src/Net/Signals/Signal2.h index 374a239..3fb9315 100644 --- a/src/Net/Signals/Signal2.h +++ b/src/Net/Signals/Signal2.h @@ -20,19 +20,23 @@ #ifndef MAD_NET_SIGNALS_SIGNAL2_H_ #define MAD_NET_SIGNALS_SIGNAL2_H_ -#include "SignalBase.h" +#include "GenericSignal.h" +#include + +#include namespace Mad { namespace Net { namespace Signals { template -class Signal2 : public SignalBase, boost::function2 > { +class Signal2 : public GenericSignal > { public: void emit(T1 arg1, T2 arg2) { - boost::lock_guard lock(SignalBase, boost::function2 >::mutex); + boost::lock_guard lock(this->mutex); - SignalBase, boost::function2 >::signal(arg1, arg2); + for(typename std::map >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler) + Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1, arg2)); } }; diff --git a/src/Net/Signals/Signal20.h b/src/Net/Signals/Signal20.h deleted file mode 100644 index 0a12640..0000000 --- a/src/Net/Signals/Signal20.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Signal20.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_NET_SIGNALS_SIGNAL20_H_ -#define MAD_NET_SIGNALS_SIGNAL20_H_ - -#include "GenericSignal.h" -#include - -#include - -namespace Mad { -namespace Net { -namespace Signals { - -class Signal20 : public GenericSignal > { - public: - void emit() { - boost::lock_guard lock(mutex); - - for(std::map::iterator handler = handlers.begin(); handler != handlers.end(); ++handler) - Net::ThreadManager::get()->pushWork(handler->second); - } -}; - -} -} -} - -#endif /* MAD_NET_SIGNALS_SIGNAL20_H_ */ diff --git a/src/Net/Signals/Signal21.h b/src/Net/Signals/Signal21.h deleted file mode 100644 index 799296f..0000000 --- a/src/Net/Signals/Signal21.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Signal21.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_NET_SIGNALS_SIGNAL21_H_ -#define MAD_NET_SIGNALS_SIGNAL21_H_ - -#include "GenericSignal.h" -#include - -#include - -namespace Mad { -namespace Net { -namespace Signals { - -template -class Signal21 : public GenericSignal > { - public: - void emit(T1 arg1) { - boost::lock_guard lock(this->mutex); - - for(typename std::map >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler) - Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1)); - } -}; - -} -} -} - -#endif /* MAD_NET_SIGNALS_SIGNAL21_H_ */ diff --git a/src/Net/Signals/Signal22.h b/src/Net/Signals/Signal22.h deleted file mode 100644 index a3b2ac4..0000000 --- a/src/Net/Signals/Signal22.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Signal22.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_NET_SIGNALS_SIGNAL22_H_ -#define MAD_NET_SIGNALS_SIGNAL22_H_ - -#include "GenericSignal.h" -#include - -#include - -namespace Mad { -namespace Net { -namespace Signals { - -template -class Signal22 : public GenericSignal > { - public: - void emit(T1 arg1, T2 arg2) { - boost::lock_guard lock(this->mutex); - - for(typename std::map >::slot_type>::iterator handler = this->handlers.begin(); handler != this->handlers.end(); ++handler) - Net::ThreadManager::get()->pushWork(boost::bind(handler->second, arg1, arg2)); - } -}; - -} -} -} - -#endif /* MAD_NET_SIGNALS_SIGNAL22_H_ */ diff --git a/src/Net/Signals/SignalBase.h b/src/Net/Signals/SignalBase.h index 9e2de62..ea1b1e9 100644 --- a/src/Net/Signals/SignalBase.h +++ b/src/Net/Signals/SignalBase.h @@ -23,54 +23,27 @@ #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; + private: + friend class Connection; - protected: - typedef SignalType signal_type; + unsigned long connectionId; - std::set connections; + protected: boost::mutex mutex; - signal_type signal; - - SignalBase() {} - ~SignalBase() { - // Wait for other threads - boost::lock_guard lock(mutex); + Connection getNewConnection() { + return Connection(this, connectionId++); } - 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); - } + SignalBase() : connectionId(0) {} + virtual ~SignalBase() {} }; } diff --git a/src/Net/Signals/SignalBase2.h b/src/Net/Signals/SignalBase2.h deleted file mode 100644 index d5cb0a7..0000000 --- a/src/Net/Signals/SignalBase2.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SignalBase2.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_SIGNALBASE2_H_ -#define MAD_SIGNALS_SIGNALBASE2_H_ - -#include "Connection2.h" - -#include -#include - -namespace Mad { -namespace Net { -namespace Signals { - -class SignalBase2 : private boost::noncopyable { - private: - friend class Connection2; - - unsigned long connectionId; - - protected: - boost::mutex mutex; - - Connection2 getNewConnection() { - return Connection2(this, connectionId++); - } - - SignalBase2() : connectionId(0) {} - virtual ~SignalBase2() {} -}; - -} -} -} - -#endif /* MAD_SIGNALS_SIGNALBASE2_H_ */ diff --git a/src/Net/Signals/Signals.h b/src/Net/Signals/Signals.h index b4c9bac..4ee4f95 100644 --- a/src/Net/Signals/Signals.h +++ b/src/Net/Signals/Signals.h @@ -23,8 +23,5 @@ #include "Signal0.h" #include "Signal1.h" #include "Signal2.h" -#include "Signal20.h" -#include "Signal21.h" -#include "Signal22.h" #endif /* MAD_SIGNALS_SIGNALS_H_ */ -- cgit v1.2.3