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