diff --git a/Classes/LinphoneCoreSettingsStore.m b/Classes/LinphoneCoreSettingsStore.m index 36fcc1dea..65918750f 100644 --- a/Classes/LinphoneCoreSettingsStore.m +++ b/Classes/LinphoneCoreSettingsStore.m @@ -590,8 +590,12 @@ extern void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); BOOL debugmode = [self boolForKey:@"debugenable_preference"]; lp_config_set_int(linphone_core_get_config(lc), LINPHONERC_APPLICATION_KEY, "debugenable_preference", debugmode); - if (debugmode) linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler); - else linphone_core_disable_logs(); + if (debugmode) { + linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler); + ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); + } else { + linphone_core_disable_logs(); + } [[NSUserDefaults standardUserDefaults] setBool:debugmode forKey:@"debugenable_preference"]; //to be used at linphone core startup BOOL animations = [self boolForKey:@"animations_preference"]; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index c8270b4b6..96f7d73c5 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -82,7 +82,7 @@ extern void libmsbcg729_init(); if ((self = [super init])) { self->batteryWarningShown = FALSE; self->notification = nil; - self->videoRequested=FALSE; + self->videoRequested = FALSE; self->userInfos = [[NSMutableDictionary alloc] init]; } return self; @@ -379,14 +379,11 @@ static void linphone_iphone_display_status(struct _LinphoneCore * lc, const char - (void)onCall:(LinphoneCall*)call StateChanged:(LinphoneCallState)state withMessage:(const char *)message { // Handling wrapper - LinphoneCallAppData* data=nil; - if (!linphone_call_get_user_pointer(call)) { + LinphoneCallAppData* data=(LinphoneCallAppData*)linphone_call_get_user_pointer(call); + if (!data) { data = [[LinphoneCallAppData alloc] init]; linphone_call_set_user_pointer(call, data); - } else { - data = (LinphoneCallAppData*) linphone_call_get_user_pointer(call); - } - + } if (state == LinphoneCallIncomingReceived) { @@ -795,6 +792,7 @@ static LinphoneCoreVTable linphonec_vtable = { /*to make sure we don't loose debug trace*/ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"debugenable_preference"]) { linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler); + ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR|ORTP_FATAL); } [LinphoneLogger logc:LinphoneLoggerLog format:"Create linphonecore"]; linphone_core_set_user_agent([@"LinphoneIPhone" UTF8String], @@ -1142,7 +1140,7 @@ static void audioRouteChangeListenerCallback ( if([self lpConfigBoolForKey:@"edge_opt_preference"]) { bool low_bandwidth = self.network == network_2g; if(low_bandwidth) { - [LinphoneLogger log:LinphoneLoggerDebug format:@"Low bandwidth mode"]; + [LinphoneLogger log:LinphoneLoggerLog format:@"Low bandwidth mode"]; } linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth); } @@ -1183,7 +1181,7 @@ static void audioRouteChangeListenerCallback ( if([self lpConfigBoolForKey:@"edge_opt_preference"]) { bool low_bandwidth = self.network == network_2g; if(low_bandwidth) { - [LinphoneLogger log:LinphoneLoggerDebug format:@"Low bandwidth mode"]; + [LinphoneLogger log:LinphoneLoggerLog format:@"Low bandwidth mode"]; } linphone_call_params_enable_low_bandwidth(lcallParams, low_bandwidth); } diff --git a/Classes/LinphoneUI/UICompositeViewController.m b/Classes/LinphoneUI/UICompositeViewController.m index 593f85a82..aa7237646 100644 --- a/Classes/LinphoneUI/UICompositeViewController.m +++ b/Classes/LinphoneUI/UICompositeViewController.m @@ -350,7 +350,7 @@ } } if(remove) { - [LinphoneLogger log:LinphoneLoggerDebug format:@"Free cached view: %@", key]; + [LinphoneLogger log:LinphoneLoggerLog format:@"Free cached view: %@", key]; UIViewController *vc = [viewControllerCache objectForKey:key]; if ([[UIDevice currentDevice].systemVersion doubleValue] >= 5.0) { [vc viewWillUnload]; diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index bd8aaeec7..0f62eb42d 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -47,6 +47,7 @@ int loadCount; NSMutableArray *viewStack; NSMutableArray *inhibitedEvents; + NSTimer *batteryTimer; } @property (nonatomic, retain) IBOutlet UICompositeViewController *mainViewController; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 7f629700d..8392df26b 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -116,6 +116,8 @@ static PhoneMainView* phoneMainViewInstance=nil; name:UIDeviceBatteryLevelDidChangeNotification object:nil]; [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; + + batteryTimer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(batteryLevelChanged:) userInfo:nil repeats:TRUE]; } - (void)viewWillDisappear:(BOOL)animated { @@ -139,6 +141,8 @@ static PhoneMainView* phoneMainViewInstance=nil; name:UIDeviceBatteryLevelDidChangeNotification object:nil]; [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO]; + + [batteryTimer invalidate]; } - (void)viewDidAppear:(BOOL)animated { @@ -577,30 +581,35 @@ static PhoneMainView* phoneMainViewInstance=nil; } - (void)batteryLevelChanged:(NSNotification*)notif { + float level = [UIDevice currentDevice].batteryLevel; + 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))) - return; - LinphoneCallAppData* appData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call); - float level = [UIDevice currentDevice].batteryLevel; - if ([UIDevice currentDevice].batteryState == UIDeviceBatteryStateUnplugged) { - [LinphoneLogger logc:LinphoneLoggerLog format:"Video call is running. Battery level: %.2f", level]; - if (level < 0.1 && !appData->batteryWarningShown) { - DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Battery is running low. Stop video ?",nil)] autorelease]; - [sheet addCancelButtonWithTitle:NSLocalizedString(@"Continue video", nil)]; - [sheet addDestructiveButtonWithTitle:NSLocalizedString(@"Stop video", nil) block:^() { - LinphoneCallParams* paramsCopy = linphone_call_params_copy(linphone_call_get_current_params(call)); - // stop video - linphone_call_params_enable_video(paramsCopy, FALSE); - linphone_core_update_call([LinphoneManager getLc], call, paramsCopy); - }]; - [sheet showInView:self.view]; - appData->batteryWarningShown = TRUE; + if (call && linphone_call_params_video_enabled(linphone_call_get_current_params(call))) { + LinphoneCallAppData* callData = (LinphoneCallAppData*) linphone_call_get_user_pointer(call); + if(callData != nil) { + if (state == UIDeviceBatteryStateUnplugged) { + if (level <= 0.2f && !callData->batteryWarningShown) { + [LinphoneLogger log:LinphoneLoggerLog format:@"Battery warning"]; + DTActionSheet *sheet = [[[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Battery is running low. Stop video ?",nil)] autorelease]; + [sheet addCancelButtonWithTitle:NSLocalizedString(@"Continue video", nil)]; + [sheet addDestructiveButtonWithTitle:NSLocalizedString(@"Stop video", nil) block:^() { + LinphoneCallParams* paramsCopy = linphone_call_params_copy(linphone_call_get_current_params(call)); + // stop video + linphone_call_params_enable_video(paramsCopy, FALSE); + linphone_core_update_call([LinphoneManager getLc], call, paramsCopy); + }]; + [sheet showInView:self.view]; + callData->batteryWarningShown = TRUE; + } + } + if (level > 0.2f) { + callData->batteryWarningShown = FALSE; + } } } - if (level >= 0.1) { - appData->batteryWarningShown = FALSE; - } } diff --git a/Classes/PhoneMainView.xib b/Classes/PhoneMainView.xib index e81cbe2de..4a6d46b1a 100644 --- a/Classes/PhoneMainView.xib +++ b/Classes/PhoneMainView.xib @@ -2,9 +2,9 @@ 784 - 11E53 + 11G63 2840 - 1138.47 + 1138.51 569.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 8e7b39d1d..fe19abf08 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -27,10 +27,10 @@ va_list args; va_start (args, format); NSString *str = [[NSString alloc] initWithFormat: format arguments:args]; - if(severity <= LinphoneLoggerLog) { - ms_message("%s", [str UTF8String]); - } else if(severity <= LinphoneLoggerDebug) { + if(severity <= LinphoneLoggerDebug) { ms_debug("%s", [str UTF8String]); + } else if(severity <= LinphoneLoggerLog) { + ms_message("%s", [str UTF8String]); } else if(severity <= LinphoneLoggerWarning) { ms_warning("%s", [str UTF8String]); } else if(severity <= LinphoneLoggerError) { @@ -45,13 +45,13 @@ + (void)logc:(LinphoneLoggerSeverity) severity format:(const char *)format,... { va_list args; va_start (args, format); - if(severity <= LinphoneLoggerLog) { - ortp_logv(ORTP_MESSAGE, format, args); - } else if(severity <= LinphoneLoggerDebug) { + if(severity <= LinphoneLoggerDebug) { ortp_logv(ORTP_DEBUG, format, args); + } else if(severity <= LinphoneLoggerLog) { + ortp_logv(ORTP_MESSAGE, format, args); } else if(severity <= LinphoneLoggerWarning) { ortp_logv(ORTP_WARNING, format, args); - } else if(severity <= LinphoneLoggerError) { + } else if(severity <= LinphoneLoggerError) { ortp_logv(ORTP_ERROR, format, args); } else if(severity <= LinphoneLoggerFatal) { ortp_logv(ORTP_FATAL, format, args); diff --git a/Classes/WizardViewController.m b/Classes/WizardViewController.m index 2d9b17c23..f11d51a34 100644 --- a/Classes/WizardViewController.m +++ b/Classes/WizardViewController.m @@ -374,7 +374,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)checkUserExist:(NSString*)username { - [LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC check_account %@", username]; + [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC check_account %@", username]; NSURL *URL = [NSURL URLWithString:[[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; @@ -389,7 +389,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)createAccount:(NSString*)identity password:(NSString*)password email:(NSString*)email { NSString *useragent = [LinphoneManager getUserAgent]; - [LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC create_account_with_useragent %@ %@ %@ %@", identity, password, email, useragent]; + [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC create_account_with_useragent %@ %@ %@ %@", identity, password, email, useragent]; NSURL *URL = [NSURL URLWithString: [[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; @@ -403,7 +403,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)checkAccountValidation:(NSString*)identity { - [LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC check_account_validated %@", identity]; + [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC check_account_validated %@", identity]; NSURL *URL = [NSURL URLWithString: [[LinphoneManager instance] lpConfigStringForKey:@"service_url" forSection:@"wizard"]]; XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithURL: URL]; @@ -659,7 +659,7 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - XMLRPCConnectionDelegate Functions - (void)request:(XMLRPCRequest *)request didReceiveResponse:(XMLRPCResponse *)response { - [LinphoneLogger log:LinphoneLoggerDebug format:@"XMLRPC %@: %@", [request method], [response body]]; + [LinphoneLogger log:LinphoneLoggerLog format:@"XMLRPC %@: %@", [request method], [response body]]; [waitView setHidden:true]; if ([response isFault]) { NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"Communication issue (%@)", nil), [response faultString]];