From e5f8862c28bb0ae7459a8c579e06afccdaca47b8 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Wed, 19 Aug 2009 21:06:05 +0000 Subject: [PATCH] created launchd plist for automatic start of BTdaemon on Mac & iPhone --- Makefile.am | 4 ++-- TODO.txt | 7 ++----- project.xcodeproj/project.pbxproj | 2 ++ resources/ch.ringwald.BTstack.plist | 32 +++++++++++++++++++++++++++++ src/daemon.c | 6 +++++- src/platform_iphone.m | 2 ++ 6 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 resources/ch.ringwald.BTstack.plist diff --git a/Makefile.am b/Makefile.am index 2bcd408f3..855d98bed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,5 +5,5 @@ iphone_ip=@IPHONE_IP@ install-iphone: src/BTdaemon cp $< $<-signed export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate ; ldid -S $<-signed - scp $<-signed root@$(iphone_ip):/var/root/BTdaemon - + scp $<-signed root@$(iphone_ip):/usr/bin/BTdaemon + scp resources/ch.ringwald.BTstack.plist root@$(iphone_ip):/Library/LaunchDaemons/ diff --git a/TODO.txt b/TODO.txt index 62f82b4b5..8a030fe5c 100644 --- a/TODO.txt +++ b/TODO.txt @@ -3,15 +3,12 @@ Last milestone reached: Restart client app without restarting BTdaemon possible NEXT: -- client/server part using unix domain sockets (faster than TCP/IP) -- autostart by launchd +- autostart by launchd: ch.ringwald.BTstack.plist + - provide SIGTERM handler - Unix Socket example Mac: http://lists.apple.com/archives/Macnetworkprog/2007/Oct/msg00078.html - Mac OS X book: 472-485 - check with launchd, too? - launch.h exists in 3.0 SDK, but also in inofficial headers before - - socket handling using kevent - - exists too. - - too complicated - stop BTdaemon after X minutes idle - iPhone status icon support - set BTstack SpringBoard icon from background deamon diff --git a/project.xcodeproj/project.pbxproj b/project.xcodeproj/project.pbxproj index 87b6d4ebd..0facae57a 100644 --- a/project.xcodeproj/project.pbxproj +++ b/project.xcodeproj/project.pbxproj @@ -67,6 +67,7 @@ 9C78A04B103C6734003B2950 /* Default_BTstackActive.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default_BTstackActive.png; path = resources/Default_BTstackActive.png; sourceTree = ""; }; 9C78A04C103C6734003B2950 /* FSO_BTstack.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = FSO_BTstack.png; path = resources/FSO_BTstack.png; sourceTree = ""; }; 9C78A04D103C6734003B2950 /* FSO_BTstackActive.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = FSO_BTstackActive.png; path = resources/FSO_BTstackActive.png; sourceTree = ""; }; + 9C78A0BB103C9DEE003B2950 /* ch.ringwald.BTstack.plist */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = text.plist.xml; name = ch.ringwald.BTstack.plist; path = resources/ch.ringwald.BTstack.plist; sourceTree = ""; }; 9C7B5ABE100BD3340065D87E /* linked_list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = linked_list.h; path = src/linked_list.h; sourceTree = ""; }; 9C7B5ABF100BD3340065D87E /* linked_list.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = linked_list.c; path = src/linked_list.c; sourceTree = ""; }; 9C7B5B7E100D04450065D87E /* test.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = test.c; path = example/test.c; sourceTree = ""; }; @@ -169,6 +170,7 @@ 9C78A049103C671D003B2950 /* Resources */ = { isa = PBXGroup; children = ( + 9C78A0BB103C9DEE003B2950 /* ch.ringwald.BTstack.plist */, 9C78A04A103C6734003B2950 /* Default_BTstack.png */, 9C78A04B103C6734003B2950 /* Default_BTstackActive.png */, 9C78A04C103C6734003B2950 /* FSO_BTstack.png */, diff --git a/resources/ch.ringwald.BTstack.plist b/resources/ch.ringwald.BTstack.plist new file mode 100644 index 000000000..c1b8fd39f --- /dev/null +++ b/resources/ch.ringwald.BTstack.plist @@ -0,0 +1,32 @@ + + + + + Label + ch.ringwald.BTstack + OnDemand + + Program + /usr/bin/BTdaemon + ServiceIPC + + ProgramArguments + + StandardErrorPath + /var/log/BTstack.log + Sockets + + Listeners + + SockFamiliy + Unix + SockType + Stream + SockPathName + /tmp/BTstack + SockPathMode + 438 + + + + diff --git a/src/daemon.c b/src/daemon.c index 4fc33eae4..76ac831e6 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -204,7 +204,11 @@ int main (int argc, const char * argv[]){ // handle CTRL-c signal(SIGINT, daemon_sigint_handler); - + // handle SIGTERM - suggested for launchd + signal(SIGTERM, daemon_sigint_handler); + // make stderr unbuffered + setbuf(stderr, NULL); + bluetooth_status_handler(BLUETOOTH_ACTIVE); // go! diff --git a/src/platform_iphone.m b/src/platform_iphone.m index 844dbd899..21dc2c088 100644 --- a/src/platform_iphone.m +++ b/src/platform_iphone.m @@ -4,6 +4,8 @@ // Created by Matthias Ringwald on 8/15/09. // +#include "../config.h" + #import "platform_iphone.h" #ifdef USE_SPRINGBOARD