Viam C++ SDK current
Loading...
Searching...
No Matches
service.hpp
1
4#pragma once
5
6#include <string>
7#include <thread>
8#include <unordered_map>
9
10#include <google/protobuf/struct.pb.h>
11#include <grpcpp/support/status.h>
12
13#include <viam/api/common/v1/common.pb.h>
14#include <viam/api/robot/v1/robot.grpc.pb.h>
15#include <viam/api/robot/v1/robot.pb.h>
16
17#include <viam/sdk/common/utils.hpp>
18#include <viam/sdk/components/component.hpp>
19#include <viam/sdk/resource/resource.hpp>
20#include <viam/sdk/resource/resource_server_base.hpp>
22
23namespace viam {
24namespace sdk {
25
26using google::protobuf::RepeatedPtrField;
27using viam::common::v1::ResourceName;
28using viam::robot::v1::Status;
29
33class RobotService_ : public ResourceServer, public viam::robot::v1::RobotService::Service {
34 public:
35 explicit RobotService_(const std::shared_ptr<ResourceManager>& manager, Server& server);
36 std::shared_ptr<Resource> resource_by_name(const Name& name);
37 ::grpc::Status ResourceNames(::grpc::ServerContext* context,
38 const ::viam::robot::v1::ResourceNamesRequest* request,
39 ::viam::robot::v1::ResourceNamesResponse* response) override;
40 ::grpc::Status GetStatus(::grpc::ServerContext* context,
41 const ::viam::robot::v1::GetStatusRequest* request,
42 ::viam::robot::v1::GetStatusResponse* response) override;
43 ::grpc::Status StreamStatus(
44 ::grpc::ServerContext* context,
45 const ::viam::robot::v1::StreamStatusRequest* request,
46 ::grpc::ServerWriter<::viam::robot::v1::StreamStatusResponse>* writer) override;
47 ::grpc::Status StopAll(::grpc::ServerContext* context,
48 const ::viam::robot::v1::StopAllRequest* request,
49 ::viam::robot::v1::StopAllResponse* response) override;
50
51 private:
52 std::mutex lock_;
53 std::vector<ResourceName> generate_metadata_();
54 std::vector<Status> generate_status_(const RepeatedPtrField<ResourceName>& resource_names);
55
56 void stream_status(const ::viam::robot::v1::StreamStatusRequest* request,
57 ::grpc::ServerWriter<::viam::robot::v1::StreamStatusResponse>* writer,
58 int interval);
59};
60
61} // namespace sdk
62} // namespace viam
A name for specific instances of resources.
Definition resource_api.hpp:63
Definition resource_server_base.hpp:8
a gRPC service for a robot.
Definition service.hpp:33
Defines gRPC Server functionality.
Definition server.hpp:25
gRPC client implementation for a robot.