Viam C++ SDK current
Loading...
Searching...
No Matches
api.hpp
1// Note that a `Gizmo` is implemented with `MyGizmo` in impl.hpp and impl.cpp.
2#pragma once
3
4#include <grpcpp/channel.h>
5#include <vector>
6
7#include <viam/sdk/common/utils.hpp>
8#include <viam/sdk/config/resource.hpp>
11
12#include "gizmo.grpc.pb.h"
13#include "gizmo.pb.h"
14
15using namespace viam::sdk;
16using namespace viam::component::gizmo::v1;
17
18// `Gizmo` is a custom modular component.
19class Gizmo : public Component {
20 public:
21 API api() const override;
22
23 virtual bool do_one(std::string arg1) = 0;
24 virtual bool do_one_client_stream(std::vector<std::string> arg1) = 0;
25 virtual std::vector<bool> do_one_server_stream(std::string arg1) = 0;
26 virtual std::vector<bool> do_one_bidi_stream(std::vector<std::string> arg1) = 0;
27 virtual std::string do_two(bool arg1) = 0;
28
29 protected:
30 explicit Gizmo(std::string name);
31};
32
33namespace viam::sdk {
34template <>
36 static ::viam::sdk::API api();
37};
38} // namespace viam::sdk
39
40// `GizmoClient` is the gRPC client implementation of a `Gizmo` component.
41class GizmoClient : public Gizmo {
42 public:
43 using interface_type = Gizmo;
44 GizmoClient(std::string name, std::shared_ptr<grpc::Channel> channel);
45
46 bool do_one(std::string arg1) override;
47 bool do_one_client_stream(std::vector<std::string> arg1) override;
48 std::vector<bool> do_one_server_stream(std::string arg1) override;
49 std::vector<bool> do_one_bidi_stream(std::vector<std::string> arg1) override;
50 std::string do_two(bool arg1) override;
51
52 private:
53 using StubType = GizmoService::StubInterface;
54 std::unique_ptr<StubType> stub_;
55 std::shared_ptr<grpc::Channel> channel_;
56};
57
58// `GizmoServer` is the gRPC server implementation of a `Gizmo` component.
59class GizmoServer : public ResourceServer, public GizmoService::Service {
60 public:
61 using interface_type = Gizmo;
62 using service_type = GizmoService;
63 explicit GizmoServer(std::shared_ptr<ResourceManager> manager);
64
65 grpc::Status DoOne(grpc::ServerContext* context,
66 const DoOneRequest* request,
67 DoOneResponse* response) override;
68
69 grpc::Status DoOneClientStream(grpc::ServerContext* context,
70 grpc::ServerReader<DoOneClientStreamRequest>* reader,
71 DoOneClientStreamResponse* response) override;
72
73 grpc::Status DoOneServerStream(grpc::ServerContext* context,
74 const DoOneServerStreamRequest* request,
75 grpc::ServerWriter<DoOneServerStreamResponse>* writer) override;
76
77 grpc::Status DoOneBiDiStream(
78 grpc::ServerContext* context,
79 grpc::ServerReaderWriter<DoOneBiDiStreamResponse, DoOneBiDiStreamRequest>* stream) override;
80
81 grpc::Status DoTwo(grpc::ServerContext* context,
82 const DoTwoRequest* request,
83 DoTwoResponse* response) override;
84};
Definition api.hpp:41
Definition api.hpp:59
Definition api.hpp:19
API api() const override
Returns the API associated with a particular resource.
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
Definition component.hpp:10
Definition resource_server_base.hpp:8
virtual std::string name() const
Return the resource's name.
Defines the resource registry and associated types.
Defines a general-purpose resource manager.
Definition resource_api.hpp:50