Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright 2015, Google Inc. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #import <UIKit/UIKit.h> |
| 35 | #import <RouteGuide/RouteGuide.pbrpc.h> |
| 36 | |
| 37 | static NSString * const kHostAddress = @"http://localhost:50051"; |
| 38 | |
Jorge Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame^] | 39 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 40 | #pragma mark Get Feature |
| 41 | |
Jorge Canizales | 3aed717 | 2015-06-04 22:56:21 -0700 | [diff] [blame] | 42 | // Run the getFeature demo. Calls getFeature with a point known to have a feature and a point known |
| 43 | // not to have a feature. |
| 44 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 45 | @interface GetFeatureViewController : UIViewController |
| 46 | @end |
| 47 | |
| 48 | @implementation GetFeatureViewController |
| 49 | |
| 50 | - (void)viewDidLoad { |
| 51 | [super viewDidLoad]; |
| 52 | |
| 53 | RTGRouteGuide *client = [[RTGRouteGuide alloc] initWithHost:kHostAddress]; |
| 54 | |
Jorge Canizales | 3aed717 | 2015-06-04 22:56:21 -0700 | [diff] [blame] | 55 | void (^handler)(RTGFeature *response, NSError *error) = ^(RTGFeature *response, NSError *error) { |
| 56 | if (response.name.length) { |
| 57 | NSLog(@"Found feature called %@ at %@.", response.name, response.location); |
| 58 | } else if (response) { |
| 59 | NSLog(@"Found no features at %@", response.location); |
| 60 | } else { |
| 61 | NSLog(@"RPC error: %@", error); |
| 62 | } |
| 63 | }; |
| 64 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 65 | RTGPoint *point = [RTGPoint message]; |
| 66 | point.latitude = 409146138; |
| 67 | point.longitude = -746188906; |
| 68 | |
Jorge Canizales | 3aed717 | 2015-06-04 22:56:21 -0700 | [diff] [blame] | 69 | [client getFeatureWithRequest:point handler:handler]; |
| 70 | [client getFeatureWithRequest:[RTGPoint message] handler:handler]; |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | @end |
| 74 | |
Jorge Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame^] | 75 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 76 | #pragma mark List Features |
| 77 | |
Jorge Canizales | 4694cdb | 2015-06-04 23:06:13 -0700 | [diff] [blame] | 78 | // Run the listFeatures demo. Calls listFeatures with a rectangle containing all of the features in |
| 79 | // the pre-generated database. Prints each response as it comes in. |
| 80 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 81 | @interface ListFeaturesViewController : UIViewController |
| 82 | @end |
| 83 | |
| 84 | @implementation ListFeaturesViewController |
| 85 | |
| 86 | - (void)viewDidLoad { |
| 87 | [super viewDidLoad]; |
Jorge Canizales | 4694cdb | 2015-06-04 23:06:13 -0700 | [diff] [blame] | 88 | |
| 89 | RTGRouteGuide *client = [[RTGRouteGuide alloc] initWithHost:kHostAddress]; |
| 90 | |
| 91 | RTGRectangle *rectangle = [RTGRectangle message]; |
| 92 | rectangle.lo.latitude = 40E7; |
| 93 | rectangle.lo.longitude = -75E7; |
| 94 | rectangle.hi.latitude = 42E7; |
| 95 | rectangle.hi.longitude = -73E7; |
| 96 | |
| 97 | NSLog(@"Looking for features between 40, -75 and 42, -73"); |
| 98 | [client listFeaturesWithRequest:rectangle handler:^(BOOL done, RTGFeature *response, NSError *error) { |
| 99 | if (response) { |
| 100 | NSLog(@"Found feature called %@ at %@.", response.name, response.location); |
| 101 | } else if (error) { |
| 102 | NSLog(@"RPC error: %@", error); |
| 103 | } |
| 104 | }]; |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | @end |
| 108 | |
Jorge Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame^] | 109 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 110 | #pragma mark Record Route |
| 111 | |
| 112 | @interface RecordRouteViewController : UIViewController |
| 113 | @end |
| 114 | |
| 115 | @implementation RecordRouteViewController |
| 116 | |
| 117 | - (void)viewDidLoad { |
| 118 | [super viewDidLoad]; |
| 119 | // Do any additional setup after loading the view. |
| 120 | } |
| 121 | |
| 122 | @end |
| 123 | |
Jorge Canizales | 3fda548 | 2015-06-05 12:05:00 -0700 | [diff] [blame^] | 124 | |
Jorge Canizales | 34b2629 | 2015-06-02 02:11:09 -0700 | [diff] [blame] | 125 | #pragma mark Route Chat |
| 126 | |
| 127 | @interface RouteChatViewController : UIViewController |
| 128 | @end |
| 129 | |
| 130 | @implementation RouteChatViewController |
| 131 | |
| 132 | - (void)viewDidLoad { |
| 133 | [super viewDidLoad]; |
| 134 | // Do any additional setup after loading the view. |
| 135 | } |
| 136 | |
| 137 | @end |