Skip to content

Commit 6018323

Browse files
committed
make instance more of a black box
1 parent 18d26c9 commit 6018323

File tree

7 files changed

+12
-21
lines changed

7 files changed

+12
-21
lines changed

src/viam/examples/modules/complex/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ int main(int argc, char** argv) {
3232
Model mybase_model("viam", "base", "mybase");
3333

3434
// Make sure to explicity register resources with custom APIs.
35-
inst.registry()->register_resource_server<GizmoServer>();
36-
inst.registry()->register_resource_server<SummationServer>();
35+
Registry::get().register_resource_server<GizmoServer>();
36+
Registry::get().register_resource_server<SummationServer>();
3737

3838
std::shared_ptr<ModelRegistration> mybase_mr = std::make_shared<ModelRegistration>(
3939
API::get<Base>(),

src/viam/examples/modules/complex/test_complex_module.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ using namespace viam::sdktests;
2424

2525
struct RegisterGizmoAndSummationFixture {
2626
RegisterGizmoAndSummationFixture() {
27-
auto* registry = Instance::current().registry();
28-
registry->register_resource<GizmoClient, GizmoServer>();
29-
registry->register_resource<SummationClient, SummationServer>();
27+
auto& registry = Registry::get();
28+
registry.register_resource<GizmoClient, GizmoServer>();
29+
registry.register_resource<SummationClient, SummationServer>();
3030
}
3131

3232
// Test teardown is a noop;

src/viam/examples/modules/tflite/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ int serve(const std::string& socket_path) try {
742742
});
743743

744744
// Register the newly created registration with the Registry.
745-
inst.registry()->register_model(module_registration);
745+
Registry::get().register_model(module_registration);
746746

747747
// Construct the module service and tell it where to place the socket path.
748748
auto module_service = std::make_shared<vsdk::ModuleService>(socket_path, inst.registry());

src/viam/sdk/common/instance.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <viam/sdk/common/instance.hpp>
22

33
#include <viam/sdk/common/exception.hpp>
4+
#include <viam/sdk/common/private/instance.hpp>
45
#include <viam/sdk/registry/registry.hpp>
56

67
#include <atomic>
@@ -17,10 +18,6 @@ std::atomic<Instance*> current_instance{nullptr};
1718

1819
} // namespace
1920

20-
struct Instance::Impl {
21-
Registry registry;
22-
};
23-
2421
Instance::Instance() {
2522
Instance* expected = nullptr;
2623

@@ -52,9 +49,5 @@ Instance& Instance::current() {
5249
return *current;
5350
}
5451

55-
Registry* Instance::registry() {
56-
return &(impl_->registry);
57-
}
58-
5952
} // namespace sdk
6053
} // namespace viam

src/viam/sdk/common/instance.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace viam {
66
namespace sdk {
77

8-
class Registry;
9-
108
/// @brief Instance management for Viam C++ SDK applications.
119
/// This is a single instance class which is responsible for global setup and teardown related to
1210
/// the SDK. An Instance must be constructed before doing anything else in a program, and it must
@@ -19,9 +17,9 @@ class Instance {
1917

2018
static Instance& current();
2119

22-
Registry* registry();
23-
2420
private:
21+
friend class Registry;
22+
2523
struct Impl;
2624
std::unique_ptr<Impl> impl_;
2725
};

src/viam/sdk/registry/registry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <grpcpp/ext/proto_server_reflection_plugin.h>
1313

1414
#include <viam/sdk/common/exception.hpp>
15-
#include <viam/sdk/common/instance.hpp>
15+
#include <viam/sdk/common/private/instance.hpp>
1616
#include <viam/sdk/components/private/arm_client.hpp>
1717
#include <viam/sdk/components/private/arm_server.hpp>
1818
#include <viam/sdk/components/private/base_client.hpp>
@@ -92,7 +92,7 @@ const Model& ModelRegistration::model() const {
9292
};
9393

9494
Registry& Registry::get() {
95-
return *Instance::current().registry();
95+
return Instance::current().impl_->registry;
9696
}
9797

9898
void Registry::register_model(std::shared_ptr<const ModelRegistration> resource) {

src/viam/sdk/tests/mocks/mock_robot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ std::vector<Name> registered_models_for_resource(const std::shared_ptr<Resource>
2626
std::string resource_type;
2727
std::string resource_subtype;
2828
std::vector<Name> resource_names;
29-
for (const auto& kv : Instance::current().registry()->registered_models()) {
29+
for (const auto& kv : Registry::get().registered_models()) {
3030
const std::shared_ptr<const ModelRegistration> reg = kv.second;
3131
if (reg->api() == resource->api()) {
3232
resource_type = reg->api().resource_type();

0 commit comments

Comments
 (0)