Viam C++ SDK current
Loading...
Searching...
No Matches
resource.hpp
1#pragma once
2
3#include <optional>
4#include <string>
5#include <unordered_map>
6
7#include <viam/sdk/common/proto_convert.hpp>
8#include <viam/sdk/common/proto_value.hpp>
10#include <viam/sdk/referenceframe/frame.hpp>
11#include <viam/sdk/resource/resource_api.hpp>
12
13namespace viam {
14namespace app {
15namespace v1 {
16
17class ComponentConfig;
18class ResourceLevelServiceConfig;
19
20} // namespace v1
21} // namespace app
22
23namespace service {
24namespace discovery {
25namespace v1 {
26
27class DiscoverResourcesResponse;
28}
29} // namespace discovery
30} // namespace service
31} // namespace viam
32
33namespace viam {
34namespace sdk {
35
37 std::string type;
38 ProtoStruct attributes;
39 ProtoValue converted_attributes;
40};
41
43 public:
44 ResourceConfig(std::string type,
45 std::string name,
46 std::string namespace_,
47 ProtoStruct attributes,
48 std::string api,
49 Model model,
50 log_level lvl = sdk::log_level::info);
51
52 ResourceConfig(std::string type,
53 std::string name,
54 std::string namespace_,
55 ProtoStruct attributes,
56 std::string api,
57 Model model,
58 LinkConfig frame,
59 log_level lvl = sdk::log_level::info);
60
61 ResourceConfig(std::string type);
62
63 Name resource_name() const;
64
65 const API& api() const;
66
67 const std::optional<LinkConfig>& frame() const;
68
69 const Model& model() const;
70
71 const std::string& name() const;
72 const std::string& namespace_() const;
73 const std::string& type() const;
74
75 log_level get_log_level() const;
76
77 const std::vector<std::string>& depends_on() const;
78
79 const std::vector<ResourceLevelServiceConfig>& service_config() const;
80
81 const ProtoStruct& attributes() const;
82
83 private:
84 void fix_api();
85
86 API api_;
87
88 std::optional<LinkConfig> frame_;
89
90 Model model_;
91
92 std::string name_;
93 std::string namespace__;
94 std::string type_;
95
96 std::vector<std::string> depends_on_;
97
98 std::vector<ResourceLevelServiceConfig> service_config_;
99
100 ProtoStruct attributes_;
101 ProtoValue converted_attributes_;
102
103 std::vector<std::string> implicit_depends_on_;
104
105 log_level log_level_;
106};
107
108namespace proto_convert_details {
109
110template <>
112 void operator()(const ResourceLevelServiceConfig&, app::v1::ResourceLevelServiceConfig*) const;
113};
114
115template <>
117 void operator()(const ResourceConfig&, app::v1::ComponentConfig*) const;
118};
119
120template <>
121struct from_proto_impl<app::v1::ComponentConfig> {
122 ResourceConfig operator()(const app::v1::ComponentConfig*) const;
123};
124
125template <>
126struct from_proto_impl<service::discovery::v1::DiscoverResourcesResponse> {
127 std::vector<ResourceConfig> operator()(
128 const service::discovery::v1::DiscoverResourcesResponse*) const;
129};
130
131} // namespace proto_convert_details
132
133} // namespace sdk
134} // namespace viam
Definition resource_api.hpp:21
Definition frame.hpp:21
Defines the namespace_, family, and name for a particular resource model.
Definition resource_api.hpp:129
A name for specific instances of resources.
Definition resource_api.hpp:61
Type-erased value for storing google::protobuf::Value types. A ProtoValue can be nullptr,...
Definition proto_value.hpp:55
Definition resource.hpp:42
log_level
Severity levels for the logger.
Definition logging.hpp:31
Defines logging infrastructure.
Definition resource.hpp:36