summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-01-18 20:10:44 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-01-18 20:27:37 (GMT)
commit0d3d7579032959203c5c52f5ced9de5494c7b0bf (patch)
tree1e166cbae3dac23e8f815bc32f856b6c0a666fbd /Swiften/EventLoop
parentc2580661a20e30abaa23c61808d6370a575665c1 (diff)
downloadswift-contrib-0d3d7579032959203c5c52f5ced9de5494c7b0bf.zip
swift-contrib-0d3d7579032959203c5c52f5ced9de5494c7b0bf.tar.bz2
Cleaned up some code.
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;
}