Browse files

Add per-field descriptions on the struct definitions

  • Loading branch information...
1 parent 4e6e490 commit 9b2bac23e089a0468db6314332e034520c3248f8 David Scott committed Mar 5, 2012
Showing with 39 additions and 24 deletions.
  1. +4 −0 Makefile
  2. +3 −1 main.ml
  3. +13 −13 smapiv2.ml
  4. +19 −10 types.ml
View
4 Makefile
@@ -5,6 +5,10 @@ idl: types.cmx smapiv2.cmx xenops.cmx main.cmx
%.cmx: %.ml
ocamlfind ocamlopt -package xmlm,yojson,stdext -c $<
+.PHONY: install
+install: idl
+ ./idl
+
.PHONY: clean
clean:
rm -f *.cmx idl
View
4 main.ml
@@ -4,7 +4,9 @@ let with_file filename f =
let oc = open_out filename in
finally (fun () -> f oc) (fun () -> close_out oc)
-let print_file_to oc = Unixext.file_lines_iter (output_string oc)
+let print_file_to oc =
+ let output_line oc txt = output_string oc txt; output_string oc "\n" in
+ Unixext.file_lines_iter (output_line oc)
let _ =
(*
View
26 smapiv2.ml
@@ -3,19 +3,19 @@ open Types
let api =
let vdi_info =
Type.(Struct(
- ( "vdi", Basic String ),
- [ "sr", Basic String;
- "content_id", Basic String;
- "name_label", Basic String;
- "name_description", Basic String;
- "ty", Basic String;
- "metadata_of_pool", Basic String;
- "is_a_snapshot", Basic Boolean;
- "snapshot_time", Basic String;
- "snapshot_of", Basic String;
- "read_only", Basic Boolean;
- "virtual_size", Basic Int64;
- "physical_utilisation", Basic Int64;
+ ( "vdi", Basic String, "The unique id of this VDI" ),
+ [ "sr", Basic String, "The SR containing this VDI";
+ "content_id", Basic String, "The unique id of the VDI contents. If two VDIs have the same content_id then they must have the same data inside";
+ "name_label", Basic String, "Human-readable name of the VDI";
+ "name_description", Basic String, "Human-readable description of the VDI";
+ "ty", Basic String, "Used by a toolstack to remember why a VDI was created";
+ "metadata_of_pool", Basic String, "In the special case of a pool metadata containing VDI, this is the pool reference";
+ "is_a_snapshot", Basic Boolean, "True if the VDI is a snapshot of another VDI";
+ "snapshot_time", Basic String, "If is_a_snapshot is true then this is the time the snapshot was created";
+ "snapshot_of", Basic String, "If is_a_snapshot is true then this is the VDI which was snapshotted";
+ "read_only", Basic Boolean, "If true then this VDI is stored on read-only media";
+ "virtual_size", Basic Int64, "Size of the VDI from the perspective of a VM (in bytes)";
+ "physical_utilisation", Basic Int64, "Amount of space currently being consumed on the physical storage media";
]
)) in
let sr = {
View
29 types.ml
@@ -29,7 +29,7 @@ module Type = struct
type t =
| Basic of basic
- | Struct of (string * t) * ((string * t) list)
+ | Struct of (string * t * string) * ((string * t * string) list)
| Array of t
| Dict of basic * t
| Name of string
@@ -38,7 +38,9 @@ module Type = struct
let rec dbus_of_t env = function
| Basic b -> string_of_basic b
- | Struct ((_, h), tl) -> Printf.sprintf "(%s%s)" (dbus_of_t env h) (String.concat "" (List.map (dbus_of_t env) (List.map snd tl)))
+ | Struct (hd, tl) ->
+ let member (_, h, _) = dbus_of_t env h in
+ Printf.sprintf "(%s%s)" (member hd) (String.concat "" (List.map member tl))
| Array x -> Printf.sprintf "a%s" (dbus_of_t env x)
| Dict (k, v) -> Printf.sprintf "a{%s%s}" (string_of_basic k) (dbus_of_t env v)
| Name x ->
@@ -56,7 +58,7 @@ module Type = struct
let rec ocaml_of_t = function
| Basic b -> ocaml_of_basic b
| Struct (hd, tl) ->
- "{ " ^ (String.concat ";" (List.map (fun (name, ty) -> Printf.sprintf "%s: %s" name (ocaml_of_t ty)) (hd :: tl))) ^ " }"
+ "{ " ^ (String.concat ";" (List.map (fun (name, ty, descr) -> Printf.sprintf "%s: %s (** %s *)" name (ocaml_of_t ty) descr) (hd :: tl))) ^ " }"
| Array t -> ocaml_of_t t ^ " list"
| Dict (key, v) -> Printf.sprintf "(%s * %s) list" (ocaml_of_basic key) (ocaml_of_t v)
| Name x -> x
@@ -219,6 +221,7 @@ let with_xmlm f =
let buffer = Buffer.create 128 in
let output = Xmlm.make_output ~nl:true ~indent:(Some 4) (`Buffer buffer) in
Xmlm.output output (`Dtd None);
+ Buffer.reset buffer;
f (Xmlm.output output);
Buffer.contents buffer
@@ -229,6 +232,7 @@ let to_html x =
let buffer = Buffer.create 128 in
let output = Xmlm.make_output ~nl:true ~indent:(Some 4) (`Buffer buffer) in
Xmlm.output output (`Dtd None);
+ Buffer.reset buffer;
let wrap ?id name body =
let attrs = match id with
| None -> []
@@ -261,8 +265,11 @@ let to_html x =
let ul ?cls = wrapf ?cls "ul" in
let li ?cls = wrapf ?cls "li" in
let p = wrap "p" in
- let a_href link txt =
- Xmlm.output output (`El_start (("", "a"), [ ("", "href"), link ]));
+ let a_href ?toggle link txt =
+ let toggle = match toggle with
+ | None -> []
+ | Some x -> [ ("", "data-toggle"), x ] in
+ Xmlm.output output (`El_start (("", "a"), [ ("", "href"), link ] @ toggle));
Xmlm.output output (`Data txt);
Xmlm.output output (`El_end) in
@@ -282,24 +289,26 @@ let to_html x =
(* Side bar *)
Xmlm.output output (`El_start (("", "div"), [ ("", "class"), "span2" ]));
+ Xmlm.output output (`El_start (("", "div"), [ ("", "class"), "well sidebar-nav" ]));
ul ~cls:"nav nav-list" (fun () ->
List.iter (fun t ->
li (fun () ->
- a_href (Printf.sprintf "#a-%s" t.TyDecl.name) t.TyDecl.name
+ a_href (* ~toggle:"tab" *) (Printf.sprintf "#a-%s" t.TyDecl.name) t.TyDecl.name
)
) x.Interfaces.type_decls;
List.iter (fun i ->
li ~cls:"nav-header" (fun () ->
- a_href (Printf.sprintf "#a-%s" i.Interface.name) i.Interface.name
+ a_href (* ~toggle:"tab" *) (Printf.sprintf "#a-%s" i.Interface.name) i.Interface.name
);
List.iter (fun m ->
li (fun () ->
- a_href (Printf.sprintf "#a-%s" m.Method.name) m.Method.name
+ a_href (* ~toggle:"tab" *) (Printf.sprintf "#a-%s" m.Method.name) m.Method.name
)
) i.Interface.methods
) x.Interfaces.interfaces
);
Xmlm.output output (`El_end);
+ Xmlm.output output (`El_end);
(* Main content *)
Xmlm.output output (`El_start (("", "div"), [ ("", "class"), "span10" ]));
@@ -316,8 +325,8 @@ let to_html x =
th (fun () -> td "Type"; td "Description");
List.iter
- (fun (name, ty) ->
- tr (fun () -> tdcode name; tdcode (Type.ocaml_of_t ty); td "foo");
+ (fun (name, ty, descr) ->
+ tr (fun () -> tdcode name; tdcode (Type.ocaml_of_t ty); td descr);
) (hd :: tl);
Xmlm.output output (`El_end);
| _ -> ()

0 comments on commit 9b2bac2

Please sign in to comment.