From 766c56a693e8b1bd4293459bb256abdc0515a0b5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 9 Jun 2009 19:01:02 +0200 Subject: Teile der Namespaces Common und Net in den neuen Namespace Core verschoben --- src/Core/Signals/Connection.h | 53 ++++++++++++++++++++++++++++++++++ src/Core/Signals/GenericSignal.h | 61 ++++++++++++++++++++++++++++++++++++++++ src/Core/Signals/Signal0.h | 46 ++++++++++++++++++++++++++++++ src/Core/Signals/Signal1.h | 47 +++++++++++++++++++++++++++++++ src/Core/Signals/Signal2.h | 47 +++++++++++++++++++++++++++++++ src/Core/Signals/SignalBase.h | 53 ++++++++++++++++++++++++++++++++++ 6 files changed, 307 insertions(+) create mode 100644 src/Core/Signals/Connection.h create mode 100644 src/Core/Signals/GenericSignal.h create mode 100644 src/Core/Signals/Signal0.h create mode 100644 src/Core/Signals/Signal1.h create mode 100644 src/Core/Signals/Signal2.h create mode 100644 src/Core/Signals/SignalBase.h (limited to 'src/Core/Signals') diff --git a/src/Core/Signals/Connection.h b/src/Core/Signals/Connection.h new file mode 100644 index 0000000..5ce7b4a --- /dev/null +++ b/src/Core/Signals/Connection.h @@ -0,0 +1,53 @@ +/* + * Connection.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_CORE_SIGNALS_CONNECTION_H_ +#define MAD_CORE_SIGNALS_CONNECTION_H_ + +namespace Mad { +namespace Core { +namespace Signals { + +class SignalBase; + +class Connection { + private: + friend class SignalBase; + + SignalBase *signal; + unsigned long id; + + Connection(SignalBase *signal0, unsigned long id0) + : signal(signal0), id(id0) {} + + public: + bool operator==(const Connection &o) const { + return (signal == o.signal && id == o.id); + } + + bool operator<(const Connection &o) const { + return (signal != o.signal) ? (signal < o.signal) : (id < o.id); + } +}; + +} +} +} + +#endif /* MAD_CORE_SIGNALS_CONNECTION_H_ */ diff --git a/src/Core/Signals/GenericSignal.h b/src/Core/Signals/GenericSignal.h new file mode 100644 index 0000000..641f575 --- /dev/null +++ b/src/Core/Signals/GenericSignal.h @@ -0,0 +1,61 @@ +/* + * GenericSignal.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_CORE_SIGNALS_GENERICSIGNAL_H_ +#define MAD_CORE_SIGNALS_GENERICSIGNAL_H_ + +#include "SignalBase.h" + +#include +#include + +namespace Mad { +namespace Core { +namespace Signals { + +template +class GenericSignal : protected SignalBase { + public: + typedef FunctionType slot_type; + + protected: + std::map handlers; + + public: + Connection connect(const slot_type &slot) { + boost::lock_guard lock(mutex); + + Connection con = getNewConnection(); + handlers.insert(std::make_pair(con, slot)); + + return con; + } + + bool disconnect(const Connection &connection) { + boost::lock_guard lock(mutex); + + return handlers.erase(connection); + } +}; + +} +} +} + +#endif /* MAD_CORE_SIGNALS_GENERICSIGNAL_H_ */ diff --git a/src/Core/Signals/Signal0.h b/src/Core/Signals/Signal0.h new file mode 100644 index 0000000..ccfb548 --- /dev/null +++ b/src/Core/Signals/Signal0.h @@ -0,0 +1,46 @@ +/* + * Signal0.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_CORE_SIGNALS_SIGNAL0_H_ +#define MAD_CORE_SIGNALS_SIGNAL0_H_ + +#include "GenericSignal.h" +#include "../ThreadManager.h" + +#include + +namespace Mad { +namespace Core { +namespace Signals { + +class Signal0 : public GenericSignal > { + public: + void emit() { + boost::lock_guard lock(mutex); + + for(std::map::iterator handler = handlers.begin(); handler != handlers.end(); ++handler) + ThreadManager::get()->pushWork(handler->second); + } +}; + +} +} +} + +#endif /* MAD_CORE_SIGNALS_SIGNAL0_H_ */ diff --git a/src/Core/Signals/Signal1.h b/src/Core/Signals/Signal1.h new file mode 100644 index 0000000..e4a946c --- /dev/null +++ b/src/Core/Signals/Signal1.h @@ -0,0 +1,47 @@ +/* + * Signal1.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_CORE_SIGNALS_SIGNAL1_H_ +#define MAD_CORE_SIGNALS_SIGNAL1_H_ + +#include "GenericSignal.h" +#include "../ThreadManager.h" + +#include + +namespace Mad { +namespace Core { +namespace Signals { + +template +class Signal1 : 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) + ThreadManager::get()->pushWork(boost::bind(handler->second, arg1)); + } +}; + +} +} +} + +#endif /* MAD_CORE_SIGNALS_SIGNAL1_H_ */ diff --git a/src/Core/Signals/Signal2.h b/src/Core/Signals/Signal2.h new file mode 100644 index 0000000..41045d7 --- /dev/null +++ b/src/Core/Signals/Signal2.h @@ -0,0 +1,47 @@ +/* + * Signal2.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_CORE_SIGNALS_SIGNAL2_H_ +#define MAD_CORE_SIGNALS_SIGNAL2_H_ + +#include "GenericSignal.h" +#include "../ThreadManager.h" + +#include + +namespace Mad { +namespace Core { +namespace Signals { + +template +class Signal2 : 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) + ThreadManager::get()->pushWork(boost::bind(handler->second, arg1, arg2)); + } +}; + +} +} +} + +#endif /* MAD_CORE_SIGNALS_SIGNAL2_H_ */ diff --git a/src/Core/Signals/SignalBase.h b/src/Core/Signals/SignalBase.h new file mode 100644 index 0000000..1a5d5a3 --- /dev/null +++ b/src/Core/Signals/SignalBase.h @@ -0,0 +1,53 @@ +/* + * 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_CORE_SIGNALS_SIGNALBASE_H_ +#define MAD_CORE_SIGNALS_SIGNALBASE_H_ + +#include "Connection.h" + +#include +#include + +namespace Mad { +namespace Core { +namespace Signals { + +class SignalBase : private boost::noncopyable { + private: + friend class Connection; + + unsigned long connectionId; + + protected: + boost::mutex mutex; + + Connection getNewConnection() { + return Connection(this, connectionId++); + } + + SignalBase() : connectionId(0) {} + virtual ~SignalBase() {} +}; + +} +} +} + +#endif /* MAD_CORE_SIGNALS_SIGNALBASE_H_ */ -- cgit v1.2.3