Viam C++ SDK current
Loading...
Searching...
No Matches
api.hpp
1// Note that `Summation` is implemented with `MySummation` in impl.hpp and impl.cpp.
2#pragma once
3
4#include <vector>
5
6#include <grpcpp/channel.h>
7
8#include <viam/sdk/common/utils.hpp>
9#include <viam/sdk/config/resource.hpp>
12#include <viam/sdk/rpc/dial.hpp>
13#include <viam/sdk/services/service.hpp>
14
15#include "summation.grpc.pb.h"
16#include "summation.pb.h"
17
18using namespace viam::sdk;
19using namespace viam::service::summation::v1;
20
21// A `Summation` is a custom modular service.
22class Summation : public Service {
23 public:
24 // methods shared across all services
25 API api() const override;
26
27 virtual double sum(std::vector<double> numbers) = 0;
28
29 protected:
30 explicit Summation(std::string name);
31};
32
33namespace viam {
34namespace sdk {
35template <>
37 static API api();
38};
39} // namespace sdk
40} // namespace viam
41
42// `SummationClient` is the gRPC client implementation of a `Summation`
43// service.
44class SummationClient : public Summation {
45 public:
47 SummationClient(std::string name, const ViamChannel& channel);
48
49 const ViamChannel& channel() const {
50 return *channel_;
51 }
52
53 double sum(std::vector<double> numbers) override;
54
55 private:
56 using StubType = SummationService::StubInterface;
57 std::unique_ptr<StubType> stub_;
58 const ViamChannel* channel_;
59};
60
61// `SummationServer` is the gRPC server implementation of a `Summation`
62// service.
63class SummationServer : public ResourceServer, public SummationService::Service {
64 public:
66 using service_type = SummationService;
67 explicit SummationServer(std::shared_ptr<ResourceManager> manager);
68
69 grpc::Status Sum(grpc::ServerContext* context,
70 const SumRequest* request,
71 SumResponse* response) override;
72};
Definition api.hpp:44
Definition api.hpp:63
Definition api.hpp:22
API api() const override
Returns the API associated with a particular resource.
Definition resource_api.hpp:21
Definition resource_server_base.hpp:8
virtual std::string name() const
Return the resource's name.
Definition service.hpp:10
Definition dial.hpp:25
Defines the resource registry and associated types.
Defines a general-purpose resource manager.
Definition resource_api.hpp:46