Skip to content

Commit 83444b3

Browse files
committed
properties struct instead of returning raw maptype in case we add more fields
1 parent 226d860 commit 83444b3

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/viam/sdk/services/navigation.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class Navigation : public Service {
3333
double compass_heading;
3434
};
3535

36+
struct Properties {
37+
MapType map_type;
38+
};
39+
3640
struct Waypoint {
3741
std::string id;
3842
geo_point location;
@@ -55,7 +59,7 @@ class Navigation : public Service {
5559
const ProtoStruct& extra) = 0;
5660
virtual std::unique_ptr<std::vector<geo_geometry>> get_obstacles(const ProtoStruct& extra) = 0;
5761
virtual std::unique_ptr<std::vector<Path>> get_paths(const ProtoStruct& extra) = 0;
58-
virtual MapType get_properties() = 0;
62+
virtual Properties get_properties() = 0;
5963
virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
6064

6165
// overloads without `extra` param.

src/viam/sdk/services/private/navigation_client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ std::unique_ptr<std::vector<NavigationClient::Path>> NavigationClient::get_paths
111111
});
112112
}
113113

114-
NavigationClient::MapType NavigationClient::get_properties() {
114+
NavigationClient::Properties NavigationClient::get_properties() {
115115
return make_client_helper(this, *stub_, &StubType::GetProperties)
116116
.with([&](auto& request) {})
117-
.invoke([](auto& response) { return MapType(response.map_type()); });
117+
.invoke([](auto& response) { return Properties{MapType(response.map_type())}; });
118118
}
119119

120120
ProtoStruct NavigationClient::do_command(const ProtoStruct& command) {

src/viam/sdk/services/private/navigation_client.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NavigationClient : public Navigation {
2929
void remove_waypoint(const std::string id, const ProtoStruct& extra) override;
3030
std::unique_ptr<std::vector<geo_geometry>> get_obstacles(const ProtoStruct& extra) override;
3131
std::unique_ptr<std::vector<Path>> get_paths(const ProtoStruct& extra) override;
32-
MapType get_properties() override;
32+
Properties get_properties() override;
3333
ProtoStruct do_command(const ProtoStruct& command) override;
3434

3535
private:

src/viam/sdk/services/private/navigation_server.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ ::grpc::Status NavigationServer::GetPaths(::grpc::ServerContext*,
109109
::grpc::Status NavigationServer::GetProperties(::grpc::ServerContext*,
110110
const GetPropertiesRequest* request,
111111
GetPropertiesResponse* response) noexcept {
112-
return make_service_helper<Navigation>("NavigationServer::GetProperties", this, request)(
113-
[&](auto&, auto& nav) { response->set_map_type(MapType(nav->get_properties())); });
112+
return make_service_helper<Navigation>(
113+
"NavigationServer::GetProperties", this, request)([&](auto&, auto& nav) {
114+
Navigation::Properties props = nav->get_properties();
115+
response->set_map_type(MapType(props.map_type));
116+
});
114117
}
115118

116119
::grpc::Status NavigationServer::DoCommand(

0 commit comments

Comments
 (0)