Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/viam/examples/modules/complex/proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 7e6f6e774e29406da95bd61cdcdbc8bc
digest: shake256:fe43dd2265ea0c07d76bd925eeba612667cf4c948d2ce53d6e367e1b4b3cb5fa69a51e6acb1a6a50d32f894f054a35e6c0406f6808a483f2752e10c866ffbf73
commit: ee48893a270147348e3edc6c1a03de0e
digest: shake256:a35b0576a2b55dad72747e786af05c03539c2b96be236c9de39fe10d551931ac252eb68445c0cef6bbd27fa20e8c26eee5b8a9fe9c2fde6f63a03e18f8cf980d
23 changes: 0 additions & 23 deletions src/viam/sdk/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ namespace sdk {

using time_point = std::chrono::time_point<long long, std::chrono::nanoseconds>;

// TODO: RSDK-6627 : move this function to `Resource` class.
std::vector<Name> resource_names_for_resource(const std::shared_ptr<Resource>& resource) {
std::string resource_type;
std::string resource_subtype;
std::vector<Name> resource_names;
for (const auto& kv : Registry::registered_models()) {
const std::shared_ptr<const ModelRegistration> reg = kv.second;
if (reg->api().to_string() == resource->api().to_string()) {
resource_type = reg->api().resource_type();
resource_subtype = reg->api().resource_subtype();
} else {
continue;
}

if (resource_subtype.empty()) {
resource_subtype = resource->name();
}

resource_names.push_back({{kRDK, resource_type, resource_subtype}, "", resource->name()});
}
return resource_names;
}

std::vector<unsigned char> string_to_bytes(const std::string& s) {
std::vector<unsigned char> bytes(s.begin(), s.end());
return bytes;
Expand Down
2 changes: 0 additions & 2 deletions src/viam/sdk/common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const std::string kService = "service";
const std::string kRDK = "rdk";
const std::string kBuiltin = "builtin";

std::vector<Name> resource_names_for_resource(const std::shared_ptr<Resource>& resource);

struct response_metadata {
std::chrono::time_point<long long, std::chrono::nanoseconds> captured_at;

Expand Down
1 change: 1 addition & 0 deletions src/viam/sdk/resource/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <viam/sdk/common/proto_type.hpp>
#include <viam/sdk/common/utils.hpp>
#include <viam/sdk/registry/registry.hpp>
#include <viam/sdk/resource/resource_api.hpp>

namespace viam {
Expand Down
28 changes: 26 additions & 2 deletions src/viam/sdk/robot/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ using google::protobuf::RepeatedPtrField;
using viam::common::v1::ResourceName;
using viam::robot::v1::Status;

namespace {
std::vector<Name> registered_models_for_resource(const std::shared_ptr<Resource>& resource) {
std::string resource_type;
std::string resource_subtype;
std::vector<Name> resource_names;
for (const auto& kv : Registry::registered_models()) {
const std::shared_ptr<const ModelRegistration> reg = kv.second;
if (reg->api() == resource->api()) {
resource_type = reg->api().resource_type();
resource_subtype = reg->api().resource_subtype();
} else {
continue;
}

if (resource_subtype.empty()) {
resource_subtype = resource->name();
}

resource_names.push_back({{kRDK, resource_type, resource_subtype}, "", resource->name()});
}
return resource_names;
}
} // namespace

RobotService_::RobotService_(const std::shared_ptr<ResourceManager>& manager, Server& server)
: ResourceServer(manager) {
server.register_service(this);
Expand All @@ -42,8 +66,8 @@ RobotService_::RobotService_(const std::shared_ptr<ResourceManager>& manager, Se
std::vector<ResourceName> RobotService_::generate_metadata_() {
std::vector<ResourceName> metadata;
for (const auto& key_and_val : resource_manager()->resources()) {
for (const Name& resource : resource_names_for_resource(key_and_val.second)) {
metadata.push_back(resource.to_proto());
for (const Name& name : registered_models_for_resource(key_and_val.second)) {
metadata.push_back(name.to_proto());
}
}
return metadata;
Expand Down