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::sdk {
33template <>
35 static API api();
36};
37} // namespace viam::sdk
38
39// `SummationClient` is the gRPC client implementation of a `Summation`
40// service.
41class SummationClient : public Summation {
42 public:
44 SummationClient(std::string name, std::shared_ptr<grpc::Channel> channel);
45
46 double sum(std::vector<double> numbers) override;
47
48 private:
49 using StubType = SummationService::StubInterface;
50 std::unique_ptr<StubType> stub_;
51 std::shared_ptr<grpc::Channel> channel_;
52};
53
54// `SummationServer` is the gRPC server implementation of a `Summation`
55// service.
56class SummationServer : public ResourceServer, public SummationService::Service {
57 public:
59 using service_type = SummationService;
60 explicit SummationServer(std::shared_ptr<ResourceManager> manager);
61
62 grpc::Status Sum(grpc::ServerContext* context,
63 const SumRequest* request,
64 SumResponse* response) override;
65};
Definition api.hpp:41
Definition api.hpp:56
Definition api.hpp:21
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 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:50