diff options
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/EventLoop/Cocoa/CocoaEvent.h | 20 | ||||
-rw-r--r-- | Swiften/EventLoop/Cocoa/CocoaEvent.mm | 25 | ||||
-rw-r--r-- | Swiften/EventLoop/Cocoa/CocoaEventLoop.h | 14 | ||||
-rw-r--r-- | Swiften/EventLoop/Cocoa/CocoaEventLoop.mm | 21 | ||||
-rw-r--r-- | Swiften/EventLoop/Cocoa/Makefile.inc | 3 | ||||
-rw-r--r-- | Swiften/EventLoop/Makefile.inc | 3 | ||||
-rw-r--r-- | Swiften/Makefile.inc | 6 |
7 files changed, 89 insertions, 3 deletions
diff --git a/Swiften/EventLoop/Cocoa/CocoaEvent.h b/Swiften/EventLoop/Cocoa/CocoaEvent.h new file mode 100644 index 0000000..0ff4453 --- /dev/null +++ b/Swiften/EventLoop/Cocoa/CocoaEvent.h @@ -0,0 +1,20 @@ +#pragma once + +#include <Cocoa/Cocoa.h> + +namespace Swift { + class Event; + class CocoaEventLoop; +} + +@interface CocoaEvent : NSObject { + Swift::Event* event; + Swift::CocoaEventLoop* eventLoop; +} + +// Takes ownership of event +- (id) initWithEvent: (Swift::Event*) e eventLoop: (Swift::CocoaEventLoop*) el; +- (void) process; +- (void) dealloc; + +@end diff --git a/Swiften/EventLoop/Cocoa/CocoaEvent.mm b/Swiften/EventLoop/Cocoa/CocoaEvent.mm new file mode 100644 index 0000000..8a90983 --- /dev/null +++ b/Swiften/EventLoop/Cocoa/CocoaEvent.mm @@ -0,0 +1,25 @@ +#include "Swiften/EventLoop/Cocoa/CocoaEvent.h" +#include "Swiften/EventLoop/Event.h" +#include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" + +@implementation CocoaEvent + +- (id) initWithEvent: (Swift::Event*) e eventLoop: (Swift::CocoaEventLoop*) el { + self = [super init]; + if (self != nil) { + event = e; + eventLoop = el; + } + return self; +} + +- (void) process { + eventLoop->handleEvent(*event); +} + +- (void) dealloc { + delete event; + [super dealloc]; +} + +@end diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.h b/Swiften/EventLoop/Cocoa/CocoaEventLoop.h new file mode 100644 index 0000000..ad8e456 --- /dev/null +++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.h @@ -0,0 +1,14 @@ +#pragma once + +#include "Swiften/EventLoop/EventLoop.h" + +namespace Swift { + class CocoaEventLoop : public EventLoop { + public: + CocoaEventLoop(); + + virtual void post(const Event& event); + + using EventLoop::handleEvent; + }; +} diff --git a/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm new file mode 100644 index 0000000..b90f3c6 --- /dev/null +++ b/Swiften/EventLoop/Cocoa/CocoaEventLoop.mm @@ -0,0 +1,21 @@ +#include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" +#include "Swiften/EventLoop/Cocoa/CocoaEvent.h" + +#pragma GCC diagnostic ignored "-Wold-style-cast" + +namespace Swift { + +CocoaEventLoop::CocoaEventLoop() { +} + +void CocoaEventLoop::post(const Event& event) { + Event* eventCopy = new Event(event); + CocoaEvent* cocoaEvent = [[CocoaEvent alloc] initWithEvent: eventCopy eventLoop: this]; + [cocoaEvent + performSelectorOnMainThread:@selector(process) + withObject: nil + waitUntilDone: NO]; + [cocoaEvent release]; +} + +} diff --git a/Swiften/EventLoop/Cocoa/Makefile.inc b/Swiften/EventLoop/Cocoa/Makefile.inc new file mode 100644 index 0000000..aaa038e --- /dev/null +++ b/Swiften/EventLoop/Cocoa/Makefile.inc @@ -0,0 +1,3 @@ +SWIFTEN_OBJECTIVE_SOURCES += \ + Swiften/EventLoop/Cocoa/CocoaEvent.mm \ + Swiften/EventLoop/Cocoa/CocoaEventLoop.mm diff --git a/Swiften/EventLoop/Makefile.inc b/Swiften/EventLoop/Makefile.inc index 3347ae6..78ebdcd 100644 --- a/Swiften/EventLoop/Makefile.inc +++ b/Swiften/EventLoop/Makefile.inc @@ -4,4 +4,7 @@ SWIFTEN_SOURCES += \ Swiften/EventLoop/SimpleEventLoop.cpp \ Swiften/EventLoop/MainEventLoop.cpp +ifeq ($(MACOSX),1) +include Swiften/EventLoop/Cocoa/Makefile.inc +endif include Swiften/EventLoop/UnitTest/Makefile.inc diff --git a/Swiften/Makefile.inc b/Swiften/Makefile.inc index d66a2b9..57ff329 100644 --- a/Swiften/Makefile.inc +++ b/Swiften/Makefile.inc @@ -30,7 +30,7 @@ CPPFLAGS += $(SQLITE_CPPFLAGS) SWIFTEN_TARGET = Swiften/Swiften.a SWIFTEN_OBJECTS = \ $(SWIFTEN_SOURCES:.cpp=.o) \ - $(SWIFTEN_OBJECTIVE_SOURCES:.mm=.o) \ + $(patsubst %.mm, %.o, $(patsubst %.m, %.o, $(SWIFTEN_OBJECTIVE_SOURCES))) \ $(LIBIDN_OBJECTS) \ $(BOOST_OBJECTS) \ $(ZLIB_OBJECTS) \ @@ -43,8 +43,8 @@ INSTALL_TARGETS += install-swiften UNITTEST_LIBS += $(SWIFTEN_TARGET) CLEANFILES += $(SWIFTEN_TARGET) $(SWIFTEN_OBJECTS) DEPS += \ - $(SWIFTEN_SOURCES:.cpp=.dep) \ - $(SWIFTEN_OBJECTIVE_SOURCES:.mm=.dep) + $(SWIFTEN_SOURCES:.cpp=.dep) +//TODO: Add objective stuff .PHONY: lib lib: $(SWIFTEN_TARGET) |