package xenstore

  1. Overview
  2. Docs

Source file xs_handle.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(*
 * Copyright (C) Citrix Systems Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; version 2.1 only. with the special
 * exception on linking described in file LICENSE.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *)

module StringSet = Set.Make (struct
  type t = string

  let compare = compare
end)

type 'a t = {
    client : 'a
  ; tid : int32 (* transaction id in use (0 means no transaction) *)
  ; mutable accessed_paths : StringSet.t option (* paths read or written to *)
  ; mutable watched_paths : StringSet.t (* paths being watched *)
}

let make client =
  {
    client
  ; tid = 0l
  ; (* no transaction *)
    accessed_paths = None
  ; (* not recording accesses *)
    watched_paths = StringSet.empty (* no paths watched *)
  }

let get_tid h = h.tid
let get_client h = h.client
let no_transaction client = make client
let transaction client tid = { (make client) with tid }

let watching client =
  { (make client) with accessed_paths = Some StringSet.empty }

let accessed_path h path =
  match h.accessed_paths with
  | None -> h
  | Some ps ->
      h.accessed_paths <- Some (StringSet.add path ps);
      h

let get_accessed_paths h =
  match h.accessed_paths with None -> StringSet.empty | Some xs -> xs

let watch h path =
  h.watched_paths <- StringSet.add path h.watched_paths;
  h

let unwatch h path =
  h.watched_paths <- StringSet.remove path h.watched_paths;
  h

let get_watched_paths h = h.watched_paths
OCaml

Innovation. Community. Security.