From 1642d13e5e8d593a36ef1945387794e0d13247be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Tue, 21 Jul 2009 01:20:08 +0200 Subject: Added Cocoa event loop. diff --git a/Makefile b/Makefile index f5bab96..8ea2c13 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ include Makefile.config CXXFLAGS += -I. +CFLAGS += -I. ARFLAGS = rcs .DEFAULT_GOAL = all diff --git a/Slimber/Cocoa/Makefile.inc b/Slimber/Cocoa/Makefile.inc index d07e0d7..6f0aa13 100644 --- a/Slimber/Cocoa/Makefile.inc +++ b/Slimber/Cocoa/Makefile.inc @@ -2,6 +2,7 @@ SLIMBER_COCOA_TARGET = Slimber/Cocoa/Slimber.app SLIMBER_COCOA_BINARY = \ Slimber/Cocoa/Slimber SLIMBER_COCOA_SOURCES = \ + Slimber/Server.cpp \ Slimber/Cocoa/main.m \ Slimber/Cocoa/Menulet.m SLIMBER_COCOA_XIBS = \ @@ -13,15 +14,15 @@ SLIMBER_COCOA_RESOURCES = \ SLIMBER_COCOA_NIBS = \ $(SLIMBER_COCOA_XIBS:.xib=.nib) SLIMBER_COCOA_OBJECTS = \ - $(SLIMBER_COCOA_SOURCES:.m=.o) + $(patsubst %.m,%.o,$(patsubst %.cpp,%.o, $(SLIMBER_COCOA_SOURCES))) CLEANFILES += \ Slimber/Cocoa/PkgInfo \ $(SLIMBER_COCOA_OBJECTS) \ $(SLIMBER_COCOA_NIBS) \ $(SLIMBER_COCOA_TARGET) \ $(SLIMBER_COCOA_BINARY) -DEPS += \ - $(SLIMBER_COCOA_SOURCES:.m=.dep) \ +//DEPS += \ +// $(SLIMBER_COCOA_SOURCES:.m=.dep) \ .PHONY: slimber-cocoa slimber-cocoa: $(SLIMBER_COCOA_TARGET) @@ -36,5 +37,5 @@ $(SLIMBER_COCOA_TARGET): $(SLIMBER_COCOA_BINARY) $(SLIMBER_COCOA_NIBS) Slimber/C cp $(SLIMBER_COCOA_NIBS) $(SLIMBER_COCOA_TARGET)/Contents/Resources cp $(SLIMBER_COCOA_RESOURCES) $(SLIMBER_COCOA_TARGET)/Contents/Resources -$(SLIMBER_COCOA_BINARY): $(SLIMBER_COCOA_OBJECTS) +$(SLIMBER_COCOA_BINARY): $(SLIMBER_COCOA_OBJECTS) $(SWIFTEN_TARGET) $(QUIET_LINK)$(CXX) -o $@ $(SLIMBER_COCOA_OBJECTS) $(LDFLAGS) $(SWIFTEN_TARGET) $(LIBS) -framework Cocoa diff --git a/Slimber/Cocoa/main.mm b/Slimber/Cocoa/main.mm index b7266b5..e777e0d 100644 --- a/Slimber/Cocoa/main.mm +++ b/Slimber/Cocoa/main.mm @@ -1,5 +1,19 @@ #include +#include +#include + +#include "Swiften/LinkLocal/AppleDNSSDService.h" +#include "Swiften/EventLoop/Cocoa/CocoaEventLoop.h" +#include "Slimber/Server.h" + +using namespace Swift; int main(int argc, char *argv[]) { + CocoaEventLoop eventLoop; + + boost::shared_ptr dnsSDService= + boost::shared_ptr(new AppleDNSSDService()); + Server server(5222, 5562, dnsSDService); + return NSApplicationMain(argc, const_cast(argv)); } 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 + +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) -- cgit v0.10.2-6-g49f6