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