From 2c67a6c460e440bd9b4d9f26cc51c34f122e3503 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Mon, 27 Oct 2014 17:05:03 +0100 Subject: [PATCH] Remove isLCReady method and don't remove the core when going into background mode. This removes a lot of code complexity and makes some strange simulator / device bugs workable (especially the very first start of the app). --- Classes/ChatRoomViewController.m | 17 --- Classes/DialerViewController.m | 88 ++++++++------- Classes/HistoryDetailsViewController.m | 3 - Classes/HistoryTableViewController.m | 18 ++-- Classes/LinphoneAppDelegate.m | 74 ++++--------- Classes/LinphoneCoreSettingsStore.m | 1 - Classes/LinphoneManager.m | 102 ++++++++---------- Classes/LinphoneUI/UICallBar.m | 4 - Classes/LinphoneUI/UICamSwitch.m | 4 - .../LinphoneUI/UICompositeViewController.m | 10 +- Classes/LinphoneUI/UIDigitButton.m | 10 +- .../LinphoneUI/UIDigitButtonLongVoiceMail.m | 5 - Classes/LinphoneUI/UIHangUpButton.m | 48 ++++----- Classes/LinphoneUI/UIMainBar.m | 6 +- Classes/LinphoneUI/UIMicroButton.m | 15 +-- Classes/LinphoneUI/UIPauseButton.m | 89 +++++++-------- Classes/LinphoneUI/UIStateBar.m | 55 +++++----- Classes/LinphoneUI/UIVideoButton.m | 89 +++++++-------- Classes/PhoneMainView.m | 1 - Classes/SettingsViewController.m | 44 ++++---- 20 files changed, 261 insertions(+), 422 deletions(-) diff --git a/Classes/ChatRoomViewController.m b/Classes/ChatRoomViewController.m index fbcf1ab8e..bcd3c89fb 100644 --- a/Classes/ChatRoomViewController.m +++ b/Classes/ChatRoomViewController.m @@ -170,10 +170,6 @@ static UICompositeViewDescription *compositeDescription = nil; selector:@selector(textComposeEvent:) name:kLinphoneTextComposeEvent object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(coreUpdateEvent:) - name:kLinphoneCoreUpdate - object:nil]; if([tableController isEditing]) [tableController setEditing:FALSE animated:FALSE]; [editButton setOff]; @@ -215,9 +211,6 @@ static UICompositeViewDescription *compositeDescription = nil; [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidChangeNotification object:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self - name:kLinphoneCoreUpdate - object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneTextComposeEvent object:nil]; @@ -312,10 +305,6 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta } - (BOOL)sendMessage:(NSString *)message withExterlBodyUrl:(NSURL*)externalUrl withInternalURL:(NSURL*)internalUrl { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot send message: Linphone core not ready"]; - return FALSE; - } if(chatRoom == NULL) { [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot send message: No chatroom"]; return FALSE; @@ -427,12 +416,6 @@ static void message_status(LinphoneChatMessage* msg,LinphoneChatMessageState sta #pragma mark - Event Functions -- (void)coreUpdateEvent:(NSNotification*)notif { - if(![LinphoneManager isLcReady]) { - chatRoom = NULL; - } -} - - (void)textReceivedEvent:(NSNotification *)notif { LinphoneAddress * from = [[[notif userInfo] objectForKey:@"from_address"] pointerValue]; LinphoneChatRoom* room = [[notif.userInfo objectForKey:@"room"] pointerValue]; diff --git a/Classes/DialerViewController.m b/Classes/DialerViewController.m index 42472a630..e9cd810ff 100644 --- a/Classes/DialerViewController.m +++ b/Classes/DialerViewController.m @@ -144,41 +144,39 @@ static UICompositeViewDescription *compositeDescription = nil; [callButton setEnabled:TRUE]; // Update on show - if([LinphoneManager isLcReady]) { - LinphoneManager *mgr=[LinphoneManager instance]; - LinphoneCore* lc = [LinphoneManager getLc]; - LinphoneCall* call = linphone_core_get_current_call(lc); - LinphoneCallState state = (call != NULL)?linphone_call_get_state(call): 0; - [self callUpdate:call state:state]; + LinphoneManager *mgr=[LinphoneManager instance]; + LinphoneCore* lc = [LinphoneManager getLc]; + LinphoneCall* call = linphone_core_get_current_call(lc); + LinphoneCallState state = (call != NULL)?linphone_call_get_state(call): 0; + [self callUpdate:call state:state]; - if([LinphoneManager runningOnIpad]) { - if(linphone_core_video_enabled(lc) && [mgr lpConfigBoolForKey:@"preview_preference"]) { - linphone_core_set_native_preview_window_id(lc, (unsigned long)videoPreview); - [backgroundView setHidden:FALSE]; - [videoCameraSwitch setHidden:FALSE]; - } else { - linphone_core_set_native_preview_window_id(lc, (unsigned long)NULL); - linphone_core_enable_video_preview(lc, FALSE); - [backgroundView setHidden:TRUE]; - [videoCameraSwitch setHidden:TRUE]; - } + if([LinphoneManager runningOnIpad]) { + if(linphone_core_video_enabled(lc) && [mgr lpConfigBoolForKey:@"preview_preference"]) { + linphone_core_set_native_preview_window_id(lc, (unsigned long)videoPreview); + [backgroundView setHidden:FALSE]; + [videoCameraSwitch setHidden:FALSE]; + } else { + linphone_core_set_native_preview_window_id(lc, (unsigned long)NULL); + linphone_core_enable_video_preview(lc, FALSE); + [backgroundView setHidden:TRUE]; + [videoCameraSwitch setHidden:TRUE]; } + } - [addressField setText:@""]; + [addressField setText:@""]; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0 // attributed string only available since iOS6 - if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { - // fix placeholder bar color in iOS7 - UIColor *color = [UIColor grayColor]; - NSAttributedString* placeHolderString = [[NSAttributedString alloc] - initWithString:NSLocalizedString(@"Enter an address", @"Enter an address") - attributes:@{NSForegroundColorAttributeName: color}]; - addressField.attributedPlaceholder = placeHolderString; - [placeHolderString release]; - } + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { + // fix placeholder bar color in iOS7 + UIColor *color = [UIColor grayColor]; + NSAttributedString* placeHolderString = [[NSAttributedString alloc] + initWithString:NSLocalizedString(@"Enter an address", @"Enter an address") + attributes:@{NSForegroundColorAttributeName: color}]; + addressField.attributedPlaceholder = placeHolderString; + [placeHolderString release]; + } #endif - } } - (void)viewWillDisappear:(BOOL)animated { @@ -256,7 +254,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)coreUpdateEvent:(NSNotification*)notif { - if([LinphoneManager isLcReady] && [LinphoneManager runningOnIpad]) { + if([LinphoneManager runningOnIpad]) { LinphoneCore* lc = [LinphoneManager getLc]; if(linphone_core_video_enabled(lc) && linphone_core_video_preview_enabled(lc)) { linphone_core_set_native_preview_window_id(lc, (unsigned long)videoPreview); @@ -273,26 +271,24 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - - (void)callUpdate:(LinphoneCall*)call state:(LinphoneCallState)state { - if([LinphoneManager isLcReady]) { - LinphoneCore *lc = [LinphoneManager getLc]; - if(linphone_core_get_calls_nb(lc) > 0) { - if(transferMode) { - [addCallButton setHidden:true]; - [transferButton setHidden:false]; - } else { - [addCallButton setHidden:false]; - [transferButton setHidden:true]; - } - [callButton setHidden:true]; - [backButton setHidden:false]; - [addContactButton setHidden:true]; - } else { + LinphoneCore *lc = [LinphoneManager getLc]; + if(linphone_core_get_calls_nb(lc) > 0) { + if(transferMode) { [addCallButton setHidden:true]; - [callButton setHidden:false]; - [backButton setHidden:true]; - [addContactButton setHidden:false]; + [transferButton setHidden:false]; + } else { + [addCallButton setHidden:false]; [transferButton setHidden:true]; } + [callButton setHidden:true]; + [backButton setHidden:false]; + [addContactButton setHidden:true]; + } else { + [addCallButton setHidden:true]; + [callButton setHidden:false]; + [backButton setHidden:true]; + [addContactButton setHidden:false]; + [transferButton setHidden:true]; } } diff --git a/Classes/HistoryDetailsViewController.m b/Classes/HistoryDetailsViewController.m index e327e4040..e918a0c2d 100644 --- a/Classes/HistoryDetailsViewController.m +++ b/Classes/HistoryDetailsViewController.m @@ -183,9 +183,6 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)update { - if(![LinphoneManager isLcReady]) { - return; - } // Look for the call log callLog = NULL; diff --git a/Classes/HistoryTableViewController.m b/Classes/HistoryTableViewController.m index 5ffe5addb..31b8e9adb 100644 --- a/Classes/HistoryTableViewController.m +++ b/Classes/HistoryTableViewController.m @@ -111,19 +111,17 @@ - (void)loadData { [callLogs removeAllObjects]; - if([LinphoneManager isLcReady]) { - const MSList * logs = linphone_core_get_call_logs([LinphoneManager getLc]); - while(logs != NULL) { - LinphoneCallLog* log = (LinphoneCallLog *) logs->data; - if(missedFilter) { - if (linphone_call_log_get_status(log) == LinphoneCallMissed) { - [callLogs addObject:[NSValue valueWithPointer: log]]; - } - } else { + const MSList * logs = linphone_core_get_call_logs([LinphoneManager getLc]); + while(logs != NULL) { + LinphoneCallLog* log = (LinphoneCallLog *) logs->data; + if(missedFilter) { + if (linphone_call_log_get_status(log) == LinphoneCallMissed) { [callLogs addObject:[NSValue valueWithPointer: log]]; } - logs = ms_list_next(logs); + } else { + [callLogs addObject:[NSValue valueWithPointer: log]]; } + logs = ms_list_next(logs); } [[self tableView] reloadData]; } diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index b29a1ec2f..9b7a9cd3a 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -56,13 +56,11 @@ - (void)applicationDidEnterBackground:(UIApplication *)application{ Linphone_log(@"%@", NSStringFromSelector(_cmd)); - if(![LinphoneManager isLcReady]) return; [[LinphoneManager instance] enterBackgroundMode]; } - (void)applicationWillResignActive:(UIApplication *)application { Linphone_log(@"%@", NSStringFromSelector(_cmd)); - if(![LinphoneManager isLcReady]) return; LinphoneCore* lc = [LinphoneManager getLc]; LinphoneCall* call = linphone_core_get_current_call(lc); @@ -87,7 +85,6 @@ - (void)applicationDidBecomeActive:(UIApplication *)application { Linphone_log(@"%@", NSStringFromSelector(_cmd)); - [self startApplication]; if( startedInBackground ){ startedInBackground = FALSE; [[PhoneMainView instance] startUp]; @@ -211,16 +208,13 @@ [[UIApplication sharedApplication] endBackgroundTask:bgStartId]; }]; - [self startApplication]; + [[LinphoneManager instance] startLibLinphone]; // initialize UI [self.window makeKeyAndVisible]; [RootViewManager setupWithPortrait:(PhoneMainView*)self.window.rootViewController]; - if( state == UIApplicationStateBackground ){ - startedInBackground = TRUE; - } else { - [[PhoneMainView instance] startUp]; - [[PhoneMainView instance] updateStatusBar:nil]; - } + [[PhoneMainView instance] startUp]; + [[PhoneMainView instance] updateStatusBar:nil]; + NSDictionary *remoteNotif =[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; @@ -233,13 +227,6 @@ return YES; } -- (void)startApplication { - // Restart Linphone Core if needed - if(![LinphoneManager isLcReady]) { - [[LinphoneManager instance] startLibLinphone]; - } -} - - (void)applicationWillTerminate:(UIApplication *)application { Linphone_log(@"%@", NSStringFromSelector(_cmd)); } @@ -257,14 +244,11 @@ [confirmation show]; [confirmation release]; } else { - [self startApplication]; - if([LinphoneManager isLcReady]) { - if([[url scheme] isEqualToString:@"sip"]) { - // Go to Dialer view - DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController); - if(controller != nil) { - [controller setAddress:[url absoluteString]]; - } + if([[url scheme] isEqualToString:@"sip"]) { + // Go to Dialer view + DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController); + if(controller != nil) { + [controller setAddress:[url absoluteString]]; } } } @@ -387,11 +371,6 @@ return; } - // check that linphone is still running - if( ![LinphoneManager isLcReady] ) - [lm startLibLinphone]; - - // save the completion handler for later execution. // 2 outcomes: // - if a new call/message is received, the completion handler will be called with "NEWDATA" @@ -522,37 +501,20 @@ { if ((alertView.tag == 1) && (buttonIndex==1)) { [self showWaitingIndicator]; - if([LinphoneManager isLcReady]) { - [self attemptRemoteConfiguration]; - } else { - [[LinphoneManager instance] startLibLinphone]; - [self performSelector:@selector(attemptRemoteConfiguration) withObject:NULL afterDelay:5.0]; - } + [self attemptRemoteConfiguration]; } - } - (void)attemptRemoteConfiguration { - if ([LinphoneManager isLcReady]) { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(ConfigurationStateUpdateEvent:) - name:kLinphoneConfiguringStateUpdate - object:nil]; - linphone_core_set_provisioning_uri([LinphoneManager getLc] , [configURL UTF8String]); - [[LinphoneManager instance] destroyLibLinphone]; - [[LinphoneManager instance] startLibLinphone]; - } else { - [_waitingIndicator dismissWithClickedButtonIndex:0 animated:true]; - UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Failure",nil) - message:NSLocalizedString(@"Linphone is not ready.",nil) - delegate:nil - cancelButtonTitle:NSLocalizedString(@"OK",nil) - otherButtonTitles:nil]; - [error show]; - [error release]; - - } + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(ConfigurationStateUpdateEvent:) + name:kLinphoneConfiguringStateUpdate + object:nil]; + linphone_core_set_provisioning_uri([LinphoneManager getLc] , [configURL UTF8String]); + [[LinphoneManager instance] destroyLibLinphone]; + [[LinphoneManager instance] startLibLinphone]; + } diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index e1a55a2a2..b48551168 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -496,7 +496,6 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); } - (BOOL)synchronize { - if (![LinphoneManager isLcReady]) return YES; LinphoneCore *lc=[LinphoneManager getLc]; BOOL account_changed; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index b81442164..f9b42dbeb 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -138,7 +138,7 @@ struct codec_name_pref_table codec_pref_table[]={ { "h264", 90000, @"h264_preference"}, { "vp8", 90000, @"vp8_preference"}, { "mpeg4-generic", 16000, @"aaceld_16k_preference"}, - { "mpeg4-generic", 22050, @"aaceld_22k_preference"}, + { "mpeg4-generic", 22050, @"aaceld_22k_preference"}, { "mpeg4-generic", 32000, @"aaceld_32k_preference"}, { "mpeg4-generic", 44100, @"aaceld_44k_preference"}, { "mpeg4-generic", 48000, @"aaceld_48k_preference"}, @@ -1409,45 +1409,39 @@ static int comp_call_id(const LinphoneCall* call , const char *callid) { } - (void)cancelLocalNotifTimerForCallId:(NSString*)callid { - //first, make sure this callid is not already involved in a call - if ([LinphoneManager isLcReady]) { - MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); - MSList* call = ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String]); - if (call != NULL) { - LinphoneCallAppData* data = linphone_call_get_user_pointer((LinphoneCall*)call->data); - if ( data->timer ) - [data->timer invalidate]; - data->timer = nil; - return; - } - } + //first, make sure this callid is not already involved in a call + MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); + MSList* call = ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String]); + if (call != NULL) { + LinphoneCallAppData* data = linphone_call_get_user_pointer((LinphoneCall*)call->data); + if ( data->timer ) + [data->timer invalidate]; + data->timer = nil; + return; + } } - (void)acceptCallForCallId:(NSString*)callid { - //first, make sure this callid is not already involved in a call - if ([LinphoneManager isLcReady]) { - MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); - MSList* call = ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String]); - if (call != NULL) { - [self acceptCall:(LinphoneCall*)call->data]; - return; - }; - } + //first, make sure this callid is not already involved in a call + MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); + MSList* call = ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String]); + if (call != NULL) { + [self acceptCall:(LinphoneCall*)call->data]; + return; + }; } - (void)enableAutoAnswerForCallId:(NSString*) callid { - //first, make sure this callid is not already involved in a call - if ([LinphoneManager isLcReady]) { - MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); - if (ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String])) { - [LinphoneLogger log:LinphoneLoggerWarning format:@"Call id [%@] already handled",callid]; - return; - }; - } - if ([pendindCallIdFromRemoteNotif count] > 10 /*max number of pending notif*/) - [pendindCallIdFromRemoteNotif removeObjectAtIndex:0]; - [pendindCallIdFromRemoteNotif addObject:callid]; + //first, make sure this callid is not already involved in a call + MSList* calls = (MSList*)linphone_core_get_calls(theLinphoneCore); + if (ms_list_find_custom(calls, (MSCompareFunc)comp_call_id, [callid UTF8String])) { + [LinphoneLogger log:LinphoneLoggerWarning format:@"Call id [%@] already handled",callid]; + return; + }; + if ([pendindCallIdFromRemoteNotif count] > 10 /*max number of pending notif*/) + [pendindCallIdFromRemoteNotif removeObjectAtIndex:0]; + [pendindCallIdFromRemoteNotif addObject:callid]; } - (BOOL)shouldAutoAcceptCallForCallId:(NSString*) callId { @@ -1549,7 +1543,6 @@ static int comp_call_state_paused (const LinphoneCall* call, const void* param) linphone_core_set_network_reachable(theLinphoneCore, FALSE); return YES; } - [self destroyLibLinphone]; return NO; } else @@ -1817,18 +1810,16 @@ static void audioRouteChangeListenerCallback ( pushNotificationToken = nil; } - if(apushNotificationToken != nil) { - pushNotificationToken = [apushNotificationToken retain]; - } - if([LinphoneManager isLcReady]) { - LinphoneProxyConfig *cfg=nil; - linphone_core_get_default_proxy(theLinphoneCore, &cfg); - if (cfg) { - linphone_proxy_config_edit(cfg); - [self addPushTokenToProxyConfig: cfg]; - linphone_proxy_config_done(cfg); - } - } + if(apushNotificationToken != nil) { + pushNotificationToken = [apushNotificationToken retain]; + } + LinphoneProxyConfig *cfg=nil; + linphone_core_get_default_proxy(theLinphoneCore, &cfg); + if (cfg) { + linphone_proxy_config_edit(cfg); + [self addPushTokenToProxyConfig: cfg]; + linphone_proxy_config_done(cfg); + } } - (void)addPushTokenToProxyConfig:(LinphoneProxyConfig*)proxyCfg{ @@ -1875,22 +1866,21 @@ static void audioRouteChangeListenerCallback ( if (! [[NSFileManager defaultManager] fileExistsAtPath:cachePath isDirectory:&isDir] && isDir == NO) { [[NSFileManager defaultManager] createDirectoryAtPath:cachePath withIntermediateDirectories:NO attributes:nil error:&error]; } - return cachePath; + return cachePath; } + (int)unreadMessageCount { int count = 0; - if( [LinphoneManager isLcReady] ){ - MSList* rooms = linphone_core_get_chat_rooms([LinphoneManager getLc]); - MSList* item = rooms; - while (item) { - LinphoneChatRoom* room = (LinphoneChatRoom*)item->data; - if( room ){ - count += linphone_chat_room_get_unread_messages_count(room); - } - item = item->next; + MSList* rooms = linphone_core_get_chat_rooms([LinphoneManager getLc]); + MSList* item = rooms; + while (item) { + LinphoneChatRoom* room = (LinphoneChatRoom*)item->data; + if( room ){ + count += linphone_chat_room_get_unread_messages_count(room); } + item = item->next; } + return count; } diff --git a/Classes/LinphoneUI/UICallBar.m b/Classes/LinphoneUI/UICallBar.m index b56c151c5..728659778 100644 --- a/Classes/LinphoneUI/UICallBar.m +++ b/Classes/LinphoneUI/UICallBar.m @@ -289,10 +289,6 @@ #pragma mark - - (void)callUpdate:(LinphoneCall*)call state:(LinphoneCallState)state { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update call bar: Linphone core not ready"]; - return; - } LinphoneCore* lc = [LinphoneManager getLc]; [speakerButton update]; diff --git a/Classes/LinphoneUI/UICamSwitch.m b/Classes/LinphoneUI/UICamSwitch.m index 371cac44e..cc5bcab87 100644 --- a/Classes/LinphoneUI/UICamSwitch.m +++ b/Classes/LinphoneUI/UICamSwitch.m @@ -66,10 +66,6 @@ #pragma mark - -(void) touchUp:(id) sender { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot tigger camswitch button: Linphone core not ready"]; - return; - } const char *currentCamId = (char*)linphone_core_get_video_device([LinphoneManager getLc]); const char **cameras=linphone_core_get_video_devices([LinphoneManager getLc]); const char *newCamId=NULL; diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index 2e28c7726..902fcc4a8 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -271,12 +271,10 @@ #pragma mark - Event Functions - (void)orientationDidChange:(NSNotification*)notif { - if([LinphoneManager isLcReady]) { - // Update rotation - UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; - if(currentOrientation != correctOrientation) { - [UICompositeViewController setOrientation:correctOrientation animated:currentOrientation != UIDeviceOrientationUnknown]; - } + // Update rotation + UIInterfaceOrientation correctOrientation = [self getCorrectInterfaceOrientation:[[UIDevice currentDevice] orientation]]; + if(currentOrientation != correctOrientation) { + [UICompositeViewController setOrientation:correctOrientation animated:currentOrientation != UIDeviceOrientationUnknown]; } } diff --git a/Classes/LinphoneUI/UIDigitButton.m b/Classes/LinphoneUI/UIDigitButton.m index 4f1fc1683..9f2f59127 100644 --- a/Classes/LinphoneUI/UIDigitButton.m +++ b/Classes/LinphoneUI/UIDigitButton.m @@ -69,11 +69,7 @@ #pragma mark - Actions Functions - (void)touchDown:(id) sender { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot trigger digit button: Linphone core not ready"]; - return; - } - if (addressField && (!dtmf || !linphone_core_in_call([LinphoneManager getLc]))) { + if (addressField && (!dtmf || !linphone_core_in_call([LinphoneManager getLc]))) { NSString* newAddress = [NSString stringWithFormat:@"%@%c",addressField.text, digit]; [addressField setText:newAddress]; linphone_core_play_dtmf([LinphoneManager getLc], digit, -1); @@ -84,10 +80,6 @@ } - (void)touchUp:(id) sender { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot trigger digit button: Linphone core not ready"]; - return; - } linphone_core_stop_dtmf([LinphoneManager getLc]); } diff --git a/Classes/LinphoneUI/UIDigitButtonLongVoiceMail.m b/Classes/LinphoneUI/UIDigitButtonLongVoiceMail.m index 87a551ee9..3fc8c767a 100644 --- a/Classes/LinphoneUI/UIDigitButtonLongVoiceMail.m +++ b/Classes/LinphoneUI/UIDigitButtonLongVoiceMail.m @@ -36,11 +36,6 @@ } - (BOOL) voiceMailEnabled { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger log:LinphoneLoggerWarning format:@"Cannot call voice mail: Linphone core not ready"]; - return FALSE; - } - NSString * voiceMailUri = [[LinphoneManager instance] lpConfigStringForKey:@"voice_mail_uri" withDefault:NULL]; return (voiceMailUri != NULL); diff --git a/Classes/LinphoneUI/UIHangUpButton.m b/Classes/LinphoneUI/UIHangUpButton.m index 6cc759087..899df975c 100644 --- a/Classes/LinphoneUI/UIHangUpButton.m +++ b/Classes/LinphoneUI/UIHangUpButton.m @@ -84,18 +84,14 @@ #pragma mark - - (void)update { - if([LinphoneManager isLcReady]) { - LinphoneCore * lc = [LinphoneManager getLc]; - if(linphone_core_get_calls_nb(lc) == 1 || // One call - linphone_core_get_current_call(lc) != NULL || // In call - linphone_core_is_in_conference(lc) || // In conference - (linphone_core_get_conference_size(lc) > 0 && [UIHangUpButton callCount:lc] == 0) // Only one conf - ) { - [self setEnabled:true]; - return; - } - } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update hangup button: Linphone core not ready"]; + LinphoneCore * lc = [LinphoneManager getLc]; + if(linphone_core_get_calls_nb(lc) == 1 || // One call + linphone_core_get_current_call(lc) != NULL || // In call + linphone_core_is_in_conference(lc) || // In conference + (linphone_core_get_conference_size(lc) > 0 && [UIHangUpButton callCount:lc] == 0) // Only one conf + ) { + [self setEnabled:true]; + return; } [self setEnabled:false]; } @@ -104,23 +100,19 @@ #pragma mark - Action Functions -(void) touchUp:(id) sender { - if([LinphoneManager isLcReady]) { - LinphoneCore* lc = [LinphoneManager getLc]; - LinphoneCall* currentcall = linphone_core_get_current_call(lc); - if (linphone_core_is_in_conference(lc) || // In conference - (linphone_core_get_conference_size(lc) > 0 && [UIHangUpButton callCount:lc] == 0) // Only one conf - ) { - linphone_core_terminate_conference(lc); - } else if(currentcall != NULL) { // In a call - linphone_core_terminate_call(lc, currentcall); - } else { - const MSList* calls = linphone_core_get_calls(lc); - if (ms_list_size(calls) == 1) { // Only one call - linphone_core_terminate_call(lc,(LinphoneCall*)(calls->data)); - } - } + LinphoneCore* lc = [LinphoneManager getLc]; + LinphoneCall* currentcall = linphone_core_get_current_call(lc); + if (linphone_core_is_in_conference(lc) || // In conference + (linphone_core_get_conference_size(lc) > 0 && [UIHangUpButton callCount:lc] == 0) // Only one conf + ) { + linphone_core_terminate_conference(lc); + } else if(currentcall != NULL) { // In a call + linphone_core_terminate_call(lc, currentcall); } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot trigger hangup button: Linphone core not ready"]; + const MSList* calls = linphone_core_get_calls(lc); + if (ms_list_size(calls) == 1) { // Only one call + linphone_core_terminate_call(lc,(LinphoneCall*)(calls->data)); + } } } diff --git a/Classes/LinphoneUI/UIMainBar.m b/Classes/LinphoneUI/UIMainBar.m index dbacbeb29..89042c02f 100644 --- a/Classes/LinphoneUI/UIMainBar.m +++ b/Classes/LinphoneUI/UIMainBar.m @@ -250,11 +250,7 @@ static NSString * const kDisappearAnimation = @"disappear"; - (void)update:(BOOL)appear{ [self updateView:[[PhoneMainView instance] firstView]]; - if([LinphoneManager isLcReady]) { - [self updateMissedCall:linphone_core_get_missed_calls_count([LinphoneManager getLc]) appear:appear]; - } else { - [self updateMissedCall:0 appear:TRUE]; - } + [self updateMissedCall:linphone_core_get_missed_calls_count([LinphoneManager getLc]) appear:appear]; [self updateUnreadMessage:appear]; } diff --git a/Classes/LinphoneUI/UIMicroButton.m b/Classes/LinphoneUI/UIMicroButton.m index 5c321134d..312d238d8 100644 --- a/Classes/LinphoneUI/UIMicroButton.m +++ b/Classes/LinphoneUI/UIMicroButton.m @@ -24,28 +24,15 @@ @implementation UIMicroButton - (void)onOn { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle mic button: Linphone core not ready"]; - return; - } linphone_core_mute_mic([LinphoneManager getLc], false); } - (void)onOff { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle mic button: Linphone core not ready"]; - return; - } linphone_core_mute_mic([LinphoneManager getLc], true); } - (bool)onUpdate { - if([LinphoneManager isLcReady]) { - return linphone_core_is_mic_muted([LinphoneManager getLc]) == false; - } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update mic button: Linphone core not ready"]; - return true; - } + return linphone_core_is_mic_muted([LinphoneManager getLc]) == false; } - (void)dealloc { diff --git a/Classes/LinphoneUI/UIPauseButton.m b/Classes/LinphoneUI/UIPauseButton.m index 17ea28857..adf20f954 100644 --- a/Classes/LinphoneUI/UIPauseButton.m +++ b/Classes/LinphoneUI/UIPauseButton.m @@ -99,10 +99,6 @@ #pragma mark - UIToggleButtonDelegate Functions - (void)onOn { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle pause button: Linphone core not ready"]; - return; - } switch (type) { case UIPauseButtonType_Call: { @@ -135,10 +131,6 @@ } - (void)onOff { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle pause button: Linphone core not ready"]; - return; - } switch (type) { case UIPauseButtonType_Call: { @@ -172,52 +164,49 @@ - (bool)onUpdate { bool ret = false; // TODO: disable pause on not running call - if([LinphoneManager isLcReady]) { - LinphoneCore *lc = [LinphoneManager getLc]; - switch (type) { - case UIPauseButtonType_Call: - { - if (call != nil) { - LinphoneCallState state = linphone_call_get_state(call); - if(state == LinphoneCallPaused || state == LinphoneCallPausing) { - ret = true; - } - [self setEnabled:TRUE]; - } else { - [self setEnabled:FALSE]; + LinphoneCore *lc = [LinphoneManager getLc]; + switch (type) { + case UIPauseButtonType_Call: + { + if (call != nil) { + LinphoneCallState state = linphone_call_get_state(call); + if(state == LinphoneCallPaused || state == LinphoneCallPausing) { + ret = true; } - break; - } - case UIPauseButtonType_Conference: - { - if(linphone_core_get_conference_size(lc) > 0) { - if (!linphone_core_is_in_conference(lc)) { - ret = true; - } - [self setEnabled:TRUE]; - } else { - [self setEnabled:FALSE]; - } - break; - } - case UIPauseButtonType_CurrentCall: - { - LinphoneCall* currentCall = [UIPauseButton getCall]; - if (currentCall != nil) { - LinphoneCallState state = linphone_call_get_state(currentCall); - if(state == LinphoneCallPaused || state == LinphoneCallPausing) { - ret = true; - } - [self setEnabled:TRUE]; - } else { - [self setEnabled:FALSE]; - } - break; + [self setEnabled:TRUE]; + } else { + [self setEnabled:FALSE]; } + break; + } + case UIPauseButtonType_Conference: + { + if(linphone_core_get_conference_size(lc) > 0) { + if (!linphone_core_is_in_conference(lc)) { + ret = true; + } + [self setEnabled:TRUE]; + } else { + [self setEnabled:FALSE]; + } + break; + } + case UIPauseButtonType_CurrentCall: + { + LinphoneCall* currentCall = [UIPauseButton getCall]; + if (currentCall != nil) { + LinphoneCallState state = linphone_call_get_state(currentCall); + if(state == LinphoneCallPaused || state == LinphoneCallPausing) { + ret = true; + } + [self setEnabled:TRUE]; + } else { + [self setEnabled:FALSE]; + } + break; } - } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update pause button: Linphone core not ready"]; } + return ret; } diff --git a/Classes/LinphoneUI/UIStateBar.m b/Classes/LinphoneUI/UIStateBar.m index 2263111b7..6e0c9cd02 100644 --- a/Classes/LinphoneUI/UIStateBar.m +++ b/Classes/LinphoneUI/UIStateBar.m @@ -106,13 +106,12 @@ int messagesUnreadCount; [callQualityImage setHidden: true]; [callSecurityImage setHidden: true]; - // Update to default state - LinphoneProxyConfig* config = NULL; - if([LinphoneManager isLcReady]) { - linphone_core_get_default_proxy([LinphoneManager getLc], &config); - messagesUnreadCount = lp_config_get_int(linphone_core_get_config([LinphoneManager getLc]), "app", "voice_mail_messages_count", 0); - } - [self proxyConfigUpdate: config]; + // Update to default state + LinphoneProxyConfig* config = NULL; + linphone_core_get_default_proxy([LinphoneManager getLc], &config); + messagesUnreadCount = lp_config_get_int(linphone_core_get_config([LinphoneManager getLc]), "app", "voice_mail_messages_count", 0); + + [self proxyConfigUpdate: config]; [self updateVoicemail]; } @@ -154,7 +153,7 @@ int messagesUnreadCount; } - (void) globalStateUpdate:(NSNotification*) notif { - if ([LinphoneManager isLcReady]) [self registrationUpdate:notif]; + [self registrationUpdate:notif]; } - (void) notifyReceived:(NSNotification*) notif { @@ -196,7 +195,7 @@ int messagesUnreadCount; // LinphoneCall *call = [[notif.userInfo objectForKey: @"call"] pointerValue]; // LinphoneCallState state = [[notif.userInfo objectForKey: @"state"] intValue]; - bool isOnCall = [LinphoneManager isLcReady] && (linphone_core_get_calls_nb([LinphoneManager getLc]) > 0); + bool isOnCall = (linphone_core_get_calls_nb([LinphoneManager getLc]) > 0); //show voicemail only when there is no call [self updateVoicemail]; @@ -216,7 +215,7 @@ int messagesUnreadCount; message = NSLocalizedString(@"Fetching remote configuration", nil); } else if (config == NULL) { state = LinphoneRegistrationNone; - if(![LinphoneManager isLcReady] || linphone_core_is_network_reachable([LinphoneManager getLc])) + if(linphone_core_is_network_reachable([LinphoneManager getLc])) message = NSLocalizedString(@"No SIP account configured", nil); else message = NSLocalizedString(@"Network down", nil); @@ -268,10 +267,6 @@ int messagesUnreadCount; BOOL pending = false; BOOL security = true; - if(![LinphoneManager isLcReady]) { - [callSecurityImage setHidden:true]; - return; - } const MSList *list = linphone_core_get_calls([LinphoneManager getLc]); if(list == NULL) { @@ -308,22 +303,20 @@ int messagesUnreadCount; - (void)callQualityUpdate { UIImage *image = nil; - if([LinphoneManager isLcReady]) { - LinphoneCall *call = linphone_core_get_current_call([LinphoneManager getLc]); - if(call != NULL) { - //FIXME double check call state before computing, may cause core dump - float quality = linphone_call_get_average_quality(call); - if(quality < 1) { - image = [UIImage imageNamed:@"call_quality_indicator_0.png"]; - } else if (quality < 2) { - image = [UIImage imageNamed:@"call_quality_indicator_1.png"]; - } else if (quality < 3) { - image = [UIImage imageNamed:@"call_quality_indicator_2.png"]; - } else { - image = [UIImage imageNamed:@"call_quality_indicator_3.png"]; - } - } - } + LinphoneCall *call = linphone_core_get_current_call([LinphoneManager getLc]); + if(call != NULL) { + //FIXME double check call state before computing, may cause core dump + float quality = linphone_call_get_average_quality(call); + if(quality < 1) { + image = [UIImage imageNamed:@"call_quality_indicator_0.png"]; + } else if (quality < 2) { + image = [UIImage imageNamed:@"call_quality_indicator_1.png"]; + } else if (quality < 3) { + image = [UIImage imageNamed:@"call_quality_indicator_2.png"]; + } else { + image = [UIImage imageNamed:@"call_quality_indicator_3.png"]; + } + } if(image != nil) { [callQualityImage setHidden:false]; [callQualityImage setImage:image]; @@ -336,7 +329,7 @@ int messagesUnreadCount; #pragma mark - Action Functions - (IBAction)doSecurityClick:(id)sender { - if([LinphoneManager isLcReady] && linphone_core_get_calls_nb([LinphoneManager getLc])) { + if(linphone_core_get_calls_nb([LinphoneManager getLc])) { LinphoneCall *call = linphone_core_get_current_call([LinphoneManager getLc]); if(call != NULL) { LinphoneMediaEncryption enc = linphone_call_params_get_media_encryption(linphone_call_get_current_params(call)); diff --git a/Classes/LinphoneUI/UIVideoButton.m b/Classes/LinphoneUI/UIVideoButton.m index 9514e3f23..e84384323 100644 --- a/Classes/LinphoneUI/UIVideoButton.m +++ b/Classes/LinphoneUI/UIVideoButton.m @@ -52,11 +52,6 @@ } - (void)onOn { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle video button: Linphone core not ready"]; - return; - } - LinphoneCore* lc = [LinphoneManager getLc]; if (!linphone_core_video_enabled(lc)) @@ -79,11 +74,6 @@ } - (void)onOff { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot toggle video button: Linphone core not ready"]; - return; - } - LinphoneCore* lc = [LinphoneManager getLc]; if (!linphone_core_video_enabled(lc)) @@ -104,56 +94,51 @@ } - (bool)onUpdate { - if([LinphoneManager isLcReady]) { - bool val = false; + bool val = false; #ifdef VIDEO_ENABLED - if(linphone_core_video_enabled([LinphoneManager getLc])) { - LinphoneCall* currentCall = linphone_core_get_current_call([LinphoneManager getLc]); - if (currentCall) { - LinphoneCallState state = linphone_call_get_state(currentCall); - switch (state) { - case LinphoneCallUpdating: - { - [self setEnabled:FALSE]; - break; - } - case LinphoneCallStreamsRunning: - { - [waitView stopAnimating]; - [self setEnabled:TRUE]; - if (linphone_call_params_video_enabled(linphone_call_get_current_params(currentCall))) { - val = true; - } - break; - } - - default: - { - // Disable button if the call is not running - [self setEnabled:FALSE]; - [waitView stopAnimating]; - break; - } - + if(linphone_core_video_enabled([LinphoneManager getLc])) { + LinphoneCall* currentCall = linphone_core_get_current_call([LinphoneManager getLc]); + if (currentCall) { + LinphoneCallState state = linphone_call_get_state(currentCall); + switch (state) { + case LinphoneCallUpdating: + { + [self setEnabled:FALSE]; + break; } - } else { - // Disable button if there is no call - [self setEnabled:FALSE]; - [waitView stopAnimating]; + case LinphoneCallStreamsRunning: + { + [waitView stopAnimating]; + [self setEnabled:TRUE]; + if (linphone_call_params_video_enabled(linphone_call_get_current_params(currentCall))) { + val = true; + } + break; + } + + default: + { + // Disable button if the call is not running + [self setEnabled:FALSE]; + [waitView stopAnimating]; + break; + } + } } else { - // Disable button if video is not enabled + // Disable button if there is no call [self setEnabled:FALSE]; [waitView stopAnimating]; } -#else //VIDEO_ENABLED - [self setEnabled:FALSE]; -#endif //VIDEO_ENABLED - return val; } else { - [LinphoneLogger logc:LinphoneLoggerWarning format:"Cannot update video button: Linphone core not ready"]; - return false; - } + // Disable button if video is not enabled + [self setEnabled:FALSE]; + [waitView stopAnimating]; + } +#else //VIDEO_ENABLED + [self setEnabled:FALSE]; +#endif //VIDEO_ENABLED + return val; } - (void)dealloc { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index d86df71d2..643cd085d 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -710,7 +710,6 @@ static RootViewManager* rootViewManagerInstance = nil; UIDeviceBatteryState state = [UIDevice currentDevice].batteryState; [LinphoneLogger log:LinphoneLoggerLog format:@"Battery state:%d level:%.2f", state, level]; - if (![LinphoneManager isLcReady]) return; LinphoneCall* call = linphone_core_get_current_call([LinphoneManager getLc]); if (call && linphone_call_params_video_enabled(linphone_call_get_current_params(call))) { LinphoneCallAppData* callData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call); diff --git a/Classes/SettingsViewController.m b/Classes/SettingsViewController.m index ca0ffd9bf..8dd86ed10 100644 --- a/Classes/SettingsViewController.m +++ b/Classes/SettingsViewController.m @@ -592,30 +592,29 @@ static UICompositeViewDescription *compositeDescription = nil; return [[[IASKSpecifier alloc] initWithSpecifier:dict] autorelease]; } #else - if([LinphoneManager isLcReady]) { - if ([[specifier key] isEqualToString:@"media_encryption_preference"]) { - NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[specifier specifierDict]]; - if(!linphone_core_media_encryption_supported([LinphoneManager getLc], LinphoneMediaEncryptionZRTP)) { - NSMutableArray *titles = [NSMutableArray arrayWithArray:[dict objectForKey:@"Titles"]]; - [titles removeObject:@"ZRTP"]; - [dict setObject:titles forKey:@"Titles"]; - NSMutableArray *values = [NSMutableArray arrayWithArray:[dict objectForKey:@"Values"]]; - [values removeObject:@"ZRTP"]; - [dict setObject:values forKey:@"Values"]; - } - if(!linphone_core_media_encryption_supported([LinphoneManager getLc], LinphoneMediaEncryptionSRTP)) { - NSMutableArray *titles = [NSMutableArray arrayWithArray:[dict objectForKey:@"Titles"]]; - [titles removeObject:@"SRTP"]; - [dict setObject:titles forKey:@"Titles"]; - NSMutableArray *values = [NSMutableArray arrayWithArray:[dict objectForKey:@"Values"]]; - [values removeObject:@"SRTP"]; - [dict setObject:values forKey:@"Values"]; - } - return [[[IASKSpecifier alloc] initWithSpecifier:dict] autorelease]; + if ([[specifier key] isEqualToString:@"media_encryption_preference"]) { + NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[specifier specifierDict]]; + if(!linphone_core_media_encryption_supported([LinphoneManager getLc], LinphoneMediaEncryptionZRTP)) { + NSMutableArray *titles = [NSMutableArray arrayWithArray:[dict objectForKey:@"Titles"]]; + [titles removeObject:@"ZRTP"]; + [dict setObject:titles forKey:@"Titles"]; + NSMutableArray *values = [NSMutableArray arrayWithArray:[dict objectForKey:@"Values"]]; + [values removeObject:@"ZRTP"]; + [dict setObject:values forKey:@"Values"]; } + if(!linphone_core_media_encryption_supported([LinphoneManager getLc], LinphoneMediaEncryptionSRTP)) { + NSMutableArray *titles = [NSMutableArray arrayWithArray:[dict objectForKey:@"Titles"]]; + [titles removeObject:@"SRTP"]; + [dict setObject:titles forKey:@"Titles"]; + NSMutableArray *values = [NSMutableArray arrayWithArray:[dict objectForKey:@"Values"]]; + [values removeObject:@"SRTP"]; + [dict setObject:values forKey:@"Values"]; + } + return [[[IASKSpecifier alloc] initWithSpecifier:dict] autorelease]; } + #endif //HAVE_SSL - + // Add "build from source" if MPEG4 or H264 disabled if ([[specifier key] isEqualToString:@"h264_preference"] && ![LinphoneManager isCodecSupported:"h264"]) { @@ -629,9 +628,6 @@ static UICompositeViewDescription *compositeDescription = nil; } - (NSSet*)findHiddenKeys { - if(![LinphoneManager isLcReady]) { - [LinphoneLogger log:LinphoneLoggerWarning format:@"Can't filter settings: Linphone core not ready"]; - } LinphoneManager* lm = [LinphoneManager instance]; NSMutableSet *hiddenKeys = [NSMutableSet set];