1(*
2 * Copyright (C) 2006-2007 XenSource Ltd.
3 * Copyright (C) 2008      Citrix Ltd.
4 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; version 2.1 only. with the special
9 * exception on linking described in file LICENSE.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU Lesser General Public License for more details.
15 *)
16open Xenbus
17
18let data_concat ls = (String.concat "\000" ls) ^ "\000"
19let queue_path ty (tid: int) (path: string) con =
20	let data = data_concat [ path; ] in
21	Xb.queue con (Xb.Packet.create tid 0 ty data)
22
23(* operations *)
24let directory tid path con = queue_path Xb.Op.Directory tid path con
25let read tid path con = queue_path Xb.Op.Read tid path con
26
27let getperms tid path con = queue_path Xb.Op.Getperms tid path con
28
29let debug commands con =
30	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Debug (data_concat commands))
31
32let watch path data con =
33	let data = data_concat [ path; data; ] in
34	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Watch data)
35
36let unwatch path data con =
37	let data = data_concat [ path; data; ] in
38	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Unwatch data)
39
40let transaction_start con =
41	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Transaction_start (data_concat []))
42
43let transaction_end tid commit con =
44	let data = data_concat [ (if commit then "T" else "F"); ] in
45	Xb.queue con (Xb.Packet.create tid 0 Xb.Op.Transaction_end data)
46
47let introduce domid mfn port con =
48	let data = data_concat [ Printf.sprintf "%u" domid;
49	                         Printf.sprintf "%nu" mfn;
50	                         string_of_int port; ] in
51	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Introduce data)
52
53let release domid con =
54	let data = data_concat [ Printf.sprintf "%u" domid; ] in
55	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Release data)
56
57let resume domid con =
58	let data = data_concat [ Printf.sprintf "%u" domid; ] in
59	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Resume data)
60
61let getdomainpath domid con =
62	let data = data_concat [ Printf.sprintf "%u" domid; ] in
63	Xb.queue con (Xb.Packet.create 0 0 Xb.Op.Getdomainpath data)
64
65let write tid path value con =
66	let data = path ^ "\000" ^ value (* no NULL at the end *) in
67	Xb.queue con (Xb.Packet.create tid 0 Xb.Op.Write data)
68
69let mkdir tid path con = queue_path Xb.Op.Mkdir tid path con
70let rm tid path con = queue_path Xb.Op.Rm tid path con
71
72let setperms tid path perms con =
73	let data = data_concat [ path; perms ] in
74	Xb.queue con (Xb.Packet.create tid 0 Xb.Op.Setperms data)
75