OSSIA
Open Scenario System for Interactive Application
json_writer.hpp
1 #pragma once
2 #include <ossia/detail/for_each.hpp>
4 #include <ossia/network/oscquery/detail/json_writer_detail.hpp>
5 
6 namespace ossia
7 {
8 namespace net
9 {
10 class network_logger;
11 }
12 namespace oscquery
13 {
14 class oscquery_server_protocol;
16 class OSSIA_EXPORT json_writer
17 {
18 public:
19  // Initialisation
20  using string_t = rapidjson::StringBuffer;
21  using writer_t = ossia::json_writer;
22 
24  static string_t device_info(int port);
25 
26  static string_t query_host_info(
27  const std::string& name, const int osc_port, const std::string& local_ip,
28  int ws_port);
29 
30  // Format interface
31  // Queries
33  static string_t query_namespace(const ossia::net::node_base& node);
34 
36  template <typename StringVec_T>
37  static string_t
38  query_attributes(const ossia::net::node_base& node, const StringVec_T& methods)
39  {
40  string_t buf;
41  writer_t wr(buf);
42 
44 
45  // Here we just write the attributes in the object directly
46  wr.StartObject();
47  for(auto& method : methods)
48  {
49  // Here we reply to the query which already has
50  // the key in the "oscquery" format so no need to convert
51  write_json_key(wr, method);
52  p.writeAttribute(node, method);
53  }
54  wr.EndObject();
55 
56  return buf;
57  }
58 
59  // Listen messages
60  static string_t listen(std::string_view address);
61  static string_t ignore(std::string_view address);
62 
63  // Extensions
64  static string_t start_osc_streaming(int local_server_port, int local_sender_port);
65 
66  // Update messages
68  static string_t path_added(const ossia::net::node_base& n);
69 
71  static string_t path_changed(const ossia::net::node_base& n);
72 
74  static string_t path_removed(const std::string& path);
75 
77  static string_t path_renamed(const std::string& old_path, const std::string& new_path);
78 
79  static string_t
80  attributes_changed(const ossia::net::node_base& n, std::string_view attribute);
81 
82  static string_t attributes_changed(
83  const ossia::net::node_base& n, const std::vector<std::string_view>& attributes);
84 
85  static string_t paths_added(const std::vector<const ossia::net::node_base*>& vec);
86 
87  static string_t paths_changed(const std::vector<const ossia::net::node_base*>& vec);
88 
89  static string_t paths_removed(const std::vector<std::string>& vec);
90 
91  static string_t attributes_changed_array(
92  const std::vector<
93  std::pair<const ossia::net::node_base*, std::vector<std::string_view>>>& vec);
94 
95 private:
96  static void
97  path_added_impl(detail::json_writer_impl& p, const ossia::net::node_base& n);
98  static void
99  path_changed_impl(detail::json_writer_impl& p, const ossia::net::node_base& n);
100  static void path_removed_impl(writer_t& wr, const std::string& path);
101  static void path_renamed_impl(
102  json_writer::writer_t& wr, const std::string& path, const std::string& old);
103  static void attribute_changed_impl(
105  std::string_view attribute);
106  static void attributes_changed_impl(
108  const std::vector<std::string_view>& attributes);
109 };
110 
111 }
112 }
The node_base class.
Definition: network/base/node.hpp:48
Creates the JSON message to send through OSCQuery.
Definition: json_writer.hpp:17
static string_t query_attributes(const ossia::net::node_base &node, const StringVec_T &methods)
Reply to a query of attributes : /foo/bar?VALUE&RANGE.
Definition: json_writer.hpp:38
Definition: git_info.h:7
Implementation of the JSON serialisation mechanism for oscquery.
Definition: json_writer_detail.hpp:8