File tree Expand file tree Collapse file tree 7 files changed +12
-21
lines changed Expand file tree Collapse file tree 7 files changed +12
-21
lines changed Original file line number Diff line number Diff 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>(),
Original file line number Diff line number Diff line change @@ -24,9 +24,9 @@ using namespace viam::sdktests;
2424
2525struct 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;
Original file line number Diff line number Diff 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 ());
Original file line number Diff line number Diff line change 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-
2421Instance::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
Original file line number Diff line number Diff line change 55namespace viam {
66namespace 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};
Original file line number Diff line number Diff line change 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
9494Registry& Registry::get () {
95- return * Instance::current ().registry () ;
95+ return Instance::current ().impl_ -> registry ;
9696}
9797
9898void Registry::register_model (std::shared_ptr<const ModelRegistration> resource) {
Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments