==> include/mesh/top_views.h <==1/* @ajax/mesh-top-views: the fleet's views as meshd serves them (`view fleet|jobs|pipes` on the
2 * control port; the same records as http /fleet, /jobs, /pipes): one record a line,
3 * `kind key=value .. [-- free text]`, `-` for none (crates/mesh-top src/views.rs). */
4#ifndef MESH_TOP_VIEWS_H
5#define MESH_TOP_VIEWS_H
6
7#include "mesh/top_clock.h"
8
9#include <stdbool.h>
10#include <stddef.h>
11#include <stdint.h>
12
13typedef struct {
14 char *key, *value;
15} mt_kv;
16
17typedef struct {
18 char *kind;
19 mt_kv *kv;
20 size_t nkv;
21 char *text;
22} mt_vrec;
23
24/* A field's value; NULL when absent or "-". */
25const char *mt_vrec_get(const mt_vrec *r, const char *k);
26/* The value, or "-". */
27const char *mt_vrec_s(const mt_vrec *r, const char *k);
28bool mt_vrec_u(const mt_vrec *r, const char *k, uint64_t *out); /* Rust's u64::from_str */
29bool mt_vrec_f(const mt_vrec *r, const char *k, double *out); /* Rust's f64::from_str */
30bool mt_vrec_flag(const mt_vrec *r, const char *k); /* "1" */
31/* A member list ("0,2"); returns the count written (at most cap). */
32size_t mt_vrec_list(const mt_vrec *r, const char *k, uint32_t *out, size_t cap);
33
34typedef struct {
35 size_t machine;
36 mt_instant at;
37 mt_vrec *recs;
38 size_t n;
39 char *err; /* NULL unless the reply was "err ..." */
40} mt_view;
41
42/* Parses text (blank lines skipped). Free with mt_vrecs_free. */
43size_t mt_views_parse(const char *text, mt_vrec **out);
44void mt_vrecs_free(mt_vrec *r, size_t n);
45mt_view mt_view_new(size_t machine, mt_instant at, const char *text);
46void mt_view_free(mt_view *v);
47const mt_vrec *mt_view_first(const mt_view *v, const char *kind);
48/* The i-th record of a kind, or NULL. */
49const mt_vrec *mt_view_nth(const mt_view *v, const char *kind, size_t i);
50size_t mt_view_count(const mt_view *v, const char *kind);
51/* Rust's f64::from_str / u64::from_str on a whole string. */
52bool mt_parse_f64(const char *s, double *out);
53bool mt_parse_u64(const char *s, uint64_t *out);
54
55#endif