summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-20 23:20:08 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-20 23:28:53 (GMT)
commit1642d13e5e8d593a36ef1945387794e0d13247be (patch)
treedae6568c7b3d67ff374ddbeea4e99f6a588aa386
parentcc03d5aab20bde58d700b329f5fa7388698d9e68 (diff)
downloadswift-1642d13e5e8d593a36ef1945387794e0d13247be.zip
swift-1642d13e5e8d593a36ef1945387794e0d13247be.tar.bz2
Added Cocoa event loop.
-rw-r--r--Makefile1
-rw-r--r--Slimber/Cocoa/Makefile.inc9
-rw-r--r--Slimber/Cocoa/main.mm14
-rw-r--r--Swiften/EventLoop/Cocoa/CocoaEvent.h20
-rw-r--r--Swiften/EventLoop/Cocoa/CocoaEvent.mm25
-rw-r--r--Swiften/EventLoop/Cocoa/CocoaEventLoop.h14
-rw-r--r--Swiften/EventLoop/Cocoa/CocoaEventLoop.mm21
-rw-r--r--Swiften/EventLoop/Cocoa/Makefile.inc3
-rw-r--r--Swiften/EventLoop/Makefile.inc3
-rw-r--r--Swiften/Makefile.inc6
10 files changed, 109 insertions, 7 deletions
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 <Cocoa/Cocoa.h>
+#include <string>
+#include <boost/bind.hpp>
+
+#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> dnsSDService=
+ boost::shared_ptr<AppleDNSSDService>(new AppleDNSSDService());
+ Server server(5222, 5562, dnsSDService);
+
return NSApplicationMain(argc, const_cast<const char **>(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 <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)