summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/EventLoop')
-rw-r--r--Swiften/EventLoop/Event.h3
-rw-r--r--Swiften/EventLoop/EventLoop.cpp17
2 files changed, 16 insertions, 4 deletions
diff --git a/Swiften/EventLoop/Event.h b/Swiften/EventLoop/Event.h
index 763fe00..6f5a9e5 100644
--- a/Swiften/EventLoop/Event.h
+++ b/Swiften/EventLoop/Event.h
@@ -14,8 +14,7 @@
namespace Swift {
class Event {
public:
- Event(boost::shared_ptr<EventOwner> owner, const boost::function<void()>& callback) :
- owner(owner), callback(callback) {
+ Event(boost::shared_ptr<EventOwner> owner, const boost::function<void()>& callback) : id(~0U), owner(owner), callback(callback) {
}
bool operator==(const Event& o) const {
diff --git a/Swiften/EventLoop/EventLoop.cpp b/Swiften/EventLoop/EventLoop.cpp
index f787e73..c6d42d8 100644
--- a/Swiften/EventLoop/EventLoop.cpp
+++ b/Swiften/EventLoop/EventLoop.cpp
@@ -10,6 +10,8 @@
#include <boost/bind.hpp>
#include <iostream>
+#include <Swiften/Base/Log.h>
+
namespace Swift {
EventLoop::EventLoop() : nextEventID_(0), handlingEvents_(false) {
@@ -37,13 +39,24 @@ void EventLoop::handleEvent(const Event& event) {
}
if (doCallback) {
handlingEvents_ = true;
- event.callback();
+ try {
+ event.callback();
+ }
+ catch (const boost::bad_function_call&) {
+ SWIFT_LOG(error) << "Invalid function call" << std::endl;
+ }
+
// Process events that were passed to handleEvent during the callback
// (i.e. through recursive calls of handleEvent)
while (!eventsToHandle_.empty()) {
Event nextEvent = eventsToHandle_.front();
eventsToHandle_.pop_front();
- nextEvent.callback();
+ try {
+ nextEvent.callback();
+ }
+ catch (const boost::bad_function_call&) {
+ SWIFT_LOG(error) << "Invalid function call" << std::endl;
+ }
}
handlingEvents_ = false;
}