summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers/XMPPEvents/EventController.cpp')
-rw-r--r--Swift/Controllers/XMPPEvents/EventController.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp
new file mode 100644
index 0000000..b14ff46
--- /dev/null
+++ b/Swift/Controllers/XMPPEvents/EventController.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swift/Controllers/XMPPEvents/EventController.h"
+
+#include <boost/bind.hpp>
+#include <algorithm>
+
+#include "Swift/Controllers/XMPPEvents/MessageEvent.h"
+#include "Swift/Controllers/XMPPEvents/ErrorEvent.h"
+#include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h"
+
+namespace Swift {
+
+EventController::EventController() {
+}
+
+void EventController::handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceEvent) {
+ boost::shared_ptr<MessageEvent> messageEvent = boost::dynamic_pointer_cast<MessageEvent>(sourceEvent);
+ boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent);
+ boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(sourceEvent);
+ if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent) {
+ events_.push_back(sourceEvent);
+ sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent));
+ onEventQueueLengthChange(events_.size());
+ onEventQueueEventAdded(sourceEvent);
+ }
+}
+
+void EventController::handleEventConcluded(boost::shared_ptr<StanzaEvent> event) {
+ events_.erase(std::remove(events_.begin(), events_.end(), event), events_.end());
+ onEventQueueLengthChange(events_.size());
+}
+
+}