├── .gitignore ├── OpenFlow ├── AFItemView.h ├── AFItemView.m ├── AFOpenFlowConstants.h ├── AFOpenFlowView.h ├── AFOpenFlowView.m ├── AFUIImageReflection.h └── AFUIImageReflection.m ├── OpenFlowDemo ├── AFCoverFlowViewController.xib ├── AFOpenFlowDemo-Info.plist ├── AFOpenFlowDemo.xcodeproj │ └── project.pbxproj ├── AFOpenFlowDemo_Prefix.pch ├── Classes │ ├── AFGetImageOperation.h │ ├── AFGetImageOperation.m │ ├── AFOpenFlowAppDelegate.h │ ├── AFOpenFlowAppDelegate.m │ ├── AFOpenFlowViewController.h │ ├── AFOpenFlowViewController.m │ ├── UIImageExtras.h │ └── UIImageExtras.m ├── MainWindow.xib ├── ObjectiveFlickr │ ├── BridgeSupport │ │ └── ObjectiveFlickr.bridgesupport │ ├── Examples │ │ ├── CommandLineTool │ │ │ ├── CommandLineTool.xcodeproj │ │ │ │ └── project.pbxproj │ │ │ └── main.m │ │ ├── RandomPublicPhoto │ │ │ ├── English.lproj │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainMenu.xib │ │ │ ├── Info.plist │ │ │ ├── MainWindowController.h │ │ │ ├── MainWindowController.m │ │ │ ├── RandomPublicPhoto.xcodeproj │ │ │ │ ├── TemplateIcon.icns │ │ │ │ └── project.pbxproj │ │ │ ├── RandomPublicPhoto_Prefix.pch │ │ │ └── main.m │ │ └── SnapAndRun-iPhone │ │ │ ├── Classes │ │ │ ├── SnapAndRunAppDelegate.h │ │ │ ├── SnapAndRunAppDelegate.m │ │ │ ├── SnapAndRunViewController.h │ │ │ └── SnapAndRunViewController.m │ │ │ ├── Images │ │ │ └── SnapAndRun.png │ │ │ ├── MainWindow.xib │ │ │ ├── SampleAPIKey.h │ │ │ ├── SnapAndRun-Info.plist │ │ │ ├── SnapAndRun.xcodeproj │ │ │ └── project.pbxproj │ │ │ ├── SnapAndRunViewController.xib │ │ │ ├── SnapAndRun_Prefix.pch │ │ │ └── main.m │ ├── LFWebAPIKit │ │ ├── LFHTTPRequest.h │ │ ├── LFHTTPRequest.m │ │ ├── LFSiteReachability.h │ │ ├── LFSiteReachability.m │ │ ├── LFWebAPIKit.h │ │ ├── NSData+LFHTTPFormExtensions.h │ │ ├── NSData+LFHTTPFormExtensions.m │ │ └── Tests │ │ │ ├── SiteReachability-Mac │ │ │ ├── English.lproj │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainMenu.xib │ │ │ ├── Info.plist │ │ │ ├── MainController.h │ │ │ ├── MainController.m │ │ │ ├── SiteReachability.xcodeproj │ │ │ │ ├── TemplateIcon.icns │ │ │ │ └── project.pbxproj │ │ │ ├── SiteReachability_Prefix.pch │ │ │ ├── main.m │ │ │ └── version.plist │ │ │ ├── SiteReachability-iPhone │ │ │ ├── Classes │ │ │ │ ├── SiteReachabilityAppDelegate.h │ │ │ │ ├── SiteReachabilityAppDelegate.m │ │ │ │ ├── SiteReachabilityViewController.h │ │ │ │ └── SiteReachabilityViewController.m │ │ │ ├── MainWindow.xib │ │ │ ├── SiteReachability-Info.plist │ │ │ ├── SiteReachability.xcodeproj │ │ │ │ └── project.pbxproj │ │ │ ├── SiteReachabilityViewController.xib │ │ │ ├── SiteReachability_Prefix.pch │ │ │ └── main.m │ │ │ ├── StreamedBodySendingTest │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── English.lproj │ │ │ │ ├── InfoPlist.strings │ │ │ │ └── MainMenu.xib │ │ │ ├── GoogleToolboxForMac-Part │ │ │ │ ├── COPYING │ │ │ │ ├── Foundation │ │ │ │ │ ├── GTMDebugSelectorValidation.h │ │ │ │ │ ├── GTMGarbageCollection.h │ │ │ │ │ ├── GTMHTTPServer.h │ │ │ │ │ └── GTMHTTPServer.m │ │ │ │ └── GTMDefines.h │ │ │ ├── Info.plist │ │ │ ├── README.txt │ │ │ ├── StreamedBodySendingTest.xcodeproj │ │ │ │ ├── TemplateIcon.icns │ │ │ │ └── project.pbxproj │ │ │ ├── StreamedBodySendingTest_Prefix.pch │ │ │ └── main.m │ │ │ └── SynchronousRequestTest │ │ │ ├── SynchronousRequestTest-Info.plist │ │ │ ├── SynchronousRequestTest.xcodeproj │ │ │ └── project.pbxproj │ │ │ ├── TestSuite.h │ │ │ └── TestSuite.m │ ├── ObjectiveFlickr-Info.plist │ ├── ObjectiveFlickr.xcodeproj │ │ └── project.pbxproj │ ├── README.markdown │ ├── SampleAPIKey.h.template │ └── Source │ │ ├── OFUtilities.h │ │ ├── OFXMLMapper.h │ │ ├── OFXMLMapper.m │ │ ├── ObjectiveFlickr.h │ │ └── ObjectiveFlickr.m ├── Sample Images │ ├── 0.jpg │ ├── 1.jpg │ ├── 10.jpg │ ├── 11.jpg │ ├── 12.jpg │ ├── 13.jpg │ ├── 14.jpg │ ├── 15.jpg │ ├── 16.jpg │ ├── 17.jpg │ ├── 18.jpg │ ├── 19.jpg │ ├── 2.jpg │ ├── 20.jpg │ ├── 21.jpg │ ├── 22.jpg │ ├── 23.jpg │ ├── 24.jpg │ ├── 25.jpg │ ├── 26.jpg │ ├── 27.jpg │ ├── 28.jpg │ ├── 29.jpg │ ├── 3.jpg │ ├── 4.jpg │ ├── 5.jpg │ ├── 6.jpg │ ├── 7.jpg │ ├── 8.jpg │ ├── 9.jpg │ └── Read me.txt ├── default.png └── main.m └── README /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .svn 3 | profile 4 | *~.nib 5 | *.swp 6 | 7 | build/ 8 | *.perspective 9 | *.perspectivev3 10 | *.pbxuser 11 | *.mode1v3 12 | *.mode2v3 13 | -------------------------------------------------------------------------------- /OpenFlow/AFItemView.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | 27 | 28 | @interface AFItemView : UIView { 29 | UIImageView *imageView; 30 | int number; 31 | CGFloat horizontalPosition; 32 | CGFloat verticalPosition; 33 | CGFloat originalImageHeight; 34 | } 35 | 36 | @property int number; 37 | @property (nonatomic, readonly) CGFloat horizontalPosition; 38 | @property (nonatomic, readonly) CGFloat verticalPosition; 39 | @property (nonatomic, readonly) UIImageView *imageView; 40 | 41 | - (void)setImage:(UIImage *)newImage originalImageHeight:(CGFloat)imageHeight reflectionFraction:(CGFloat)reflectionFraction; 42 | - (CGSize)calculateNewSize:(CGSize)originalImageSize boundingBox:(CGSize)boundingBox; 43 | 44 | @end -------------------------------------------------------------------------------- /OpenFlow/AFItemView.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import "AFItemView.h" 26 | #import 27 | #import "AFOpenFlowConstants.h" 28 | 29 | 30 | @implementation AFItemView 31 | @synthesize number, imageView, horizontalPosition, verticalPosition; 32 | 33 | - (id)initWithFrame:(CGRect)frame { 34 | if (self = [super initWithFrame:frame]) { 35 | self.opaque = YES; 36 | self.backgroundColor = NULL; 37 | verticalPosition = 0; 38 | horizontalPosition = 0; 39 | 40 | // Image View 41 | imageView = [[UIImageView alloc] initWithFrame:frame]; 42 | imageView.opaque = YES; 43 | [self addSubview:imageView]; 44 | } 45 | 46 | return self; 47 | } 48 | 49 | - (void)setImage:(UIImage *)newImage originalImageHeight:(CGFloat)imageHeight reflectionFraction:(CGFloat)reflectionFraction { 50 | [imageView setImage:newImage]; 51 | verticalPosition = imageHeight * reflectionFraction / 2; 52 | originalImageHeight = imageHeight; 53 | self.frame = CGRectMake(0, 0, newImage.size.width, newImage.size.height); 54 | } 55 | 56 | - (void)setNumber:(int)newNumber { 57 | horizontalPosition = COVER_SPACING * newNumber; 58 | number = newNumber; 59 | } 60 | 61 | - (CGSize)calculateNewSize:(CGSize)baseImageSize boundingBox:(CGSize)boundingBox { 62 | CGFloat boundingRatio = boundingBox.width / boundingBox.height; 63 | CGFloat originalImageRatio = baseImageSize.width / baseImageSize.height; 64 | 65 | CGFloat newWidth; 66 | CGFloat newHeight; 67 | if (originalImageRatio > boundingRatio) { 68 | newWidth = boundingBox.width; 69 | newHeight = boundingBox.width * baseImageSize.height / baseImageSize.width; 70 | } else { 71 | newHeight = boundingBox.height; 72 | newWidth = boundingBox.height * baseImageSize.width / baseImageSize.height; 73 | } 74 | 75 | return CGSizeMake(newWidth, newHeight); 76 | } 77 | 78 | - (void)setFrame:(CGRect)newFrame { 79 | [super setFrame:newFrame]; 80 | [imageView setFrame:newFrame]; 81 | } 82 | 83 | - (void)dealloc { 84 | [imageView release]; 85 | 86 | [super dealloc]; 87 | } 88 | 89 | @end -------------------------------------------------------------------------------- /OpenFlow/AFOpenFlowConstants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | // For OpenFlow 27 | #define COVER_SPACING 40 28 | #define CENTER_COVER_OFFSET 70 29 | #define SIDE_COVER_ANGLE .79 30 | #define SIDE_COVER_ZPOSITION -80 -------------------------------------------------------------------------------- /OpenFlow/AFOpenFlowView.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | #import "AFItemView.h" 27 | #import 28 | 29 | 30 | @protocol AFOpenFlowViewDataSource; 31 | @protocol AFOpenFlowViewDelegate; 32 | 33 | @interface AFOpenFlowView : UIView { 34 | id dataSource; 35 | id viewDelegate; 36 | NSMutableSet *offscreenCovers; 37 | NSMutableDictionary *onscreenCovers; 38 | NSMutableDictionary *coverImages; 39 | NSMutableDictionary *coverImageHeights; 40 | UIImage *defaultImage; 41 | CGFloat defaultImageHeight; 42 | 43 | UIScrollView *scrollView; 44 | int lowerVisibleCover; 45 | int upperVisibleCover; 46 | int numberOfImages; 47 | int beginningCover; 48 | 49 | AFItemView *selectedCoverView; 50 | 51 | CATransform3D leftTransform, rightTransform; 52 | 53 | CGFloat halfScreenHeight; 54 | CGFloat halfScreenWidth; 55 | 56 | Boolean isSingleTap; 57 | Boolean isDoubleTap; 58 | Boolean isDraggingACover; 59 | CGFloat startPosition; 60 | } 61 | 62 | @property (nonatomic, assign) id dataSource; 63 | @property (nonatomic, assign) id viewDelegate; 64 | @property (nonatomic, retain) UIImage *defaultImage; 65 | @property int numberOfImages; 66 | 67 | - (void)setSelectedCover:(int)newSelectedCover; 68 | - (void)centerOnSelectedCover:(BOOL)animated; 69 | - (void)setImage:(UIImage *)image forIndex:(int)index; 70 | 71 | @end 72 | 73 | @protocol AFOpenFlowViewDelegate 74 | @optional 75 | - (void)openFlowView:(AFOpenFlowView *)openFlowView selectionDidChange:(int)index; 76 | @end 77 | 78 | @protocol AFOpenFlowViewDataSource 79 | - (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index; 80 | - (UIImage *)defaultImage; 81 | @end -------------------------------------------------------------------------------- /OpenFlow/AFUIImageReflection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | 27 | @interface UIImage (AFUIImageReflection) 28 | 29 | - (UIImage *)addImageReflection:(CGFloat)reflectionFraction; 30 | 31 | @end -------------------------------------------------------------------------------- /OpenFlow/AFUIImageReflection.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import "AFUIImageReflection.h" 26 | 27 | 28 | @implementation UIImage (AFUIImageReflection) 29 | 30 | - (UIImage *)addImageReflection:(CGFloat)reflectionFraction { 31 | int reflectionHeight = self.size.height * reflectionFraction; 32 | 33 | // create a 2 bit CGImage containing a gradient that will be used for masking the 34 | // main view content to create the 'fade' of the reflection. The CGImageCreateWithMask 35 | // function will stretch the bitmap image as required, so we can create a 1 pixel wide gradient 36 | CGImageRef gradientMaskImage = NULL; 37 | 38 | // gradient is always black-white and the mask must be in the gray colorspace 39 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); 40 | 41 | // create the bitmap context 42 | CGContextRef gradientBitmapContext = CGBitmapContextCreate(nil, 1, reflectionHeight, 43 | 8, 0, colorSpace, kCGImageAlphaNone); 44 | 45 | // define the start and end grayscale values (with the alpha, even though 46 | // our bitmap context doesn't support alpha the gradient requires it) 47 | CGFloat colors[] = {0.0, 1.0, 1.0, 1.0}; 48 | 49 | // create the CGGradient and then release the gray color space 50 | CGGradientRef grayScaleGradient = CGGradientCreateWithColorComponents(colorSpace, colors, NULL, 2); 51 | CGColorSpaceRelease(colorSpace); 52 | 53 | // create the start and end points for the gradient vector (straight down) 54 | CGPoint gradientStartPoint = CGPointMake(0, reflectionHeight); 55 | CGPoint gradientEndPoint = CGPointZero; 56 | 57 | // draw the gradient into the gray bitmap context 58 | CGContextDrawLinearGradient(gradientBitmapContext, grayScaleGradient, gradientStartPoint, 59 | gradientEndPoint, kCGGradientDrawsAfterEndLocation); 60 | CGGradientRelease(grayScaleGradient); 61 | 62 | // add a black fill with 50% opacity 63 | CGContextSetGrayFillColor(gradientBitmapContext, 0.0, 0.5); 64 | CGContextFillRect(gradientBitmapContext, CGRectMake(0, 0, 1, reflectionHeight)); 65 | 66 | // convert the context into a CGImageRef and release the context 67 | gradientMaskImage = CGBitmapContextCreateImage(gradientBitmapContext); 68 | CGContextRelease(gradientBitmapContext); 69 | 70 | // create an image by masking the bitmap of the mainView content with the gradient view 71 | // then release the pre-masked content bitmap and the gradient bitmap 72 | CGImageRef reflectionImage = CGImageCreateWithMask(self.CGImage, gradientMaskImage); 73 | CGImageRelease(gradientMaskImage); 74 | 75 | CGSize size = CGSizeMake(self.size.width, self.size.height + reflectionHeight); 76 | 77 | UIGraphicsBeginImageContext(size); 78 | 79 | [self drawAtPoint:CGPointZero]; 80 | CGContextRef context = UIGraphicsGetCurrentContext(); 81 | CGContextDrawImage(context, CGRectMake(0, self.size.height, self.size.width, reflectionHeight), reflectionImage); 82 | 83 | UIImage* result = UIGraphicsGetImageFromCurrentImageContext(); 84 | UIGraphicsEndImageContext(); 85 | CGImageRelease(reflectionImage); 86 | 87 | return result; 88 | } 89 | 90 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/AFOpenFlowDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.apparentlogic.openflowdemo 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | UIStatusBarStyle 30 | UIStatusBarStyleDefault 31 | 32 | 33 | -------------------------------------------------------------------------------- /OpenFlowDemo/AFOpenFlowDemo_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'AFOpenFlow' target in the 'AFOpenFlow' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/AFGetImageOperation.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | #import "AFOpenFlowViewController.h" 27 | 28 | @interface AFGetImageOperation : NSOperation { 29 | NSURL *imageURL; 30 | AFOpenFlowViewController *mainViewController; 31 | int photoIndex; 32 | } 33 | 34 | @property (nonatomic, retain) NSURL *imageURL; 35 | 36 | - (id)initWithIndex:(int)imageIndex viewController:(AFOpenFlowViewController *)viewController; 37 | 38 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/AFGetImageOperation.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import "AFGetImageOperation.h" 26 | #import "UIImageExtras.h" 27 | 28 | 29 | @implementation AFGetImageOperation 30 | @synthesize imageURL; 31 | 32 | - (id)initWithIndex:(int)imageIndex viewController:(AFOpenFlowViewController *)viewController { 33 | if (self = [super init]) { 34 | imageURL = nil; 35 | photoIndex = imageIndex; 36 | mainViewController = [viewController retain]; 37 | } 38 | return self; 39 | } 40 | 41 | - (void)dealloc { 42 | [imageURL release]; 43 | [mainViewController release]; 44 | 45 | [super dealloc]; 46 | } 47 | 48 | - (void)main { 49 | NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 50 | 51 | if (imageURL) { 52 | // Create a UIImage from the imageURL. 53 | NSData *photoData = [NSData dataWithContentsOfURL:imageURL]; 54 | UIImage *photo = [UIImage imageWithData:photoData]; 55 | 56 | if (photo) { 57 | [mainViewController performSelectorOnMainThread:@selector(imageDidLoad:) 58 | withObject:[NSArray arrayWithObjects:photo, [NSNumber numberWithInt:photoIndex], nil] 59 | waitUntilDone:YES]; 60 | } 61 | } else { 62 | // Load an image named photoIndex.jpg from our Resources. 63 | NSString *imageName = [[NSString alloc] initWithFormat:@"%d.jpg", photoIndex]; 64 | UIImage *theImage = [UIImage imageNamed:imageName]; 65 | if (theImage) { 66 | [mainViewController performSelectorOnMainThread:@selector(imageDidLoad:) 67 | withObject:[NSArray arrayWithObjects:theImage, [NSNumber numberWithInt:photoIndex], nil] 68 | waitUntilDone:YES]; 69 | } else 70 | NSLog(@"Unable to find sample image: %@", imageName); 71 | [imageName release]; 72 | } 73 | 74 | [pool release]; 75 | } 76 | 77 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/AFOpenFlowAppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | 27 | @class AFOpenFlowViewController; 28 | 29 | @interface AFOpenFlowAppDelegate : NSObject { 30 | UIWindow *window; 31 | AFOpenFlowViewController *viewController; 32 | } 33 | 34 | @property (nonatomic, retain) IBOutlet UIWindow *window; 35 | @property (nonatomic, retain) IBOutlet AFOpenFlowViewController *viewController; 36 | 37 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/AFOpenFlowAppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import "AFOpenFlowAppDelegate.h" 26 | #import "AFOpenFlowViewController.h" 27 | 28 | @implementation AFOpenFlowAppDelegate 29 | @synthesize viewController; 30 | 31 | @synthesize window; 32 | 33 | 34 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 35 | 36 | // Override point for customization after app launch 37 | [window addSubview:viewController.view]; 38 | [window makeKeyAndVisible]; 39 | } 40 | 41 | 42 | - (void)dealloc { 43 | [viewController release]; 44 | [window release]; 45 | [super dealloc]; 46 | } 47 | 48 | 49 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/AFOpenFlowViewController.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | #import "AFOpenFlowView.h" 27 | #import "ObjectiveFlickr.h" 28 | 29 | 30 | @interface AFOpenFlowViewController : UIViewController { 31 | NSArray *coverImageData; 32 | OFFlickrAPIContext *flickrContext; 33 | OFFlickrAPIRequest *interestingnessRequest; 34 | NSDictionary *interestingPhotosDictionary; 35 | NSOperationQueue *loadImagesOperationQueue; 36 | } 37 | 38 | - (void)imageDidLoad:(NSArray *)arguments; 39 | - (IBAction)infoButtonPressed:(id)sender; 40 | 41 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/AFOpenFlowViewController.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import "AFOpenFlowViewController.h" 26 | #import "UIImageExtras.h" 27 | #import "AFGetImageOperation.h" 28 | 29 | 30 | @implementation AFOpenFlowViewController 31 | 32 | #error Change theses values to your Flickr API key & secret 33 | #define flickrAPIKey @"MYAPIKEY" 34 | #define flickrAPISecret @"MYAPISECRET" 35 | 36 | - (void)dealloc { 37 | [loadImagesOperationQueue release]; 38 | [interestingPhotosDictionary release]; 39 | [flickrContext release]; 40 | [interestingnessRequest release]; 41 | 42 | [super dealloc]; 43 | } 44 | 45 | - (void)awakeFromNib { 46 | loadImagesOperationQueue = [[NSOperationQueue alloc] init]; 47 | UIAlertView *openFlowImageSourceAlertView = [[UIAlertView alloc] initWithTitle:@"OpenFlow Demo Data Source" 48 | message:@"Would you like to download images from Flickr or use 30 sample images included with this project?" 49 | delegate:self 50 | cancelButtonTitle:@"Flickr" 51 | otherButtonTitles:@"Samples (all at once)", @"Samples (NSThread)", nil]; 52 | [openFlowImageSourceAlertView show]; 53 | [openFlowImageSourceAlertView release]; 54 | } 55 | 56 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary { 57 | // Hold onto the response dictionary. 58 | interestingPhotosDictionary = [inResponseDictionary retain]; 59 | int numberOfImages = [[inResponseDictionary valueForKeyPath:@"photos.photo"] count]; 60 | [(AFOpenFlowView *)self.view setNumberOfImages:numberOfImages]; 61 | } 62 | 63 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)inError { 64 | NSLog(@"Flickr API request failed with error: %@", [inError description]); 65 | UIAlertView *flickrErrorAlertView = [[UIAlertView alloc] initWithTitle:@"Flickr API Error" 66 | message:[inError description] 67 | delegate:self 68 | cancelButtonTitle:@"Quit" 69 | otherButtonTitles:@"Retry", nil]; 70 | [flickrErrorAlertView show]; 71 | [flickrErrorAlertView release]; 72 | } 73 | 74 | - (IBAction)infoButtonPressed:(id)sender { 75 | NSString *alertString; 76 | if (interestingnessRequest) 77 | alertString = @"Many thanks to Lukhnos D. Liu's ObjectiveFlickr library for making it easy to access Flickr's 'Interestingness' photo stream."; 78 | else 79 | alertString = @"Sample images included in this project are all in the public domain, courtesy of NASA."; 80 | UIAlertView *infoAlertPanel = [[UIAlertView alloc] initWithTitle:@"OpenFlow Demo App" 81 | message:[NSString stringWithFormat:@"%@\n\nFor more info about the OpenFlow API, visit apparentlogic.com.", alertString] 82 | delegate:nil 83 | cancelButtonTitle:nil 84 | otherButtonTitles:@"Dismiss", nil]; 85 | [infoAlertPanel show]; 86 | [infoAlertPanel release]; 87 | } 88 | 89 | - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 90 | if ([[alertView title] isEqualToString:@"Flickr API Error"]) { 91 | if (buttonIndex == 0) { 92 | // Exit 93 | exit(-1); 94 | } else if (buttonIndex == 1) { 95 | // Retry 96 | [interestingnessRequest callAPIMethodWithGET:@"flickr.interestingness.getList" arguments:nil]; 97 | } 98 | } else { 99 | // Assume we're in the initial alert view. 100 | if (buttonIndex == 0) { 101 | // Ask flickr for images. 102 | flickrContext = [[OFFlickrAPIContext alloc] initWithAPIKey:flickrAPIKey 103 | sharedSecret:flickrAPISecret]; 104 | interestingnessRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:flickrContext]; 105 | interestingnessRequest.delegate = self; 106 | [interestingnessRequest callAPIMethodWithGET:@"flickr.interestingness.getList" arguments:nil]; 107 | } else if (buttonIndex == 1) { 108 | // Use sample images, but load them all at once. 109 | NSString *imageName; 110 | for (int i=0; i < 30; i++) { 111 | imageName = [[NSString alloc] initWithFormat:@"%d.jpg", i]; 112 | [(AFOpenFlowView *)self.view setImage:[UIImage imageNamed:imageName] forIndex:i]; 113 | [imageName release]; 114 | } 115 | [(AFOpenFlowView *)self.view setNumberOfImages:30]; 116 | } else if (buttonIndex == 2) { 117 | // Use sample images. 118 | [(AFOpenFlowView *)self.view setNumberOfImages:30]; 119 | } 120 | 121 | } 122 | } 123 | 124 | - (void)imageDidLoad:(NSArray *)arguments { 125 | UIImage *loadedImage = (UIImage *)[arguments objectAtIndex:0]; 126 | NSNumber *imageIndex = (NSNumber *)[arguments objectAtIndex:1]; 127 | 128 | // Only resize our images if they are coming from Flickr (samples are already scaled). 129 | // Resize the image on the main thread (UIKit is not thread safe). 130 | if (interestingnessRequest) 131 | loadedImage = [loadedImage cropCenterAndScaleImageToSize:CGSizeMake(225, 225)]; 132 | 133 | [(AFOpenFlowView *)self.view setImage:loadedImage forIndex:[imageIndex intValue]]; 134 | } 135 | 136 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 137 | return YES; 138 | } 139 | 140 | - (UIImage *)defaultImage { 141 | return [UIImage imageNamed:@"default.png"]; 142 | } 143 | 144 | - (void)openFlowView:(AFOpenFlowView *)openFlowView requestImageForIndex:(int)index { 145 | AFGetImageOperation *getImageOperation = [[AFGetImageOperation alloc] initWithIndex:index viewController:self]; 146 | 147 | if (interestingnessRequest) { 148 | // We're getting our images from the Flickr API. 149 | NSDictionary *photoDictionary = [[interestingPhotosDictionary valueForKeyPath:@"photos.photo"] objectAtIndex:index]; 150 | NSURL *photoURL = [flickrContext photoSourceURLFromDictionary:photoDictionary size:OFFlickrMediumSize]; 151 | getImageOperation.imageURL = photoURL; 152 | } 153 | 154 | [loadImagesOperationQueue addOperation:getImageOperation]; 155 | [getImageOperation release]; 156 | } 157 | 158 | - (void)openFlowView:(AFOpenFlowView *)openFlowView selectionDidChange:(int)index { 159 | NSLog(@"Cover Flow selection did change to %d", index); 160 | } 161 | 162 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/UIImageExtras.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | 27 | /** 28 | * Convenience methods to help with resizing images retrieved from the 29 | * ObjectiveFlickr library. 30 | */ 31 | @interface UIImage (OpenFlowExtras) 32 | 33 | - (UIImage *)rescaleImageToSize:(CGSize)size; 34 | - (UIImage *)cropImageToRect:(CGRect)cropRect; 35 | - (CGSize)calculateNewSizeForCroppingBox:(CGSize)croppingBox; 36 | - (UIImage *)cropCenterAndScaleImageToSize:(CGSize)cropSize; 37 | 38 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/Classes/UIImageExtras.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import "UIImageExtras.h" 26 | 27 | 28 | @implementation UIImage (OpenFlowExtras) 29 | 30 | - (UIImage *)rescaleImageToSize:(CGSize)size { 31 | CGRect rect = CGRectMake(0.0, 0.0, size.width, size.height); 32 | UIGraphicsBeginImageContext(rect.size); 33 | [self drawInRect:rect]; // scales image to rect 34 | UIImage *resImage = UIGraphicsGetImageFromCurrentImageContext(); 35 | UIGraphicsEndImageContext(); 36 | return resImage; 37 | } 38 | 39 | - (UIImage *)cropImageToRect:(CGRect)cropRect { 40 | // Begin the drawing (again) 41 | UIGraphicsBeginImageContext(cropRect.size); 42 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 43 | 44 | // Tanslate and scale upside-down to compensate for Quartz's inverted coordinate system 45 | CGContextTranslateCTM(ctx, 0.0, cropRect.size.height); 46 | CGContextScaleCTM(ctx, 1.0, -1.0); 47 | 48 | // Draw view into context 49 | CGRect drawRect = CGRectMake(-cropRect.origin.x, cropRect.origin.y - (self.size.height - cropRect.size.height) , self.size.width, self.size.height); 50 | CGContextDrawImage(ctx, drawRect, self.CGImage); 51 | 52 | // Create the new UIImage from the context 53 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 54 | 55 | // End the drawing 56 | UIGraphicsEndImageContext(); 57 | 58 | return newImage; 59 | } 60 | 61 | - (CGSize)calculateNewSizeForCroppingBox:(CGSize)croppingBox { 62 | // Make the shortest side be equivalent to the cropping box. 63 | CGFloat newHeight, newWidth; 64 | if (self.size.width < self.size.height) { 65 | newWidth = croppingBox.width; 66 | newHeight = (self.size.height / self.size.width) * croppingBox.width; 67 | } else { 68 | newHeight = croppingBox.height; 69 | newWidth = (self.size.width / self.size.height) *croppingBox.height; 70 | } 71 | 72 | return CGSizeMake(newWidth, newHeight); 73 | } 74 | 75 | - (UIImage *)cropCenterAndScaleImageToSize:(CGSize)cropSize { 76 | UIImage *scaledImage = [self rescaleImageToSize:[self calculateNewSizeForCroppingBox:cropSize]]; 77 | return [scaledImage cropImageToRect:CGRectMake((scaledImage.size.width-cropSize.width)/2, (scaledImage.size.height-cropSize.height)/2, cropSize.width, cropSize.height)]; 78 | } 79 | 80 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/MainWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 9J61 6 | 677 7 | 949.46 8 | 353.00 9 | 10 | YES 11 | 12 | 13 | YES 14 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 15 | 16 | 17 | YES 18 | 19 | YES 20 | 21 | 22 | YES 23 | 24 | 25 | 26 | YES 27 | 28 | IBFilesOwner 29 | 30 | 31 | IBFirstResponder 32 | 33 | 34 | 35 | AFCoverFlowViewController 36 | 37 | 38 | 39 | 40 | 292 41 | {320, 480} 42 | 43 | 1 44 | MC4yIDAuMiAwLjIAA 45 | 46 | NO 47 | NO 48 | 49 | 50 | 51 | 52 | 53 | YES 54 | 55 | 56 | delegate 57 | 58 | 59 | 60 | 4 61 | 62 | 63 | 64 | window 65 | 66 | 67 | 68 | 14 69 | 70 | 71 | 72 | viewController 73 | 74 | 75 | 76 | 22 77 | 78 | 79 | 80 | 81 | YES 82 | 83 | 0 84 | 85 | YES 86 | 87 | 88 | 89 | 90 | 91 | -1 92 | 93 | 94 | RmlsZSdzIE93bmVyA 95 | 96 | 97 | 3 98 | 99 | 100 | AFCoverFlow App Delegate 101 | 102 | 103 | -2 104 | 105 | 106 | 107 | 108 | 12 109 | 110 | 111 | YES 112 | 113 | 114 | 115 | 116 | 19 117 | 118 | 119 | 120 | 121 | 122 | 123 | YES 124 | 125 | YES 126 | -1.CustomClassName 127 | -2.CustomClassName 128 | 12.IBEditorWindowLastContentRect 129 | 12.IBPluginDependency 130 | 19.CustomClassName 131 | 19.IBEditorWindowLastContentRect 132 | 19.IBPluginDependency 133 | 3.CustomClassName 134 | 3.IBPluginDependency 135 | 136 | 137 | YES 138 | UIApplication 139 | UIResponder 140 | {{405, 195}, {320, 480}} 141 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 142 | AFOpenFlowViewController 143 | {{14, 376}, {320, 480}} 144 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 145 | AFOpenFlowAppDelegate 146 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 147 | 148 | 149 | 150 | YES 151 | 152 | YES 153 | 154 | 155 | YES 156 | 157 | 158 | 159 | 160 | YES 161 | 162 | YES 163 | 164 | 165 | YES 166 | 167 | 168 | 169 | 25 170 | 171 | 172 | 173 | YES 174 | 175 | AFOpenFlowAppDelegate 176 | NSObject 177 | 178 | YES 179 | 180 | YES 181 | viewController 182 | window 183 | 184 | 185 | YES 186 | AFOpenFlowViewController 187 | UIWindow 188 | 189 | 190 | 191 | IBProjectSource 192 | Classes/AFOpenFlowAppDelegate.h 193 | 194 | 195 | 196 | AFOpenFlowViewController 197 | UIViewController 198 | 199 | infoButtonPressed: 200 | id 201 | 202 | 203 | IBProjectSource 204 | Classes/AFOpenFlowViewController.h 205 | 206 | 207 | 208 | AFOpenFlowViewController 209 | UIViewController 210 | 211 | flipSideView 212 | UIView 213 | 214 | 215 | IBUserSource 216 | 217 | 218 | 219 | 220 | 221 | 0 222 | AFCoverFlow.xcodeproj 223 | 3 224 | 3.0 225 | 226 | 227 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/BridgeSupport/ObjectiveFlickr.bridgesupport: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/CommandLineTool/CommandLineTool.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 42; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6ABF73300F939D2000B9179E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6ABF732F0F939D2000B9179E /* Foundation.framework */; }; 11 | 6ABF73320F939D2000B9179E /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6ABF73310F939D2000B9179E /* SystemConfiguration.framework */; }; 12 | 6ABF73370F939D3600B9179E /* libObjectiveFlickr.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6ABF732C0F939CFD00B9179E /* libObjectiveFlickr.a */; }; 13 | 6ABF73480F939D9100B9179E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ABF73470F939D9100B9179E /* main.m */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXContainerItemProxy section */ 17 | 6ABF732B0F939CFD00B9179E /* PBXContainerItemProxy */ = { 18 | isa = PBXContainerItemProxy; 19 | containerPortal = 6ABF73270F939CFD00B9179E /* ObjectiveFlickr.xcodeproj */; 20 | proxyType = 2; 21 | remoteGlobalIDString = 6ABF72E60F939BE600B9179E; 22 | remoteInfo = "ObjectiveFlickr (library)"; 23 | }; 24 | 6ABF732D0F939D0600B9179E /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 6ABF73270F939CFD00B9179E /* ObjectiveFlickr.xcodeproj */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 6ABF72E50F939BE600B9179E; 29 | remoteInfo = "ObjectiveFlickr (library)"; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 6ABF731F0F939CEC00B9179E /* flickr-list-public-photos */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "flickr-list-public-photos"; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 6ABF73270F939CFD00B9179E /* ObjectiveFlickr.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ObjectiveFlickr.xcodeproj; path = ../../ObjectiveFlickr.xcodeproj; sourceTree = SOURCE_ROOT; }; 36 | 6ABF732F0F939D2000B9179E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 37 | 6ABF73310F939D2000B9179E /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = ""; }; 38 | 6ABF73470F939D9100B9179E /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 39 | 6ABF73490F939D9D00B9179E /* SampleAPIKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SampleAPIKey.h; path = ../../SampleAPIKey.h; sourceTree = SOURCE_ROOT; }; 40 | /* End PBXFileReference section */ 41 | 42 | /* Begin PBXFrameworksBuildPhase section */ 43 | 6ABF731D0F939CEC00B9179E /* Frameworks */ = { 44 | isa = PBXFrameworksBuildPhase; 45 | buildActionMask = 2147483647; 46 | files = ( 47 | 6ABF73300F939D2000B9179E /* Foundation.framework in Frameworks */, 48 | 6ABF73320F939D2000B9179E /* SystemConfiguration.framework in Frameworks */, 49 | 6ABF73370F939D3600B9179E /* libObjectiveFlickr.a in Frameworks */, 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | 6ABF73110F939CB100B9179E = { 57 | isa = PBXGroup; 58 | children = ( 59 | 6ABF73490F939D9D00B9179E /* SampleAPIKey.h */, 60 | 6ABF73470F939D9100B9179E /* main.m */, 61 | 6ABF73270F939CFD00B9179E /* ObjectiveFlickr.xcodeproj */, 62 | 6ABF73200F939CEC00B9179E /* Products */, 63 | 6ABF732F0F939D2000B9179E /* Foundation.framework */, 64 | 6ABF73310F939D2000B9179E /* SystemConfiguration.framework */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 6ABF73200F939CEC00B9179E /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 6ABF731F0F939CEC00B9179E /* flickr-list-public-photos */, 72 | ); 73 | name = Products; 74 | sourceTree = ""; 75 | }; 76 | 6ABF73280F939CFD00B9179E /* Products */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | 6ABF732C0F939CFD00B9179E /* libObjectiveFlickr.a */, 80 | ); 81 | name = Products; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | 6ABF731E0F939CEC00B9179E /* flickr-list-public-photos */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = 6ABF73240F939CED00B9179E /* Build configuration list for PBXNativeTarget "flickr-list-public-photos" */; 90 | buildPhases = ( 91 | 6ABF731C0F939CEC00B9179E /* Sources */, 92 | 6ABF731D0F939CEC00B9179E /* Frameworks */, 93 | ); 94 | buildRules = ( 95 | ); 96 | dependencies = ( 97 | 6ABF732E0F939D0600B9179E /* PBXTargetDependency */, 98 | ); 99 | name = "flickr-list-public-photos"; 100 | productName = "flickr-list-public-photos"; 101 | productReference = 6ABF731F0F939CEC00B9179E /* flickr-list-public-photos */; 102 | productType = "com.apple.product-type.tool"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | 6ABF73130F939CB100B9179E /* Project object */ = { 108 | isa = PBXProject; 109 | buildConfigurationList = 6ABF73160F939CB100B9179E /* Build configuration list for PBXProject "CommandLineTool" */; 110 | compatibilityVersion = "Xcode 2.4"; 111 | hasScannedForEncodings = 0; 112 | mainGroup = 6ABF73110F939CB100B9179E; 113 | productRefGroup = 6ABF73200F939CEC00B9179E /* Products */; 114 | projectDirPath = ""; 115 | projectReferences = ( 116 | { 117 | ProductGroup = 6ABF73280F939CFD00B9179E /* Products */; 118 | ProjectRef = 6ABF73270F939CFD00B9179E /* ObjectiveFlickr.xcodeproj */; 119 | }, 120 | ); 121 | projectRoot = ""; 122 | targets = ( 123 | 6ABF731E0F939CEC00B9179E /* flickr-list-public-photos */, 124 | ); 125 | }; 126 | /* End PBXProject section */ 127 | 128 | /* Begin PBXReferenceProxy section */ 129 | 6ABF732C0F939CFD00B9179E /* libObjectiveFlickr.a */ = { 130 | isa = PBXReferenceProxy; 131 | fileType = archive.ar; 132 | path = libObjectiveFlickr.a; 133 | remoteRef = 6ABF732B0F939CFD00B9179E /* PBXContainerItemProxy */; 134 | sourceTree = BUILT_PRODUCTS_DIR; 135 | }; 136 | /* End PBXReferenceProxy section */ 137 | 138 | /* Begin PBXSourcesBuildPhase section */ 139 | 6ABF731C0F939CEC00B9179E /* Sources */ = { 140 | isa = PBXSourcesBuildPhase; 141 | buildActionMask = 2147483647; 142 | files = ( 143 | 6ABF73480F939D9100B9179E /* main.m in Sources */, 144 | ); 145 | runOnlyForDeploymentPostprocessing = 0; 146 | }; 147 | /* End PBXSourcesBuildPhase section */ 148 | 149 | /* Begin PBXTargetDependency section */ 150 | 6ABF732E0F939D0600B9179E /* PBXTargetDependency */ = { 151 | isa = PBXTargetDependency; 152 | name = "ObjectiveFlickr (library)"; 153 | targetProxy = 6ABF732D0F939D0600B9179E /* PBXContainerItemProxy */; 154 | }; 155 | /* End PBXTargetDependency section */ 156 | 157 | /* Begin XCBuildConfiguration section */ 158 | 6ABF73140F939CB100B9179E /* Debug */ = { 159 | isa = XCBuildConfiguration; 160 | buildSettings = { 161 | COPY_PHASE_STRIP = NO; 162 | }; 163 | name = Debug; 164 | }; 165 | 6ABF73150F939CB100B9179E /* Release */ = { 166 | isa = XCBuildConfiguration; 167 | buildSettings = { 168 | COPY_PHASE_STRIP = YES; 169 | }; 170 | name = Release; 171 | }; 172 | 6ABF73220F939CED00B9179E /* Debug */ = { 173 | isa = XCBuildConfiguration; 174 | buildSettings = { 175 | ALWAYS_SEARCH_USER_PATHS = NO; 176 | COPY_PHASE_STRIP = NO; 177 | GCC_DYNAMIC_NO_PIC = NO; 178 | GCC_ENABLE_FIX_AND_CONTINUE = YES; 179 | GCC_MODEL_TUNING = G5; 180 | GCC_OPTIMIZATION_LEVEL = 0; 181 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 182 | GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; 183 | HEADER_SEARCH_PATHS = ( 184 | ../../LFWebAPIKit, 185 | ../../Source, 186 | ); 187 | INSTALL_PATH = /usr/local/bin; 188 | LIBRARY_SEARCH_PATHS = ( 189 | "$(inherited)", 190 | "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)", 191 | ); 192 | LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../../build/Debug\""; 193 | OTHER_LDFLAGS = ( 194 | "-framework", 195 | Foundation, 196 | "-framework", 197 | AppKit, 198 | ); 199 | PREBINDING = NO; 200 | PRODUCT_NAME = "flickr-list-public-photos"; 201 | }; 202 | name = Debug; 203 | }; 204 | 6ABF73230F939CED00B9179E /* Release */ = { 205 | isa = XCBuildConfiguration; 206 | buildSettings = { 207 | ALWAYS_SEARCH_USER_PATHS = NO; 208 | COPY_PHASE_STRIP = YES; 209 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 210 | GCC_ENABLE_FIX_AND_CONTINUE = NO; 211 | GCC_MODEL_TUNING = G5; 212 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 213 | GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h"; 214 | HEADER_SEARCH_PATHS = ( 215 | ../../LFWebAPIKit, 216 | ../../Source, 217 | ); 218 | INSTALL_PATH = /usr/local/bin; 219 | LIBRARY_SEARCH_PATHS = ( 220 | "$(inherited)", 221 | "$(LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1)", 222 | ); 223 | LIBRARY_SEARCH_PATHS_QUOTED_FOR_TARGET_1 = "\"$(SRCROOT)/../../build/Debug\""; 224 | OTHER_LDFLAGS = ( 225 | "-framework", 226 | Foundation, 227 | "-framework", 228 | AppKit, 229 | ); 230 | PREBINDING = NO; 231 | PRODUCT_NAME = "flickr-list-public-photos"; 232 | ZERO_LINK = NO; 233 | }; 234 | name = Release; 235 | }; 236 | /* End XCBuildConfiguration section */ 237 | 238 | /* Begin XCConfigurationList section */ 239 | 6ABF73160F939CB100B9179E /* Build configuration list for PBXProject "CommandLineTool" */ = { 240 | isa = XCConfigurationList; 241 | buildConfigurations = ( 242 | 6ABF73140F939CB100B9179E /* Debug */, 243 | 6ABF73150F939CB100B9179E /* Release */, 244 | ); 245 | defaultConfigurationIsVisible = 0; 246 | defaultConfigurationName = Release; 247 | }; 248 | 6ABF73240F939CED00B9179E /* Build configuration list for PBXNativeTarget "flickr-list-public-photos" */ = { 249 | isa = XCConfigurationList; 250 | buildConfigurations = ( 251 | 6ABF73220F939CED00B9179E /* Debug */, 252 | 6ABF73230F939CED00B9179E /* Release */, 253 | ); 254 | defaultConfigurationIsVisible = 0; 255 | defaultConfigurationName = Release; 256 | }; 257 | /* End XCConfigurationList section */ 258 | }; 259 | rootObject = 6ABF73130F939CB100B9179E /* Project object */; 260 | } 261 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/CommandLineTool/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import "ObjectiveFlickr.h" 29 | #import "SampleAPIKey.h" 30 | 31 | BOOL RunLoopShouldContinue = YES; 32 | 33 | @interface SimpleDelegate : NSObject 34 | @end 35 | 36 | @implementation SimpleDelegate 37 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary 38 | { 39 | NSLog(@"%s %@", __PRETTY_FUNCTION__, inResponseDictionary); 40 | 41 | NSArray *photos = [inResponseDictionary valueForKeyPath:@"photos.photo"]; 42 | for (NSDictionary *photo in photos) { 43 | NSLog(@"%@", [inRequest.context photoSourceURLFromDictionary:photo size:OFFlickrMediumSize]); 44 | } 45 | 46 | RunLoopShouldContinue = NO; 47 | } 48 | 49 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)error 50 | { 51 | NSLog(@"%s %@", __PRETTY_FUNCTION__, error); 52 | 53 | RunLoopShouldContinue = NO; 54 | } 55 | @end 56 | 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 61 | 62 | if (argc < 2) { 63 | fprintf(stderr, "usage: flickr-list-public-photos \n"); 64 | return 1; 65 | } 66 | 67 | NSString *userID = [NSString stringWithUTF8String:argv[1]]; 68 | 69 | SimpleDelegate *delegate = [[SimpleDelegate alloc] init]; 70 | OFFlickrAPIContext *context = [[OFFlickrAPIContext alloc] initWithAPIKey:OBJECTIVE_FLICKR_SAMPLE_API_KEY sharedSecret:OBJECTIVE_FLICKR_SAMPLE_API_SHARED_SECRET]; 71 | OFFlickrAPIRequest *request = [[OFFlickrAPIRequest alloc] initWithAPIContext:context]; 72 | 73 | [request setDelegate:delegate]; 74 | BOOL callResult = [request callAPIMethodWithGET:@"flickr.people.getPublicPhotos" arguments:[NSDictionary dictionaryWithObjectsAndKeys:userID, @"user_id", @"50", @"per_page", nil]]; 75 | 76 | while (RunLoopShouldContinue) { 77 | [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 78 | } 79 | 80 | [request release]; 81 | [context release]; 82 | [delegate release]; 83 | 84 | [pool drain]; 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | org.lukhnos.RandomPublicPhoto 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | LUKH 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/MainWindowController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MainWindowController.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | #import 30 | #import 31 | 32 | @interface MainWindowController : NSWindowController 33 | { 34 | OFFlickrAPIContext *flickrContext; 35 | OFFlickrAPIRequest *flickrRequest; 36 | IBOutlet NSTextView *textView; 37 | IBOutlet WebView *webView; 38 | } 39 | - (IBAction)nextRandomPhotoAction:(id)sender; 40 | @end 41 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/MainWindowController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MainWindowController.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import "MainWindowController.h" 29 | #import "SampleAPIKey.h" 30 | 31 | @implementation MainWindowController 32 | - (void)dealloc 33 | { 34 | [flickrContext release]; 35 | [flickrRequest release]; 36 | [super dealloc]; 37 | } 38 | 39 | - (void)awakeFromNib 40 | { 41 | flickrContext = [[OFFlickrAPIContext alloc] initWithAPIKey:OBJECTIVE_FLICKR_SAMPLE_API_KEY sharedSecret:OBJECTIVE_FLICKR_SAMPLE_API_SHARED_SECRET]; 42 | flickrRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:flickrContext]; 43 | [flickrRequest setDelegate:self]; 44 | [self nextRandomPhotoAction:self]; 45 | 46 | [[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(nextRandomPhotoAction:) userInfo:nil repeats:YES] fire]; 47 | 48 | [webView setDrawsBackground:NO]; 49 | 50 | [[self window] center]; 51 | } 52 | 53 | - (IBAction)nextRandomPhotoAction:(id)sender 54 | { 55 | if (![flickrRequest isRunning]) { 56 | [flickrRequest callAPIMethodWithGET:@"flickr.photos.getRecent" arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"1", @"per_page", nil]]; 57 | } 58 | } 59 | 60 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary 61 | { 62 | NSDictionary *photoDict = [[inResponseDictionary valueForKeyPath:@"photos.photo"] objectAtIndex:0]; 63 | 64 | NSString *title = [photoDict objectForKey:@"title"]; 65 | if (![title length]) { 66 | title = @"No title"; 67 | } 68 | 69 | NSURL *photoSourcePage = [flickrContext photoWebPageURLFromDictionary:photoDict]; 70 | NSDictionary *linkAttr = [NSDictionary dictionaryWithObjectsAndKeys:photoSourcePage, NSLinkAttributeName, nil]; 71 | NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString:title attributes:linkAttr] autorelease]; 72 | [[textView textStorage] setAttributedString:attrString]; 73 | 74 | NSURL *photoURL = [flickrContext photoSourceURLFromDictionary:photoDict size:OFFlickrSmallSize]; 75 | NSString *htmlSource = [NSString stringWithFormat: 76 | @"" 77 | @"" 78 | @" " 79 | @"" 80 | @"" 81 | @" " 82 | @" " 83 | @"
" 84 | @"" 85 | @"" 86 | , photoURL]; 87 | 88 | [[webView mainFrame] loadHTMLString:htmlSource baseURL:nil]; 89 | } 90 | 91 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)inError 92 | { 93 | } 94 | @end 95 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/RandomPublicPhoto.xcodeproj/TemplateIcon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/RandomPublicPhoto.xcodeproj/TemplateIcon.icns -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/RandomPublicPhoto_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RandomPublicPhoto' target in the 'RandomPublicPhoto' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/RandomPublicPhoto/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | return NSApplicationMain(argc, (const char **) argv); 33 | } 34 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/Classes/SnapAndRunAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SnapAndRunAppDelegate.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | #import "ObjectiveFlickr.h" 30 | 31 | extern NSString *SnapAndRunShouldUpdateAuthInfoNotification; 32 | 33 | @interface SnapAndRunAppDelegate : NSObject 34 | { 35 | UINavigationController *viewController; 36 | UIWindow *window; 37 | 38 | UIActivityIndicatorView *activityIndicator; 39 | UIView *progressView; 40 | UIButton *cancelButton; 41 | UILabel *progressDescription; 42 | 43 | OFFlickrAPIContext *flickrContext; 44 | OFFlickrAPIRequest *flickrRequest; 45 | NSString *flickrUserName; 46 | } 47 | 48 | + (SnapAndRunAppDelegate *)sharedDelegate; 49 | - (void)setAndStoreFlickrAuthToken:(NSString *)inAuthToken; 50 | 51 | - (IBAction)cancelAction; 52 | 53 | @property (nonatomic, retain) IBOutlet UINavigationController *viewController; 54 | @property (nonatomic, retain) IBOutlet UIWindow *window; 55 | @property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator; 56 | @property (nonatomic, retain) IBOutlet UIView *progressView; 57 | @property (nonatomic, retain) IBOutlet UIButton *cancelButton; 58 | @property (nonatomic, retain) IBOutlet UILabel *progressDescription; 59 | 60 | @property (nonatomic, readonly) OFFlickrAPIContext *flickrContext; 61 | @property (nonatomic, retain) NSString *flickrUserName; 62 | @end 63 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/Classes/SnapAndRunAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // SnapAndRunAppDelegate.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import "SnapAndRunAppDelegate.h" 29 | #import "SnapAndRunViewController.h" 30 | #import "SampleAPIKey.h" 31 | 32 | NSString *SnapAndRunShouldUpdateAuthInfoNotification = @"SnapAndRunShouldUpdateAuthInfoNotification"; 33 | 34 | // preferably, the auth token is stored in the keychain, but since working with keychain is a pain, we use the simpler default system 35 | NSString *kStoredAuthTokenKeyName = @"FlickrAuthToken"; 36 | NSString *kGetAuthTokenStep = @"kGetAuthTokenStep"; 37 | NSString *kCheckTokenStep = @"kCheckTokenStep"; 38 | 39 | @implementation SnapAndRunAppDelegate 40 | - (void)dealloc 41 | { 42 | [viewController release]; 43 | [window release]; 44 | [flickrContext release]; 45 | [flickrRequest release]; 46 | [flickrUserName release]; 47 | [super dealloc]; 48 | } 49 | 50 | - (OFFlickrAPIRequest *)flickrRequest 51 | { 52 | if (!flickrRequest) { 53 | flickrRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:self.flickrContext]; 54 | flickrRequest.delegate = self; 55 | } 56 | 57 | return flickrRequest; 58 | } 59 | 60 | - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 61 | { 62 | // query has the form of "&frob=", the rest is the frob 63 | NSString *frob = [[url query] substringFromIndex:6]; 64 | 65 | [self flickrRequest].sessionInfo = kGetAuthTokenStep; 66 | [flickrRequest callAPIMethodWithGET:@"flickr.auth.getToken" arguments:[NSDictionary dictionaryWithObjectsAndKeys:frob, @"frob", nil]]; 67 | 68 | [activityIndicator startAnimating]; 69 | [viewController.view addSubview:progressView]; 70 | 71 | return YES; 72 | } 73 | 74 | - (void)_applicationDidFinishLaunchingContinued 75 | { 76 | if ([self flickrRequest].sessionInfo) { 77 | // is getting auth token 78 | return; 79 | } 80 | 81 | if ([self.flickrContext.authToken length]) { 82 | [self flickrRequest].sessionInfo = kCheckTokenStep; 83 | [flickrRequest callAPIMethodWithGET:@"flickr.auth.checkToken" arguments:nil]; 84 | 85 | [activityIndicator startAnimating]; 86 | [viewController.view addSubview:progressView]; 87 | } 88 | } 89 | 90 | - (void)applicationDidFinishLaunching:(UIApplication *)application 91 | { 92 | [window addSubview:viewController.view]; 93 | [window makeKeyAndVisible]; 94 | 95 | // Apple trick: Do this so after we got a chance to let application:handleOpenURL: run before our next stage of init... 96 | [self performSelector:@selector(_applicationDidFinishLaunchingContinued) withObject:nil afterDelay:0.0]; 97 | } 98 | 99 | + (SnapAndRunAppDelegate *)sharedDelegate 100 | { 101 | return (SnapAndRunAppDelegate *)[[UIApplication sharedApplication] delegate]; 102 | } 103 | 104 | - (void)cancelAction 105 | { 106 | [flickrRequest cancel]; 107 | [activityIndicator stopAnimating]; 108 | [progressView removeFromSuperview]; 109 | [self setAndStoreFlickrAuthToken:nil]; 110 | [[NSNotificationCenter defaultCenter] postNotificationName:SnapAndRunShouldUpdateAuthInfoNotification object:self]; 111 | } 112 | 113 | - (void)setAndStoreFlickrAuthToken:(NSString *)inAuthToken 114 | { 115 | if (![inAuthToken length]) { 116 | self.flickrContext.authToken = nil; 117 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:kStoredAuthTokenKeyName]; 118 | } 119 | else { 120 | self.flickrContext.authToken = inAuthToken; 121 | [[NSUserDefaults standardUserDefaults] setObject:inAuthToken forKey:kStoredAuthTokenKeyName]; 122 | } 123 | } 124 | 125 | - (OFFlickrAPIContext *)flickrContext 126 | { 127 | if (!flickrContext) { 128 | flickrContext = [[OFFlickrAPIContext alloc] initWithAPIKey:OBJECTIVE_FLICKR_SAMPLE_API_KEY sharedSecret:OBJECTIVE_FLICKR_SAMPLE_API_SHARED_SECRET]; 129 | 130 | NSString *authToken; 131 | if (authToken = [[NSUserDefaults standardUserDefaults] objectForKey:kStoredAuthTokenKeyName]) { 132 | flickrContext.authToken = authToken; 133 | } 134 | } 135 | 136 | return flickrContext; 137 | } 138 | 139 | #pragma mark OFFlickrAPIRequest delegate methods 140 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary 141 | { 142 | if (inRequest.sessionInfo == kGetAuthTokenStep) { 143 | [self setAndStoreFlickrAuthToken:[[inResponseDictionary valueForKeyPath:@"auth.token"] textContent]]; 144 | self.flickrUserName = [inResponseDictionary valueForKeyPath:@"auth.user.username"]; 145 | } 146 | else if (inRequest.sessionInfo == kCheckTokenStep) { 147 | self.flickrUserName = [inResponseDictionary valueForKeyPath:@"auth.user.username"]; 148 | } 149 | 150 | [activityIndicator stopAnimating]; 151 | [progressView removeFromSuperview]; 152 | [[NSNotificationCenter defaultCenter] postNotificationName:SnapAndRunShouldUpdateAuthInfoNotification object:self]; 153 | } 154 | 155 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)inError 156 | { 157 | if (inRequest.sessionInfo == kGetAuthTokenStep) { 158 | } 159 | else if (inRequest.sessionInfo == kCheckTokenStep) { 160 | [self setAndStoreFlickrAuthToken:nil]; 161 | } 162 | 163 | [activityIndicator stopAnimating]; 164 | [progressView removeFromSuperview]; 165 | 166 | [[[[UIAlertView alloc] initWithTitle:@"API Failed" message:[inError description] delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil] autorelease] show]; 167 | [[NSNotificationCenter defaultCenter] postNotificationName:SnapAndRunShouldUpdateAuthInfoNotification object:self]; 168 | } 169 | 170 | @synthesize viewController; 171 | @synthesize window; 172 | @synthesize flickrContext; 173 | @synthesize flickrUserName; 174 | 175 | @synthesize activityIndicator; 176 | @synthesize progressView; 177 | @synthesize cancelButton; 178 | @synthesize progressDescription; 179 | @end 180 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/Classes/SnapAndRunViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SnapAndRunViewController.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | #import "ObjectiveFlickr.h" 30 | 31 | @interface SnapAndRunViewController : UIViewController 32 | { 33 | OFFlickrAPIRequest *flickrRequest; 34 | 35 | UIImagePickerController *imagePicker; 36 | 37 | UILabel *authorizeDescriptionLabel; 38 | UILabel *snapPictureDescriptionLabel; 39 | UIButton *authorizeButton; 40 | UIButton *snapPictureButton; 41 | } 42 | - (IBAction)authorizeAction; 43 | - (IBAction)snapPictureAction; 44 | 45 | @property (nonatomic, retain) IBOutlet UILabel *authorizeDescriptionLabel; 46 | @property (nonatomic, retain) IBOutlet UILabel *snapPictureDescriptionLabel; 47 | @property (nonatomic, retain) IBOutlet UIButton *snapPictureButton; 48 | @property (nonatomic, retain) IBOutlet UIButton *authorizeButton; 49 | 50 | @property (nonatomic, retain) OFFlickrAPIRequest *flickrRequest; 51 | @property (nonatomic, retain) UIImagePickerController *imagePicker; 52 | @end 53 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/Images/SnapAndRun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/Images/SnapAndRun.png -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/SampleAPIKey.h: -------------------------------------------------------------------------------- 1 | // 2 | // SampleAPIKey.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | #define OBJECTIVE_FLICKR_SAMPLE_API_KEY @"43e93fdbe6b9c2299c3f5ca47b5efcfc" 28 | #define OBJECTIVE_FLICKR_SAMPLE_API_SHARED_SECRET @"ff67245fea8665c1" 29 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/SnapAndRun-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | SnapAndRun.png 13 | CFBundleIdentifier 14 | org.lukhnos.SnapAndRun 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | LTGF 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | CFBundleURLTypes 30 | 31 | 32 | CFBundleURLName 33 | org.lukhnos.SnapAndRun 34 | CFBundleURLSchemes 35 | 36 | snapnrun 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/SnapAndRun_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SnapAndRun' target in the 'SnapAndRun' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Examples/SnapAndRun-iPhone/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 33 | int retVal = UIApplicationMain(argc, argv, nil, nil); 34 | [pool release]; 35 | return retVal; 36 | } 37 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/LFHTTPRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // LFHTTPRequest.h 3 | // 4 | // Copyright (c) 2007-2009 Lithoglyph Inc. (http://lithoglyph.com) 5 | // Copyright (c) 2007-2009 Lukhnos D. Liu (http://lukhnos.org) 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | #if TARGET_OS_IPHONE 31 | #import 32 | #import 33 | #import 34 | #endif 35 | 36 | extern NSString *LFHTTPRequestConnectionError; 37 | extern NSString *LFHTTPRequestTimeoutError; 38 | extern NSTimeInterval LFHTTPRequestDefaultTimeoutInterval; 39 | extern NSString *LFHTTPRequestWWWFormURLEncodedContentType; 40 | extern NSString *LFHTTPRequestGETMethod; 41 | extern NSString *LFHTTPRequestHEADMethod; 42 | extern NSString *LFHTTPRequestPOSTMethod; 43 | 44 | @interface LFHTTPRequest : NSObject 45 | { 46 | id _delegate; 47 | 48 | NSTimeInterval _timeoutInterval; 49 | NSString *_userAgent; 50 | NSString *_contentType; 51 | 52 | NSDictionary *_requestHeader; 53 | 54 | NSMutableData *_receivedData; 55 | NSString *_receivedContentType; 56 | 57 | CFReadStreamRef _readStream; 58 | NSTimer *_receivedDataTracker; 59 | NSTimeInterval _lastReceivedDataUpdateTime; 60 | 61 | NSTimer *_requestMessageBodyTracker; 62 | NSTimeInterval _lastSentDataUpdateTime; 63 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 64 | NSUInteger _requestMessageBodySize; 65 | NSUInteger _expectedDataLength; 66 | NSUInteger _lastReceivedBytes; 67 | NSUInteger _lastSentBytes; 68 | #else 69 | unsigned int _requestMessageBodySize; 70 | unsigned int _expectedDataLength; 71 | unsigned int _lastReceivedBytes; 72 | unsigned int _lastSentBytes; 73 | #endif 74 | 75 | void *_readBuffer; 76 | size_t _readBufferSize; 77 | 78 | id _sessionInfo; 79 | 80 | BOOL _shouldWaitUntilDone; 81 | } 82 | 83 | - (id)init; 84 | - (BOOL)isRunning; 85 | - (void)cancel; 86 | - (void)cancelWithoutDelegateMessage; 87 | 88 | - (BOOL)shouldWaitUntilDone; 89 | - (void)setShouldWaitUntilDone:(BOOL)waitUntilDone; 90 | 91 | - (BOOL)performMethod:(NSString *)methodName onURL:(NSURL *)url withData:(NSData *)data; 92 | 93 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 94 | - (BOOL)performMethod:(NSString *)methodName onURL:(NSURL *)url withInputStream:(NSInputStream *)inputStream knownContentSize:(NSUInteger)byteStreamSize; 95 | #else 96 | - (BOOL)performMethod:(NSString *)methodName onURL:(NSURL *)url withInputStream:(NSInputStream *)inputStream knownContentSize:(unsigned int)byteStreamSize; 97 | #endif 98 | 99 | - (NSData *)getReceivedDataAndDetachFromRequest; 100 | 101 | - (NSDictionary *)requestHeader; 102 | - (void)setRequestHeader:(NSDictionary *)requestHeader; 103 | - (NSTimeInterval)timeoutInterval; 104 | - (void)setTimeoutInterval:(NSTimeInterval)timeoutInterval; 105 | - (NSString *)userAgent; 106 | - (void)setUserAgent:(NSString *)userAgent; 107 | - (NSString *)contentType; 108 | - (void)setContentType:(NSString *)contentType; 109 | - (NSData *)receivedData; 110 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 111 | - (NSUInteger)expectedDataLength; 112 | #else 113 | - (unsigned int)expectedDataLength; 114 | #endif 115 | - (id)delegate; 116 | - (void)setDelegate:(id)delegate; 117 | 118 | - (void)setSessionInfo:(id)aSessionInfo; 119 | - (id)sessionInfo; 120 | 121 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 122 | @property (copy) NSDictionary *requestHeader; 123 | @property (assign) NSTimeInterval timeoutInterval; 124 | @property (copy) NSString *userAgent; 125 | @property (copy) NSString *contentType; 126 | @property (readonly) NSData *receivedData; 127 | @property (readonly) NSUInteger expectedDataLength; 128 | @property (assign) id delegate; 129 | @property (retain) id sessionInfo; 130 | @property (assign) BOOL shouldWaitUntilDone; 131 | #endif 132 | @end 133 | 134 | @interface NSObject (LFHTTPRequestDelegate) 135 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 136 | - (void)httpRequest:(LFHTTPRequest *)request didReceiveStatusCode:(NSUInteger)statusCode URL:(NSURL *)url responseHeader:(CFHTTPMessageRef)header; 137 | - (void)httpRequestDidComplete:(LFHTTPRequest *)request; 138 | - (void)httpRequestDidCancel:(LFHTTPRequest *)request; 139 | - (void)httpRequest:(LFHTTPRequest *)request didFailWithError:(NSString *)error; 140 | - (void)httpRequest:(LFHTTPRequest *)request receivedBytes:(NSUInteger)bytesReceived expectedTotal:(NSUInteger)total; 141 | - (void)httpRequest:(LFHTTPRequest *)request sentBytes:(NSUInteger)bytesSent total:(NSUInteger)total; 142 | 143 | // note if you implemented this, the data is never written to the receivedData of the HTTP request instance 144 | - (void)httpRequest:(LFHTTPRequest *)request writeReceivedBytes:(void *)bytes size:(NSUInteger)blockSize expectedTotal:(NSUInteger)total; 145 | #else 146 | - (void)httpRequest:(LFHTTPRequest *)request didReceiveStatusCode:(unsigned int)statusCode URL:(NSURL *)url responseHeader:(CFHTTPMessageRef)header; 147 | - (void)httpRequestDidComplete:(LFHTTPRequest *)request; 148 | - (void)httpRequestDidCancel:(LFHTTPRequest *)request; 149 | - (void)httpRequest:(LFHTTPRequest *)request didFailWithError:(NSString *)error; 150 | - (void)httpRequest:(LFHTTPRequest *)request receivedBytes:(unsigned int)bytesReceived expectedTotal:(unsigned int)total; 151 | - (void)httpRequest:(LFHTTPRequest *)request sentBytes:(unsigned int)bytesSent total:(unsigned int)total; 152 | - (void)httpRequest:(LFHTTPRequest *)request writeReceivedBytes:(void *)bytes size:(unsigned int)blockSize expectedTotal:(unsigned int)total; 153 | #endif 154 | @end -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/LFSiteReachability.h: -------------------------------------------------------------------------------- 1 | // 2 | // LFSiteReachability.h 3 | // 4 | // Copyright (c) 2007-2009 Lithoglyph Inc. (http://lithoglyph.com) 5 | // Copyright (c) 2007-2009 Lukhnos D. Liu (http://lukhnos.org) 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | #import "LFHTTPRequest.h" 31 | 32 | extern NSString *LFSiteReachabilityConnectionTypeWiFi; 33 | extern NSString *LFSiteReachabilityConnectionTypeWWAN; 34 | 35 | @class LFSiteReachability; 36 | 37 | @protocol LFSiteReachabilityDelegate 38 | - (void)reachability:(LFSiteReachability *)inReachability site:(NSURL *)inURL isAvailableOverConnectionType:(NSString *)inConnectionType; 39 | - (void)reachability:(LFSiteReachability *)inReachability siteIsNotAvailable:(NSURL *)inURL; 40 | @end 41 | 42 | @interface LFSiteReachability : NSObject 43 | { 44 | id delegate; 45 | NSURL *siteURL; 46 | SCNetworkReachabilityRef reachability; 47 | LFHTTPRequest *siteRequest; 48 | NSTimer *timeoutTimer; 49 | id lastCheckStatus; 50 | } 51 | - (void)startChecking; 52 | - (void)stopChecking; 53 | - (BOOL)isChecking; 54 | 55 | // When networkConnectivityExists returns YES, it simply means network interface is available 56 | // (e.g. WiFi not disabled, has 3G, etc.); that is, the device has the "potential" to connect, 57 | // but that does not mean that an HTTP request will succeed, for various reasons--such as 58 | // the IP is not yet obtained; the interface is not yet fully "up", base station or WiFi hasn't 59 | // assigned a valid IP yet, etc. To read this way: If this method returns NO, it means 60 | // "forget about network, it doesn't exist at all" 61 | - (BOOL)networkConnectivityExists; 62 | 63 | @property (assign, nonatomic) id delegate; 64 | @property (retain, nonatomic) NSURL *siteURL; 65 | @property (nonatomic) NSTimeInterval timeoutInterval; 66 | @end 67 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/LFSiteReachability.m: -------------------------------------------------------------------------------- 1 | // 2 | // LFSiteReachability.m 3 | // 4 | // Copyright (c) 2007-2009 Lithoglyph Inc. (http://lithoglyph.com) 5 | // Copyright (c) 2007-2009 Lukhnos D. Liu (http://lukhnos.org) 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "LFSiteReachability.h" 30 | #import 31 | 32 | #define kDefaultSite @"http://google.com" 33 | #define kDefaultTimeoutInterval 15.0 34 | 35 | #define LFSRDebug(format, ...) 36 | // #define LFSRDebug NSLog 37 | 38 | NSString *LFSiteReachabilityConnectionTypeWiFi = @"LFSiteReachabilityConnectionTypeWiFi"; 39 | NSString *LFSiteReachabilityConnectionTypeWWAN = @"LFSiteReachabilityConnectionTypeWWAN"; 40 | NSString *LFSiteReachabilityNotReachableStatus = @"LFSiteReachabilityNotReachable"; 41 | 42 | #ifndef TARGET_OS_IPHONE 43 | #define SCNetworkReachabilityFlags SCNetworkConnectionFlags 44 | #define kSCNetworkReachabilityFlagsConnectionRequired kSCNetworkFlagsConnectionRequired 45 | #define kSCNetworkReachabilityFlagsReachable kSCNetworkFlagsReachable 46 | #define kSCNetworkReachabilityFlagsIsWWAN 0 47 | #endif 48 | 49 | static void LFSiteReachabilityCallback(SCNetworkReachabilityRef inTarget, SCNetworkReachabilityFlags inFlags, void *inInfo); 50 | 51 | @implementation LFSiteReachability 52 | - (void)dealloc 53 | { 54 | delegate = nil; 55 | 56 | [siteRequest setDelegate:nil]; 57 | [self stopChecking]; 58 | [siteRequest release]; 59 | [siteURL release]; 60 | 61 | [super dealloc]; 62 | } 63 | 64 | - (void)finalize 65 | { 66 | [siteRequest setDelegate:nil]; 67 | [self stopChecking]; 68 | [super finalize]; 69 | } 70 | 71 | - (id)init 72 | { 73 | if (self = [super init]) { 74 | siteRequest = [[LFHTTPRequest alloc] init]; 75 | [siteRequest setDelegate:self]; 76 | [siteRequest setTimeoutInterval:kDefaultTimeoutInterval]; 77 | 78 | siteURL = [[NSURL URLWithString:kDefaultSite] retain]; 79 | } 80 | 81 | return self; 82 | } 83 | 84 | - (void)handleTimeoutTimer:(NSTimer *)inTimer 85 | { 86 | LFSRDebug(@"%s", __PRETTY_FUNCTION__); 87 | [inTimer invalidate]; 88 | 89 | if (lastCheckStatus != LFSiteReachabilityNotReachableStatus) { 90 | lastCheckStatus = LFSiteReachabilityNotReachableStatus; 91 | if ([delegate respondsToSelector:@selector(reachability:siteIsNotAvailable:)]) { 92 | [delegate reachability:self siteIsNotAvailable:siteURL]; 93 | } 94 | } 95 | } 96 | 97 | - (void)stopTimeoutTimer 98 | { 99 | if ([timeoutTimer isValid]) { 100 | [timeoutTimer invalidate]; 101 | } 102 | 103 | [timeoutTimer release]; 104 | timeoutTimer = nil; 105 | } 106 | 107 | - (void)handleReachabilityCallbackFlags:(SCNetworkReachabilityFlags)inFlags 108 | { 109 | [self stopTimeoutTimer]; 110 | 111 | LFSRDebug(@"%s, flags: 0x%08x", __PRETTY_FUNCTION__, inFlags); 112 | 113 | if (inFlags & kSCNetworkReachabilityFlagsReachable) { 114 | NSString *connectionType = (inFlags & 0) ? LFSiteReachabilityConnectionTypeWWAN : LFSiteReachabilityConnectionTypeWiFi; 115 | 116 | BOOL connectionRequestNotRequired = !(inFlags & kSCNetworkReachabilityFlagsConnectionRequired); 117 | 118 | if (siteURL) { 119 | LFSRDebug(@"%s, connectionRequestNotRequired: %d, attempting to request from: %@", __PRETTY_FUNCTION__, connectionRequestNotRequired, siteURL); 120 | 121 | // next stage: send the request 122 | [siteRequest cancelWithoutDelegateMessage]; 123 | [siteRequest setSessionInfo:connectionType]; 124 | if ([siteRequest performMethod:LFHTTPRequestHEADMethod onURL:siteURL withData:nil]) { 125 | return; 126 | } 127 | } 128 | else { 129 | if (lastCheckStatus != connectionType) { 130 | lastCheckStatus = connectionType; 131 | if (connectionRequestNotRequired && [delegate respondsToSelector:@selector(reachability:site:isAvailableOverConnectionType:)]) { 132 | [delegate reachability:self site:siteURL isAvailableOverConnectionType:connectionType]; 133 | return; 134 | } 135 | } 136 | } 137 | } 138 | 139 | // if all fails 140 | if (lastCheckStatus != LFSiteReachabilityNotReachableStatus) { 141 | lastCheckStatus = LFSiteReachabilityNotReachableStatus; 142 | if ([delegate respondsToSelector:@selector(reachability:siteIsNotAvailable:)]) { 143 | [delegate reachability:self siteIsNotAvailable:siteURL]; 144 | } 145 | } 146 | } 147 | 148 | - (BOOL)networkConnectivityExists 149 | { 150 | // 0.0.0.0 151 | struct sockaddr_in zeroAddress; 152 | bzero(&zeroAddress, sizeof(zeroAddress)); 153 | zeroAddress.sin_len = sizeof(zeroAddress); 154 | zeroAddress.sin_family = AF_INET; 155 | 156 | SCNetworkReachabilityRef localReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); 157 | SCNetworkReachabilityFlags flags = 0; 158 | 159 | BOOL capable = NO; 160 | if (SCNetworkReachabilityGetFlags(localReachability, &flags)) { 161 | if (flags & kSCNetworkReachabilityFlagsReachable) { 162 | capable = YES; 163 | } 164 | } 165 | 166 | CFRelease(localReachability); 167 | return capable; 168 | } 169 | 170 | - (void)startChecking 171 | { 172 | [self stopChecking]; 173 | 174 | // 0.0.0.0 175 | struct sockaddr_in zeroAddress; 176 | bzero(&zeroAddress, sizeof(zeroAddress)); 177 | zeroAddress.sin_len = sizeof(zeroAddress); 178 | zeroAddress.sin_family = AF_INET; 179 | 180 | reachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); 181 | SCNetworkReachabilityFlags flags = 0; 182 | 183 | BOOL createTimeoutTimer = YES; 184 | if (SCNetworkReachabilityGetFlags(reachability, &flags)) { 185 | [self handleReachabilityCallbackFlags:flags]; 186 | createTimeoutTimer = NO; 187 | } 188 | 189 | SCNetworkReachabilityContext context = {0, self, NULL, NULL, NULL}; 190 | SCNetworkReachabilitySetCallback(reachability, LFSiteReachabilityCallback, &context); 191 | SCNetworkReachabilityScheduleWithRunLoop(reachability, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 192 | 193 | if (createTimeoutTimer) { 194 | timeoutTimer = [[NSTimer scheduledTimerWithTimeInterval:[siteRequest timeoutInterval] target:self selector:@selector(handleTimeoutTimer:) userInfo:NULL repeats:NO] retain]; 195 | } 196 | } 197 | 198 | - (void)stopChecking 199 | { 200 | [siteRequest cancelWithoutDelegateMessage]; 201 | [self stopTimeoutTimer]; 202 | 203 | if (reachability) { 204 | SCNetworkReachabilityUnscheduleFromRunLoop(reachability, CFRunLoopGetCurrent(), kCFRunLoopCommonModes); 205 | CFRelease(reachability); 206 | reachability = NULL; 207 | } 208 | 209 | lastCheckStatus = nil; 210 | } 211 | 212 | - (BOOL)isChecking 213 | { 214 | return !!reachability; 215 | } 216 | 217 | - (NSTimeInterval)timeoutInterval 218 | { 219 | return [siteRequest timeoutInterval]; 220 | } 221 | 222 | - (void)setTimeoutInterval:(NSTimeInterval)inInterval 223 | { 224 | [siteRequest setTimeoutInterval:inInterval]; 225 | } 226 | 227 | - (void)httpRequest:(LFHTTPRequest *)request didReceiveStatusCode:(NSUInteger)statusCode URL:(NSURL *)url responseHeader:(CFHTTPMessageRef)header 228 | { 229 | LFSRDebug(@"%s, code: %d, URL: %@, header: %@", __PRETTY_FUNCTION__, statusCode, url, (id)header); 230 | } 231 | 232 | - (void)httpRequestDidComplete:(LFHTTPRequest *)request 233 | { 234 | LFSRDebug(@"%s, connection type: %@, received data: %@", __PRETTY_FUNCTION__, [request sessionInfo], [request receivedData]); 235 | 236 | if (lastCheckStatus != [request sessionInfo]) { 237 | lastCheckStatus = [request sessionInfo]; 238 | if ([delegate respondsToSelector:@selector(reachability:site:isAvailableOverConnectionType:)]) { 239 | [delegate reachability:self site:siteURL isAvailableOverConnectionType:[request sessionInfo]]; 240 | } 241 | } 242 | } 243 | 244 | - (void)httpRequest:(LFHTTPRequest *)request didFailWithError:(NSString *)error 245 | { 246 | LFSRDebug(@"%s, error: %@", __PRETTY_FUNCTION__, error); 247 | 248 | if (lastCheckStatus != LFSiteReachabilityNotReachableStatus) { 249 | lastCheckStatus = LFSiteReachabilityNotReachableStatus; 250 | if ([delegate respondsToSelector:@selector(reachability:siteIsNotAvailable:)]) { 251 | [delegate reachability:self siteIsNotAvailable:siteURL]; 252 | } 253 | } 254 | } 255 | 256 | @synthesize delegate; 257 | @synthesize siteURL; 258 | @end 259 | 260 | 261 | void LFSiteReachabilityCallback(SCNetworkReachabilityRef inTarget, SCNetworkReachabilityFlags inFlags, void *inInfo) 262 | { 263 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 264 | LFSRDebug(@"%s, flags: 0x%08x", __PRETTY_FUNCTION__, inFlags); 265 | 266 | [(LFSiteReachability *)inInfo handleReachabilityCallbackFlags:inFlags]; 267 | [pool drain]; 268 | } 269 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/LFWebAPIKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // LFWebAPIKit.h 3 | // 4 | // Copyright (c) 2007-2009 Lithoglyph Inc. (http://lithoglyph.com) 5 | // Copyright (c) 2007-2009 Lukhnos D. Liu (http://lukhnos.org) 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "LFHTTPRequest.h" 30 | #import "NSData+LFHTTPFormExtensions.h" 31 | 32 | // LFSiteReachability is only available when built aginst OS X 10.5+ or iPhone SDK 33 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 34 | #import "LFSiteReachability.h" 35 | #endif 36 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/NSData+LFHTTPFormExtensions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+LFHTTPFormExtensions.h 3 | // 4 | // Copyright (c) 2007-2009 Lithoglyph Inc. (http://lithoglyph.com) 5 | // Copyright (c) 2007-2009 Lukhnos D. Liu (http://lukhnos.org) 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import 30 | 31 | @interface NSData (LFHTTPFormExtensions) 32 | + (id)dataAsWWWURLEncodedFormFromDictionary:(NSDictionary *)formDictionary; 33 | @end 34 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/NSData+LFHTTPFormExtensions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSData+LFHTTPFormExtensions.m 3 | // 4 | // Copyright (c) 2007-2009 Lithoglyph Inc. (http://lithoglyph.com) 5 | // Copyright (c) 2007-2009 Lukhnos D. Liu (http://lukhnos.org) 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | #import "NSData+LFHTTPFormExtensions.h" 30 | 31 | @implementation NSData (LFHTTPFormExtensions) 32 | + (id)dataAsWWWURLEncodedFormFromDictionary:(NSDictionary *)formDictionary 33 | { 34 | NSMutableString *combinedDataString = [NSMutableString string]; 35 | NSEnumerator *enumerator = [formDictionary keyEnumerator]; 36 | id key; 37 | id value; 38 | 39 | if (key = [enumerator nextObject]) { 40 | value = [formDictionary objectForKey:key]; 41 | [combinedDataString appendString:[NSString stringWithFormat:@"%@=%@", [(NSString*)key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 42 | 43 | while ((key = [enumerator nextObject])) { 44 | value = [formDictionary objectForKey:key]; 45 | [combinedDataString appendString:[NSString stringWithFormat:@"&%@=%@", [(NSString*)key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 46 | } 47 | } 48 | 49 | 50 | return [combinedDataString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:NO]; 51 | } 52 | @end 53 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.lithoglyph.LFSiteReachabilityTest.Mac 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | LTGF 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/MainController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MainController.h 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 7/1/09. 6 | // Copyright 2009 Lithoglyph Inc.. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LFWebAPIKit.h" 11 | 12 | @interface MainController : NSWindowController 13 | { 14 | LFSiteReachability *reachability; 15 | 16 | NSButton *startButton; 17 | NSTextField *statusLabel; 18 | } 19 | - (IBAction)startCheckingAction:(id)sender; 20 | 21 | @property (retain, nonatomic) IBOutlet NSButton *startButton; 22 | @property (retain, nonatomic) IBOutlet NSTextField *statusLabel; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/MainController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MainController.m 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 7/1/09. 6 | // Copyright 2009 Lithoglyph Inc.. All rights reserved. 7 | // 8 | 9 | #import "MainController.h" 10 | 11 | 12 | @implementation MainController 13 | - (void)dealloc 14 | { 15 | self.startButton = nil; 16 | self.statusLabel = nil; 17 | [super dealloc]; 18 | } 19 | 20 | - (void)updateNotCheckingStatusLabel 21 | { 22 | [statusLabel setStringValue:[NSString stringWithFormat:@"Not checking, connectivity: %@", ([reachability networkConnectivityExists] ? @"exists" : @"not exists")]]; 23 | } 24 | 25 | - (void)awakeFromNib 26 | { 27 | if (!reachability) { 28 | reachability = [[LFSiteReachability alloc] init]; 29 | reachability.delegate = self; 30 | } 31 | 32 | [startButton setTitle:([reachability isChecking] ? @"Stop Checking" : @"Start Checking")]; 33 | [self updateNotCheckingStatusLabel]; 34 | } 35 | 36 | - (IBAction)startCheckingAction:(id)sender 37 | { 38 | if ([reachability isChecking]) { 39 | [reachability stopChecking]; 40 | [startButton setTitle:@"Start Checking"]; 41 | [self updateNotCheckingStatusLabel]; 42 | } 43 | else { 44 | [statusLabel setStringValue:@"Checking"]; 45 | [reachability startChecking]; 46 | [startButton setTitle:@"Stop Checking"]; 47 | } 48 | } 49 | 50 | - (void)reachability:(LFSiteReachability *)inReachability site:(NSURL *)inURL isAvailableOverConnectionType:(NSString *)inConnectionType 51 | { 52 | [statusLabel setStringValue:[NSString stringWithFormat:@"Reachable, type: %@", ((inConnectionType == LFSiteReachabilityConnectionTypeWiFi) ? @"WiFi" : @"WWAN")]]; 53 | } 54 | 55 | - (void)reachability:(LFSiteReachability *)inReachability siteIsNotAvailable:(NSURL *)inURL 56 | { 57 | [statusLabel setStringValue:@"Not reachable"]; 58 | } 59 | 60 | @synthesize statusLabel; 61 | @synthesize startButton; 62 | @end 63 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/SiteReachability.xcodeproj/TemplateIcon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/SiteReachability.xcodeproj/TemplateIcon.icns -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/SiteReachability_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SiteReachability' target in the 'SiteReachability' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 7/1/09. 6 | // Copyright Lithoglyph Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **) argv); 14 | } 15 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-Mac/version.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildVersion 6 | 3 7 | CFBundleVersion 8 | 1.0 9 | ProductBuildVersion 10 | 9M2729 11 | ProjectName 12 | DevToolsWizardTemplates 13 | SourceVersion 14 | 11600000 15 | 16 | 17 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/Classes/SiteReachabilityAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // SiteReachabilityAppDelegate.h 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 6/30/09. 6 | // Copyright Lithoglyph Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class SiteReachabilityViewController; 12 | 13 | @interface SiteReachabilityAppDelegate : NSObject { 14 | UIWindow *window; 15 | SiteReachabilityViewController *viewController; 16 | } 17 | 18 | @property (nonatomic, retain) IBOutlet UIWindow *window; 19 | @property (nonatomic, retain) IBOutlet SiteReachabilityViewController *viewController; 20 | 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/Classes/SiteReachabilityAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // SiteReachabilityAppDelegate.m 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 6/30/09. 6 | // Copyright Lithoglyph Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import "SiteReachabilityAppDelegate.h" 10 | #import "SiteReachabilityViewController.h" 11 | 12 | @implementation SiteReachabilityAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize viewController; 16 | 17 | 18 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 19 | 20 | // Override point for customization after app launch 21 | [window addSubview:viewController.view]; 22 | [window makeKeyAndVisible]; 23 | } 24 | 25 | 26 | - (void)dealloc { 27 | [viewController release]; 28 | [window release]; 29 | [super dealloc]; 30 | } 31 | 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/Classes/SiteReachabilityViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SiteReachabilityViewController.h 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 6/30/09. 6 | // Copyright Lithoglyph Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LFWebAPIKit.h" 11 | 12 | @interface SiteReachabilityViewController : UIViewController 13 | { 14 | LFSiteReachability *reachability; 15 | 16 | UIButton *startButton; 17 | UILabel *statusLabel; 18 | } 19 | - (IBAction)startCheckingAction:(id)sender; 20 | 21 | @property (retain, nonatomic) IBOutlet UIButton *startButton; 22 | @property (retain, nonatomic) IBOutlet UILabel *statusLabel; 23 | @end 24 | 25 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/Classes/SiteReachabilityViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SiteReachabilityViewController.m 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 6/30/09. 6 | // Copyright Lithoglyph Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import "SiteReachabilityViewController.h" 10 | 11 | @implementation SiteReachabilityViewController 12 | - (void)viewDidLoad 13 | { 14 | [super viewDidLoad]; 15 | 16 | if (!reachability) { 17 | reachability = [[LFSiteReachability alloc] init]; 18 | reachability.delegate = self; 19 | } 20 | } 21 | 22 | 23 | - (void)viewDidUnload 24 | { 25 | self.startButton = nil; 26 | self.statusLabel = nil; 27 | } 28 | 29 | - (void)updateNotCheckingStatusLabel 30 | { 31 | statusLabel.text = [NSString stringWithFormat:@"Not checking, connectivity: %@", ([reachability networkConnectivityExists] ? @"exists" : @"not exists")]; 32 | } 33 | 34 | - (void)viewWillAppear:(BOOL)animated 35 | { 36 | [super viewWillAppear:animated]; 37 | 38 | [startButton setTitle:([reachability isChecking] ? @"Stop Checking" : @"Start Checking") forState:UIControlStateNormal]; 39 | [self updateNotCheckingStatusLabel]; 40 | } 41 | 42 | - (void)dealloc 43 | { 44 | self.startButton = nil; 45 | self.statusLabel = nil; 46 | [super dealloc]; 47 | } 48 | 49 | - (IBAction)startCheckingAction:(id)sender 50 | { 51 | if ([reachability isChecking]) { 52 | [reachability stopChecking]; 53 | [startButton setTitle:@"Start Checking" forState:UIControlStateNormal]; 54 | [self updateNotCheckingStatusLabel]; 55 | } 56 | else { 57 | statusLabel.text = @"Checking"; 58 | [reachability startChecking]; 59 | [startButton setTitle:@"Stop Checking" forState:UIControlStateNormal]; 60 | } 61 | } 62 | 63 | - (void)reachability:(LFSiteReachability *)inReachability site:(NSURL *)inURL isAvailableOverConnectionType:(NSString *)inConnectionType 64 | { 65 | NSLog(@"%s, connection type: ", __PRETTY_FUNCTION__, inConnectionType); 66 | statusLabel.text = [NSString stringWithFormat:@"Reachable, type: %@", ((inConnectionType == LFSiteReachabilityConnectionTypeWiFi) ? @"WiFi" : @"WWAN")]; 67 | } 68 | 69 | - (void)reachability:(LFSiteReachability *)inReachability siteIsNotAvailable:(NSURL *)inURL 70 | { 71 | NSLog(@"%s", __PRETTY_FUNCTION__); 72 | statusLabel.text = @"Not reachable"; 73 | } 74 | 75 | @synthesize statusLabel; 76 | @synthesize startButton; 77 | @end 78 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/MainWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 768 5 | 10A288 6 | 715 7 | 1010 8 | 411.00 9 | 10 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 11 | 46 12 | 13 | 14 | YES 15 | 16 | 17 | 18 | YES 19 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 20 | 21 | 22 | YES 23 | 24 | YES 25 | 26 | 27 | YES 28 | 29 | 30 | 31 | YES 32 | 33 | IBFilesOwner 34 | 35 | 36 | IBFirstResponder 37 | 38 | 39 | 40 | SiteReachabilityViewController 41 | 42 | 43 | 44 | 45 | 292 46 | {320, 480} 47 | 48 | 1 49 | MSAxIDEAA 50 | 51 | NO 52 | NO 53 | 54 | 55 | 56 | 57 | 58 | YES 59 | 60 | 61 | delegate 62 | 63 | 64 | 65 | 4 66 | 67 | 68 | 69 | viewController 70 | 71 | 72 | 73 | 11 74 | 75 | 76 | 77 | window 78 | 79 | 80 | 81 | 14 82 | 83 | 84 | 85 | 86 | YES 87 | 88 | 0 89 | 90 | 91 | 92 | 93 | 94 | -1 95 | 96 | 97 | File's Owner 98 | 99 | 100 | 3 101 | 102 | 103 | SiteReachability App Delegate 104 | 105 | 106 | -2 107 | 108 | 109 | 110 | 111 | 10 112 | 113 | 114 | 115 | 116 | 12 117 | 118 | 119 | 120 | 121 | 122 | 123 | YES 124 | 125 | YES 126 | -1.CustomClassName 127 | -2.CustomClassName 128 | 10.CustomClassName 129 | 10.IBEditorWindowLastContentRect 130 | 10.IBPluginDependency 131 | 12.IBEditorWindowLastContentRect 132 | 12.IBPluginDependency 133 | 3.CustomClassName 134 | 3.IBPluginDependency 135 | 136 | 137 | YES 138 | UIApplication 139 | UIResponder 140 | SiteReachabilityViewController 141 | {{512, 351}, {320, 480}} 142 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 143 | {{525, 346}, {320, 480}} 144 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 145 | SiteReachabilityAppDelegate 146 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin 147 | 148 | 149 | 150 | YES 151 | 152 | 153 | YES 154 | 155 | 156 | 157 | 158 | YES 159 | 160 | 161 | YES 162 | 163 | 164 | 165 | 14 166 | 167 | 168 | 169 | YES 170 | 171 | SiteReachabilityAppDelegate 172 | NSObject 173 | 174 | YES 175 | 176 | YES 177 | viewController 178 | window 179 | 180 | 181 | YES 182 | SiteReachabilityViewController 183 | UIWindow 184 | 185 | 186 | 187 | IBProjectSource 188 | Classes/SiteReachabilityAppDelegate.h 189 | 190 | 191 | 192 | SiteReachabilityAppDelegate 193 | NSObject 194 | 195 | IBUserSource 196 | 197 | 198 | 199 | 200 | SiteReachabilityViewController 201 | UIViewController 202 | 203 | IBProjectSource 204 | Classes/SiteReachabilityViewController.h 205 | 206 | 207 | 208 | 209 | 0 210 | 211 | com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 212 | 213 | 214 | YES 215 | SiteReachability.xcodeproj 216 | 3 217 | 218 | 219 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/SiteReachability-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.lithoglyph.LFSiteReachabilityTest.iPhone 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | LTGF 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/SiteReachability_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'SiteReachability' target in the 'SiteReachability' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SiteReachability-iPhone/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // SiteReachability 4 | // 5 | // Created by Lukhnos D. Liu on 6/30/09. 6 | // Copyright Lithoglyph Inc. 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | #import "GTMHTTPServer.h" 30 | #import "LFHTTPRequest.h" 31 | 32 | @interface AppDelegate : NSObject 33 | { 34 | IBOutlet NSTextField *messageText; 35 | 36 | GTMHTTPServer *HTTPServer; 37 | LFHTTPRequest *HTTPRequest; 38 | NSMutableData *randomData; 39 | } 40 | - (IBAction)testButtonAction:(id)sender; 41 | @end 42 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import "AppDelegate.h" 29 | 30 | @implementation AppDelegate 31 | - (void)dealloc 32 | { 33 | [HTTPServer stop]; 34 | [HTTPServer release]; 35 | [HTTPRequest release]; 36 | [randomData release]; 37 | [super dealloc]; 38 | } 39 | 40 | - (void)awakeFromNib 41 | { 42 | HTTPServer = [[GTMHTTPServer alloc] initWithDelegate:self]; 43 | HTTPRequest = [[LFHTTPRequest alloc] init]; 44 | [HTTPRequest setDelegate:self]; 45 | 46 | NSError *error; 47 | [HTTPServer setPort:25642]; 48 | [HTTPServer start:&error]; 49 | 50 | NSAssert(!error, @"Server must start"); 51 | [messageText setStringValue:@"Server started at port 25642, press button to test"]; 52 | } 53 | - (IBAction)testButtonAction:(id)sender 54 | { 55 | if (randomData) { 56 | [randomData release]; 57 | } 58 | 59 | randomData = [[NSMutableData dataWithLength:1024 * 1024] retain]; 60 | uint8_t *bytes = [randomData mutableBytes]; 61 | size_t i; 62 | for (i = 0 ; i < 1024 * 1024 ; i++) { 63 | bytes[i] = 0x80; 64 | } 65 | 66 | NSInputStream *inputStream = [NSInputStream inputStreamWithData:randomData]; 67 | [HTTPRequest performMethod:LFHTTPRequestPOSTMethod onURL:[NSURL URLWithString:@"http://localhost:25642"] withInputStream:inputStream knownContentSize:[randomData length]]; 68 | } 69 | 70 | - (GTMHTTPResponseMessage *)httpServer:(GTMHTTPServer *)server handleRequest:(GTMHTTPRequestMessage *)request 71 | { 72 | NSLog(@"%s %lu", __PRETTY_FUNCTION__, [[request body] length]); 73 | return [GTMHTTPResponseMessage responseWithHTMLString:@"Hello, world!"]; 74 | } 75 | 76 | - (void)httpRequestDidComplete:(LFHTTPRequest *)request 77 | { 78 | NSLog(@"%s %@", __PRETTY_FUNCTION__, [request receivedData]); 79 | } 80 | 81 | - (void)httpRequest:(LFHTTPRequest *)request didFailWithError:(NSString *)error 82 | { 83 | NSLog(@"%s %@", __PRETTY_FUNCTION__, error); 84 | } 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/English.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/GoogleToolboxForMac-Part/Foundation/GTMDebugSelectorValidation.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMDebugSelectorValidation.h 3 | // 4 | // This file should only be included within an implimation file. In any 5 | // function that takes an object and selector to invoke, you should call: 6 | // 7 | // GTMAssertSelectorNilOrImplementedWithArguments(obj, sel, @encode(arg1type), ..., NULL) 8 | // or 9 | // GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(obj, sel, @encode(returnType), @encode(arg1type), ..., NULL) 10 | // 11 | // This will then validate that the selector is defined and using the right 12 | // type(s), this can help catch errors much earlier then waiting for the 13 | // selector to actually fire (and in the case of error selectors, might never 14 | // really be tested until in the field). 15 | // 16 | // Copyright 2007-2008 Google Inc. 17 | // 18 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 19 | // use this file except in compliance with the License. You may obtain a copy 20 | // of the License at 21 | // 22 | // http://www.apache.org/licenses/LICENSE-2.0 23 | // 24 | // Unless required by applicable law or agreed to in writing, software 25 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 26 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 27 | // License for the specific language governing permissions and limitations under 28 | // the License. 29 | // 30 | 31 | #if DEBUG 32 | 33 | #import 34 | #import "GTMDefines.h" 35 | 36 | static void GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(id obj, SEL sel, const char *retType, ...) { 37 | 38 | // verify that the object's selector is implemented with the proper 39 | // number and type of arguments 40 | va_list argList; 41 | va_start(argList, retType); 42 | 43 | if (obj && sel) { 44 | // check that the selector is implemented 45 | _GTMDevAssert([obj respondsToSelector:sel], 46 | @"\"%@\" selector \"%@\" is unimplemented or misnamed", 47 | NSStringFromClass([obj class]), 48 | NSStringFromSelector(sel)); 49 | 50 | const char *expectedArgType; 51 | NSUInteger argCount = 2; // skip self and _cmd 52 | NSMethodSignature *sig = [obj methodSignatureForSelector:sel]; 53 | 54 | // check that each expected argument is present and of the correct type 55 | while ((expectedArgType = va_arg(argList, const char*)) != 0) { 56 | 57 | if ([sig numberOfArguments] > argCount) { 58 | const char *foundArgType = [sig getArgumentTypeAtIndex:argCount]; 59 | 60 | _GTMDevAssert(0 == strncmp(foundArgType, expectedArgType, strlen(expectedArgType)), 61 | @"\"%@\" selector \"%@\" argument %d should be type %s", 62 | NSStringFromClass([obj class]), 63 | NSStringFromSelector(sel), 64 | (argCount - 2), 65 | expectedArgType); 66 | } 67 | argCount++; 68 | } 69 | 70 | // check that the proper number of arguments are present in the selector 71 | _GTMDevAssert(argCount == [sig numberOfArguments], 72 | @"\"%@\" selector \"%@\" should have %d arguments", 73 | NSStringFromClass([obj class]), 74 | NSStringFromSelector(sel), 75 | (argCount - 2)); 76 | 77 | // if asked, validate the return type 78 | if (retType && (strcmp("gtm_skip_return_test", retType) != 0)) { 79 | const char *foundRetType = [sig methodReturnType]; 80 | _GTMDevAssert(0 == strncmp(foundRetType, retType, strlen(retType)), 81 | @"\"%@\" selector \"%@\" return type should be type %s", 82 | NSStringFromClass([obj class]), 83 | NSStringFromSelector(sel), 84 | retType); 85 | } 86 | } 87 | 88 | va_end(argList); 89 | } 90 | 91 | #define GTMAssertSelectorNilOrImplementedWithArguments(obj, sel, ...) \ 92 | GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments((obj), (sel), "gtm_skip_return_test", __VA_ARGS__) 93 | 94 | #else // DEBUG 95 | 96 | // make it go away if not debug 97 | #define GTMAssertSelectorNilOrImplementedWithReturnTypeAndArguments(obj, sel, retType, ...) do { } while (0) 98 | #define GTMAssertSelectorNilOrImplementedWithArguments(obj, sel, ...) do { } while (0) 99 | 100 | #endif // DEBUG 101 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/GoogleToolboxForMac-Part/Foundation/GTMGarbageCollection.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMGarbageCollection.h 3 | // 4 | // Copyright 2007-2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | #import 20 | 21 | #import "GTMDefines.h" 22 | 23 | // This allows us to easily move our code from GC to non GC. 24 | // They are no-ops unless we are require Leopard or above. 25 | // See 26 | // http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/index.html 27 | // and 28 | // http://developer.apple.com/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcCoreFoundation.html#//apple_ref/doc/uid/TP40006687-SW1 29 | // for details. 30 | 31 | #if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) && !GTM_IPHONE_SDK 32 | // General use would be to call this through GTMCFAutorelease 33 | // but there may be a reason the you want to make something collectable 34 | // but not autoreleased, especially in pure GC code where you don't 35 | // want to bother with the nop autorelease. Done as a define instead of an 36 | // inline so that tools like Clang's scan-build don't report code as leaking. 37 | #define GTMNSMakeCollectable(cf) ((id)NSMakeCollectable(cf)) 38 | 39 | // GTMNSMakeUncollectable is for global maps, etc. that we don't 40 | // want released ever. You should still retain these in non-gc code. 41 | GTM_INLINE void GTMNSMakeUncollectable(id object) { 42 | [[NSGarbageCollector defaultCollector] disableCollectorForPointer:object]; 43 | } 44 | 45 | // Hopefully no code really needs this, but GTMIsGarbageCollectionEnabled is 46 | // a common way to check at runtime if GC is on. 47 | // There are some places where GC doesn't work w/ things w/in Apple's 48 | // frameworks, so this is here so GTM unittests and detect it, and not run 49 | // individual tests to work around bugs in Apple's frameworks. 50 | GTM_INLINE BOOL GTMIsGarbageCollectionEnabled(void) { 51 | return ([NSGarbageCollector defaultCollector] != nil); 52 | } 53 | 54 | #else 55 | 56 | #define GTMNSMakeCollectable(cf) ((id)(cf)) 57 | 58 | GTM_INLINE void GTMNSMakeUncollectable(id object) { 59 | } 60 | 61 | GTM_INLINE BOOL GTMIsGarbageCollectionEnabled(void) { 62 | return NO; 63 | } 64 | 65 | #endif 66 | 67 | // GTMCFAutorelease makes a CF object collectable in GC mode, or adds it 68 | // to the autorelease pool in non-GC mode. Either way it is taken care 69 | // of. Done as a define instead of an inline so that tools like Clang's 70 | // scan-build don't report code as leaking. 71 | #define GTMCFAutorelease(cf) ([GTMNSMakeCollectable(cf) autorelease]) 72 | 73 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/GoogleToolboxForMac-Part/Foundation/GTMHTTPServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMHTTPServer.h 3 | // 4 | // This is a *very* *simple* webserver that can be built into something, it is 5 | // not meant to stand up a site, it sends all requests to its delegate for 6 | // processing on the main thread. It does not support pipelining, etc. It's 7 | // great for places where you need a simple webserver to unittest some code 8 | // that hits a server. 9 | // 10 | // NOTE: there are several TODOs left in here as markers for things that could 11 | // be done if one wanted to add more to this class. 12 | // 13 | // Copyright 2008 Google Inc. 14 | // 15 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 16 | // use this file except in compliance with the License. You may obtain a copy 17 | // of the License at 18 | // 19 | // http://www.apache.org/licenses/LICENSE-2.0 20 | // 21 | // Unless required by applicable law or agreed to in writing, software 22 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 23 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 24 | // License for the specific language governing permissions and limitations under 25 | // the License. 26 | // 27 | // Based a little on HTTPServer, part of the CocoaHTTPServer sample code 28 | // http://developer.apple.com/samplecode/CocoaHTTPServer/index.html 29 | // 30 | 31 | #import 32 | #import "GTMDefines.h" 33 | 34 | #if GTM_IPHONE_SDK 35 | #import 36 | #endif // GTM_IPHONE_SDK 37 | 38 | // Global contants needed for errors from start 39 | 40 | #undef _EXTERN 41 | #undef _INITIALIZE_AS 42 | #ifdef GTMHTTPSERVER_DEFINE_GLOBALS 43 | #define _EXTERN 44 | #define _INITIALIZE_AS(x) =x 45 | #else 46 | #define _EXTERN GTM_EXTERN 47 | #define _INITIALIZE_AS(x) 48 | #endif 49 | 50 | _EXTERN NSString* kGTMHTTPServerErrorDomain _INITIALIZE_AS(@"com.google.mactoolbox.HTTPServerDomain"); 51 | enum { 52 | kGTMHTTPServerSocketCreateFailedError = -100, 53 | kGTMHTTPServerBindFailedError = -101, 54 | kGTMHTTPServerListenFailedError = -102, 55 | kGTMHTTPServerHandleCreateFailedError = -103, 56 | }; 57 | 58 | @class GTMHTTPRequestMessage, GTMHTTPResponseMessage; 59 | 60 | // ---------------------------------------------------------------------------- 61 | 62 | // See comment at top of file for the intened use of this class. 63 | @interface GTMHTTPServer : NSObject { 64 | @private 65 | __weak id delegate_; 66 | uint16_t port_; 67 | BOOL localhostOnly_; 68 | NSFileHandle *listenHandle_; 69 | NSMutableArray *connections_; 70 | } 71 | 72 | // The delegate must support the httpServer:handleRequest: method in 73 | // NSObject(GTMHTTPServerDeletateMethods) below. 74 | - (id)initWithDelegate:(id)delegate; 75 | 76 | - (id)delegate; 77 | 78 | // Passing port zero will let one get assigned. 79 | - (uint16_t)port; 80 | - (void)setPort:(uint16_t)port; 81 | 82 | // Receive connections on the localHost loopback address only or on all 83 | // interfaces for this machine. The default is to only listen on localhost. 84 | - (BOOL)localhostOnly; 85 | - (void)setLocalhostOnly:(BOOL)yesno; 86 | 87 | // Start/Stop the web server. If there is an error starting up the server, |NO| 88 | // is returned, and the specific startup failure can be returned in |error| (see 89 | // above for the error domain and error codes). If the server is started, |YES| 90 | // is returned and the server's delegate is called for any requests that come 91 | // in. 92 | - (BOOL)start:(NSError **)error; 93 | - (void)stop; 94 | 95 | // returns the number of requests currently active in the server (i.e.-being 96 | // read in, sent replies). 97 | - (NSUInteger)activeRequestCount; 98 | 99 | @end 100 | 101 | @interface NSObject (GTMHTTPServerDeletateMethods) 102 | - (GTMHTTPResponseMessage *)httpServer:(GTMHTTPServer *)server 103 | handleRequest:(GTMHTTPRequestMessage *)request; 104 | @end 105 | 106 | // ---------------------------------------------------------------------------- 107 | 108 | // Encapsulates an http request, one of these is sent to the server's delegate 109 | // for each request. 110 | @interface GTMHTTPRequestMessage : NSObject { 111 | @private 112 | CFHTTPMessageRef message_; 113 | } 114 | - (NSString *)version; 115 | - (NSURL *)URL; 116 | - (NSString *)method; 117 | - (NSData *)body; 118 | - (NSDictionary *)allHeaderFieldValues; 119 | @end 120 | 121 | // ---------------------------------------------------------------------------- 122 | 123 | // Encapsulates an http response, the server's delegate should return one for 124 | // each request received. 125 | @interface GTMHTTPResponseMessage : NSObject { 126 | @private 127 | CFHTTPMessageRef message_; 128 | } 129 | + (id)responseWithHTMLString:(NSString *)htmlString; 130 | + (id)responseWithBody:(NSData *)body 131 | contentType:(NSString *)contentType 132 | statusCode:(int)statusCode; 133 | + (id)emptyResponseWithCode:(int)statusCode; 134 | // TODO: class method for redirections? 135 | // TODO: add helper for expire/no-cache 136 | - (void)setValue:(NSString*)value forHeaderField:(NSString*)headerField; 137 | @end 138 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/GoogleToolboxForMac-Part/GTMDefines.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMDefines.h 3 | // 4 | // Copyright 2008 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | // ============================================================================ 20 | 21 | #include 22 | #include 23 | 24 | // Not all MAC_OS_X_VERSION_10_X macros defined in past SDKs 25 | #ifndef MAC_OS_X_VERSION_10_5 26 | #define MAC_OS_X_VERSION_10_5 1050 27 | #endif 28 | #ifndef MAC_OS_X_VERSION_10_6 29 | #define MAC_OS_X_VERSION_10_6 1060 30 | #endif 31 | 32 | // ---------------------------------------------------------------------------- 33 | // CPP symbols that can be overridden in a prefix to control how the toolbox 34 | // is compiled. 35 | // ---------------------------------------------------------------------------- 36 | 37 | 38 | // By setting the GTM_CONTAINERS_VALIDATION_FAILED_LOG and 39 | // GTM_CONTAINERS_VALIDATION_FAILED_ASSERT macros you can control what happens 40 | // when a validation fails. If you implement your own validators, you may want 41 | // to control their internals using the same macros for consistency. 42 | #ifndef GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 43 | #define GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 0 44 | #endif 45 | 46 | // Give ourselves a consistent way to do inlines. Apple's macros even use 47 | // a few different actual definitions, so we're based off of the foundation 48 | // one. 49 | #if !defined(GTM_INLINE) 50 | #if defined (__GNUC__) && (__GNUC__ == 4) 51 | #define GTM_INLINE static __inline__ __attribute__((always_inline)) 52 | #else 53 | #define GTM_INLINE static __inline__ 54 | #endif 55 | #endif 56 | 57 | // Give ourselves a consistent way of doing externs that links up nicely 58 | // when mixing objc and objc++ 59 | #if !defined (GTM_EXTERN) 60 | #if defined __cplusplus 61 | #define GTM_EXTERN extern "C" 62 | #else 63 | #define GTM_EXTERN extern 64 | #endif 65 | #endif 66 | 67 | // Give ourselves a consistent way of exporting things if we have visibility 68 | // set to hidden. 69 | #if !defined (GTM_EXPORT) 70 | #define GTM_EXPORT __attribute__((visibility("default"))) 71 | #endif 72 | 73 | // _GTMDevLog & _GTMDevAssert 74 | // 75 | // _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for 76 | // developer level errors. This implementation simply macros to NSLog/NSAssert. 77 | // It is not intended to be a general logging/reporting system. 78 | // 79 | // Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert 80 | // for a little more background on the usage of these macros. 81 | // 82 | // _GTMDevLog log some error/problem in debug builds 83 | // _GTMDevAssert assert if conditon isn't met w/in a method/function 84 | // in all builds. 85 | // 86 | // To replace this system, just provide different macro definitions in your 87 | // prefix header. Remember, any implementation you provide *must* be thread 88 | // safe since this could be called by anything in what ever situtation it has 89 | // been placed in. 90 | // 91 | 92 | // We only define the simple macros if nothing else has defined this. 93 | #ifndef _GTMDevLog 94 | 95 | #ifdef DEBUG 96 | #define _GTMDevLog(...) NSLog(__VA_ARGS__) 97 | #else 98 | #define _GTMDevLog(...) do { } while (0) 99 | #endif 100 | 101 | #endif // _GTMDevLog 102 | 103 | // Declared here so that it can easily be used for logging tracking if 104 | // necessary. See GTMUnitTestDevLog.h for details. 105 | @class NSString; 106 | GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...); 107 | 108 | #ifndef _GTMDevAssert 109 | // we directly invoke the NSAssert handler so we can pass on the varargs 110 | // (NSAssert doesn't have a macro we can use that takes varargs) 111 | #if !defined(NS_BLOCK_ASSERTIONS) 112 | #define _GTMDevAssert(condition, ...) \ 113 | do { \ 114 | if (!(condition)) { \ 115 | [[NSAssertionHandler currentHandler] \ 116 | handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \ 117 | file:[NSString stringWithUTF8String:__FILE__] \ 118 | lineNumber:__LINE__ \ 119 | description:__VA_ARGS__]; \ 120 | } \ 121 | } while(0) 122 | #else // !defined(NS_BLOCK_ASSERTIONS) 123 | #define _GTMDevAssert(condition, ...) do { } while (0) 124 | #endif // !defined(NS_BLOCK_ASSERTIONS) 125 | 126 | #endif // _GTMDevAssert 127 | 128 | // _GTMCompileAssert 129 | // _GTMCompileAssert is an assert that is meant to fire at compile time if you 130 | // want to check things at compile instead of runtime. For example if you 131 | // want to check that a wchar is 4 bytes instead of 2 you would use 132 | // _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X) 133 | // Note that the second "arg" is not in quotes, and must be a valid processor 134 | // symbol in it's own right (no spaces, punctuation etc). 135 | 136 | // Wrapping this in an #ifndef allows external groups to define their own 137 | // compile time assert scheme. 138 | #ifndef _GTMCompileAssert 139 | // We got this technique from here: 140 | // http://unixjunkie.blogspot.com/2007/10/better-compile-time-asserts_29.html 141 | 142 | #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg 143 | #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg) 144 | #define _GTMCompileAssert(test, msg) \ 145 | typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ] 146 | #endif // _GTMCompileAssert 147 | 148 | // Macro to allow fast enumeration when building for 10.5 or later, and 149 | // reliance on NSEnumerator for 10.4. Remember, NSDictionary w/ FastEnumeration 150 | // does keys, so pick the right thing, nothing is done on the FastEnumeration 151 | // side to be sure you're getting what you wanted. 152 | #ifndef GTM_FOREACH_OBJECT 153 | #if TARGET_OS_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) 154 | #define GTM_FOREACH_OBJECT(element, collection) \ 155 | for (element in collection) 156 | #define GTM_FOREACH_KEY(element, collection) \ 157 | for (element in collection) 158 | #else 159 | #define GTM_FOREACH_OBJECT(element, collection) \ 160 | for (NSEnumerator * _ ## element ## _enum = [collection objectEnumerator]; \ 161 | (element = [_ ## element ## _enum nextObject]) != nil; ) 162 | #define GTM_FOREACH_KEY(element, collection) \ 163 | for (NSEnumerator * _ ## element ## _enum = [collection keyEnumerator]; \ 164 | (element = [_ ## element ## _enum nextObject]) != nil; ) 165 | #endif 166 | #endif 167 | 168 | // ============================================================================ 169 | 170 | // ---------------------------------------------------------------------------- 171 | // CPP symbols defined based on the project settings so the GTM code has 172 | // simple things to test against w/o scattering the knowledge of project 173 | // setting through all the code. 174 | // ---------------------------------------------------------------------------- 175 | 176 | // Provide a single constant CPP symbol that all of GTM uses for ifdefing 177 | // iPhone code. 178 | #if TARGET_OS_IPHONE // iPhone SDK 179 | // For iPhone specific stuff 180 | #define GTM_IPHONE_SDK 1 181 | #if TARGET_IPHONE_SIMULATOR 182 | #define GTM_IPHONE_SIMULATOR 1 183 | #else 184 | #define GTM_IPHONE_DEVICE 1 185 | #endif // TARGET_IPHONE_SIMULATOR 186 | #else 187 | // For MacOS specific stuff 188 | #define GTM_MACOS_SDK 1 189 | #endif 190 | 191 | // Provide a symbol to include/exclude extra code for GC support. (This mainly 192 | // just controls the inclusion of finalize methods). 193 | #ifndef GTM_SUPPORT_GC 194 | #if GTM_IPHONE_SDK 195 | // iPhone never needs GC 196 | #define GTM_SUPPORT_GC 0 197 | #else 198 | // We can't find a symbol to tell if GC is supported/required, so best we 199 | // do on Mac targets is include it if we're on 10.5 or later. 200 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 201 | #define GTM_SUPPORT_GC 0 202 | #else 203 | #define GTM_SUPPORT_GC 1 204 | #endif 205 | #endif 206 | #endif 207 | 208 | // To simplify support for 64bit (and Leopard in general), we provide the type 209 | // defines for non Leopard SDKs 210 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 211 | // NSInteger/NSUInteger and Max/Mins 212 | #ifndef NSINTEGER_DEFINED 213 | #if __LP64__ || NS_BUILD_32_LIKE_64 214 | typedef long NSInteger; 215 | typedef unsigned long NSUInteger; 216 | #else 217 | typedef int NSInteger; 218 | typedef unsigned int NSUInteger; 219 | #endif 220 | #define NSIntegerMax LONG_MAX 221 | #define NSIntegerMin LONG_MIN 222 | #define NSUIntegerMax ULONG_MAX 223 | #define NSINTEGER_DEFINED 1 224 | #endif // NSINTEGER_DEFINED 225 | // CGFloat 226 | #ifndef CGFLOAT_DEFINED 227 | #if defined(__LP64__) && __LP64__ 228 | // This really is an untested path (64bit on Tiger?) 229 | typedef double CGFloat; 230 | #define CGFLOAT_MIN DBL_MIN 231 | #define CGFLOAT_MAX DBL_MAX 232 | #define CGFLOAT_IS_DOUBLE 1 233 | #else /* !defined(__LP64__) || !__LP64__ */ 234 | typedef float CGFloat; 235 | #define CGFLOAT_MIN FLT_MIN 236 | #define CGFLOAT_MAX FLT_MAX 237 | #define CGFLOAT_IS_DOUBLE 0 238 | #endif /* !defined(__LP64__) || !__LP64__ */ 239 | #define CGFLOAT_DEFINED 1 240 | #endif // CGFLOAT_DEFINED 241 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 242 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.lithoglyph.${PRODUCT_NAME:identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleSignature 20 | LTGF 21 | CFBundleVersion 22 | 1.0 23 | NSMainNibFile 24 | MainMenu 25 | NSPrincipalClass 26 | NSApplication 27 | 28 | 29 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/README.txt: -------------------------------------------------------------------------------- 1 | 2 | This test contains parts from Google Toolbox for Mac 3 | (http://code.google.com/p/google-toolbox-for-mac/) 4 | 5 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/StreamedBodySendingTest.xcodeproj/TemplateIcon.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/StreamedBodySendingTest.xcodeproj/TemplateIcon.icns -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/StreamedBodySendingTest_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 3 | // 4 | // Permission is hereby granted, free of charge, to any person 5 | // obtaining a copy of this software and associated documentation 6 | // files (the "Software"), to deal in the Software without 7 | // restriction, including without limitation the rights to use, 8 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the 10 | // Software is furnished to do so, subject to the following 11 | // conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be 14 | // included in all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | // OTHER DEALINGS IN THE SOFTWARE. 24 | // 25 | 26 | #ifdef __OBJC__ 27 | #import 28 | #endif 29 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/StreamedBodySendingTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | return NSApplicationMain(argc, (const char **)argv); 33 | } 34 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SynchronousRequestTest/SynchronousRequestTest-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yourcompany.${PRODUCT_NAME:identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | 20 | 21 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SynchronousRequestTest/SynchronousRequestTest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 42; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6AB623730FE2CB7500AD3BB4 /* LFHTTPRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AB6236F0FE2CB7500AD3BB4 /* LFHTTPRequest.m */; }; 11 | 6AB623740FE2CB7500AD3BB4 /* NSData+LFHTTPFormExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AB623720FE2CB7500AD3BB4 /* NSData+LFHTTPFormExtensions.m */; }; 12 | 6AB623770FE2CB7F00AD3BB4 /* TestSuite.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AB623760FE2CB7F00AD3BB4 /* TestSuite.m */; }; 13 | 6AB6237B0FE2CC1600AD3BB4 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AB6237A0FE2CC1600AD3BB4 /* SystemConfiguration.framework */; }; 14 | /* End PBXBuildFile section */ 15 | 16 | /* Begin PBXFileReference section */ 17 | 6AB623670FE2CB6800AD3BB4 /* SynchronousRequestTest.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SynchronousRequestTest.octest; sourceTree = BUILT_PRODUCTS_DIR; }; 18 | 6AB623690FE2CB6800AD3BB4 /* SynchronousRequestTest-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "SynchronousRequestTest-Info.plist"; sourceTree = ""; }; 19 | 6AB6236E0FE2CB7500AD3BB4 /* LFHTTPRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LFHTTPRequest.h; path = ../../LFHTTPRequest.h; sourceTree = SOURCE_ROOT; }; 20 | 6AB6236F0FE2CB7500AD3BB4 /* LFHTTPRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LFHTTPRequest.m; path = ../../LFHTTPRequest.m; sourceTree = SOURCE_ROOT; }; 21 | 6AB623700FE2CB7500AD3BB4 /* LFWebAPIKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LFWebAPIKit.h; path = ../../LFWebAPIKit.h; sourceTree = SOURCE_ROOT; }; 22 | 6AB623710FE2CB7500AD3BB4 /* NSData+LFHTTPFormExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSData+LFHTTPFormExtensions.h"; path = "../../NSData+LFHTTPFormExtensions.h"; sourceTree = SOURCE_ROOT; }; 23 | 6AB623720FE2CB7500AD3BB4 /* NSData+LFHTTPFormExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSData+LFHTTPFormExtensions.m"; path = "../../NSData+LFHTTPFormExtensions.m"; sourceTree = SOURCE_ROOT; }; 24 | 6AB623750FE2CB7F00AD3BB4 /* TestSuite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestSuite.h; sourceTree = ""; }; 25 | 6AB623760FE2CB7F00AD3BB4 /* TestSuite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestSuite.m; sourceTree = ""; }; 26 | 6AB6237A0FE2CC1600AD3BB4 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 6AB623640FE2CB6800AD3BB4 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | 6AB6237B0FE2CC1600AD3BB4 /* SystemConfiguration.framework in Frameworks */, 35 | ); 36 | runOnlyForDeploymentPostprocessing = 0; 37 | }; 38 | /* End PBXFrameworksBuildPhase section */ 39 | 40 | /* Begin PBXGroup section */ 41 | 6AB623570FE2CB5700AD3BB4 = { 42 | isa = PBXGroup; 43 | children = ( 44 | 6AB6236E0FE2CB7500AD3BB4 /* LFHTTPRequest.h */, 45 | 6AB6236F0FE2CB7500AD3BB4 /* LFHTTPRequest.m */, 46 | 6AB623700FE2CB7500AD3BB4 /* LFWebAPIKit.h */, 47 | 6AB623710FE2CB7500AD3BB4 /* NSData+LFHTTPFormExtensions.h */, 48 | 6AB623720FE2CB7500AD3BB4 /* NSData+LFHTTPFormExtensions.m */, 49 | 6AB623680FE2CB6800AD3BB4 /* Products */, 50 | 6AB623690FE2CB6800AD3BB4 /* SynchronousRequestTest-Info.plist */, 51 | 6AB623750FE2CB7F00AD3BB4 /* TestSuite.h */, 52 | 6AB623760FE2CB7F00AD3BB4 /* TestSuite.m */, 53 | 6AB6237A0FE2CC1600AD3BB4 /* SystemConfiguration.framework */, 54 | ); 55 | sourceTree = ""; 56 | }; 57 | 6AB623680FE2CB6800AD3BB4 /* Products */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 6AB623670FE2CB6800AD3BB4 /* SynchronousRequestTest.octest */, 61 | ); 62 | name = Products; 63 | sourceTree = ""; 64 | }; 65 | /* End PBXGroup section */ 66 | 67 | /* Begin PBXNativeTarget section */ 68 | 6AB623660FE2CB6800AD3BB4 /* SynchronousRequestTest */ = { 69 | isa = PBXNativeTarget; 70 | buildConfigurationList = 6AB6236C0FE2CB6800AD3BB4 /* Build configuration list for PBXNativeTarget "SynchronousRequestTest" */; 71 | buildPhases = ( 72 | 6AB623620FE2CB6800AD3BB4 /* Resources */, 73 | 6AB623630FE2CB6800AD3BB4 /* Sources */, 74 | 6AB623640FE2CB6800AD3BB4 /* Frameworks */, 75 | 6AB623650FE2CB6800AD3BB4 /* ShellScript */, 76 | ); 77 | buildRules = ( 78 | ); 79 | dependencies = ( 80 | ); 81 | name = SynchronousRequestTest; 82 | productName = SynchronousRequestTest; 83 | productReference = 6AB623670FE2CB6800AD3BB4 /* SynchronousRequestTest.octest */; 84 | productType = "com.apple.product-type.bundle"; 85 | }; 86 | /* End PBXNativeTarget section */ 87 | 88 | /* Begin PBXProject section */ 89 | 6AB623590FE2CB5700AD3BB4 /* Project object */ = { 90 | isa = PBXProject; 91 | buildConfigurationList = 6AB6235C0FE2CB5700AD3BB4 /* Build configuration list for PBXProject "SynchronousRequestTest" */; 92 | compatibilityVersion = "Xcode 2.4"; 93 | hasScannedForEncodings = 0; 94 | mainGroup = 6AB623570FE2CB5700AD3BB4; 95 | productRefGroup = 6AB623680FE2CB6800AD3BB4 /* Products */; 96 | projectDirPath = ""; 97 | projectRoot = ""; 98 | targets = ( 99 | 6AB623660FE2CB6800AD3BB4 /* SynchronousRequestTest */, 100 | ); 101 | }; 102 | /* End PBXProject section */ 103 | 104 | /* Begin PBXResourcesBuildPhase section */ 105 | 6AB623620FE2CB6800AD3BB4 /* Resources */ = { 106 | isa = PBXResourcesBuildPhase; 107 | buildActionMask = 2147483647; 108 | files = ( 109 | ); 110 | runOnlyForDeploymentPostprocessing = 0; 111 | }; 112 | /* End PBXResourcesBuildPhase section */ 113 | 114 | /* Begin PBXShellScriptBuildPhase section */ 115 | 6AB623650FE2CB6800AD3BB4 /* ShellScript */ = { 116 | isa = PBXShellScriptBuildPhase; 117 | buildActionMask = 2147483647; 118 | files = ( 119 | ); 120 | inputPaths = ( 121 | ); 122 | outputPaths = ( 123 | ); 124 | runOnlyForDeploymentPostprocessing = 0; 125 | shellPath = /bin/sh; 126 | shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; 127 | }; 128 | /* End PBXShellScriptBuildPhase section */ 129 | 130 | /* Begin PBXSourcesBuildPhase section */ 131 | 6AB623630FE2CB6800AD3BB4 /* Sources */ = { 132 | isa = PBXSourcesBuildPhase; 133 | buildActionMask = 2147483647; 134 | files = ( 135 | 6AB623730FE2CB7500AD3BB4 /* LFHTTPRequest.m in Sources */, 136 | 6AB623740FE2CB7500AD3BB4 /* NSData+LFHTTPFormExtensions.m in Sources */, 137 | 6AB623770FE2CB7F00AD3BB4 /* TestSuite.m in Sources */, 138 | ); 139 | runOnlyForDeploymentPostprocessing = 0; 140 | }; 141 | /* End PBXSourcesBuildPhase section */ 142 | 143 | /* Begin XCBuildConfiguration section */ 144 | 6AB6235A0FE2CB5700AD3BB4 /* Debug */ = { 145 | isa = XCBuildConfiguration; 146 | buildSettings = { 147 | COPY_PHASE_STRIP = NO; 148 | GCC_ENABLE_OBJC_GC = NO; 149 | }; 150 | name = Debug; 151 | }; 152 | 6AB6235B0FE2CB5700AD3BB4 /* Release */ = { 153 | isa = XCBuildConfiguration; 154 | buildSettings = { 155 | COPY_PHASE_STRIP = YES; 156 | GCC_ENABLE_OBJC_GC = NO; 157 | }; 158 | name = Release; 159 | }; 160 | 6AB6236A0FE2CB6800AD3BB4 /* Debug */ = { 161 | isa = XCBuildConfiguration; 162 | buildSettings = { 163 | ALWAYS_SEARCH_USER_PATHS = NO; 164 | COPY_PHASE_STRIP = NO; 165 | FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; 166 | GCC_DYNAMIC_NO_PIC = NO; 167 | GCC_ENABLE_FIX_AND_CONTINUE = NO; 168 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 169 | GCC_OPTIMIZATION_LEVEL = 0; 170 | INFOPLIST_FILE = "SynchronousRequestTest-Info.plist"; 171 | OTHER_LDFLAGS = ( 172 | "-framework", 173 | Foundation, 174 | "-framework", 175 | SenTestingKit, 176 | "-framework", 177 | AppKit, 178 | ); 179 | PREBINDING = NO; 180 | PRODUCT_NAME = SynchronousRequestTest; 181 | WRAPPER_EXTENSION = octest; 182 | }; 183 | name = Debug; 184 | }; 185 | 6AB6236B0FE2CB6800AD3BB4 /* Release */ = { 186 | isa = XCBuildConfiguration; 187 | buildSettings = { 188 | ALWAYS_SEARCH_USER_PATHS = NO; 189 | COPY_PHASE_STRIP = YES; 190 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 191 | FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks"; 192 | GCC_ENABLE_FIX_AND_CONTINUE = NO; 193 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 194 | INFOPLIST_FILE = "SynchronousRequestTest-Info.plist"; 195 | OTHER_LDFLAGS = ( 196 | "-framework", 197 | Foundation, 198 | "-framework", 199 | SenTestingKit, 200 | "-framework", 201 | AppKit, 202 | ); 203 | PREBINDING = NO; 204 | PRODUCT_NAME = SynchronousRequestTest; 205 | WRAPPER_EXTENSION = octest; 206 | ZERO_LINK = NO; 207 | }; 208 | name = Release; 209 | }; 210 | /* End XCBuildConfiguration section */ 211 | 212 | /* Begin XCConfigurationList section */ 213 | 6AB6235C0FE2CB5700AD3BB4 /* Build configuration list for PBXProject "SynchronousRequestTest" */ = { 214 | isa = XCConfigurationList; 215 | buildConfigurations = ( 216 | 6AB6235A0FE2CB5700AD3BB4 /* Debug */, 217 | 6AB6235B0FE2CB5700AD3BB4 /* Release */, 218 | ); 219 | defaultConfigurationIsVisible = 0; 220 | defaultConfigurationName = Release; 221 | }; 222 | 6AB6236C0FE2CB6800AD3BB4 /* Build configuration list for PBXNativeTarget "SynchronousRequestTest" */ = { 223 | isa = XCConfigurationList; 224 | buildConfigurations = ( 225 | 6AB6236A0FE2CB6800AD3BB4 /* Debug */, 226 | 6AB6236B0FE2CB6800AD3BB4 /* Release */, 227 | ); 228 | defaultConfigurationIsVisible = 0; 229 | defaultConfigurationName = Release; 230 | }; 231 | /* End XCConfigurationList section */ 232 | }; 233 | rootObject = 6AB623590FE2CB5700AD3BB4 /* Project object */; 234 | } 235 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SynchronousRequestTest/TestSuite.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestSuite.h 3 | // SynchronousRequestTest 4 | // 5 | // Created by Lukhnos D. Liu on 6/12/09. 6 | // Copyright 2009 Lithoglyph Inc.. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LFWebAPIKit.h" 11 | 12 | @interface TestSuite : SenTestCase 13 | { 14 | LFHTTPRequest *HTTPRequest; 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/LFWebAPIKit/Tests/SynchronousRequestTest/TestSuite.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestSuite.m 3 | // SynchronousRequestTest 4 | // 5 | // Created by Lukhnos D. Liu on 6/12/09. 6 | // Copyright 2009 Lithoglyph Inc.. All rights reserved. 7 | // 8 | 9 | #import "TestSuite.h" 10 | 11 | 12 | @implementation TestSuite 13 | - (void)setUp 14 | { 15 | HTTPRequest = [[LFHTTPRequest alloc] init]; 16 | HTTPRequest.delegate = self; 17 | HTTPRequest.shouldWaitUntilDone = YES; 18 | } 19 | 20 | - (void)tearDown 21 | { 22 | [HTTPRequest release]; 23 | HTTPRequest = nil; 24 | } 25 | 26 | - (void)testFetchData 27 | { 28 | [HTTPRequest performMethod:LFHTTPRequestGETMethod onURL:[NSURL URLWithString:@"http://google.com"] withData:nil]; 29 | NSLog(@"received data: %s", [[HTTPRequest receivedData] bytes]); 30 | } 31 | 32 | - (void)httpRequestDidComplete:(LFHTTPRequest *)request 33 | { 34 | NSLog(@"%s %@", __PRETTY_FUNCTION__, [request receivedData]); 35 | } 36 | 37 | - (void)httpRequest:(LFHTTPRequest *)request didFailWithError:(NSString *)error 38 | { 39 | NSLog(@"%@ %@", __PRETTY_FUNCTION__, error); 40 | } 41 | 42 | @end 43 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/ObjectiveFlickr-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | org.lukhnos.ObjectiveFlickr 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | FMWK 15 | CFBundleSignature 16 | LUKH 17 | CFBundleVersion 18 | 2.0 19 | 20 | 21 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/SampleAPIKey.h.template: -------------------------------------------------------------------------------- 1 | // 2 | // SampleAPIKey.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | 27 | #error Supply your own Flickr API key and shared secret it, or apply from http://flickr.com/services/api/keys/apply 28 | #define OBJECTIVE_FLICKR_SAMPLE_API_KEY @"" 29 | #define OBJECTIVE_FLICKR_SAMPLE_API_SHARED_SECRET @"" 30 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Source/OFUtilities.h: -------------------------------------------------------------------------------- 1 | // 2 | // OFUtilities.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | 30 | NS_INLINE NSString *OFMD5HexStringFromNSString(NSString *inStr) 31 | { 32 | const char *data = [inStr UTF8String]; 33 | size_t length = strlen(data); 34 | 35 | unsigned char *md5buf = (unsigned char*)calloc(1, CC_MD5_DIGEST_LENGTH); 36 | 37 | CC_MD5_CTX md5ctx; 38 | CC_MD5_Init(&md5ctx); 39 | CC_MD5_Update(&md5ctx, data, length); 40 | CC_MD5_Final(md5buf, &md5ctx); 41 | 42 | NSMutableString *md5hex = [NSMutableString string]; 43 | size_t i; 44 | for (i = 0 ; i < CC_MD5_DIGEST_LENGTH ; i++) { 45 | [md5hex appendFormat:@"%02x", md5buf[i]]; 46 | } 47 | free(md5buf); 48 | return md5hex; 49 | } 50 | 51 | NS_INLINE NSString *OFEscapedURLStringFromNSString(NSString *inStr) 52 | { 53 | CFStringRef escaped = CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)inStr, NULL, CFSTR("&"), kCFStringEncodingUTF8); 54 | 55 | #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4 56 | return (NSString *)[escaped autorelease]; 57 | #else 58 | return (NSString *)[NSMakeCollectable(escaped) autorelease]; 59 | #endif 60 | } 61 | 62 | NS_INLINE NSString *OFGenerateUUIDString() 63 | { 64 | CFUUIDRef uuid = CFUUIDCreate(NULL); 65 | CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid); 66 | CFRelease(uuid); 67 | return [NSMakeCollectable(uuidStr) autorelease]; 68 | } 69 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Source/OFXMLMapper.h: -------------------------------------------------------------------------------- 1 | // 2 | // OFXMLMapper.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import 29 | 30 | extern NSString *OFXMLTextContentKey; 31 | 32 | @interface OFXMLMapper : NSObject 33 | { 34 | NSMutableDictionary *resultantDictionary; 35 | 36 | NSMutableArray *elementStack; 37 | NSMutableDictionary *currentDictionary; 38 | NSString *currentElementName; 39 | } 40 | + (NSDictionary *)dictionaryMappedFromXMLData:(NSData *)inData; 41 | @end 42 | 43 | @interface NSDictionary (OFXMLMapperExtension) 44 | - (NSString *)textContent; 45 | 46 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 47 | @property (nonatomic, readonly) NSString *textContent; 48 | #endif 49 | @end 50 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Source/OFXMLMapper.m: -------------------------------------------------------------------------------- 1 | // 2 | // OFXMLMapper.m 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import "OFXMLMapper.h" 29 | 30 | NSString *OFXMLMapperExceptionName = @"OFXMLMapperException"; 31 | NSString *OFXMLTextContentKey = @"_text"; 32 | 33 | @implementation OFXMLMapper 34 | - (void)dealloc 35 | { 36 | [resultantDictionary release]; 37 | [elementStack release]; 38 | [currentElementName release]; 39 | [super dealloc]; 40 | } 41 | 42 | - (id)init 43 | { 44 | if (self = [super init]) { 45 | resultantDictionary = [[NSMutableDictionary alloc] init]; 46 | elementStack = [[NSMutableArray alloc] init]; 47 | } 48 | 49 | return self; 50 | } 51 | 52 | - (void)runWithData:(NSData *)inData 53 | { 54 | currentDictionary = resultantDictionary; 55 | 56 | NSXMLParser *parser = [[NSXMLParser alloc] initWithData:inData]; 57 | [parser setDelegate:self]; 58 | [parser parse]; 59 | [parser release]; 60 | } 61 | 62 | - (NSDictionary *)resultantDictionary 63 | { 64 | return [[resultantDictionary retain] autorelease]; 65 | } 66 | 67 | + (NSDictionary *)dictionaryMappedFromXMLData:(NSData *)inData 68 | { 69 | OFXMLMapper *mapper = [[OFXMLMapper alloc] init]; 70 | [mapper runWithData:inData]; 71 | NSDictionary *result = [mapper resultantDictionary]; 72 | [mapper release]; 73 | return result; 74 | } 75 | 76 | - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict 77 | { 78 | NSMutableDictionary *mutableAttrDict = attributeDict ? [NSMutableDictionary dictionaryWithDictionary:attributeDict] : [NSMutableDictionary dictionary]; 79 | 80 | // see if it's duplicated 81 | id element; 82 | if (element = [currentDictionary objectForKey:elementName]) { 83 | if (![element isKindOfClass:[NSMutableArray class]]) { 84 | if ([element isKindOfClass:[NSMutableDictionary class]]) { 85 | [element retain]; 86 | [currentDictionary removeObjectForKey:elementName]; 87 | 88 | NSMutableArray *newArray = [NSMutableArray arrayWithObject:element]; 89 | [currentDictionary setObject:newArray forKey:elementName]; 90 | [element release]; 91 | 92 | element = newArray; 93 | } 94 | else { 95 | @throw [NSException exceptionWithName:OFXMLMapperExceptionName reason:@"Faulty XML structure" userInfo:nil]; 96 | } 97 | } 98 | 99 | [element addObject:mutableAttrDict]; 100 | } 101 | else { 102 | // plural tag rule: if the parent's tag is plural and the incoming is singular, we'll make it into an array (we only handles the -s case) 103 | 104 | if ([currentElementName length] > [elementName length] && [currentElementName hasPrefix:elementName] && [currentElementName hasSuffix:@"s"]) { 105 | [currentDictionary setObject:[NSMutableArray arrayWithObject:mutableAttrDict] forKey:elementName]; 106 | } 107 | else { 108 | [currentDictionary setObject:mutableAttrDict forKey:elementName]; 109 | } 110 | } 111 | 112 | [elementStack insertObject:currentDictionary atIndex:0]; 113 | currentDictionary = mutableAttrDict; 114 | 115 | NSString *tmp = currentElementName; 116 | currentElementName = [elementName retain]; 117 | [tmp release]; 118 | } 119 | 120 | - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 121 | { 122 | if (![elementStack count]) { 123 | @throw [NSException exceptionWithName:OFXMLMapperExceptionName reason:@"Unbalanced XML element tag closing" userInfo:nil]; 124 | } 125 | 126 | currentDictionary = [elementStack objectAtIndex:0]; 127 | [elementStack removeObjectAtIndex:0]; 128 | } 129 | 130 | - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string 131 | { 132 | NSString *existingContent = [currentDictionary objectForKey:OFXMLTextContentKey]; 133 | if (existingContent) { 134 | NSString *newContent = [existingContent stringByAppendingString:string]; 135 | [currentDictionary setObject:newContent forKey:OFXMLTextContentKey]; 136 | } 137 | else { 138 | [currentDictionary setObject:string forKey:OFXMLTextContentKey]; 139 | } 140 | } 141 | 142 | - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError 143 | { 144 | [resultantDictionary release]; 145 | resultantDictionary = nil; 146 | } 147 | @end 148 | 149 | @implementation NSDictionary (OFXMLMapperExtension) 150 | - (NSString *)textContent 151 | { 152 | return [self objectForKey:OFXMLTextContentKey]; 153 | } 154 | @end 155 | -------------------------------------------------------------------------------- /OpenFlowDemo/ObjectiveFlickr/Source/ObjectiveFlickr.h: -------------------------------------------------------------------------------- 1 | // 2 | // ObjectiveFlickr.h 3 | // 4 | // Copyright (c) 2009 Lukhnos D. Liu (http://lukhnos.org) 5 | // 6 | // Permission is hereby granted, free of charge, to any person 7 | // obtaining a copy of this software and associated documentation 8 | // files (the "Software"), to deal in the Software without 9 | // restriction, including without limitation the rights to use, 10 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the 12 | // Software is furnished to do so, subject to the following 13 | // conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be 16 | // included in all copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | // OTHER DEALINGS IN THE SOFTWARE. 26 | // 27 | 28 | #import "LFWebAPIKit.h" 29 | #import "OFUtilities.h" 30 | #import "OFXMLMapper.h" 31 | 32 | extern NSString *OFFlickrSmallSquareSize; // "s" - 75x75 33 | extern NSString *OFFlickrThumbnailSize; // "t" - 100 on longest side 34 | extern NSString *OFFlickrSmallSize; // "m" - 240 on longest side 35 | extern NSString *OFFlickrMediumSize; // (no size modifier) - 500 on longest side 36 | extern NSString *OFFlickrLargeSize; // "b" - 1024 on longest side 37 | 38 | extern NSString *OFFlickrReadPermission; 39 | extern NSString *OFFlickrWritePermission; 40 | extern NSString *OFFlickrDeletePermission; 41 | 42 | @interface OFFlickrAPIContext : NSObject 43 | { 44 | NSString *key; 45 | NSString *sharedSecret; 46 | NSString *authToken; 47 | 48 | NSString *RESTAPIEndpoint; 49 | NSString *photoSource; 50 | NSString *photoWebPageSource; 51 | NSString *authEndpoint; 52 | NSString *uploadEndpoint; 53 | } 54 | - (id)initWithAPIKey:(NSString *)inKey sharedSecret:(NSString *)inSharedSecret; 55 | 56 | - (void)setAuthToken:(NSString *)inAuthToken; 57 | - (NSString *)authToken; 58 | 59 | // URL provisioning 60 | - (NSURL *)photoSourceURLFromDictionary:(NSDictionary *)inDictionary size:(NSString *)inSizeModifier; 61 | - (NSURL *)photoWebPageURLFromDictionary:(NSDictionary *)inDictionary; 62 | - (NSURL *)loginURLFromFrobDictionary:(NSDictionary *)inFrob requestedPermission:(NSString *)inPermission; 63 | 64 | // API endpoints 65 | - (void)setRESTAPIEndpoint:(NSString *)inEndpoint; 66 | - (NSString *)RESTAPIEndpoint; 67 | 68 | - (void)setPhotoSource:(NSString *)inSource; 69 | - (NSString *)photoSource; 70 | 71 | - (void)setAuthEndpoint:(NSString *)inEndpoint; 72 | - (NSString *)authEndpoint; 73 | 74 | - (void)setUploadEndpoint:(NSString *)inEndpoint; 75 | - (NSString *)uploadEndpoint; 76 | 77 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 78 | @property (nonatomic, readonly) NSString *key; 79 | @property (nonatomic, readonly) NSString *sharedSecret; 80 | @property (nonatomic, retain) NSString *authToken; 81 | 82 | @property (nonatomic, retain) NSString *RESTAPIEndpoint; 83 | @property (nonatomic, retain) NSString *photoSource; 84 | @property (nonatomic, retain) NSString *photoWebPageSource; 85 | @property (nonatomic, retain) NSString *authEndpoint; 86 | @property (nonatomic, retain) NSString *uploadEndpoint; 87 | #endif 88 | @end 89 | 90 | extern NSString *OFFlickrAPIReturnedErrorDomain; 91 | extern NSString *OFFlickrAPIRequestErrorDomain; 92 | 93 | enum { 94 | // refer to Flickr API document for Flickr's own error codes 95 | OFFlickrAPIRequestConnectionError = 0x7fff0001, 96 | OFFlickrAPIRequestTimeoutError = 0x7fff0002, 97 | OFFlickrAPIRequestFaultyXMLResponseError = 0x7fff0003, 98 | OFFlickrAPIRequestUnknownError = 0x7fff0042 99 | }; 100 | 101 | @class OFFlickrAPIRequest; 102 | 103 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 104 | @protocol OFFlickrAPIRequestDelegate 105 | @optional 106 | #else 107 | @interface NSObject (OFFlickrAPIRequestDelegateCategory) 108 | #endif 109 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary; 110 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)inError; 111 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4 112 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest imageUploadSentBytes:(NSUInteger)inSentBytes totalBytes:(NSUInteger)inTotalBytes; 113 | #else 114 | - (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest imageUploadSentBytes:(unsigned int)inSentBytes totalBytes:(unsigned int)inTotalBytes; 115 | #endif 116 | @end 117 | 118 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 119 | typedef id OFFlickrAPIRequestDelegateType; 120 | #else 121 | typedef id OFFlickrAPIRequestDelegateType; 122 | #endif 123 | 124 | @interface OFFlickrAPIRequest : NSObject 125 | { 126 | OFFlickrAPIContext *context; 127 | LFHTTPRequest *HTTPRequest; 128 | 129 | OFFlickrAPIRequestDelegateType delegate; 130 | id sessionInfo; 131 | 132 | NSString *uploadTempFilename; 133 | } 134 | - (id)initWithAPIContext:(OFFlickrAPIContext *)inContext; 135 | - (OFFlickrAPIContext *)context; 136 | 137 | - (OFFlickrAPIRequestDelegateType)delegate; 138 | - (void)setDelegate:(OFFlickrAPIRequestDelegateType)inDelegate; 139 | 140 | - (id)sessionInfo; 141 | - (void)setSessionInfo:(id)inInfo; 142 | 143 | - (NSTimeInterval)requestTimeoutInterval; 144 | - (void)setRequestTimeoutInterval:(NSTimeInterval)inTimeInterval; 145 | - (BOOL)isRunning; 146 | - (void)cancel; 147 | 148 | // elementary methods 149 | - (BOOL)callAPIMethodWithGET:(NSString *)inMethodName arguments:(NSDictionary *)inArguments; 150 | - (BOOL)callAPIMethodWithPOST:(NSString *)inMethodName arguments:(NSDictionary *)inArguments; 151 | 152 | // image upload—we use NSInputStream here because we want to have flexibity; with this you can upload either a file or NSData from NSImage 153 | - (BOOL)uploadImageStream:(NSInputStream *)inImageStream suggestedFilename:(NSString *)inFilename MIMEType:(NSString *)inType arguments:(NSDictionary *)inArguments; 154 | 155 | #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4 156 | @property (nonatomic, readonly) OFFlickrAPIContext *context; 157 | @property (nonatomic, assign) OFFlickrAPIRequestDelegateType delegate; 158 | @property (nonatomic, retain) id sessionInfo; 159 | @property (nonatomic, assign) NSTimeInterval requestTimeoutInterval; 160 | #endif 161 | @end 162 | -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/0.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/1.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/10.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/11.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/12.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/13.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/14.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/15.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/16.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/17.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/18.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/19.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/2.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/20.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/21.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/21.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/22.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/22.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/23.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/23.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/24.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/24.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/25.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/25.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/26.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/26.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/27.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/27.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/28.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/28.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/29.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/29.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/3.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/4.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/5.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/6.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/7.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/8.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/Sample Images/9.jpg -------------------------------------------------------------------------------- /OpenFlowDemo/Sample Images/Read me.txt: -------------------------------------------------------------------------------- 1 | All pictures in this folder have been released by NASA to the public domain. -------------------------------------------------------------------------------- /OpenFlowDemo/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thefaj/OpenFlow/314049c671c13c6c84731efe8732ea9d32aa58d5/OpenFlowDemo/default.png -------------------------------------------------------------------------------- /OpenFlowDemo/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2009 Alex Fajkowski, Apparent Logic LLC 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, 8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the 10 | * Software is furnished to do so, subject to the following 11 | * conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 | * OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | #import 26 | 27 | int main(int argc, char *argv[]) { 28 | 29 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 30 | int retVal = UIApplicationMain(argc, argv, nil, nil); 31 | [pool release]; 32 | return retVal; 33 | } 34 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Follow the project's status at http://apparentlogic.com/openflow and on Twitter at @openflow 2 | 3 | 4 | When I released my first iPhone app, Presenter, two months ago, Apple accused me of using their private iPhone CoverFlow API. After appealing to Apple & writing a blog post about my roadblock, Apple reversed their decision. 5 | 6 | The initial release is simple, but it is also efficient and very fast, even on first generation iPhones. 7 | 8 | The API should be easy to include in your own program. The main class, AFOpenFlowView, is a subclass of UIView. 9 | To use this in your own project: 10 | -Add the OpenFlow source code to your project. 11 | -Add the QuartzCore and CoreGraphics frameworks. 12 | -Import “AFOpenFlowView.h” & interact with it as you would a normal UIView. 13 | -You should implement both the AFOpenFlowViewDelegate and AFOpenFlowViewDataSource protocols. 14 | 15 | Currently, the delegate protocol is used to let your code know when the user selected a new object. The datasource protocol is called when AFOpenFlowView needs a UIImage object. This method should be *fast*. Don’t do NSURL requests or even disk access in this method. See the AFOpenFlowDemo app I provided for an example how to load images from a remote server. The datasource also needs to provide a default UIImage. 16 | 17 | At any point, you can set UIImage’s on your AFOpenFlowView. You don’t need to wait for the datasource protocol to ask you. Your AFOpenFlowView will start displaying images as soon as you call setNumberOfImages. 18 | 19 | This is an initial release of OpenFlow. I licensed it under the liberal MIT open source license. 20 | Please drop me a line to let me know what you think & where you want the project to go from here. 21 | 22 | The source code for both OpenFlow and the AFOpenFlowDemo project are currently available on Github at http://github.com/thefaj/OpenFlow. For the demo application, you will need to register for a Flickr API key and secret. If you try to compile the demo, you will quickly find the error message where your Key & Secret should be added. 23 | 24 | Enjoy! 25 | -Alex --------------------------------------------------------------------------------