mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-31 19:20:26 +00:00
use CoreFoundation to store remote device DB, seems to work on iOS
This commit is contained in:
parent
2139f61875
commit
8c0e108c98
@ -29,21 +29,33 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "remote_device_db.h"
|
#include "remote_device_db.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#define BTdaemonID @"ch.ringwald.btdaemon"
|
#define BTdaemonID "ch.ringwald.btdaemon"
|
||||||
|
#define BTDaemonPrefsPath "Library/Preferences/ch.ringwald.btdaemon.plist"
|
||||||
|
#define DEVICES_KEY "devices"
|
||||||
#define PREFS_REMOTE_NAME @"RemoteName"
|
#define PREFS_REMOTE_NAME @"RemoteName"
|
||||||
#define PREFS_LINK_KEY @"LinkKey"
|
#define PREFS_LINK_KEY @"LinkKey"
|
||||||
|
|
||||||
|
static void put_name(bd_addr_t *bd_addr, device_name_t *device_name);
|
||||||
|
|
||||||
static NSMutableDictionary *remote_devices = nil;
|
static NSMutableDictionary *remote_devices = nil;
|
||||||
|
|
||||||
// Device info
|
// Device info
|
||||||
static void db_open(){
|
static void db_open(){
|
||||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
||||||
NSDictionary * dict = [defaults persistentDomainForName:BTdaemonID];
|
// NSUserDefaults didn't work
|
||||||
remote_devices = [[NSMutableDictionary alloc] initWithCapacity:([dict count]+5)];
|
//
|
||||||
|
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
// NSDictionary * dict = [defaults persistentDomainForName:BTdaemonID];
|
||||||
|
|
||||||
|
// NSDictionary * dict = (NSDictionary*) CFPreferencesCopyAppValue(CFSTR(DEVICES_KEY), CFSTR(BTdaemonID));
|
||||||
|
NSDictionary * dict = (NSDictionary*) CFPreferencesCopyAppValue(CFSTR(DEVICES_KEY), CFSTR(BTdaemonID));
|
||||||
|
remote_devices = [[NSMutableDictionary alloc] initWithCapacity:([dict count]+5)];
|
||||||
|
|
||||||
// copy entries
|
// copy entries
|
||||||
for (id key in dict) {
|
for (id key in dict) {
|
||||||
NSDictionary *value = [dict objectForKey:key];
|
NSDictionary *value = [dict objectForKey:key];
|
||||||
@ -51,17 +63,28 @@ static void db_open(){
|
|||||||
[deviceEntry addEntriesFromDictionary:value];
|
[deviceEntry addEntriesFromDictionary:value];
|
||||||
[remote_devices setObject:deviceEntry forKey:key];
|
[remote_devices setObject:deviceEntry forKey:key];
|
||||||
}
|
}
|
||||||
NSLog(@"read prefs (retain %u) %@", [remote_devices retainCount], remote_devices );
|
|
||||||
|
log_dbg("read prefs for %u devices\n", [dict count]);
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void db_close(){
|
static void db_close(){
|
||||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||||
NSLog(@"store prefs %@", remote_devices );
|
|
||||||
|
log_dbg("stored prefs for %u devices\n", [remote_devices count]);
|
||||||
|
|
||||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
// 3 different ways
|
||||||
[defaults setPersistentDomain:remote_devices forName:BTdaemonID];
|
|
||||||
[defaults synchronize];
|
// Core Foundation
|
||||||
|
CFPreferencesSetValue(CFSTR(DEVICES_KEY), (CFPropertyListRef) remote_devices, CFSTR(BTdaemonID), kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
||||||
|
CFPreferencesSynchronize(CFSTR(BTdaemonID), kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
||||||
|
|
||||||
|
// NSUserDefaults didn't work
|
||||||
|
//
|
||||||
|
// NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
// [defaults setPersistentDomain:remote_devices forName:BTdaemonID];
|
||||||
|
// [defaults synchronize];
|
||||||
|
|
||||||
[remote_devices release];
|
[remote_devices release];
|
||||||
remote_devices = nil;
|
remote_devices = nil;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user