mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-22 15:40:16 +00:00
cocoa: fix compile
This commit is contained in:
parent
e505764193
commit
cdfcecd214
@ -52,6 +52,11 @@
|
|||||||
static struct timeval init_tv;
|
static struct timeval init_tv;
|
||||||
static const btstack_run_loop_t btstack_run_loop_cocoa;
|
static const btstack_run_loop_t btstack_run_loop_cocoa;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
CFSocketRef socket;
|
||||||
|
CFRunLoopSourceRef socketRunLoop;
|
||||||
|
} btstack_cocoa_data_source_helper_t;
|
||||||
|
|
||||||
static void theCFRunLoopTimerCallBack (CFRunLoopTimerRef timer,void *info){
|
static void theCFRunLoopTimerCallBack (CFRunLoopTimerRef timer,void *info){
|
||||||
btstack_timer_source_t * ts = (btstack_timer_source_t*)info;
|
btstack_timer_source_t * ts = (btstack_timer_source_t*)info;
|
||||||
ts->process(ts);
|
ts->process(ts);
|
||||||
@ -75,6 +80,13 @@ void btstack_run_loop_cocoa_add_data_source(btstack_data_source_t *dataSource){
|
|||||||
|
|
||||||
// add fd as CFSocket
|
// add fd as CFSocket
|
||||||
|
|
||||||
|
// allocate memory for Core Foundation references
|
||||||
|
btstack_cocoa_data_source_helper_t * references = malloc(sizeof(btstack_cocoa_data_source_helper_t));
|
||||||
|
if (!references){
|
||||||
|
log_error("btstack_run_loop_cocoa_add_data_source could not allocate btstack_cocoa_data_source_helper_t");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// store our dataSource in socket context
|
// store our dataSource in socket context
|
||||||
CFSocketContext socketContext;
|
CFSocketContext socketContext;
|
||||||
memset(&socketContext, 0, sizeof(CFSocketContext));
|
memset(&socketContext, 0, sizeof(CFSocketContext));
|
||||||
@ -95,9 +107,12 @@ void btstack_run_loop_cocoa_add_data_source(btstack_data_source_t *dataSource){
|
|||||||
// create run loop source
|
// create run loop source
|
||||||
CFRunLoopSourceRef socketRunLoop = CFSocketCreateRunLoopSource ( kCFAllocatorDefault, socket, 0);
|
CFRunLoopSourceRef socketRunLoop = CFSocketCreateRunLoopSource ( kCFAllocatorDefault, socket, 0);
|
||||||
|
|
||||||
// hack: store CFSocketRef in "next" and CFRunLoopSourceRef in "user_data" of btstack_linked_item_t
|
// store CFSocketRef and CFRunLoopSource in struct on heap
|
||||||
dataSource->item.next = (void *) socket;
|
references->socket = socket;
|
||||||
dataSource->item.user_data = (void *) socketRunLoop;
|
references->socketRunLoop = socketRunLoop;
|
||||||
|
|
||||||
|
// hack: store btstack_cocoa_data_source_helper_t in "next" of btstack_linked_item_t
|
||||||
|
dataSource->item.next = (void *) references;
|
||||||
|
|
||||||
// add to run loop
|
// add to run loop
|
||||||
CFRunLoopAddSource( CFRunLoopGetCurrent(), socketRunLoop, kCFRunLoopCommonModes);
|
CFRunLoopAddSource( CFRunLoopGetCurrent(), socketRunLoop, kCFRunLoopCommonModes);
|
||||||
@ -106,11 +121,15 @@ void btstack_run_loop_cocoa_add_data_source(btstack_data_source_t *dataSource){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int btstack_run_loop_cocoa_remove_data_source(btstack_data_source_t *dataSource){
|
int btstack_run_loop_cocoa_remove_data_source(btstack_data_source_t *dataSource){
|
||||||
|
btstack_cocoa_data_source_helper_t * references = (btstack_cocoa_data_source_helper_t *) dataSource->item.next;
|
||||||
// printf("btstack_run_loop_cocoa_remove_data_source %x - fd %u, CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->fd, (int) dataSource->item.next, (int) dataSource->item.user_data);
|
// printf("btstack_run_loop_cocoa_remove_data_source %x - fd %u, CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->fd, (int) dataSource->item.next, (int) dataSource->item.user_data);
|
||||||
CFRunLoopRemoveSource( CFRunLoopGetCurrent(), (CFRunLoopSourceRef) dataSource->item.user_data, kCFRunLoopCommonModes);
|
CFRunLoopRemoveSource( CFRunLoopGetCurrent(), references->socketRunLoop, kCFRunLoopCommonModes);
|
||||||
CFRelease(dataSource->item.user_data);
|
CFRelease(references->socketRunLoop);
|
||||||
CFSocketInvalidate((CFSocketRef) dataSource->item.next);
|
|
||||||
CFRelease(dataSource->item.next);
|
CFSocketInvalidate(references->socket);
|
||||||
|
CFRelease(references->socket);
|
||||||
|
|
||||||
|
free(references);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user