Skip to content

Commit 78b0187

Browse files
authored
Merge branch 'main' into fix/conan
2 parents 5916479 + 9dc2143 commit 78b0187

29 files changed

+290
-101
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ set(VIAMCPPSDK_XTL_VERSION_MINIMUM 0.7.2)
324324
set(VIAMCPPSDK_XTENSOR_VERSION_MINIMUM 0.24.3)
325325

326326
# Time to find `BOOST`.
327-
find_package(Boost ${VIAMCPPSDK_BOOST_VERSION_MINIMUM} REQUIRED COMPONENTS headers log program_options)
327+
if (VIAMCPPSDK_BUILD_TESTS)
328+
set(VIAMCPPSDK_BOOST_TEST "unit_test_framework")
329+
endif()
330+
331+
find_package(Boost ${VIAMCPPSDK_BOOST_VERSION_MINIMUM} REQUIRED COMPONENTS headers log program_options ${VIAMCPPSDK_BOOST_TEST})
328332

329333
# Time to find `protobuf` and `gRPC[++]`. Normally this would just be
330334
# something like `find_package(gRPC <version> CONFIG REQUIRED)`, and

src/viam/examples/camera/example_camera.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <unistd.h>
44
#include <vector>
55

6+
#include <viam/sdk/common/instance.hpp>
67
#include <viam/sdk/components/camera.hpp>
78
#include <viam/sdk/robot/client.hpp>
89
#include <viam/sdk/rpc/dial.hpp>
@@ -13,6 +14,11 @@ int main() {
1314
using std::endl;
1415
namespace vs = ::viam::sdk;
1516
try {
17+
// Every Viam C++ SDK program must have one and only one Instance object which is created
18+
// before
19+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
20+
vs::Instance inst;
21+
1622
// If you want to connect to a remote robot, this should be the url of the robot
1723
// Ex: xxx.xxx.viam.cloud
1824
std::string robot_address("localhost:8080");

src/viam/examples/dial/example_dial.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99

1010
#include <boost/optional.hpp>
1111

12+
#include <viam/sdk/common/instance.hpp>
1213
#include <viam/sdk/components/generic.hpp>
1314
#include <viam/sdk/robot/client.hpp>
1415
#include <viam/sdk/rpc/dial.hpp>
1516

1617
using namespace viam::sdk;
1718

1819
int main() {
20+
// Every Viam C++ SDK program must have one and only one Instance object which is created before
21+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
22+
Instance inst;
23+
1924
const char* uri = "<your robot URI here>";
2025
DialOptions dial_options;
2126
std::string type = "<your authentication type>";

src/viam/examples/dial_api_key/example_dial_api_key.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <boost/optional.hpp>
1111
#include <boost/program_options.hpp>
1212

13+
#include <viam/sdk/common/instance.hpp>
1314
#include <viam/sdk/robot/client.hpp>
1415
#include <viam/sdk/rpc/dial.hpp>
1516

@@ -18,6 +19,10 @@ using namespace viam::sdk;
1819
namespace po = boost::program_options;
1920

2021
int main(int argc, char* argv[]) {
22+
// Every Viam C++ SDK program must have one and only one Instance object which is created before
23+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
24+
Instance inst;
25+
2126
po::options_description desc("Allowed options");
2227
desc.add_options()("help", "List options and exit")(
2328
"uri", po::value<std::string>(), "URI of robot")(

src/viam/examples/mlmodel/example_audio_classification_client.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <boost/program_options.hpp>
3030
#include <boost/variant/get.hpp>
3131

32+
#include <viam/sdk/common/instance.hpp>
3233
#include <viam/sdk/robot/client.hpp>
3334
#include <viam/sdk/services/mlmodel.hpp>
3435

@@ -78,6 +79,10 @@ constexpr char kRobotConfigTemplate[] = R"(
7879
} // namespace
7980

8081
int main(int argc, char* argv[]) try {
82+
// Every Viam C++ SDK program must have one and only one Instance object which is created before
83+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
84+
viam::sdk::Instance inst;
85+
8186
// Build up our command line options. The example operates in two
8287
// modes. In the "--generate" mode, it takes command line
8388
// parameters needed to satisfy the interpolation points in the

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <grpcpp/grpcpp.h>
1212
#include <grpcpp/support/status.h>
1313

14+
#include <viam/sdk/common/instance.hpp>
1415
#include <viam/sdk/components/motor.hpp>
1516
#include <viam/sdk/robot/client.hpp>
1617
#include <viam/sdk/rpc/dial.hpp>
@@ -21,6 +22,10 @@
2122
using namespace viam::sdk;
2223

2324
int main() {
25+
// Every Viam C++ SDK program must have one and only one Instance object which is created before
26+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
27+
Instance inst;
28+
2429
const char* uri = "http://localhost:8080/"; // replace with your URI if connecting securely
2530
DialOptions dial_options;
2631
dial_options.set_allow_insecure_downgrade(true); // set to false if connecting securely
@@ -37,8 +42,8 @@ int main() {
3742

3843
// Register custom gizmo and summation clients so robot client can access resources
3944
// of that type from the server.
40-
Registry::register_resource_client<GizmoClient>();
41-
Registry::register_resource_client<SummationClient>();
45+
Registry::get().register_resource_client<GizmoClient>();
46+
Registry::get().register_resource_client<SummationClient>();
4247

4348
// Connect to robot.
4449
std::shared_ptr<RobotClient> robot = RobotClient::at_address(address, options);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <grpcpp/grpcpp.h>
66
#include <grpcpp/server_context.h>
77

8+
#include <viam/sdk/common/instance.hpp>
89
#include <viam/sdk/components/base.hpp>
910
#include <viam/sdk/components/component.hpp>
1011
#include <viam/sdk/config/resource.hpp>
@@ -24,11 +25,15 @@
2425
using namespace viam::sdk;
2526

2627
int main(int argc, char** argv) {
28+
// Every Viam C++ SDK program must have one and only one Instance object which is created before
29+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
30+
Instance inst;
31+
2732
Model mybase_model("viam", "base", "mybase");
2833

2934
// Make sure to explicity register resources with custom APIs.
30-
Registry::register_resource_server<GizmoServer>();
31-
Registry::register_resource_server<SummationServer>();
35+
Registry::get().register_resource_server<GizmoServer>();
36+
Registry::get().register_resource_server<SummationServer>();
3237

3338
std::shared_ptr<ModelRegistration> mybase_mr = std::make_shared<ModelRegistration>(
3439
API::get<Base>(),

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

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

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

3132
// Test teardown is a noop;

src/viam/examples/modules/simple/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# VIAM Simple Module Example
2-
This example goes through how to create custom modular resources using Viam's C++ SDK, and how to connect it to a Robot.
2+
This example goes through how to create custom modular resources using Viam's C++ SDK, and how to connect it to a machine.
33

44
This is a limited document. For a more in-depth understanding of modules, see the [documentation](https://docs.viam.com/registry/).
55

66
## Purpose
7-
Modular resources allow you to define custom components and services and add them to your robot. Viam ships with many component types, but you're not limited to only using those types -- you can create your own using modules.
7+
Modular resources allow you to define custom components and services and add them to your machine. Viam ships with many component types, but you're not limited to only using those types -- you can create your own using modules.
88

99
For more information, see the [documentation](https://docs.viam.com/registry/). For a more complex example, take a look at the [complex module example](https://github.com/viamrobotics/viam-cpp-sdk/tree/main/src/viam/examples/modules/complex), which contains multiple new APIs and custom resource models.
1010

@@ -17,12 +17,12 @@ The validator function can throw errors that are triggered due to errors in the
1717

1818
The reconfiguration method reconfigures the resource based on the new configuration passed in.
1919

20-
When simple_module is run, the main function creates and starts the module. Read further to learn how to connect this module to your robot.
20+
When simple_module is run, the main function creates and starts the module. Read further to learn how to connect this module to your machine.
2121

2222
## Configuring and using the module
23-
The `simple_module` binary generated after building is the entrypoint for this module. To connect this module with your robot, you must add this module's entrypoint to the robot's config. For example, this could be `/home/viam-cpp-sdk/build/install/bin/simple_module`. See the [documentation](https://docs.viam.com/registry/configure/#add-a-local-module) for more details.
23+
The `simple_module` binary generated after building is the entrypoint for this module. To connect this module with your machine, you must add this module's entrypoint to the machine's config. For example, this could be `/home/viam-cpp-sdk/build/install/bin/simple_module`. See the [documentation](https://docs.viam.com/registry/configure/#add-a-local-module) for more details.
2424

25-
Once the module has been added to your robot, you will then need to add a component that uses the `viam:sensor:mysensor` model. See the [documentation](https://docs.viam.com/registry/configure/#add-a-local-modular-resource) for more details.
25+
Once the module has been added to your machine, you will then need to add a component that uses the `viam:sensor:mysensor` model. See the [documentation](https://docs.viam.com/registry/configure/#add-a-local-modular-resource) for more details.
2626

2727
An example configuration for our sensor could look like this:
2828
```json{

src/viam/examples/modules/simple/client.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <memory>
33
#include <string>
44

5+
#include <viam/sdk/common/instance.hpp>
56
#include <viam/sdk/common/proto_value.hpp>
67
#include <viam/sdk/components/sensor.hpp>
78
#include <viam/sdk/robot/client.hpp>
@@ -10,6 +11,10 @@
1011
using namespace viam::sdk;
1112

1213
int main() {
14+
// Every Viam C++ SDK program must have one and only one Instance object which is created before
15+
// any other C++ SDK objects and stays alive until all Viam C++ SDK objects are destroyed.
16+
Instance inst;
17+
1318
const char* uri = "http://localhost:8080/"; // replace with your URI if connecting securely
1419
DialOptions dial_options;
1520
dial_options.set_allow_insecure_downgrade(true); // set to false if connecting securely

0 commit comments

Comments
 (0)