Shift X2 status from legacy to archived
[khatus.git] / ocaml / lib / khatus_msg.ml
1 module Time = Khatus_time
2
3 type content =
4 | Alert of {priority : [`low | `med | `hi]; subject : string; body : string}
5 | Data of {key : string list; value : string}
6 | Cache of
7 { mtime : Time.t
8 ; node : string
9 ; modul : string
10 ; key : string list
11 ; value : string
12 }
13 | Error of string
14 | Log of {location : string; level : [`info | `error]; msg : string}
15 | Status_bar of string
16
17 type t =
18 {node : string; modul : string; content : content}
19
20 type 'a data_handler =
21 node:string -> modul:string -> key:string list -> value:string -> 'a
22
23 let sep_1 = "|"
24 let sep_2 = ":"
25
26 let to_string {node; modul; content} =
27 match content with
28 | Alert {priority; subject; body} ->
29 let priority =
30 match priority with
31 | `hi -> "hi"
32 | `med -> "med"
33 | `low -> "low"
34 in
35 String.concat sep_1 [node; modul; "alert"; priority; subject; body]
36 | Data {key; value} ->
37 let key = String.concat sep_2 key in
38 String.concat sep_1 [node; modul; "data"; key; value]
39 | Cache {mtime; node=node'; modul=modul'; key; value} ->
40 let key = String.concat sep_2 key in
41 let mtime = Time.to_string mtime in
42 String.concat
43 sep_1
44 [node; modul; "cache"; mtime; node'; modul'; key; value]
45 | Error text ->
46 String.concat sep_1 [node; modul; "error"; text]
47 | Log {location; level; msg} ->
48 let level =
49 match level with
50 | `info -> "info"
51 | `error -> "error"
52 in
53 String.concat sep_1 [node; modul; "log"; location; level; msg]
54 | Status_bar text ->
55 String.concat sep_1 [node; modul; "status_bar"; text]
56
57 let handle_data t ~f ~otherwise =
58 match t with
59 | {content = Data {key; value}; node; modul} ->
60 f ~node ~modul ~key ~value
61 | {content = Alert _; _}
62 | {content = Cache _; _}
63 | {content = Error _; _}
64 | {content = Log _; _}
65 | {content = Status_bar _; _}
66 ->
67 otherwise
This page took 0.058229 seconds and 4 git commands to generate.