Commit e25ef850 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI
Browse files

Use background task names when possible (ios7+) and use better names for them

parent b29b6335
...@@ -22,11 +22,19 @@ ...@@ -22,11 +22,19 @@
unsigned int belle_sip_begin_background_task(const char *name, belle_sip_background_task_end_callback_t cb, void *data){ unsigned int belle_sip_begin_background_task(const char *name, belle_sip_background_task_end_callback_t cb, void *data){
UIApplication *app=[UIApplication sharedApplication]; UIApplication *app=[UIApplication sharedApplication];
UIBackgroundTaskIdentifier bgid=[app beginBackgroundTaskWithExpirationHandler:^{ UIBackgroundTaskIdentifier bgid = UIBackgroundTaskInvalid;
void (^handler)() = ^{
cb(data); cb(data);
}]; };
if([app respondsToSelector:@selector(beginBackgroundTaskWithName:expirationHandler:)]){
bgid = [app beginBackgroundTaskWithName:[NSString stringWithUTF8String:name] expirationHandler:handler];
} else {
bgid = [app beginBackgroundTaskWithExpirationHandler:handler];
}
if (bgid==UIBackgroundTaskInvalid){ if (bgid==UIBackgroundTaskInvalid){
belle_sip_error("Could not start background task."); belle_sip_error("Could not start background task %s.", name);
return 0; return 0;
} }
return (unsigned int)bgid; return (unsigned int)bgid;
......
...@@ -768,7 +768,7 @@ static void channel_on_send_background_task_ended(belle_sip_channel_t *obj){ ...@@ -768,7 +768,7 @@ static void channel_on_send_background_task_ended(belle_sip_channel_t *obj){
static void channel_begin_send_background_task(belle_sip_channel_t *obj){ static void channel_begin_send_background_task(belle_sip_channel_t *obj){
if (obj->bg_task_id==0){ if (obj->bg_task_id==0){
obj->bg_task_id=belle_sip_begin_background_task("belle-sip channel in progress",(void (*)(void*))channel_on_send_background_task_ended, obj); obj->bg_task_id=belle_sip_begin_background_task("belle-sip send channel",(void (*)(void*))channel_on_send_background_task_ended, obj);
if (obj->bg_task_id) belle_sip_message("channel [%p]: starting send background task with id=[%x].",obj,obj->bg_task_id); if (obj->bg_task_id) belle_sip_message("channel [%p]: starting send background task with id=[%x].",obj,obj->bg_task_id);
} }
} }
...@@ -788,7 +788,7 @@ static void channel_on_recv_background_task_ended(belle_sip_channel_t *obj){ ...@@ -788,7 +788,7 @@ static void channel_on_recv_background_task_ended(belle_sip_channel_t *obj){
static void channel_begin_recv_background_task(belle_sip_channel_t *obj){ static void channel_begin_recv_background_task(belle_sip_channel_t *obj){
if (obj->recv_bg_task_id==0){ if (obj->recv_bg_task_id==0){
obj->recv_bg_task_id=belle_sip_begin_background_task("belle-sip channel in progress",(void (*)(void*))channel_on_recv_background_task_ended, obj); obj->recv_bg_task_id=belle_sip_begin_background_task("belle-sip recv channel",(void (*)(void*))channel_on_recv_background_task_ended, obj);
if (obj->recv_bg_task_id) belle_sip_message("channel [%p]: starting recv background task with id=[%x].",obj,obj->recv_bg_task_id); if (obj->recv_bg_task_id) belle_sip_message("channel [%p]: starting recv background task with id=[%x].",obj,obj->recv_bg_task_id);
} }
} }
......
...@@ -405,7 +405,7 @@ int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_requ ...@@ -405,7 +405,7 @@ int belle_http_provider_send_request(belle_http_provider_t *obj, belle_http_requ
fix_request(req); fix_request(req);
if( req->background_task_id != 0){ if( req->background_task_id != 0){
req->background_task_id = belle_sip_begin_background_task("http", belle_http_end_background_task, req); req->background_task_id = belle_sip_begin_background_task("belle-sip http", belle_http_end_background_task, req);
} }
belle_sip_channel_queue_message(chan,BELLE_SIP_MESSAGE(req)); belle_sip_channel_queue_message(chan,BELLE_SIP_MESSAGE(req));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment