RAPP Platform API
 All Classes Namespaces Files Functions Variables Typedefs
user.hpp
Go to the documentation of this file.
1 #ifndef RAPP_CLOUD_USER
2 #define RAPP_CLOUD_USER
3 #include "includes.ihh"
4 namespace rapp {
5 namespace cloud {
14 {
15 public:
20  const std::string token,
21  std::function<void(std::vector<std::string>)> callback
22  )
23  : asio_service_http(token), delegate_(callback)
24  {
25  header_ = "GET /hop/available_services HTTP/1.1\r\n";
26  callback_ = std::bind(&available_services::handle_reply, this, std::placeholders::_1);
27  }
28 private:
32  void handle_reply(std::string json)
33  {
34  std::stringstream ss(json);
35  std::vector<std::string> services;
36  try {
37  boost::property_tree::ptree tree;
38  boost::property_tree::read_json(ss, tree);
39  for (auto child : tree.get_child("services")) {
40  services.push_back(child.second.get_value<std::string>());
41  }
42  for (auto child : tree.get_child("error")) {
43  const std::string value = child.second.get_value<std::string>();
44  if (!value.empty()) {
45  std::cerr << "available_services JSON error: " << value << std::endl;
46  }
47  }
48  }
49  catch (boost::property_tree::json_parser::json_parser_error & je) {
50  std::cerr << "available_services::handle_reply Error parsing: " << je.filename()
51  << " on line: " << je.line() << std::endl;
52  std::cerr << je.message() << std::endl;
53  }
54  delegate_(std::move(services));
55  }
57  std::function<void(std::vector<std::string> services)> delegate_;
58 };
59 }
60 }
61 #endif
std::string header_
Header that will be used.
void handle_reply(std::string json)
handle platform's JSON reply
Definition: user.hpp:32
available_services(const std::string token, std::function< void(std::vector< std::string >)> callback)
Definition: user.hpp:19
std::function< void(std::string)> callback_
Callback Handler - use with std::bind or boost variant.
void handle_reply(std::string json)
handle platform's JSON reply
base class for asynchronous http websockets used for connecting to cloud services ...
std::function< void(std::vector< std::string > services)> delegate_
Definition: user.hpp:57