diff --git a/src/viam/sdk/config/resource.cpp b/src/viam/sdk/config/resource.cpp index 8f19dadef..bbec60d6d 100644 --- a/src/viam/sdk/config/resource.cpp +++ b/src/viam/sdk/config/resource.cpp @@ -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_, @@ -63,7 +84,7 @@ const API& ResourceConfig::api() const { return api_; } -const LinkConfig& ResourceConfig::frame() const { +const boost::optional& ResourceConfig::frame() const { return frame_; } @@ -150,7 +171,9 @@ void to_proto_impl::operator()(const ResourceConfig& self, *proto->mutable_depends_on() = ::google::protobuf::RepeatedPtrField( 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::operator()( diff --git a/src/viam/sdk/config/resource.hpp b/src/viam/sdk/config/resource.hpp index d2531b5ff..4f352beb2 100644 --- a/src/viam/sdk/config/resource.hpp +++ b/src/viam/sdk/config/resource.hpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include #include @@ -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_, @@ -55,7 +65,7 @@ class ResourceConfig { const API& api() const; - const LinkConfig& frame() const; + const boost::optional& frame() const; const Model& model() const; @@ -76,7 +86,7 @@ class ResourceConfig { API api_; - LinkConfig frame_; + boost::optional frame_; Model model_; diff --git a/src/viam/sdk/tests/test_resource.cpp b/src/viam/sdk/tests/test_resource.cpp index 68e6b47b5..0fef864e4 100644 --- a/src/viam/sdk/tests/test_resource.cpp +++ b/src/viam/sdk/tests/test_resource.cpp @@ -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_(), ""); @@ -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()) {