summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2015-09-17 18:21:44 (GMT)
committerSwift Review <review@swift.im>2015-12-17 08:58:51 (GMT)
commit9bce26254aa3c2feffdd751b59cdee5e903fd2bc (patch)
tree27bf31b4564216db6bf74818dc76f0ba23af074e /Swiften/EventLoop
parentbea3559998c0ae0a2afca566046f08d0a201c0b2 (diff)
downloadswift-9bce26254aa3c2feffdd751b59cdee5e903fd2bc.zip
swift-9bce26254aa3c2feffdd751b59cdee5e903fd2bc.tar.bz2
Add event loop for integration in Boost ASIO
This allows execution of events inside an existing io_service if an application is already using Boost ASIO for other things and can share the io_service. Test-Information: Builds on OS X 10.11.2. Change-Id: I092ed7a25b24ef95d4664bae98ed84cc0f149073
Diffstat (limited to 'Swiften/EventLoop')
-rw-r--r--Swiften/EventLoop/BoostASIOEventLoop.cpp37
-rw-r--r--Swiften/EventLoop/BoostASIOEventLoop.h34
-rw-r--r--Swiften/EventLoop/SConscript5
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",
]