Viam C++ SDK current
Loading...
Searching...
No Matches
resource.hpp
1#pragma once
2
3#include <unordered_map>
4
5#include <viam/sdk/common/proto_value.hpp>
6#include <viam/sdk/config/resource.hpp>
8#include <viam/sdk/resource/resource_api.hpp>
9
10namespace viam {
11namespace sdk {
12
13class Resource;
14
15using Dependencies = std::unordered_map<Name, std::shared_ptr<Resource>>;
16
17namespace log_detail {
18
19struct logger_access;
20
21} // namespace log_detail
22
23class Resource {
24 public:
25 virtual ~Resource();
26
27 explicit Resource(std::string name);
28
31 explicit Resource(const ResourceConfig& cfg);
32
34 virtual API api() const = 0;
35
37 virtual Name get_resource_name() const;
38
40 virtual std::string name() const;
41
44
45 private:
46 std::string name_;
47
48 protected:
50
51 Name get_resource_name(const std::string& type) const;
52
53 mutable LogSource logger_;
54};
55
56template <>
58 static API api() {
59 return {"rdk", "resource", "Resource"};
60 }
61};
62
63namespace log_detail {
64
65// This is an attorney-client helper to avoid making the logger an outright public member of
66// Resource.
68 static LogSource& logger(const Resource&);
69};
70
71} // namespace log_detail
72
73} // namespace sdk
74} // namespace viam
Definition resource_api.hpp:21
A name for specific instances of resources.
Definition resource_api.hpp:61
Definition resource.hpp:43
Definition resource.hpp:23
void set_log_level(log_level) const
Set the log level for log messages originating from this Resource.
virtual std::string name() const
Return the resource's name.
virtual Name get_resource_name() const
Returns the Name for a particular resource.
virtual API api() const =0
Returns the API associated with a particular resource.
Resource(const ResourceConfig &cfg)
Construct from a resource config. Use this overload to ensure Viam App log filtering works immediatel...
log_level
Severity levels for the logger.
Definition logging.hpp:31
boost::log::sources::severity_channel_logger_mt< log_level > LogSource
Type alias for the log source in the C++ SDK.
Definition logging.hpp:51
Defines logging infrastructure.
Definition resource_api.hpp:46
Definition resource.hpp:67