Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/viam/sdk/config/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@
namespace viam {
namespace sdk {

ResourceConfig::ResourceConfig(std::string type,
std::string name,
std::string namespace_,
ProtoStruct attributes,
std::string api,
Model model,
log_level lvl)
: api_({kRDK, type, ""}),
frame_(boost::none),
model_(std::move(model)),
name_(std::move(name)),
namespace__(std::move(namespace_)),
type_(std::move(type)),
attributes_(std::move(attributes)),
log_level_(lvl) {
if (api.find(':') != std::string::npos) {
api_ = API::from_string(std::move(api));
}
fix_api();
}

ResourceConfig::ResourceConfig(std::string type,
std::string name,
std::string namespace_,
Expand Down Expand Up @@ -63,7 +84,7 @@ const API& ResourceConfig::api() const {
return api_;
}

const LinkConfig& ResourceConfig::frame() const {
const boost::optional<LinkConfig>& ResourceConfig::frame() const {
return frame_;
}

Expand Down Expand Up @@ -150,7 +171,9 @@ void to_proto_impl<ResourceConfig>::operator()(const ResourceConfig& self,
*proto->mutable_depends_on() = ::google::protobuf::RepeatedPtrField<std::string>(
self.depends_on().begin(), self.depends_on().end());

*proto->mutable_frame() = to_proto(self.frame());
if (self.frame()) {
*proto->mutable_frame() = to_proto(self.frame().get());
}
}

ResourceConfig from_proto_impl<app::v1::ComponentConfig>::operator()(
Expand Down
14 changes: 12 additions & 2 deletions src/viam/sdk/config/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <string>
#include <unordered_map>

#include <boost/optional.hpp>

#include <viam/sdk/common/proto_convert.hpp>
#include <viam/sdk/common/proto_value.hpp>
#include <viam/sdk/log/logging.hpp>
Expand Down Expand Up @@ -40,6 +42,14 @@ struct ResourceLevelServiceConfig {

class ResourceConfig {
public:
ResourceConfig(std::string type,
std::string name,
std::string namespace_,
ProtoStruct attributes,
std::string api,
Model model,
log_level lvl = sdk::log_level::info);

ResourceConfig(std::string type,
std::string name,
std::string namespace_,
Expand All @@ -55,7 +65,7 @@ class ResourceConfig {

const API& api() const;

const LinkConfig& frame() const;
const boost::optional<LinkConfig>& frame() const;

const Model& model() const;

Expand All @@ -76,7 +86,7 @@ class ResourceConfig {

API api_;

LinkConfig frame_;
boost::optional<LinkConfig> frame_;

Model model_;

Expand Down
4 changes: 2 additions & 2 deletions src/viam/sdk/tests/test_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(test_linkconfig) {
BOOST_AUTO_TEST_CASE(test_resource) {
ResourceConfig resource1("type");
BOOST_CHECK_EQUAL(resource1.api().to_string(), "rdk:type:");
BOOST_CHECK_EQUAL(resource1.frame().get_parent(), "");
BOOST_CHECK(!resource1.frame());
BOOST_CHECK_EQUAL(resource1.model().to_string(), "rdk:builtin:builtin");
BOOST_CHECK_EQUAL(resource1.name(), "");
BOOST_CHECK_EQUAL(resource1.namespace_(), "");
Expand Down Expand Up @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(test_resource) {
BOOST_CHECK_EQUAL(resource2.type(), "type");
BOOST_CHECK_EQUAL(resource2.model().to_string(), "ns:mf:model1");
BOOST_CHECK_EQUAL(resource2.api().to_string(), "ns:component:type");
BOOST_CHECK_EQUAL(resource2.frame().get_parent(), "parent");
BOOST_CHECK_EQUAL(resource2.frame()->get_parent(), "parent");
std::string key;
Value value;
for (const auto& key_and_value : resource2.attributes()) {
Expand Down