aboutsummaryrefslogtreecommitdiffstats
path: root/src/json_helper.hpp
blob: 7d6e77ead5aa993cf584f52c4332a49620b6f149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef TMCAGLWM_JSON_HELPER_HPP
#define TMCAGLWM_JSON_HELPER_HPP

#include "result.hpp"
#include "wayland.hpp"
#include <json.hpp>

struct json_object;

json_object *to_json(genivi::screen const *s);
json_object *to_json(genivi::controller::props_map const &s);
json_object *to_json(std::vector<uint32_t> const &v);

// We ned to manually unwrap numbers
template <typename T>
wm::result<T> get(nlohmann::json const &j) {
   // DB(j);
   T r;
   std::istringstream s(j.get<std::string>());
   s >> r;
   return !s.eof() || s.fail() ? wm::Err<T>("Could not read int") : wm::Ok(r);
}

#endif  // TMCAGLWM_JSON_HELPER_HPP