diff options
Diffstat (limited to 'Swiften/EventLoop')
-rw-r--r-- | Swiften/EventLoop/BoostASIOEventLoop.cpp | 37 | ||||
-rw-r--r-- | Swiften/EventLoop/BoostASIOEventLoop.h | 34 | ||||
-rw-r--r-- | Swiften/EventLoop/SConscript | 5 |
3 files changed, 74 insertions, 2 deletions
diff --git a/Swiften/EventLoop/BoostASIOEventLoop.cpp b/Swiften/EventLoop/BoostASIOEventLoop.cpp new file mode 100644 index 0000000..f3c5618 --- /dev/null +++ b/Swiften/EventLoop/BoostASIOEventLoop.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swiften/EventLoop/BoostASIOEventLoop.h> + +#include <boost/bind.hpp> + +namespace Swift { + +BoostASIOEventLoop::BoostASIOEventLoop(boost::shared_ptr<boost::asio::io_service> ioService) : ioService_(ioService) { + +} + +BoostASIOEventLoop::~BoostASIOEventLoop() { + +} + +void BoostASIOEventLoop::handleASIOEvent() { + { + boost::recursive_mutex::scoped_lock lock(isEventInASIOEventLoopMutex_); + isEventInASIOEventLoop_ = false; + } + handleNextEvent(); +} + +void BoostASIOEventLoop::eventPosted() { + boost::recursive_mutex::scoped_lock lock(isEventInASIOEventLoopMutex_); + if (!isEventInASIOEventLoop_) { + isEventInASIOEventLoop_ = true; + ioService_->post(boost::bind(&BoostASIOEventLoop::handleASIOEvent, this)); + } +} + +} diff --git a/Swiften/EventLoop/BoostASIOEventLoop.h b/Swiften/EventLoop/BoostASIOEventLoop.h new file mode 100644 index 0000000..a093199 --- /dev/null +++ b/Swiften/EventLoop/BoostASIOEventLoop.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#pragma once + +#include <boost/asio/io_service.hpp> +#include <boost/shared_ptr.hpp> +#include <boost/thread.hpp> + +#include <Swiften/Base/API.h> +#include <Swiften/EventLoop/Event.h> +#include <Swiften/EventLoop/EventLoop.h> + +namespace Swift { + class SWIFTEN_API BoostASIOEventLoop : public EventLoop { + public: + BoostASIOEventLoop(boost::shared_ptr<boost::asio::io_service> ioService); + virtual ~BoostASIOEventLoop(); + + protected: + void handleASIOEvent(); + + virtual void eventPosted(); + + private: + boost::shared_ptr<boost::asio::io_service> ioService_; + + bool isEventInASIOEventLoop_; + boost::recursive_mutex isEventInASIOEventLoopMutex_; + }; +} diff --git a/Swiften/EventLoop/SConscript b/Swiften/EventLoop/SConscript index d26661c..b810e8c 100644 --- a/Swiften/EventLoop/SConscript +++ b/Swiften/EventLoop/SConscript @@ -1,11 +1,12 @@ Import("swiften_env") sources = [ + "BoostASIOEventLoop.cpp", + "DummyEventLoop.cpp", + "Event.cpp", "EventLoop.cpp", "EventOwner.cpp", - "Event.cpp", "SimpleEventLoop.cpp", - "DummyEventLoop.cpp", "SingleThreadedEventLoop.cpp", ] |