Skip to content

Commit 15bbce2

Browse files
authored
Merge branch 'main' into as-func
2 parents 44411cf + 7ab3a97 commit 15bbce2

File tree

5 files changed

+0
-169
lines changed

5 files changed

+0
-169
lines changed

src/viam/sdk/robot/client.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ namespace sdk {
3535

3636
using google::protobuf::RepeatedPtrField;
3737
using viam::common::v1::Transform;
38-
using viam::robot::v1::Discovery;
39-
using viam::robot::v1::DiscoveryQuery;
4038
using viam::robot::v1::FrameSystemConfig;
4139
using viam::robot::v1::Operation;
4240
using viam::robot::v1::RobotService;
@@ -48,28 +46,6 @@ using viam::robot::v1::RobotService;
4846
// NOLINTNEXTLINE
4947
const std::string kStreamRemoved("Stream removed");
5048

51-
// TODO: add a traits class for proto to type and back conversion
52-
DiscoveryQuery to_proto(const RobotClient::discovery_query& query) {
53-
DiscoveryQuery proto;
54-
*proto.mutable_subtype() = query.subtype;
55-
*proto.mutable_model() = query.model;
56-
return proto;
57-
}
58-
59-
RobotClient::discovery_query from_proto(const DiscoveryQuery& proto) {
60-
RobotClient::discovery_query query;
61-
query.subtype = proto.subtype();
62-
query.model = proto.model();
63-
return query;
64-
}
65-
66-
RobotClient::discovery from_proto(const Discovery& proto) {
67-
RobotClient::discovery discovery;
68-
discovery.query = from_proto(proto.query());
69-
discovery.results = from_proto(proto.results());
70-
return discovery;
71-
}
72-
7349
RobotClient::frame_system_config from_proto(const FrameSystemConfig& proto) {
7450
RobotClient::frame_system_config fsconfig;
7551
fsconfig.frame = from_proto(proto.frame());
@@ -95,15 +71,6 @@ RobotClient::operation from_proto(const Operation& proto) {
9571
return op;
9672
}
9773

98-
bool operator==(const RobotClient::discovery_query& lhs, const RobotClient::discovery_query& rhs) {
99-
return lhs.subtype == rhs.subtype && lhs.model == rhs.model;
100-
}
101-
102-
bool operator==(const RobotClient::discovery& lhs, const RobotClient::discovery& rhs) {
103-
return lhs.query == rhs.query &&
104-
to_proto(lhs.results).SerializeAsString() == to_proto(rhs.results).SerializeAsString();
105-
}
106-
10774
bool operator==(const RobotClient::frame_system_config& lhs,
10875
const RobotClient::frame_system_config& rhs) {
10976
return lhs.frame == rhs.frame && to_proto(lhs.kinematics).SerializeAsString() ==
@@ -354,32 +321,6 @@ pose_in_frame RobotClient::transform_pose(
354321
return from_proto(resp.pose());
355322
}
356323

357-
std::vector<RobotClient::discovery> RobotClient::discover_components(
358-
const std::vector<discovery_query>& queries) {
359-
viam::robot::v1::DiscoverComponentsRequest req;
360-
viam::robot::v1::DiscoverComponentsResponse resp;
361-
ClientContext ctx;
362-
363-
RepeatedPtrField<DiscoveryQuery>* req_queries = req.mutable_queries();
364-
365-
for (const discovery_query& query : queries) {
366-
*req_queries->Add() = to_proto(query);
367-
}
368-
369-
const grpc::Status response = impl_->stub_->DiscoverComponents(ctx, req, &resp);
370-
if (is_error_response(response)) {
371-
BOOST_LOG_TRIVIAL(error) << "Error discovering components: " << response.error_message();
372-
}
373-
374-
std::vector<discovery> components = std::vector<discovery>();
375-
376-
for (const Discovery& d : resp.discovery()) {
377-
components.push_back(from_proto(d));
378-
}
379-
380-
return components;
381-
}
382-
383324
std::shared_ptr<Resource> RobotClient::resource_by_name(const Name& name) {
384325
return resource_manager_.resource(name.name());
385326
}

src/viam/sdk/robot/client.hpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ namespace sdk {
3434
/// `with_channel` require a user call to `close()`.
3535
class RobotClient {
3636
public:
37-
struct discovery_query {
38-
std::string subtype;
39-
std::string model;
40-
friend bool operator==(const discovery_query& lhs, const discovery_query& rhs);
41-
};
42-
43-
struct discovery {
44-
discovery_query query;
45-
ProtoStruct results;
46-
friend bool operator==(const discovery& lhs, const discovery& rhs);
47-
};
48-
4937
struct frame_system_config {
5038
WorldState::transform frame;
5139
ProtoStruct kinematics;
@@ -120,8 +108,6 @@ class RobotClient {
120108
/// @return The list of operations currently running on the calling robot.
121109
std::vector<operation> get_operations();
122110

123-
std::vector<discovery> discover_components(const std::vector<discovery_query>& queries);
124-
125111
/// @brief Transform a given `Pose` to a new specified destination which is a reference frame.
126112
/// @param query The pose that should be transformed.
127113
/// @param destination The name of the reference frame to transform the given pose to.

src/viam/sdk/tests/mocks/mock_robot.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ using namespace viam::sdk;
1818
using common::v1::Pose;
1919
using common::v1::PoseInFrame;
2020
using common::v1::ResourceName;
21-
using viam::robot::v1::Discovery;
22-
using viam::robot::v1::DiscoveryQuery;
2321
using viam::robot::v1::FrameSystemConfig;
2422
using viam::robot::v1::Operation;
2523

@@ -93,41 +91,6 @@ std::vector<Operation> mock_proto_operations_response() {
9391
return resp;
9492
}
9593

96-
std::vector<RobotClient::discovery> mock_discovery_response() {
97-
RobotClient::discovery_query query;
98-
query.subtype = "camera";
99-
query.model = "webcam";
100-
ProtoValue s("bar");
101-
ProtoValue map(fake_map());
102-
103-
ProtoList inner{{map}};
104-
ProtoList l{{s, ProtoValue{false}, ProtoValue{3.0}, ProtoValue{4.2}, map, std::move(inner)}};
105-
106-
ProtoStruct results{{"foo", l}};
107-
108-
RobotClient::discovery discovery;
109-
discovery.query = std::move(query);
110-
discovery.results = std::move(results);
111-
return std::vector<RobotClient::discovery>{std::move(discovery)};
112-
}
113-
114-
std::vector<Discovery> mock_proto_discovery_response() {
115-
std::vector<viam::robot::v1::Discovery> v;
116-
for (const auto& d : mock_discovery_response()) {
117-
DiscoveryQuery query;
118-
*query.mutable_subtype() = d.query.subtype;
119-
*query.mutable_model() = d.query.model;
120-
121-
viam::robot::v1::Discovery discovery;
122-
*discovery.mutable_query() = query;
123-
*discovery.mutable_results() = to_proto(d.results);
124-
125-
v.push_back(std::move(discovery));
126-
}
127-
128-
return v;
129-
}
130-
13194
pose_in_frame mock_transform_response() {
13295
return {"arm", default_pose()};
13396
}
@@ -347,22 +310,6 @@ ::grpc::Status MockRobotService::FrameSystemConfig(
347310
return ::grpc::Status();
348311
}
349312

350-
::grpc::Status MockRobotService::DiscoverComponents(
351-
::grpc::ServerContext* context,
352-
const ::viam::robot::v1::DiscoverComponentsRequest*,
353-
::viam::robot::v1::DiscoverComponentsResponse* response) {
354-
auto client_md = context->client_metadata();
355-
if (auto client_info = client_md.find("viam_client"); client_info == client_md.end()) {
356-
return ::grpc::Status(::grpc::StatusCode::FAILED_PRECONDITION,
357-
"viam_client info not properly set in metadata");
358-
}
359-
auto* discovery = response->mutable_discovery();
360-
for (auto& d : mock_proto_discovery_response()) {
361-
*discovery->Add() = d;
362-
}
363-
return ::grpc::Status();
364-
}
365-
366313
::grpc::Status MockRobotService::TransformPose(::grpc::ServerContext* context,
367314
const ::viam::robot::v1::TransformPoseRequest*,
368315
::viam::robot::v1::TransformPoseResponse* response) {

src/viam/sdk/tests/mocks/mock_robot.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ class MockRobotService : public ResourceServer, public viam::robot::v1::RobotSer
4646
const ::viam::robot::v1::TransformPoseRequest* request,
4747
::viam::robot::v1::TransformPoseResponse* response) override;
4848

49-
::grpc::Status DiscoverComponents(
50-
::grpc::ServerContext* context,
51-
const ::viam::robot::v1::DiscoverComponentsRequest* request,
52-
::viam::robot::v1::DiscoverComponentsResponse* response) override;
53-
5449
::grpc::Status GetOperations(::grpc::ServerContext* context,
5550
const ::viam::robot::v1::GetOperationsRequest* request,
5651
::viam::robot::v1::GetOperationsResponse* response) override;
@@ -63,8 +58,6 @@ class MockRobotService : public ResourceServer, public viam::robot::v1::RobotSer
6358
pose default_pose(int offset = 0);
6459
std::vector<RobotClient::operation> mock_operations_response();
6560
std::vector<viam::robot::v1::Operation> mock_proto_operations_response();
66-
std::vector<RobotClient::discovery> mock_discovery_response();
67-
std::vector<viam::robot::v1::Discovery> mock_proto_discovery_response();
6861
std::vector<Name> mock_resource_names_response();
6962
std::vector<common::v1::ResourceName> mock_proto_resource_names_response();
7063
std::vector<RobotClient::frame_system_config> mock_config_response();

src/viam/sdk/tests/test_robot.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <viam/sdk/tests/mocks/mock_robot.hpp>
2020
#include <viam/sdk/tests/test_utils.hpp>
2121

22-
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::discovery_query)
23-
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::discovery)
2422
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::frame_system_config)
2523
BOOST_TEST_DONT_PRINT_LOG_VALUE(viam::sdk::RobotClient::operation)
2624

@@ -181,40 +179,6 @@ BOOST_AUTO_TEST_CASE(test_get_operations) {
181179
});
182180
}
183181

184-
// This test ensures that the functions in the `mock_robot` files have the same fields for both
185-
// the proto and custom type versions.
186-
BOOST_AUTO_TEST_CASE(test_discovery) {
187-
robot_client_to_mocks_pipeline(
188-
[](std::shared_ptr<RobotClient> client, MockRobotService& service) -> void {
189-
auto components = mock_discovery_response();
190-
auto component = components[0];
191-
auto results = component.results.begin();
192-
auto protos = mock_proto_discovery_response();
193-
auto proto = protos[0];
194-
auto proto_results = proto.results().fields().begin();
195-
196-
BOOST_CHECK_EQUAL(component.query.subtype, proto.query().subtype());
197-
BOOST_CHECK_EQUAL(component.query.model, proto.query().model());
198-
BOOST_CHECK_EQUAL(results->first, proto_results->first);
199-
// the `Value` type in our mock responses is a `list` type so we can comprehensively
200-
// test `ProtoValue` conversions. Unfortunately the protobuf `ListValue` type doesn't
201-
// seem to have `==` defined, so we convert to a `DebugString` here to verify
202-
// comparison and to provide helpful printing of differences in case of an error.
203-
BOOST_CHECK_EQUAL(to_proto(results->second).DebugString(),
204-
proto_results->second.DebugString());
205-
});
206-
}
207-
208-
BOOST_AUTO_TEST_CASE(test_discover_components) {
209-
robot_client_to_mocks_pipeline(
210-
[](std::shared_ptr<RobotClient> client, MockRobotService& service) -> void {
211-
auto components = client->discover_components({});
212-
auto mock_components = mock_discovery_response();
213-
214-
BOOST_TEST(components == mock_components, boost::test_tools::per_element());
215-
});
216-
}
217-
218182
BOOST_AUTO_TEST_CASE(test_transform_pose) {
219183
robot_client_to_mocks_pipeline(
220184
[](std::shared_ptr<RobotClient> client, MockRobotService& service) -> void {

0 commit comments

Comments
 (0)