| 1 |
(* |
| 2 |
* Copyright (C) 2006-2007 XenSource Ltd. |
| 3 |
* Copyright (C) 2008 Citrix Ltd. |
| 4 |
* Author Vincent Hanquez <[email protected]> |
| 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 |
*) |
| 16 |
|
| 17 |
type operation = Debug | Directory | Read | Getperms | |
| 18 |
Watch | Unwatch | Transaction_start | |
| 19 |
Transaction_end | Introduce | Release | |
| 20 |
Getdomainpath | Write | Mkdir | Rm | |
| 21 |
Setperms | Watchevent | Error | Isintroduced | |
| 22 |
Resume | Set_target | Reset_watches | |
| 23 |
Invalid |
| 24 |
|
| 25 |
let operation_c_mapping = |
| 26 |
[| Debug; Directory; Read; Getperms; |
| 27 |
Watch; Unwatch; Transaction_start; |
| 28 |
Transaction_end; Introduce; Release; |
| 29 |
Getdomainpath; Write; Mkdir; Rm; |
| 30 |
Setperms; Watchevent; Error; Isintroduced; |
| 31 |
Resume; Set_target; Invalid; Reset_watches |] |
| 32 |
let size = Array.length operation_c_mapping |
| 33 |
|
| 34 |
let array_search el a = |
| 35 |
let len = Array.length a in |
| 36 |
let rec search i = |
| 37 |
if i > len then raise Not_found; |
| 38 |
if a.(i) = el then i else search (i + 1) in |
| 39 |
search 0 |
| 40 |
|
| 41 |
let of_cval i = |
| 42 |
if i >= 0 && i < size |
| 43 |
then operation_c_mapping.(i) |
| 44 |
else Invalid |
| 45 |
|
| 46 |
let to_cval op = |
| 47 |
array_search op operation_c_mapping |
| 48 |
|
| 49 |
let to_string ty = |
| 50 |
match ty with |
| 51 |
| Debug -> "DEBUG" |
| 52 |
| Directory -> "DIRECTORY" |
| 53 |
| Read -> "READ" |
| 54 |
| Getperms -> "GET_PERMS" |
| 55 |
| Watch -> "WATCH" |
| 56 |
| Unwatch -> "UNWATCH" |
| 57 |
| Transaction_start -> "TRANSACTION_START" |
| 58 |
| Transaction_end -> "TRANSACTION_END" |
| 59 |
| Introduce -> "INTRODUCE" |
| 60 |
| Release -> "RELEASE" |
| 61 |
| Getdomainpath -> "GET_DOMAIN_PATH" |
| 62 |
| Write -> "WRITE" |
| 63 |
| Mkdir -> "MKDIR" |
| 64 |
| Rm -> "RM" |
| 65 |
| Setperms -> "SET_PERMS" |
| 66 |
| Watchevent -> "WATCH_EVENT" |
| 67 |
| Error -> "ERROR" |
| 68 |
| Isintroduced -> "IS_INTRODUCED" |
| 69 |
| Resume -> "RESUME" |
| 70 |
| Set_target -> "SET_TARGET" |
| 71 |
| Reset_watches -> "RESET_WATCHES" |
| 72 |
| Invalid -> "INVALID" |