main_service_client.h
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2020,
6  * TU Dortmund - Institute of Control Theory and Systems Engineering.
7  * All rights reserved.
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  *
22  * Authors: Christoph Rösmann
23  *********************************************************************/
24 
25 #ifndef SRC_COMMUNICATION_INCLUDE_CORBO_COMMUNICATION_MAIN_SERVICE_CLIENT_H_
26 #define SRC_COMMUNICATION_INCLUDE_CORBO_COMMUNICATION_MAIN_SERVICE_CLIENT_H_
27 
28 #ifdef RPC_SUPPORT
29 
30 #include <corbo-communication/services/master_service.grpc.pb.h>
31 #include <corbo-core/console.h>
32 #include <grpc++/grpc++.h>
33 #include <functional>
34 #include <memory>
35 
36 namespace corbo {
37 
52 class MasterServiceClient
53 {
54  public:
56  MasterServiceClient() = default;
57 
59  virtual ~MasterServiceClient() = default;
60 
70  explicit MasterServiceClient(std::shared_ptr<grpc::Channel> channel) : _stub(services::MasterService::NewStub(channel)) {}
71 
73  void setChannel(std::shared_ptr<grpc::Channel> channel) { _stub = services::MasterService::NewStub(channel); }
74 
89  virtual std::unique_ptr<google::protobuf::Message> createParameterMsg() const;
90 
101  virtual bool setParameters(const google::protobuf::Message& parameters, messages::Status& status_msg, int timeout_ms = 1000);
102 
110  virtual bool getParameters(google::protobuf::Message& parameters, int timeout_ms = 1000);
111 
119  bool setPlant(const messages::Plant& plant_msg, messages::Status& status_msg, int timeout_ms = 500);
120 
127  bool getPlant(messages::Plant& plant_msg, int timeout_ms = 500);
128 
136  bool setController(const messages::Controller& ctrl_msg, messages::Status& status_msg, int timeout_ms = 500);
137 
144  bool getController(messages::Controller& ctrl_msg, int timeout_ms = 500);
145 
153  bool setObserver(const messages::Observer& obs_msg, messages::Status& status_msg, int timeout_ms = 500);
154 
161  bool getObserver(messages::Observer& obs_msg, int timeout_ms = 500);
162 
170  bool setTask(const messages::Task& task_msg, messages::Status& status_msg, int timeout_ms = 500);
171 
178  bool getTask(messages::Task& task_msg, int timeout_ms = 500);
179 
193  bool getAvailableSignals(std::function<void(const messages::Signal&)> feedback, int timeout_ms = 500);
194 
216  bool performTask(std::function<void(const messages::Signal&)> feedback, std::string* msg = nullptr,
217  int timeout_ms = 99999999); // TODO(roesmann): timeout != deadline!!!
218 
229  bool verifyConfig(messages::Status& status_msg, int timeout_ms = 2000);
230 
236  bool ping(int timeout_ms);
237 
247  bool stopTask(int timeout_ms = 2000);
248 
249  private:
250  std::unique_ptr<services::MasterService::Stub> _stub;
251 };
252 
253 } // namespace corbo
254 
255 #endif // RPC_SUPPORT
256 
257 #endif // SRC_COMMUNICATION_INCLUDE_CORBO_COMMUNICATION_MAIN_SERVICE_CLIENT_H_


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Mon Feb 28 2022 22:07:00