diff options
Diffstat (limited to 'noatun/library/noatunarts/Session_impl.cpp')
-rw-r--r-- | noatun/library/noatunarts/Session_impl.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/noatun/library/noatunarts/Session_impl.cpp b/noatun/library/noatunarts/Session_impl.cpp new file mode 100644 index 00000000..63912801 --- /dev/null +++ b/noatun/library/noatunarts/Session_impl.cpp @@ -0,0 +1,82 @@ +#include "noatunarts.h" +#include <list> +#include <algorithm> + +using namespace Arts; +using namespace std; + +static bool compareArtsObjects(const Noatun::Listener &left, const Noatun::Listener &right) +{ + return left._isEqual(right); +} + +list<Noatun::Listener>::iterator find(list<Noatun::Listener> &v, const Noatun::Listener &is, + bool (*compare)(const Noatun::Listener& left, const Noatun::Listener& right)) +{ + for (list<Noatun::Listener>::iterator i=v.begin(); i!=v.end(); ++i) + { + if ((*compare)(is, *i)) + return i; + } + + return v.end(); +} + +static void sendMessage(Noatun::Listener l) +{ + l.message(); +} + +namespace Noatun +{ + +class Session_impl : public Session_skel +{ + list<Listener> listeners; + + long mPid; + +public: + + ~Session_impl() + { + for_each(listeners.begin(), listeners.end(), sendMessage); + } + + long pid() { return mPid; } + void pid(long p) { mPid=p; } + + + void addListener(Noatun::Listener listener) + { + listeners.push_back(listener); + } + + void removeListener(Noatun::Listener listener) + { + list<Listener>::iterator i= + find(listeners, listener, &compareArtsObjects); + if (i!=listeners.end()) + listeners.erase(i); + } + +}; + +class Listener_impl : public Listener_skel +{ + +private: + virtual void message() + { + // hmm + } + +}; + + +REGISTER_IMPLEMENTATION(Session_impl); +REGISTER_IMPLEMENTATION(Listener_impl); + + +} // namespace Noatun + |