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/services/service.hpp>
13
14#include "summation.grpc.pb.h"
15#include "summation.pb.h"
16
17using namespace viam::sdk;
18using namespace viam::service::summation::v1;
19
20// A `Summation` is a custom modular service.
21class Summation : public Service {
22 public:
23 // methods shared across all services
24 API api() const override;
25
26 virtual double sum(std::vector<double> numbers) = 0;
27
28 protected:
29 explicit Summation(std::string name);
30};
31
32namespace viam {
33namespace sdk {
34template <>
36 static API api();
37};
38} // namespace sdk
39} // namespace viam
40
41// `SummationClient` is the gRPC client implementation of a `Summation`
42// service.
43class SummationClient : public Summation {
44 public:
46 SummationClient(std::string name, std::shared_ptr<grpc::Channel> channel);
47
48 double sum(std::vector<double> numbers) override;
49
50 private:
51 using StubType = SummationService::StubInterface;
52 std::unique_ptr<StubType> stub_;
53 std::shared_ptr<grpc::Channel> channel_;
54};
55
56// `SummationServer` is the gRPC server implementation of a `Summation`
57// service.
58class SummationServer : public ResourceServer, public SummationService::Service {
59 public:
61 using service_type = SummationService;
62 explicit SummationServer(std::shared_ptr<ResourceManager> manager);
63
64 grpc::Status Sum(grpc::ServerContext* context,
65 const SumRequest* request,
66 SumResponse* response) override;
67};
Definition api.hpp:43
Definition api.hpp:58
Definition api.hpp:21
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
Defines the resource registry and associated types.
Defines a general-purpose resource manager.
Definition resource_api.hpp:46