mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
cocoa_ -> run_loop_cocoa_
This commit is contained in:
parent
8a5131287b
commit
3e39f9f6b5
@ -66,12 +66,12 @@ static void socketDataCallback (
|
||||
|
||||
if (callbackType == kCFSocketReadCallBack && info){
|
||||
data_source_t *dataSource = (data_source_t *) info;
|
||||
// printf("cocoa_data_source %x - fd %u, CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->fd, (int) s, (int) dataSource->item.next);
|
||||
// printf("run_loop_cocoa_data_source %x - fd %u, CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->fd, (int) s, (int) dataSource->item.next);
|
||||
dataSource->process(dataSource);
|
||||
}
|
||||
}
|
||||
|
||||
void cocoa_add_data_source(data_source_t *dataSource){
|
||||
void run_loop_cocoa_add_data_source(data_source_t *dataSource){
|
||||
|
||||
// add fd as CFSocket
|
||||
|
||||
@ -101,12 +101,12 @@ void cocoa_add_data_source(data_source_t *dataSource){
|
||||
|
||||
// add to run loop
|
||||
CFRunLoopAddSource( CFRunLoopGetCurrent(), socketRunLoop, kCFRunLoopCommonModes);
|
||||
// printf("cocoa_add_data_source %x - fd %u - CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->fd, (int) socket, (int) socketRunLoop);
|
||||
// printf("run_loop_cocoa_add_data_source %x - fd %u - CFSocket %x, CFRunLoopSource %x\n", (int) dataSource, dataSource->fd, (int) socket, (int) socketRunLoop);
|
||||
|
||||
}
|
||||
|
||||
int cocoa_remove_data_source(data_source_t *dataSource){
|
||||
// printf("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);
|
||||
int run_loop_cocoa_remove_data_source(data_source_t *dataSource){
|
||||
// printf("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);
|
||||
CFRelease(dataSource->item.user_data);
|
||||
CFSocketInvalidate((CFSocketRef) dataSource->item.next);
|
||||
@ -114,7 +114,7 @@ int cocoa_remove_data_source(data_source_t *dataSource){
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cocoa_add_timer(timer_source_t * ts)
|
||||
void run_loop_cocoa_add_timer(timer_source_t * ts)
|
||||
{
|
||||
// note: ts uses unix time: seconds since Jan 1st 1970, CF uses Jan 1st 2001 as reference date
|
||||
// printf("kCFAbsoluteTimeIntervalSince1970 = %f\n", kCFAbsoluteTimeIntervalSince1970);
|
||||
@ -125,12 +125,12 @@ void cocoa_add_timer(timer_source_t * ts)
|
||||
|
||||
// hack: store CFRunLoopTimerRef in next pointer of linked_item
|
||||
ts->item.next = (void *)timerRef;
|
||||
// printf("cocoa_add_timer %x -> %x now %f, then %f\n", (int) ts, (int) ts->item.next, CFAbsoluteTimeGetCurrent(),fireDate);
|
||||
// printf("run_loop_cocoa_add_timer %x -> %x now %f, then %f\n", (int) ts, (int) ts->item.next, CFAbsoluteTimeGetCurrent(),fireDate);
|
||||
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timerRef, kCFRunLoopCommonModes);
|
||||
}
|
||||
|
||||
int cocoa_remove_timer(timer_source_t * ts){
|
||||
// printf("cocoa_remove_timer %x -> %x\n", (int) ts, (int) ts->item.next);
|
||||
int run_loop_cocoa_remove_timer(timer_source_t * ts){
|
||||
// printf("run_loop_cocoa_remove_timer %x -> %x\n", (int) ts, (int) ts->item.next);
|
||||
if (ts->item.next != NULL) {
|
||||
CFRunLoopTimerInvalidate((CFRunLoopTimerRef) ts->item.next); // also removes timer from run loops + releases it
|
||||
CFRelease((CFRunLoopTimerRef) ts->item.next);
|
||||
@ -139,7 +139,7 @@ int cocoa_remove_timer(timer_source_t * ts){
|
||||
}
|
||||
|
||||
// set timer
|
||||
static void cocoa_set_timer(timer_source_t *a, uint32_t timeout_in_ms){
|
||||
static void run_loop_cocoa_set_timer(timer_source_t *a, uint32_t timeout_in_ms){
|
||||
gettimeofday(&a->timeout, NULL);
|
||||
a->timeout.tv_sec += timeout_in_ms / 1000;
|
||||
a->timeout.tv_usec += (timeout_in_ms % 1000) * 1000;
|
||||
@ -152,36 +152,36 @@ static void cocoa_set_timer(timer_source_t *a, uint32_t timeout_in_ms){
|
||||
/**
|
||||
* @brief Queries the current time in ms since start
|
||||
*/
|
||||
static uint32_t cocoa_get_time_ms(void){
|
||||
static uint32_t run_loop_cocoa_get_time_ms(void){
|
||||
struct timeval current_tv;
|
||||
gettimeofday(¤t_tv, NULL);
|
||||
return (current_tv.tv_sec - init_tv.tv_sec) * 1000
|
||||
+ (current_tv.tv_usec - init_tv.tv_usec) / 1000;
|
||||
}
|
||||
|
||||
void cocoa_init(void){
|
||||
void run_loop_cocoa_init(void){
|
||||
gettimeofday(&init_tv, NULL);
|
||||
}
|
||||
|
||||
void cocoa_execute(void)
|
||||
void run_loop_cocoa_execute(void)
|
||||
{
|
||||
CFRunLoopRun();
|
||||
}
|
||||
|
||||
void cocoa_dump_timer(void){
|
||||
void run_loop_cocoa_dump_timer(void){
|
||||
log_error("WARNING: run_loop_dump_timer not implemented!");
|
||||
return;
|
||||
}
|
||||
|
||||
run_loop_t run_loop_cocoa = {
|
||||
&cocoa_init,
|
||||
&cocoa_add_data_source,
|
||||
&cocoa_remove_data_source,
|
||||
&cocoa_set_timer,
|
||||
&cocoa_add_timer,
|
||||
&cocoa_remove_timer,
|
||||
&cocoa_execute,
|
||||
&cocoa_dump_timer,
|
||||
&cocoa_get_time_ms,
|
||||
&run_loop_cocoa_init,
|
||||
&run_loop_cocoa_add_data_source,
|
||||
&run_loop_cocoa_remove_data_source,
|
||||
&run_loop_cocoa_set_timer,
|
||||
&run_loop_cocoa_add_timer,
|
||||
&run_loop_cocoa_remove_timer,
|
||||
&run_loop_cocoa_execute,
|
||||
&run_loop_cocoa_dump_timer,
|
||||
&run_loop_cocoa_get_time_ms,
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user