register for SpringBoardDidLaunch notifications and wait up to ten seconds for SpringBoardAccess server before adding BTstack icon again

This commit is contained in:
matthias.ringwald 2011-02-02 21:37:40 +00:00
parent 30d108b309
commit 33871ba6fd
5 changed files with 55 additions and 21 deletions

View File

@ -14,21 +14,21 @@
- power handling: handle power changes in all states, receive and handle power notifications, keep track of individual clients
- fixed bugs in cocoa run loop implementation
- automate scan enable management: hci_set_discoverable(bool) sets inquiry scan, page scan is always active
- removed link key and name caching from BTstackManager, honor BTSTACK_EVENT_REMOTE_NAME_CACHED
- check if connection to SpringBoardAcccess server gets broken on respring
- detect respring to refresh SpringBoard status bar icons
NEXT:
- update WiiMote example to use BTstackManager
- check apps for sleep/wake mode compatibility - see what happens on ACTIVATED event
- update WiiMote example to use BTstackManager
- fix broken host detection in configure.in (make it compile on linux)
- BTstackManager & new remote_db
- don't keep device info
- don't handle link keys
- react to remote_name_cached event
- create Retina status bar icons
- bugs:
- verify: if (hic?) disconnect fails, l2cap channels are never discarded
- verify: if (hci?) disconnect fails, l2cap channels are never discarded
- verify: TestBTstackManager can do an inquiry, with 0 or more devices in the list
- get rid of BTInquireViewController
- update WiiMoteExample to use BTstackManager
- Update/rewrite BTstack Keyboard

View File

@ -23,7 +23,7 @@ BTdaemon_SOURCES = $(libBTstack_SOURCES) \
l2cap.c \
l2cap_signaling.c \
$(remote_device_db_sources) \
platform_iphone.c \
platform_iphone.m \
sdp.c \
$(springboard_access_sources)

View File

@ -283,11 +283,22 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
return err;
}
// local cache used to manage UI status
static HCI_STATE hci_state = HCI_STATE_OFF;
static int num_connections = 0;
static void update_ui_status(){
if (hci_state != HCI_STATE_WORKING) {
bluetooth_status_handler(BLUETOOTH_OFF);
} else {
if (num_connections) {
bluetooth_status_handler(BLUETOOTH_ACTIVE);
} else {
bluetooth_status_handler(BLUETOOTH_ON);
}
}
}
static void deamon_status_event_handler(uint8_t *packet, uint16_t size){
// local cache
static HCI_STATE hci_state = HCI_STATE_OFF;
static int num_connections = 0;
uint8_t update_status = 0;
@ -309,15 +320,7 @@ static void deamon_status_event_handler(uint8_t *packet, uint16_t size){
// choose full bluetooth state
if (update_status) {
if (hci_state != HCI_STATE_WORKING) {
bluetooth_status_handler(BLUETOOTH_OFF);
} else {
if (num_connections) {
bluetooth_status_handler(BLUETOOTH_ACTIVE);
} else {
bluetooth_status_handler(BLUETOOTH_ON);
}
}
update_ui_status();
}
}
@ -335,6 +338,7 @@ static void daemon_packet_handler(void * connection, uint8_t packet_type, uint16
}
}
static void power_notification_callback(POWER_NOTIFICATION_t notification){
switch (notification) {
case POWER_WILL_SLEEP:
@ -449,6 +453,7 @@ int main (int argc, char * const * argv){
#ifdef USE_SPRINGBOARD
bluetooth_status_handler = platform_iphone_status_handler;
platform_iphone_register_window_manager_restart(update_ui_status);
#endif
#ifdef REMOTE_DEVICE_DB

View File

@ -41,4 +41,5 @@
#include "hci.h"
void platform_iphone_status_handler(BLUETOOTH_STATE state);
void platform_iphone_status_handler(BLUETOOTH_STATE state);
void platform_iphone_register_window_manager_restart(void (*callback)());

View File

@ -43,6 +43,7 @@
#include <stdio.h>
#ifdef USE_SPRINGBOARD
#include <CoreFoundation/CoreFoundation.h>
// update SpringBoard icons
void platform_iphone_status_handler(BLUETOOTH_STATE state){
@ -67,4 +68,31 @@ void platform_iphone_status_handler(BLUETOOTH_STATE state){
}
}
static void (*window_manager_restart_callback)() = NULL;
static void springBoardDidLaunch(){
printf("springBoardDidLaunch!\n");
if (window_manager_restart_callback) {
int timer;
for (timer = 0 ; timer < 10 ; timer++){
printf("ping SBA %u\n", timer);
if (SBA_available()){
printf("pong from SBA!\n");
break;
}
sleep(1);
}
(*window_manager_restart_callback)();
}
}
void platform_iphone_register_window_manager_restart(void (*callback)() ){
static int registered = 0;
if (!registered) {
// register for launch notification
CFNotificationCenterRef darwin = CFNotificationCenterGetDarwinNotifyCenter();
CFNotificationCenterAddObserver(darwin, NULL, (CFNotificationCallback) springBoardDidLaunch,
(CFStringRef) @"SBSpringBoardDidLaunchNotification", NULL, 0);
}
window_manager_restart_callback = callback;
}
#endif