Skip to content

Commit 90246f0

Browse files
authored
RSDK-8892: Remove ProtoType (#301)
1 parent 78bba79 commit 90246f0

File tree

153 files changed

+888
-1432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+888
-1432
lines changed

src/viam/examples/mlmodel/example_audio_classification_client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <boost/format.hpp>
2828
#include <boost/optional.hpp>
2929
#include <boost/program_options.hpp>
30+
#include <boost/variant/get.hpp>
3031

3132
#include <viam/sdk/robot/client.hpp>
3233
#include <viam/sdk/services/mlmodel.hpp>

src/viam/examples/modules/complex/base/impl.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@ using namespace viam::sdk;
1616

1717
std::string find_motor(ResourceConfig cfg, std::string motor_name) {
1818
auto base_name = cfg.name();
19-
auto motor = cfg.attributes()->find(motor_name);
20-
if (motor == cfg.attributes()->end()) {
19+
auto motor = cfg.attributes().find(motor_name);
20+
if (motor == cfg.attributes().end()) {
2121
std::ostringstream buffer;
2222
buffer << base_name << ": Required parameter `" << motor_name
2323
<< "` not found in configuration";
2424
throw std::invalid_argument(buffer.str());
2525
}
26-
const auto* const motor_string = motor->second->get<std::string>();
27-
if (!motor_string || motor_string->empty()) {
28-
std::ostringstream buffer;
29-
buffer << base_name << ": Required non-empty string parameter `" << motor_name
30-
<< "` is either not a string "
31-
"or is an empty string";
32-
throw std::invalid_argument(buffer.str());
26+
const ProtoValue& motor_val = motor->second;
27+
if (motor_val.is_a<std::string>() && !motor_val.get_unchecked<std::string>().empty()) {
28+
return motor_val.get_unchecked<std::string>();
3329
}
34-
return *motor_string;
30+
31+
std::ostringstream buffer;
32+
buffer << base_name << ": Required non-empty string parameter `" << motor_name
33+
<< "` is either not a string "
34+
"or is an empty string";
35+
throw std::invalid_argument(buffer.str());
3536
}
3637

3738
void MyBase::reconfigure(const Dependencies& deps, const ResourceConfig& cfg) {
@@ -64,7 +65,7 @@ bool MyBase::is_moving() {
6465
return left_->is_moving() || right_->is_moving();
6566
}
6667

67-
void MyBase::stop(const AttributeMap& extra) {
68+
void MyBase::stop(const ProtoStruct& extra) {
6869
std::string err_message;
6970
bool throw_err = false;
7071

@@ -89,7 +90,7 @@ void MyBase::stop(const AttributeMap& extra) {
8990
}
9091
}
9192

92-
void MyBase::set_power(const Vector3& linear, const Vector3& angular, const AttributeMap& extra) {
93+
void MyBase::set_power(const Vector3& linear, const Vector3& angular, const ProtoStruct& extra) {
9394
// Stop the base if absolute value of linear and angular velocity is less
9495
// than 0.01.
9596
if (abs(linear.y()) < 0.01 && abs(angular.z()) < 0.01) {
@@ -104,20 +105,20 @@ void MyBase::set_power(const Vector3& linear, const Vector3& angular, const Attr
104105
right_->set_power(((linear.y() + angular.z()) / sum), extra);
105106
}
106107

107-
AttributeMap MyBase::do_command(const AttributeMap& command) {
108+
ProtoStruct MyBase::do_command(const ProtoStruct& command) {
108109
std::cout << "Received DoCommand request for MyBase " << Resource::name() << std::endl;
109110
return command;
110111
}
111112

112-
std::vector<GeometryConfig> MyBase::get_geometries(const AttributeMap& extra) {
113+
std::vector<GeometryConfig> MyBase::get_geometries(const ProtoStruct& extra) {
113114
auto left_geometries = left_->get_geometries(extra);
114115
auto right_geometries = right_->get_geometries(extra);
115116
std::vector<GeometryConfig> geometries(left_geometries);
116117
geometries.insert(geometries.end(), right_geometries.begin(), right_geometries.end());
117118
return geometries;
118119
}
119120

120-
Base::properties MyBase::get_properties(const AttributeMap& extra) {
121+
Base::properties MyBase::get_properties(const ProtoStruct& extra) {
121122
// Return fake properties.
122123
return {2, 4, 8};
123124
}

src/viam/examples/modules/complex/base/impl.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@ class MyBase : public Base, public Reconfigurable {
2121
static std::vector<std::string> validate(ResourceConfig cfg);
2222

2323
bool is_moving() override;
24-
void stop(const AttributeMap& extra) override;
24+
void stop(const ProtoStruct& extra) override;
2525
void set_power(const Vector3& linear,
2626
const Vector3& angular,
27-
const AttributeMap& extra) override;
27+
const ProtoStruct& extra) override;
2828

29-
AttributeMap do_command(const AttributeMap& command) override;
30-
std::vector<GeometryConfig> get_geometries(const AttributeMap& extra) override;
31-
Base::properties get_properties(const AttributeMap& extra) override;
29+
ProtoStruct do_command(const ProtoStruct& command) override;
30+
std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) override;
31+
Base::properties get_properties(const ProtoStruct& extra) override;
3232

33-
void move_straight(int64_t distance_mm, double mm_per_sec, const AttributeMap& extra) override {
33+
void move_straight(int64_t distance_mm, double mm_per_sec, const ProtoStruct& extra) override {
3434
throw std::runtime_error("move_straight unimplemented");
3535
}
36-
void spin(double angle_deg, double degs_per_sec, const AttributeMap& extra) override {
36+
void spin(double angle_deg, double degs_per_sec, const ProtoStruct& extra) override {
3737
throw std::runtime_error("spin unimplemented");
3838
}
3939
void set_velocity(const Vector3& linear,
4040
const Vector3& angular,
41-
const AttributeMap& extra) override {
41+
const ProtoStruct& extra) override {
4242
throw std::runtime_error("set_velocity unimplemented");
4343
}
4444

src/viam/examples/modules/complex/gizmo/impl.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ using namespace viam::sdk;
1515

1616
std::string find_arg1(ResourceConfig cfg) {
1717
auto gizmo_name = cfg.name();
18-
auto arg1 = cfg.attributes()->find("arg1");
19-
if (arg1 == cfg.attributes()->end()) {
18+
auto arg1 = cfg.attributes().find("arg1");
19+
if (arg1 == cfg.attributes().end()) {
2020
std::ostringstream buffer;
2121
buffer << gizmo_name << ": Required parameter `arg1` not found in configuration";
2222
throw std::invalid_argument(buffer.str());
2323
}
24-
const auto* const arg1_string = arg1->second->get<std::string>();
25-
if (!arg1_string || arg1_string->empty()) {
26-
std::ostringstream buffer;
27-
buffer << gizmo_name << ": Required non-empty string parameter `arg1`"
28-
<< "` is either not a string or is an empty string";
29-
throw std::invalid_argument(buffer.str());
24+
25+
const ProtoValue& arg1_val = arg1->second;
26+
if (arg1_val.is_a<std::string>() && !arg1_val.get_unchecked<std::string>().empty()) {
27+
return arg1_val.get_unchecked<std::string>();
3028
}
31-
return *arg1_string;
29+
std::ostringstream buffer;
30+
buffer << gizmo_name << ": Required non-empty string parameter `arg1`"
31+
<< "` is either not a string or is an empty string";
32+
throw std::invalid_argument(buffer.str());
3233
}
3334

3435
void MyGizmo::reconfigure(const Dependencies& deps, const ResourceConfig& cfg) {

src/viam/examples/modules/complex/gizmo/impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <vector>
44

5-
#include <viam/sdk/common/proto_type.hpp>
5+
#include <viam/sdk/common/proto_value.hpp>
66
#include <viam/sdk/resource/reconfigurable.hpp>
77

88
#include "api.hpp"

src/viam/examples/modules/complex/summation/impl.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ using namespace viam::sdk;
1313
// Returns value of "subtract" in cfg.attributes() or `false` if subtract is not
1414
// in attributes or is not a boolean value.
1515
bool find_subtract(ResourceConfig cfg) {
16-
auto subtract = cfg.attributes()->find("subtract");
17-
if (subtract == cfg.attributes()->end()) {
16+
auto subtract = cfg.attributes().find("subtract");
17+
if (subtract == cfg.attributes().end()) {
1818
return false;
1919
}
20-
const bool* const subtract_bool = subtract->second->get<bool>();
21-
if (!subtract_bool) {
22-
return false;
23-
}
24-
return *subtract_bool;
20+
21+
return subtract->second.is_a<bool>() && subtract->second.get_unchecked<bool>();
2522
}
2623

2724
void MySummation::reconfigure(const Dependencies& deps, const ResourceConfig& cfg) {

src/viam/examples/modules/complex/test_complex_module.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <viam/api/common/v1/common.pb.h>
1111

12-
#include <viam/sdk/common/proto_type.hpp>
12+
#include <viam/sdk/common/proto_value.hpp>
1313
#include <viam/sdk/tests/test_utils.hpp>
1414

1515
#include "gizmo.grpc.pb.h"

src/viam/examples/modules/simple/client.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <memory>
22
#include <string>
33

4-
#include <viam/sdk/common/proto_type.hpp>
4+
#include <viam/sdk/common/proto_value.hpp>
55
#include <viam/sdk/robot/client.hpp>
66
#include <viam/sdk/rpc/dial.hpp>
77
#include <viam/sdk/services/generic.hpp>
@@ -39,22 +39,10 @@ int main() {
3939
return EXIT_FAILURE;
4040
}
4141

42-
auto proto_ptr = std::make_shared<ProtoType>(std::string("world"));
43-
AttributeMap command =
44-
std::make_shared<std::unordered_map<std::string, std::shared_ptr<ProtoType>>>();
45-
command->insert({{std::string("hello"), proto_ptr}});
42+
ProtoStruct command{{"hello", "world"}};
43+
ProtoStruct resp = printer->do_command(command);
4644

47-
auto resp = printer->do_command(command);
48-
49-
if (!resp) {
50-
std::cerr << "Failed to get a response from 'printer1'\n";
51-
return EXIT_FAILURE;
52-
}
53-
54-
std::shared_ptr<ProtoType> expected = command->at(std::string("hello"));
55-
std::shared_ptr<ProtoType> result = resp->at(std::string("hello"));
56-
57-
if (!(*expected == *result)) {
45+
if (command != resp) {
5846
std::cerr << "Got unexpected result from 'printer1'\n";
5947
return EXIT_FAILURE;
6048
}

src/viam/examples/modules/simple/main.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <viam/api/service/generic/v1/generic.grpc.pb.h>
1212

1313
#include <viam/sdk/common/exception.hpp>
14+
#include <viam/sdk/common/proto_value.hpp>
1415
#include <viam/sdk/config/resource.hpp>
1516
#include <viam/sdk/module/module.hpp>
1617
#include <viam/sdk/module/service.hpp>
@@ -44,29 +45,31 @@ class Printer : public GenericService, public Reconfigurable {
4445
std::cout << "Printer " << Resource::name() << " will print " << to_print_ << std::endl;
4546
}
4647

47-
AttributeMap do_command(const AttributeMap& command) {
48+
ProtoStruct do_command(const ProtoStruct& command) {
4849
std::cout << "Received DoCommand request for Printer " << Resource::name() << std::endl;
4950
std::cout << "Printer " << Resource::name() << " has printed " << to_print_ << std::endl;
5051
return command;
5152
}
5253

5354
static std::string find_to_print(ResourceConfig cfg) {
5455
auto& printer_name = cfg.name();
55-
auto to_print = cfg.attributes()->find("to_print");
56-
if (to_print == cfg.attributes()->end()) {
56+
auto to_print = cfg.attributes().find("to_print");
57+
if (to_print == cfg.attributes().end()) {
5758
std::ostringstream buffer;
5859
buffer << printer_name << ": Required parameter `to_print` not found in configuration";
5960
throw std::invalid_argument(buffer.str());
6061
}
61-
const auto* const to_print_string = to_print->second->get<std::string>();
62-
if (!to_print_string || to_print_string->empty()) {
63-
std::ostringstream buffer;
64-
buffer << printer_name
65-
<< ": Required non-empty string parameter `to_print` is either not a string "
66-
"or is an empty string";
67-
throw std::invalid_argument(buffer.str());
62+
const ProtoValue& to_print_val = to_print->second;
63+
if (to_print_val.is_a<std::string>() &&
64+
!to_print_val.get_unchecked<std::string>().empty()) {
65+
return to_print_val.get_unchecked<std::string>();
6866
}
69-
return *to_print_string;
67+
68+
std::ostringstream buffer;
69+
buffer << printer_name
70+
<< ": Required non-empty string parameter `to_print` is either not a string "
71+
"or is an empty string";
72+
throw std::invalid_argument(buffer.str());
7073
}
7174

7275
private:

0 commit comments

Comments
 (0)