9#include <unordered_map>
11#include <boost/optional/optional.hpp>
12#include <grpcpp/impl/service_type.h>
14#include <viam/api/component/generic/v1/generic.grpc.pb.h>
16#include <viam/sdk/resource/resource.hpp>
17#include <viam/sdk/resource/resource_api.hpp>
29 std::shared_ptr<Resource>
resource(
const std::string& name);
35 std::shared_ptr<T>
resource(
const std::string& name) {
36 static_assert(std::is_base_of<Resource, T>::value,
"T is not derived from Resource");
37 return std::dynamic_pointer_cast<T>(
resource(name));
52 void add(std::string name, std::shared_ptr<Resource>
resource);
64 const std::unordered_map<std::string, std::shared_ptr<Resource>>&
resources()
const;
70 std::unordered_map<std::string, std::shared_ptr<Resource>> resources_;
72 std::unordered_map<std::string, std::string> short_names_;
73 void do_add(
const Name& name, std::shared_ptr<Resource>
resource);
74 void do_add(std::string name, std::shared_ptr<Resource>
resource);
75 void do_remove(
const Name& name);
A name for specific instances of resources.
Definition resource_api.hpp:63
Defines a resource manager for use by anything that tracks resources.
Definition resource_manager.hpp:24
void add(std::string name, std::shared_ptr< Resource > resource)
Adds a single resource to the manager.
void replace_one(const Name &name, std::shared_ptr< Resource > resource)
Replaces an existing resource. No-op if the named resource does not exist.
const std::unordered_map< std::string, std::shared_ptr< Resource > > & resources() const
Returns a reference to the existing resources within the manager.
std::shared_ptr< T > resource(const std::string &name)
Returns a resource after dynamically downcasting to T.
Definition resource_manager.hpp:35
void add(const Name &name, std::shared_ptr< Resource > resource)
Adds a single resource to the manager.
std::shared_ptr< Resource > resource(const std::string &name)
Returns a resource.
void replace_all(const std::unordered_map< Name, std::shared_ptr< Resource > > &resources)
Replaces all resources in the manager.
void remove(const Name &name)
Remodes a single resource from the manager.