From f686d43079badbb08ab4d078bdd32cdb9072d5c0 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Fri, 12 Feb 2010 08:47:27 +0100 Subject: [PATCH] force pdp context activation --- Classes/linphoneAppDelegate.h | 7 +++++- Classes/linphoneAppDelegate.m | 47 ++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Classes/linphoneAppDelegate.h b/Classes/linphoneAppDelegate.h index 2e5bbdb3d..a587e5d9a 100644 --- a/Classes/linphoneAppDelegate.h +++ b/Classes/linphoneAppDelegate.h @@ -27,7 +27,8 @@ @protocol LinphoneTabManagerDelegate -(void)selectDialerTab; - +-(void) kickOffNetworkConnection; +-(LinphoneCore*) getLinphoneCore; @end @class ContactPickerDelegate; @@ -45,6 +46,7 @@ ContactPickerDelegate* myContactPickerDelegate; bool isDebug; + bool isStarted; LinphoneCore* myLinphoneCore; SCNetworkReachabilityContext proxyReachabilityContext; SCNetworkReachabilityRef proxyReachability; @@ -71,6 +73,9 @@ */ bool networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info); +-(void) doRegister; + + @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController* myTabBarController; @property (nonatomic, retain) ABPeoplePickerNavigationController* myPeoplePickerController; diff --git a/Classes/linphoneAppDelegate.m b/Classes/linphoneAppDelegate.m index f7e069e9d..112372d50 100644 --- a/Classes/linphoneAppDelegate.m +++ b/Classes/linphoneAppDelegate.m @@ -155,6 +155,24 @@ LinphoneCoreVTable linphonec_vtable = { } +-(void) kickOffNetworkConnection { + CFWriteStreamRef writeStream; + CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"linphone.org", 15000, nil, &writeStream); + CFWriteStreamOpen (writeStream); + const char* buff="hello"; + CFWriteStreamWrite (writeStream,(const UInt8*)buff,strlen(buff)); + CFWriteStreamClose (writeStream); + +} +- (void)applicationDidBecomeActive:(UIApplication *)application { + if (isStarted) { + NSLog(@"becomming active, make sure we are registered"); + [self doRegister]; + } else { + isStarted=true; + } +} + -(void)selectDialerTab { [myTabBarController setSelectedIndex:DIALER_TAB_INDEX]; } @@ -188,7 +206,7 @@ LinphoneCoreVTable linphonec_vtable = { isDebug = [[NSUserDefaults standardUserDefaults] boolForKey:@"debugenable_preference"]; if (isDebug) { //redirect all traces to the iphone log framework - linphone_core_enable_logs_with_cb(linphone_iphone_log_handler); + linphone_core_enable_logs_with_cb((OrtpLogFunc)linphone_iphone_log_handler); } else { linphone_core_disable_logs(); @@ -270,13 +288,10 @@ LinphoneCoreVTable linphonec_vtable = { LinphoneAddress* addr=linphone_address_new(linphone_proxy_config_get_addr(proxyCfg)); proxyReachability=SCNetworkReachabilityCreateWithName(nil, linphone_address_get_domain(addr)); - proxyReachabilityContext.info=myLinphoneCore; - bool result=SCNetworkReachabilitySetCallback(proxyReachability, networkReachabilityCallBack,&proxyReachabilityContext); - SCNetworkReachabilityFlags reachabilityFlags; - result=SCNetworkReachabilityGetFlags (proxyReachability,&reachabilityFlags); + proxyReachabilityContext.info=self; + bool result=SCNetworkReachabilitySetCallback(proxyReachability, (SCNetworkReachabilityCallBack)networkReachabilityCallBack,&proxyReachabilityContext); SCNetworkReachabilityScheduleWithRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - networkReachabilityCallBack(proxyReachability,reachabilityFlags,myLinphoneCore); - + [self doRegister]; } //Configure Codecs @@ -380,9 +395,16 @@ LinphoneCoreVTable linphonec_vtable = { bool networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info) { LinphoneProxyConfig* proxyCfg; - linphone_core_get_default_proxy((LinphoneCore*)info,&proxyCfg); + id linphoneDelegate=info; + if (linphone_core_get_default_proxy([linphoneDelegate getLinphoneCore],&proxyCfg)) { + //glob, no default proxy + return false; + } linphone_proxy_config_edit(proxyCfg); bool result = false; + if ((flags == 0) | (flags & (kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic))) { + [linphoneDelegate kickOffNetworkConnection]; + } if (flags) { // register whatever connection type linphone_proxy_config_enable_register(proxyCfg,TRUE); @@ -394,5 +416,12 @@ bool networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach linphone_proxy_config_done(proxyCfg); return result; } - +-(LinphoneCore*) getLinphoneCore { + return myLinphoneCore; +} +-(void) doRegister { + SCNetworkReachabilityFlags reachabilityFlags; + SCNetworkReachabilityGetFlags (proxyReachability,&reachabilityFlags); + networkReachabilityCallBack(proxyReachability,reachabilityFlags,self); +} @end