Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
c0b85e5a
Commit
c0b85e5a
authored
5 years ago
by
Muxi Yan
Browse files
Options
Downloads
Patches
Plain Diff
clang-format
parent
264d71be
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/objective-c/route_guide/ViewControllers.m
+78
-65
78 additions, 65 deletions
examples/objective-c/route_guide/ViewControllers.m
with
78 additions
and
65 deletions
examples/objective-c/route_guide/ViewControllers.m
+
78
−
65
View file @
c0b85e5a
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
#import <GRPCClient/GRPCTransport.h>
#import <GRPCClient/GRPCTransport.h>
static
NSString
*
const
kHostAddress
=
@"localhost:50051"
;
static
NSString
*
const
kHostAddress
=
@"localhost:50051"
;
/** Category to override RTGPoint's description. */
/** Category to override RTGPoint's description. */
@interface
RTGPoint
(
Description
)
@interface
RTGPoint
(
Description
)
...
@@ -36,9 +36,9 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -36,9 +36,9 @@ static NSString * const kHostAddress = @"localhost:50051";
-
(
NSString
*
)
description
{
-
(
NSString
*
)
description
{
NSString
*
verticalDirection
=
self
.
latitude
>=
0
?
@"N"
:
@"S"
;
NSString
*
verticalDirection
=
self
.
latitude
>=
0
?
@"N"
:
@"S"
;
NSString
*
horizontalDirection
=
self
.
longitude
>=
0
?
@"E"
:
@"W"
;
NSString
*
horizontalDirection
=
self
.
longitude
>=
0
?
@"E"
:
@"W"
;
return
[
NSString
stringWithFormat
:
@"%.02f%@ %.02f%@"
,
return
abs
(
self
.
latitude
)
/
1E7
f
,
verticalDirection
,
[
NSString
stringWithFormat
:
@"%.02f%@ %.02f%@"
,
abs
(
self
.
latitude
)
/
1E7
f
,
verticalDirection
,
abs
(
self
.
longitude
)
/
1E7
f
,
horizontalDirection
];
abs
(
self
.
longitude
)
/
1E7
f
,
horizontalDirection
];
}
}
@end
@end
...
@@ -55,13 +55,12 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -55,13 +55,12 @@ static NSString * const kHostAddress = @"localhost:50051";
longitude
:(
float
)
longitude
{
longitude
:(
float
)
longitude
{
RTGRouteNote
*
note
=
[
self
message
];
RTGRouteNote
*
note
=
[
self
message
];
note
.
message
=
message
;
note
.
message
=
message
;
note
.
location
.
latitude
=
(
int32_t
)
latitude
*
1E7
;
note
.
location
.
latitude
=
(
int32_t
)
latitude
*
1E7
;
note
.
location
.
longitude
=
(
int32_t
)
longitude
*
1E7
;
note
.
location
.
longitude
=
(
int32_t
)
longitude
*
1E7
;
return
note
;
return
note
;
}
}
@end
@end
#pragma mark Demo: Get Feature
#pragma mark Demo: Get Feature
/**
/**
...
@@ -70,7 +69,7 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -70,7 +69,7 @@ static NSString * const kHostAddress = @"localhost:50051";
*/
*/
@interface
GetFeatureViewController
:
UIViewController
@interface
GetFeatureViewController
:
UIViewController
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@end
@end
...
@@ -82,15 +81,19 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -82,15 +81,19 @@ static NSString * const kHostAddress = @"localhost:50051";
void
(
^
handler
)(
RTGFeature
*
response
,
NSError
*
error
)
=
^
(
RTGFeature
*
response
,
NSError
*
error
)
{
void
(
^
handler
)(
RTGFeature
*
response
,
NSError
*
error
)
=
^
(
RTGFeature
*
response
,
NSError
*
error
)
{
// TODO(makdharma): Remove boilerplate by consolidating into one log function.
// TODO(makdharma): Remove boilerplate by consolidating into one log function.
if
(
response
.
name
.
length
)
{
if
(
response
.
name
.
length
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Found feature called %@ at %@."
,
self
.
outputLabel
.
text
,
response
.
location
,
response
.
name
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Found feature called %@ at %@."
,
self
.
outputLabel
.
text
,
response
.
location
,
response
.
name
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"Found feature called %@ at %@."
,
response
.
name
,
response
.
location
);
NSLog
(
@"Found feature called %@ at %@."
,
response
.
name
,
response
.
location
);
}
else
if
(
response
)
{
}
else
if
(
response
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Found no features at %@"
,
self
.
outputLabel
.
text
,
response
.
location
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Found no features at %@"
,
self
.
outputLabel
.
text
,
response
.
location
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"Found no features at %@"
,
response
.
location
);
NSLog
(
@"Found no features at %@"
,
response
.
location
);
}
else
{
}
else
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"RPC error: %@"
,
error
);
NSLog
(
@"RPC error: %@"
,
error
);
}
}
...
@@ -100,15 +103,18 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -100,15 +103,18 @@ static NSString * const kHostAddress = @"localhost:50051";
point
.
latitude
=
409146138
;
point
.
latitude
=
409146138
;
point
.
longitude
=
-
746188906
;
point
.
longitude
=
-
746188906
;
GRPCUnaryProtoCall
*
call
=
[
_service
getFeatureWithMessage
:
point
GRPCUnaryProtoCall
*
call
=
[
_service
responseHandler:
[[
GRPCUnaryResponseHandler
alloc
]
initWithResponseHandler
:
handler
responseDispatchQueue
:
nil
]
getFeatureWithMessage:
point
callOptions:
nil
];
responseHandler:
[[
GRPCUnaryResponseHandler
alloc
]
initWithResponseHandler
:
handler
responseDispatchQueue:
nil
]
callOptions:
nil
];
[
call
start
];
[
call
start
];
call
=
[
_service
getFeatureWithMessage
:[
RTGPoint
message
]
call
=
[
_service
responseHandler:
[[
GRPCUnaryResponseHandler
alloc
]
initWithResponseHandler
:
handler
responseDispatchQueue
:
nil
]
getFeatureWithMessage:
[
RTGPoint
message
]
callOptions:
nil
];
responseHandler:
[[
GRPCUnaryResponseHandler
alloc
]
initWithResponseHandler
:
handler
responseDispatchQueue:
nil
]
callOptions:
nil
];
[
call
start
];
[
call
start
];
}
}
-
(
void
)
viewDidLoad
{
-
(
void
)
viewDidLoad
{
...
@@ -129,16 +135,15 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -129,16 +135,15 @@ static NSString * const kHostAddress = @"localhost:50051";
@end
@end
#pragma mark Demo: List Features
#pragma mark Demo: List Features
/**
/**
* Run the listFeatures demo. Calls listFeatures with a rectangle containing all of the features in
* Run the listFeatures demo. Calls listFeatures with a rectangle containing all of the features in
* the pre-generated database. Prints each response as it comes in.
* the pre-generated database. Prints each response as it comes in.
*/
*/
@interface
ListFeaturesViewController
:
UIViewController
<
GRPCProtoResponseHandler
>
@interface
ListFeaturesViewController
:
UIViewController
<
GRPCProtoResponseHandler
>
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@end
@end
...
@@ -167,7 +172,9 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -167,7 +172,9 @@ static NSString * const kHostAddress = @"localhost:50051";
-
(
void
)
didReceiveProtoMessage
:(
GPBMessage
*
)
message
{
-
(
void
)
didReceiveProtoMessage
:(
GPBMessage
*
)
message
{
RTGFeature
*
response
=
(
RTGFeature
*
)
message
;
RTGFeature
*
response
=
(
RTGFeature
*
)
message
;
if
(
response
)
{
if
(
response
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Found feature at %@ called %@."
,
self
.
outputLabel
.
text
,
response
.
location
,
response
.
name
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Found feature at %@ called %@."
,
self
.
outputLabel
.
text
,
response
.
location
,
response
.
name
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"Found feature at %@ called %@."
,
response
.
location
,
response
.
name
);
NSLog
(
@"Found feature at %@ called %@."
,
response
.
location
,
response
.
name
);
}
}
...
@@ -175,7 +182,7 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -175,7 +182,7 @@ static NSString * const kHostAddress = @"localhost:50051";
-
(
void
)
didCloseWithTrailingMetadata
:(
NSDictionary
*
)
trailingMetadata
error
:(
NSError
*
)
error
{
-
(
void
)
didCloseWithTrailingMetadata
:(
NSDictionary
*
)
trailingMetadata
error
:(
NSError
*
)
error
{
if
(
error
)
{
if
(
error
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"RPC error: %@"
,
error
);
NSLog
(
@"RPC error: %@"
,
error
);
}
}
...
@@ -208,7 +215,7 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -208,7 +215,7 @@ static NSString * const kHostAddress = @"localhost:50051";
*/
*/
@interface
RecordRouteViewController
:
UIViewController
@interface
RecordRouteViewController
:
UIViewController
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@end
@end
...
@@ -217,11 +224,12 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -217,11 +224,12 @@ static NSString * const kHostAddress = @"localhost:50051";
}
}
-
(
void
)
execRequest
{
-
(
void
)
execRequest
{
NSString
*
dataBasePath
=
[
NSBundle
.
mainBundle
pathForResource
:
@"route_guide_db"
NSString
*
dataBasePath
=
[
NSBundle
.
mainBundle
pathForResource
:
@"route_guide_db"
ofType
:
@"json"
];
ofType:
@"json"
];
NSData
*
dataBaseContent
=
[
NSData
dataWithContentsOfFile
:
dataBasePath
];
NSData
*
dataBaseContent
=
[
NSData
dataWithContentsOfFile
:
dataBasePath
];
NSError
*
error
;
NSError
*
error
;
NSArray
*
features
=
[
NSJSONSerialization
JSONObjectWithData
:
dataBaseContent
options
:
0
error
:&
error
];
NSArray
*
features
=
[
NSJSONSerialization
JSONObjectWithData
:
dataBaseContent
options:
0
error:
&
error
];
if
(
error
)
{
if
(
error
)
{
NSLog
(
@"Error reading database."
);
NSLog
(
@"Error reading database."
);
...
@@ -230,34 +238,39 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -230,34 +238,39 @@ static NSString * const kHostAddress = @"localhost:50051";
return
;
return
;
}
}
void
(
^
handler
)(
RTGRouteSummary
*
response
,
NSError
*
error
)
=
^
(
RTGRouteSummary
*
response
,
NSError
*
error
)
{
void
(
^
handler
)(
RTGRouteSummary
*
response
,
NSError
*
error
)
=
if
(
response
)
{
^
(
RTGRouteSummary
*
response
,
NSError
*
error
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
if
(
response
)
{
@"%@
\n
Finished trip with %i points
\n
Passed %i features
\n
"
NSString
*
str
=
[
NSString
"Travelled %i meters
\n
It took %i seconds"
,
stringWithFormat:
@"%@
\n
Finished trip with %i points
\n
Passed %i features
\n
"
self
.
outputLabel
.
text
,
response
.
pointCount
,
response
.
featureCount
,
"Travelled %i meters
\n
It took %i seconds"
,
response
.
distance
,
response
.
elapsedTime
];
self
.
outputLabel
.
text
,
response
.
pointCount
,
response
.
featureCount
,
self
.
outputLabel
.
text
=
str
;
response
.
distance
,
response
.
elapsedTime
];
NSLog
(
@"Finished trip with %i points"
,
response
.
pointCount
);
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"Passed %i features"
,
response
.
featureCount
);
NSLog
(
@"Finished trip with %i points"
,
response
.
pointCount
);
NSLog
(
@"Travelled %i meters"
,
response
.
distance
);
NSLog
(
@"Passed %i features"
,
response
.
featureCount
);
NSLog
(
@"It took %i seconds"
,
response
.
elapsedTime
);
NSLog
(
@"Travelled %i meters"
,
response
.
distance
);
}
else
{
NSLog
(
@"It took %i seconds"
,
response
.
elapsedTime
);
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
}
else
{
self
.
outputLabel
.
text
=
str
;
NSString
*
str
=
NSLog
(
@"RPC error: %@"
,
error
);
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
}
self
.
outputLabel
.
text
=
str
;
};
NSLog
(
@"RPC error: %@"
,
error
);
}
GRPCStreamingProtoCall
*
call
=
[
_service
recordRouteWithResponseHandler
:[[
GRPCUnaryResponseHandler
alloc
]
initWithResponseHandler
:
handler
};
responseDispatchQueue:
nil
]
callOptions:
nil
];
GRPCStreamingProtoCall
*
call
=
[
_service
recordRouteWithResponseHandler
:[[
GRPCUnaryResponseHandler
alloc
]
initWithResponseHandler:
handler
responseDispatchQueue:
nil
]
callOptions:
nil
];
[
call
start
];
[
call
start
];
for
(
id
feature
in
features
)
{
for
(
id
feature
in
features
)
{
RTGPoint
*
location
=
[
RTGPoint
message
];
RTGPoint
*
location
=
[
RTGPoint
message
];
location
.
longitude
=
[((
NSNumber
*
)
feature
[
@"location"
][
@"longitude"
])
intValue
];
location
.
longitude
=
[((
NSNumber
*
)
feature
[
@"location"
][
@"longitude"
])
intValue
];
location
.
latitude
=
[((
NSNumber
*
)
feature
[
@"location"
][
@"latitude"
])
intValue
];
location
.
latitude
=
[((
NSNumber
*
)
feature
[
@"location"
][
@"latitude"
])
intValue
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Visiting point %@"
,
self
.
outputLabel
.
text
,
location
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Visiting point %@"
,
self
.
outputLabel
.
text
,
location
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"Visiting point %@"
,
location
);
NSLog
(
@"Visiting point %@"
,
location
);
[
call
writeMessage
:
location
];
[
call
writeMessage
:
location
];
...
@@ -283,16 +296,15 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -283,16 +296,15 @@ static NSString * const kHostAddress = @"localhost:50051";
@end
@end
#pragma mark Demo: Route Chat
#pragma mark Demo: Route Chat
/**
/**
* Run the routeChat demo. Send some chat messages, and print any chat messages that are sent from
* Run the routeChat demo. Send some chat messages, and print any chat messages that are sent from
* the server.
* the server.
*/
*/
@interface
RouteChatViewController
:
UIViewController
<
GRPCProtoResponseHandler
>
@interface
RouteChatViewController
:
UIViewController
<
GRPCProtoResponseHandler
>
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@property
(
weak
,
nonatomic
)
IBOutlet
UILabel
*
outputLabel
;
@end
@end
...
@@ -305,13 +317,14 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -305,13 +317,14 @@ static NSString * const kHostAddress = @"localhost:50051";
}
}
-
(
void
)
execRequest
{
-
(
void
)
execRequest
{
NSArray
*
notes
=
@[[
RTGRouteNote
noteWithMessage
:
@"First message"
latitude
:
0
longitude
:
0
],
NSArray
*
notes
=
@[
[
RTGRouteNote
noteWithMessage
:
@"Second message"
latitude
:
0
longitude
:
1
],
[
RTGRouteNote
noteWithMessage
:
@"First message"
latitude
:
0
longitude
:
0
],
[
RTGRouteNote
noteWithMessage
:
@"Third message"
latitude
:
1
longitude
:
0
],
[
RTGRouteNote
noteWithMessage
:
@"Second message"
latitude
:
0
longitude
:
1
],
[
RTGRouteNote
noteWithMessage
:
@"Fourth message"
latitude
:
0
longitude
:
0
]];
[
RTGRouteNote
noteWithMessage
:
@"Third message"
latitude
:
1
longitude
:
0
],
[
RTGRouteNote
noteWithMessage
:
@"Fourth message"
latitude
:
0
longitude
:
0
]
GRPCStreamingProtoCall
*
call
=
[
_service
routeChatWithResponseHandler
:
self
];
callOptions:
nil
];
GRPCStreamingProtoCall
*
call
=
[
_service
routeChatWithResponseHandler
:
self
callOptions
:
nil
];
[
call
start
];
[
call
start
];
for
(
RTGRouteNote
*
note
in
notes
)
{
for
(
RTGRouteNote
*
note
in
notes
)
{
[
call
writeMessage
:
note
];
[
call
writeMessage
:
note
];
...
@@ -322,8 +335,8 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -322,8 +335,8 @@ static NSString * const kHostAddress = @"localhost:50051";
-
(
void
)
didReceiveProtoMessage
:(
GPBMessage
*
)
message
{
-
(
void
)
didReceiveProtoMessage
:(
GPBMessage
*
)
message
{
RTGRouteNote
*
note
=
(
RTGRouteNote
*
)
message
;
RTGRouteNote
*
note
=
(
RTGRouteNote
*
)
message
;
if
(
note
)
{
if
(
note
)
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Got message %@ at %@"
,
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
Got message %@ at %@"
,
self
.
outputLabel
.
text
,
self
.
outputLabel
.
text
,
note
.
message
,
note
.
location
];
note
.
message
,
note
.
location
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"Got message %@ at %@"
,
note
.
message
,
note
.
location
);
NSLog
(
@"Got message %@ at %@"
,
note
.
message
,
note
.
location
);
}
}
...
@@ -333,7 +346,7 @@ static NSString * const kHostAddress = @"localhost:50051";
...
@@ -333,7 +346,7 @@ static NSString * const kHostAddress = @"localhost:50051";
if
(
!
error
)
{
if
(
!
error
)
{
NSLog
(
@"Chat ended."
);
NSLog
(
@"Chat ended."
);
}
else
{
}
else
{
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
NSString
*
str
=
[
NSString
stringWithFormat
:
@"%@
\n
RPC error: %@"
,
self
.
outputLabel
.
text
,
error
];
self
.
outputLabel
.
text
=
str
;
self
.
outputLabel
.
text
=
str
;
NSLog
(
@"RPC error: %@"
,
error
);
NSLog
(
@"RPC error: %@"
,
error
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment