dashboard_client.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2019 FZI Forschungszentrum Informatik
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 // -- END LICENSE BLOCK ------------------------------------------------
18 
19 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 #ifndef UR_ROBOT_DRIVER_DASHBOARD_CLIENT_DASHBOARD_CLIENT_H_INCLUDED
28 #define UR_ROBOT_DRIVER_DASHBOARD_CLIENT_DASHBOARD_CLIENT_H_INCLUDED
29 
31 
32 namespace urcl
33 {
45 {
46 public:
52  DashboardClient(const std::string& host);
53  DashboardClient() = delete;
54  virtual ~DashboardClient() = default;
55 
56  const int DASHBOARD_SERVER_PORT = 29999;
57 
63  bool connect();
64 
68  void disconnect();
69 
78  std::string sendAndReceive(const std::string& command);
79 
80 protected:
81  virtual bool open(int socket_fd, struct sockaddr* address, size_t address_len)
82  {
83  return ::connect(socket_fd, address, address_len) == 0;
84  }
85 
86 private:
87  bool send(const std::string& text);
88  std::string read();
89 
90  void rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
91  {
92  str.erase(str.find_last_not_of(chars) + 1);
93  }
94 
95  std::string host_;
96  int port_;
97  std::mutex write_mutex_;
98 };
99 } // namespace urcl
100 #endif // ifndef UR_ROBOT_DRIVER_DASHBOARD_CLIENT_DASHBOARD_CLIENT_H_INCLUDED
bool send(const std::string &text)
void rtrim(std::string &str, const std::string &chars="\t\n\v\f\r ")
virtual ~DashboardClient()=default
std::string sendAndReceive(const std::string &command)
Sends a command through the socket and waits for an answer.
bool connect()
Opens a connection to the dasboard server on the host as specified in the constructor.
Class for TCP socket abstraction.
Definition: tcp_socket.h:48
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len)
This class is a wrapper around the dashboard server.
void disconnect()
Makes sure no connection to the dashboard server is held inside the object.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26