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 | |
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')
5 files changed, 236 insertions, 67 deletions
diff --git a/cpp/test/ios/controller/Bundle/ControllerI.mm b/cpp/test/ios/controller/Bundle/ControllerI.mm index 406b33aa077..5f65e515712 100644 --- a/cpp/test/ios/controller/Bundle/ControllerI.mm +++ b/cpp/test/ios/controller/Bundle/ControllerI.mm @@ -13,6 +13,8 @@ #include <Controller.h> #include <TestHelper.h> +#include <dlfcn.h> + @protocol ViewController -(void) print:(NSString*)msg; -(void) println:(NSString*)msg; @@ -23,32 +25,32 @@ using namespace Test::Common; namespace { - + typedef int (*MAIN_ENTRY_POINT)(int argc, char** argv, Test::MainHelper* helper); typedef int (*SHUTDOWN_ENTRY_POINT)(); - + class MainHelperI : public Test::MainHelper, private IceUtil::Monitor<IceUtil::Mutex>, public IceUtil::Thread { public: - + MainHelperI(id<ViewController>, const string&, const StringSeq&); virtual ~MainHelperI(); - + virtual void serverReady(); virtual void shutdown(); virtual void waitForCompleted() {} virtual bool redirect(); virtual void print(const std::string&); - + virtual void run(); - + void completed(int); void waitReady(int) const; int waitSuccess(int) const; string getOutput() const; - + private: - + id<ViewController> _controller; std::string _dll; StringSeq _args; @@ -59,55 +61,57 @@ namespace int _status; std::ostringstream _out; }; - + class ProcessI : public Process { public: - + ProcessI(id<ViewController>, MainHelperI*); virtual ~ProcessI(); - + void waitReady(int, const Ice::Current&); int waitSuccess(int, const Ice::Current&); string terminate(const Ice::Current&); - + private: - + id<ViewController> _controller; IceUtil::Handle<MainHelperI> _helper; }; - + class ProcessControllerI : public ProcessController { public: - - ProcessControllerI(id<ViewController>); - + + ProcessControllerI(id<ViewController>, NSString*, NSString*); + #ifdef ICE_CPP11_MAPPING - virtual shared_ptr<ProcessPrx> - start(string, string, StringSeq, const Ice::Current&); + virtual shared_ptr<ProcessPrx> start(string, string, StringSeq, const Ice::Current&); + virtual string getHost(string, bool, const Ice::Current&); #else - virtual ProcessPrx - start(const string&, const string&, const StringSeq&, const Ice::Current&); + virtual ProcessPrx start(const string&, const string&, const StringSeq&, const Ice::Current&); + virtual string getHost(const string&, bool, const Ice::Current&); #endif - + private: - + id<ViewController> _controller; + string _ipv4; + string _ipv6; }; - + class ControllerHelper { public: - - ControllerHelper(id<ViewController>); + + ControllerHelper(id<ViewController>, NSString*, NSString*); virtual ~ControllerHelper(); - + private: - + Ice::CommunicatorPtr _communicator; }; - + } MainHelperI::MainHelperI(id<ViewController> controller, const string& dll, const StringSeq& args) : @@ -144,7 +148,7 @@ MainHelperI::shutdown() { return; } - + if(_dllTestShutdown) { _dllTestShutdown(); @@ -169,9 +173,9 @@ void MainHelperI::run() { NSString* bundlePath = [[NSBundle mainBundle] privateFrameworksPath]; - + bundlePath = [bundlePath stringByAppendingPathComponent:[NSString stringWithUTF8String:_dll.c_str()]]; - + NSURL* bundleURL = [NSURL fileURLWithPath:bundlePath]; _handle = CFBundleCreate(NULL, (CFURLRef)bundleURL); if(!_handle) @@ -180,7 +184,7 @@ MainHelperI::run() completed(EXIT_FAILURE); return; } - + CFErrorRef error = nil; Boolean loaded = CFBundleLoadExecutableAndReturnError(_handle, &error); if(error != nil || !loaded) @@ -189,7 +193,10 @@ MainHelperI::run() completed(EXIT_FAILURE); return; } - + + // The following call is necessary to prevent random failures from CFBundleGetFunctionPointerForName + dlsym(_handle, "dllTestShutdown"); + void* sym = CFBundleGetFunctionPointerForName(_handle, CFSTR("dllTestShutdown")); if(sym == 0) { @@ -200,7 +207,7 @@ MainHelperI::run() return; } _dllTestShutdown = (SHUTDOWN_ENTRY_POINT)sym; - + sym = CFBundleGetFunctionPointerForName(_handle, CFSTR("dllMain")); if(sym == 0) { @@ -210,7 +217,7 @@ MainHelperI::run() completed(EXIT_FAILURE); return; } - + MAIN_ENTRY_POINT dllMain = (MAIN_ENTRY_POINT)sym; char** argv = new char*[_args.size() + 1]; for(unsigned int i = 0; i < _args.size(); ++i) @@ -309,7 +316,8 @@ ProcessI::terminate(const Ice::Current& current) return _helper->getOutput(); } -ProcessControllerI::ProcessControllerI(id<ViewController> controller) : _controller(controller) +ProcessControllerI::ProcessControllerI(id<ViewController> controller, NSString* ipv4, NSString* ipv6) : + _controller(controller), _ipv4([ipv4 UTF8String]), _ipv6([ipv6 UTF8String]) { } @@ -329,23 +337,33 @@ ProcessControllerI::start(const string& testSuite, const string& exe, const Stri return ICE_UNCHECKED_CAST(ProcessPrx, c.adapter->addWithUUID(ICE_MAKE_SHARED(ProcessI, _controller, helper.get()))); } -ControllerHelper::ControllerHelper(id<ViewController> controller) +string +#ifdef ICE_CPP11_MAPPING +ProcessControllerI::getHost(string protocol, bool ipv6, const Ice::Current& c) +#else +ProcessControllerI::getHost(const string& protocol, bool ipv6, const Ice::Current& c) +#endif +{ + return ipv6 ? _ipv6 : _ipv4; +} + +ControllerHelper::ControllerHelper(id<ViewController> controller, NSString* ipv4, NSString* ipv6) { Ice::registerIceDiscovery(); - + Ice::InitializationData initData = Ice::InitializationData(); initData.properties = Ice::createProperties(); initData.properties->setProperty("Ice.ThreadPool.Server.SizeMax", "10"); initData.properties->setProperty("IceDiscovery.DomainId", "TestController"); - initData.properties->setProperty("IceDiscovery.Interface", "127.0.0.1"); - initData.properties->setProperty("Ice.Default.Host", "127.0.0.1"); + initData.properties->setProperty("IceDiscovery.Interface", [ipv4 UTF8String]); + initData.properties->setProperty("Ice.Default.Host", [ipv4 UTF8String]); initData.properties->setProperty("ControllerAdapter.Endpoints", "tcp"); //initData.properties->setProperty("Ice.Trace.Network", "2"); //initData.properties->setProperty("Ice.Trace.Protocol", "2"); initData.properties->setProperty("ControllerAdapter.AdapterId", Ice::generateUUID()); - + _communicator = Ice::initialize(initData); - + Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapter("ControllerAdapter"); Ice::Identity ident; #if TARGET_IPHONE_SIMULATOR != 0 @@ -354,7 +372,7 @@ ControllerHelper::ControllerHelper(id<ViewController> controller) ident.category = "iPhoneOS"; #endif ident.name = [[[NSBundle mainBundle] bundleIdentifier] UTF8String]; - adapter->add(ICE_MAKE_SHARED(ProcessControllerI, controller), ident); + adapter->add(ICE_MAKE_SHARED(ProcessControllerI, controller, ipv4, ipv6), ident); adapter->activate(); } @@ -370,15 +388,19 @@ extern "C" { void -startController(id<ViewController> controller) +startController(id<ViewController> controller, NSString* ipv4, NSString* ipv6) { - controllerHelper = new ControllerHelper(controller); + controllerHelper = new ControllerHelper(controller, ipv4, ipv6); } void stopController() { - delete controllerHelper; + if(controllerHelper) + { + delete controllerHelper; + controllerHelper = 0; + } } } diff --git a/cpp/test/ios/controller/C++ Test Controller.xcodeproj/project.pbxproj b/cpp/test/ios/controller/C++ Test Controller.xcodeproj/project.pbxproj index 6ec0a93ba1c..4903666f1fd 100644 --- a/cpp/test/ios/controller/C++ Test Controller.xcodeproj/project.pbxproj +++ b/cpp/test/ios/controller/C++ Test Controller.xcodeproj/project.pbxproj @@ -7,7 +7,9 @@ objects = { /* Begin PBXBuildFile section */ - 1440D8731E01877300CF7ED3 /* Controller.ice in Sources */ = {isa = PBXBuildFile; fileRef = 14905C6D1DF991F2002AE61B /* Controller.ice */; }; + 1419EB451E028A0700352FD7 /* Controller.ice in Resources */ = {isa = PBXBuildFile; fileRef = 1419EB441E028A0700352FD7 /* Controller.ice */; }; + 1419EB461E028A3300352FD7 /* Controller.ice in Sources */ = {isa = PBXBuildFile; fileRef = 1419EB441E028A0700352FD7 /* Controller.ice */; }; + 1419EB471E028A3A00352FD7 /* Controller.ice in Sources */ = {isa = PBXBuildFile; fileRef = 1419EB441E028A0700352FD7 /* Controller.ice */; }; 1440D8761E0187BA00CF7ED3 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 14B70D0F1E0160FD00118DE3 /* UIKit.framework */; }; 1440D8841E0188A600CF7ED3 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1440D8821E0188A600CF7ED3 /* Info.plist */; }; 1440D88A1E0189F300CF7ED3 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1440D8891E0189F300CF7ED3 /* Foundation.framework */; }; @@ -34,7 +36,6 @@ 14905C611DF98FD8002AE61B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14905C601DF98FD8002AE61B /* Assets.xcassets */; }; 14905C641DF98FD8002AE61B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14905C621DF98FD8002AE61B /* LaunchScreen.storyboard */; }; 14E398261E01B14B00A89291 /* ControllerI.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1440D8811E0188A600CF7ED3 /* ControllerI.mm */; }; - 14E398271E01B14B00A89291 /* Controller.ice in Sources */ = {isa = PBXBuildFile; fileRef = 14905C6D1DF991F2002AE61B /* Controller.ice */; }; 14E398291E01B14B00A89291 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 14B70D0F1E0160FD00118DE3 /* UIKit.framework */; }; 14E3982B1E01B14B00A89291 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1440D8891E0189F300CF7ED3 /* Foundation.framework */; }; 14E398361E01B18100A89291 /* Cpp98ControllerBundle.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 14E398311E01B14B00A89291 /* Cpp98ControllerBundle.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -110,6 +111,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1419EB441E028A0700352FD7 /* Controller.ice */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Controller.ice; path = ../../../../../scripts/Controller.ice; sourceTree = "<group>"; }; 1440D86C1E0186FF00CF7ED3 /* Cpp11ControllerBundle.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Cpp11ControllerBundle.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 1440D8811E0188A600CF7ED3 /* ControllerI.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ControllerI.mm; path = Bundle/ControllerI.mm; sourceTree = SOURCE_ROOT; }; 1440D8821E0188A600CF7ED3 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Bundle/Info.plist; sourceTree = SOURCE_ROOT; }; @@ -130,7 +132,6 @@ 14905C601DF98FD8002AE61B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 14905C631DF98FD8002AE61B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 14905C651DF98FD8002AE61B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; - 14905C6D1DF991F2002AE61B /* Controller.ice */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Controller.ice; path = ../../../../../scripts/Controller.ice; sourceTree = "<group>"; }; 14B70D0F1E0160FD00118DE3 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 14E398311E01B14B00A89291 /* Cpp98ControllerBundle.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Cpp98ControllerBundle.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 14E398371E01B30500A89291 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; @@ -216,8 +217,8 @@ 14905C5A1DF98FD8002AE61B /* ViewController.h */, 14905C5B1DF98FD8002AE61B /* ViewController.m */, 14905C5D1DF98FD8002AE61B /* Main.storyboard */, - 14905C601DF98FD8002AE61B /* Assets.xcassets */, 14905C621DF98FD8002AE61B /* LaunchScreen.storyboard */, + 14905C601DF98FD8002AE61B /* Assets.xcassets */, 14905C651DF98FD8002AE61B /* Info.plist */, 14905C541DF98FD8002AE61B /* Supporting Files */, ); @@ -235,12 +236,11 @@ 14B70CFA1E015C8B00118DE3 /* Bundle */ = { isa = PBXGroup; children = ( + 1419EB441E028A0700352FD7 /* Controller.ice */, 1440D8811E0188A600CF7ED3 /* ControllerI.mm */, 1440D8821E0188A600CF7ED3 /* Info.plist */, - 14905C6D1DF991F2002AE61B /* Controller.ice */, ); - name = Bundle; - path = "C++ Controller Framework"; + path = Bundle; sourceTree = "<group>"; }; 14B70D0C1E0160F700118DE3 /* Frameworks */ = { @@ -409,6 +409,7 @@ files = ( 148ABA1A1DFB12C800594F70 /* client.p12 in Resources */, 14905C641DF98FD8002AE61B /* LaunchScreen.storyboard in Resources */, + 1419EB451E028A0700352FD7 /* Controller.ice in Resources */, 148ABA1B1DFB12C800594F70 /* server.p12 in Resources */, 14905C611DF98FD8002AE61B /* Assets.xcassets in Resources */, 14905C5F1DF98FD8002AE61B /* Main.storyboard in Resources */, @@ -463,8 +464,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1419EB471E028A3A00352FD7 /* Controller.ice in Sources */, 1440D88C1E018B0C00CF7ED3 /* ControllerI.mm in Sources */, - 1440D8731E01877300CF7ED3 /* Controller.ice in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -492,8 +493,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1419EB461E028A3300352FD7 /* Controller.ice in Sources */, 14E398261E01B14B00A89291 /* ControllerI.mm in Sources */, - 14E398271E01B14B00A89291 /* Controller.ice in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -538,11 +539,14 @@ CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = U4TBVKNQ7F; + ENABLE_BITCODE = NO; + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", ICE_CPP11_MAPPING, "$(inherited)", ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; HEADER_SEARCH_PATHS = ../../include; INFOPLIST_FILE = Bundle/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; @@ -567,10 +571,13 @@ CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = U4TBVKNQ7F; + ENABLE_BITCODE = NO; + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_PREPROCESSOR_DEFINITIONS = ( ICE_CPP11_MAPPING, ICE_STATIC_LIBS, ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; HEADER_SEARCH_PATHS = ../../include; INFOPLIST_FILE = Bundle/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; @@ -769,10 +776,13 @@ CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = U4TBVKNQ7F; + ENABLE_BITCODE = NO; + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; HEADER_SEARCH_PATHS = ../../include; INFOPLIST_FILE = Bundle/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; @@ -797,7 +807,10 @@ CODE_SIGN_IDENTITY = "-"; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = U4TBVKNQ7F; + ENABLE_BITCODE = NO; + GCC_INLINES_ARE_PRIVATE_EXTERN = NO; GCC_PREPROCESSOR_DEFINITIONS = ICE_STATIC_LIBS; + GCC_SYMBOLS_PRIVATE_EXTERN = NO; HEADER_SEARCH_PATHS = ../../include; INFOPLIST_FILE = Bundle/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; 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 |