RestApi.hh
Go to the documentation of this file.
1 /*
2  * copyright (C) 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GAZEBO_PLUGINS_REST_WEB_RESTAPI_HH_
19 #define GAZEBO_PLUGINS_REST_WEB_RESTAPI_HH_
20 
21 #include <string>
22 #include <list>
23 #include <mutex>
24 #include <gazebo/common/Console.hh>
25 
26 #include "RestException.hh"
27 
28 namespace gazebo
29 {
32  class RestApi
33  {
35  public: RestApi();
36 
38  public: virtual ~RestApi();
39 
46  public: std::string Login(const std::string &_url,
47  const std::string &_route,
48  const std::string &_user,
49  const std::string &_pass);
50 
54  public: void Logout();
55 
59  public: void PostJsonData(const char *_route, const char *_json);
60 
63  public: std::string GetUser() const;
64 
71  private: std::string Request(const std::string &_requestUrl,
72  const std::string &_postStr);
73 
75  private: void SendUnpostedPosts();
76 
78  private: std::string url;
79 
81  private: std::string user;
82 
84  private: std::string pass;
85 
87  private: std::string loginRoute;
88 
90  private: bool isLoggedIn;
91 
93  private: struct Post
94  {
95  std::string route;
96  std::string json;
97  };
98 
100  private: std::list<Post> posts;
101 
103  private: std::mutex postsMutex;
104  };
105 }
106 
107 #endif
std::string Login(const std::string &_url, const std::string &_route, const std::string &_user, const std::string &_pass)
Connects to the REST service.
void Logout()
Stops sending messages to the REST service.
Forward declarations for the common classes.
Definition: Animation.hh:33
std::string GetUser() const
Returns the username.
REST interface.
Definition: RestApi.hh:32
virtual ~RestApi()
Destructor.
RestApi()
Constructor.
void PostJsonData(const char *_route, const char *_json)
Notify the service with a http POST.