diff options
author | Benoit Foucher <benoit@zeroc.com> | 2016-12-15 16:09:25 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2016-12-15 16:09:25 +0100 |
commit | 49e1618006301fdbe090f11851557c386466028c (patch) | |
tree | a0d206bfb536995e959f6b4d2b2671e3e0b362e3 /cpp/test/ios/controller/Classes | |
parent | Fix (ICE-7111) - iceboxnet --version/-v (diff) | |
download | ice-49e1618006301fdbe090f11851557c386466028c.tar.bz2 ice-49e1618006301fdbe090f11851557c386466028c.tar.xz ice-49e1618006301fdbe090f11851557c386466028c.zip |
iOS C++ controller fixes
Diffstat (limited to 'cpp/test/ios/controller/Classes')
-rw-r--r-- | cpp/test/ios/controller/Classes/Base.lproj/Main.storyboard | 42 | ||||
-rw-r--r-- | cpp/test/ios/controller/Classes/ViewController.h | 7 | ||||
-rw-r--r-- | cpp/test/ios/controller/Classes/ViewController.m | 107 |
3 files changed, 145 insertions, 11 deletions
diff --git a/cpp/test/ios/controller/Classes/Base.lproj/Main.storyboard b/cpp/test/ios/controller/Classes/Base.lproj/Main.storyboard index 9550d1821c9..7bd9da90e09 100644 --- a/cpp/test/ios/controller/Classes/Base.lproj/Main.storyboard +++ b/cpp/test/ios/controller/Classes/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16B2555" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r"> <device id="retina4_7" orientation="portrait"> <adaptation id="fullscreen"/> </device> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> </dependencies> <scenes> @@ -21,23 +21,55 @@ <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <subviews> + <pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xR3-DO-y6j" userLabel="InterfaceIPv6"> + <rect key="frame" x="40" y="49" width="296" height="75"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> + <connections> + <outlet property="dataSource" destination="BYZ-38-t0r" id="qqe-Ub-kJJ"/> + <outlet property="delegate" destination="BYZ-38-t0r" id="F6m-Y2-o1H"/> + </connections> + </pickerView> <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="nZ9-dY-qBC" userLabel="Output"> - <rect key="frame" x="16" y="20" width="343" height="627"/> - <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> + <rect key="frame" x="40" y="258" width="296" height="389"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <fontDescription key="fontDescription" type="system" pointSize="14"/> <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/> </textView> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="IPv4" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="StB-MO-pSa" userLabel="LabelInterfaceIPv4"> + <rect key="frame" x="40" y="28" width="34" height="21"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> + <fontDescription key="fontDescription" type="system" pointSize="17"/> + <nil key="textColor"/> + <nil key="highlightedColor"/> + </label> + <pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BKi-XY-5kF" userLabel="InterfaceIPv6"> + <rect key="frame" x="40" y="161" width="296" height="75"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> + <connections> + <outlet property="dataSource" destination="BYZ-38-t0r" id="Ksd-8b-gVb"/> + <outlet property="delegate" destination="BYZ-38-t0r" id="NT1-QV-RAh"/> + </connections> + </pickerView> + <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="IPv6" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="PhT-kW-Fyr" userLabel="LabelInterfaceIPv6"> + <rect key="frame" x="40" y="140" width="34" height="21"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> + <fontDescription key="fontDescription" type="system" pointSize="17"/> + <nil key="textColor"/> + <nil key="highlightedColor"/> + </label> </subviews> <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/> </view> <connections> + <outlet property="interfaceIPv4" destination="xR3-DO-y6j" id="UZt-T6-HRh"/> + <outlet property="interfaceIPv6" destination="BKi-XY-5kF" id="1bQ-Zn-Pd2"/> <outlet property="output" destination="nZ9-dY-qBC" id="drk-4a-vAK"/> </connections> </viewController> <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="136.80000000000001" y="138.98050974512745"/> + <point key="canvasLocation" x="133.59999999999999" y="136.28185907046478"/> </scene> </scenes> </document> diff --git a/cpp/test/ios/controller/Classes/ViewController.h b/cpp/test/ios/controller/Classes/ViewController.h index 1ce9af06153..645dbbab57f 100644 --- a/cpp/test/ios/controller/Classes/ViewController.h +++ b/cpp/test/ios/controller/Classes/ViewController.h @@ -14,11 +14,16 @@ -(void) println:(NSString*)msg; @end -@interface ViewController : UIViewController<ViewController> +@interface ViewController : UIViewController<ViewController, UIPickerViewDataSource, UIPickerViewDelegate> { @private + IBOutlet UIPickerView* interfaceIPv4; + IBOutlet UIPickerView* interfaceIPv6; IBOutlet UITextView* output; + void (*startController)(id<ViewController>, NSString*, NSString*); void (*stopController)(id<ViewController>); + NSMutableArray* interfacesIPv4; + NSMutableArray* interfacesIPv6; } @end diff --git a/cpp/test/ios/controller/Classes/ViewController.m b/cpp/test/ios/controller/Classes/ViewController.m index 10f99f408c6..92c1dfca50e 100644 --- a/cpp/test/ios/controller/Classes/ViewController.m +++ b/cpp/test/ios/controller/Classes/ViewController.m @@ -9,12 +9,19 @@ #import "ViewController.h" +#include <ifaddrs.h> +#include <arpa/inet.h> +#include <net/if.h> + @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - + + // + // Load the controller bundle. + // NSString* bundlePath = [[NSBundle mainBundle] privateFrameworksPath]; #ifdef ICE_CPP11_MAPPING const char* bundle = "Cpp11ControllerBundle.bundle"; @@ -39,7 +46,7 @@ return; } - void (*startController)(id<ViewController>) = CFBundleGetFunctionPointerForName(handle, CFSTR("startController")); + startController = CFBundleGetFunctionPointerForName(handle, CFSTR("startController")); if(startController == 0) { NSString* err = [NSString stringWithFormat:@"Could not get function pointer startController from bundle %@", @@ -47,7 +54,7 @@ [self println:err]; return; } - + stopController = CFBundleGetFunctionPointerForName(handle, CFSTR("stopController")); if(stopController == 0) { @@ -56,20 +63,68 @@ [self println:err]; return; } - - (*startController)(self); + // + // Search for local network interfaces + // + interfacesIPv4 = [NSMutableArray array]; + [interfacesIPv4 addObject:@"127.0.0.1"]; + interfacesIPv6 = [NSMutableArray array]; + [interfacesIPv6 addObject:@"::1"]; + struct ifaddrs* ifap; + if(getifaddrs(&ifap) == 0) + { + struct ifaddrs* curr = ifap; + while(curr != 0) + { + if(curr->ifa_addr && curr->ifa_flags & IFF_UP && !(curr->ifa_flags & IFF_LOOPBACK)) + { + if(curr->ifa_addr->sa_family == AF_INET) + { + char buf[INET_ADDRSTRLEN]; + const struct sockaddr_in *addr = (const struct sockaddr_in*)curr->ifa_addr; + if(inet_ntop(AF_INET, &addr->sin_addr, buf, INET_ADDRSTRLEN)) + { + [interfacesIPv4 addObject:[NSString stringWithUTF8String:buf]]; + } + } + else if(curr->ifa_addr->sa_family == AF_INET6) + { + char buf[INET6_ADDRSTRLEN]; + const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6*)curr->ifa_addr; + if(inet_ntop(AF_INET6, &addr6->sin6_addr, buf, INET6_ADDRSTRLEN)) + { + [interfacesIPv6 addObject:[NSString stringWithUTF8String:buf]]; + } + } + } + curr = curr->ifa_next; + } + freeifaddrs(ifap); + } + + // By default, use the loopback + [interfaceIPv4 selectRow:0 inComponent:0 animated:NO]; + [interfaceIPv6 selectRow:0 inComponent:0 animated:NO]; + (*startController)(self, + [interfacesIPv4 objectAtIndex:[interfaceIPv4 selectedRowInComponent:0]], + [interfacesIPv6 objectAtIndex:[interfaceIPv6 selectedRowInComponent:0]]); } + - (void) dealloc { (*stopController)(self); } + -(void) write:(NSString*)msg { [output insertText:msg]; [output layoutIfNeeded]; [output scrollRangeToVisible:NSMakeRange([output.text length] - 1, 1)]; } + +#pragma mark ViewController + -(void) print:(NSString*)msg { [self performSelectorOnMainThread:@selector(write:) withObject:msg waitUntilDone:NO]; @@ -78,4 +133,46 @@ { [self print:[msg stringByAppendingString:@"\n"]]; } + +#pragma mark UIPickerViewDelegate + +- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component +{ + if(pickerView == interfaceIPv4) + { + return [interfacesIPv4 objectAtIndex:row]; + } + else + { + return [interfacesIPv6 objectAtIndex:row]; + } +} + +- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component +{ + (*stopController)(self); + (*startController)(self, + [interfacesIPv4 objectAtIndex:[interfaceIPv4 selectedRowInComponent:0]], + [interfacesIPv6 objectAtIndex:[interfaceIPv6 selectedRowInComponent:0]]); +} + +#pragma mark UIPickerViewDataSource + +- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView +{ + return 1; +} + +- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component +{ + if(pickerView == interfaceIPv4) + { + return interfacesIPv4.count; + } + else + { + return interfacesIPv6.count; + } +} + @end |