Skip to content

Commit

Permalink
Dump the IDL output in JSON format
Browse files Browse the repository at this point in the history
  • Loading branch information
David Scott committed Feb 21, 2012
1 parent 3bd4032 commit 514f4e3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

idl: types.cmx
ocamlfind ocamlopt -package xmlm -linkpkg -o idl types.cmx
ocamlfind ocamlopt -package xmlm,yojson -linkpkg -o idl types.cmx

%.cmx: %.ml
ocamlfind ocamlopt -package xmlm -c $<
ocamlfind ocamlopt -package xmlm,yojson -c $<

.PHONY: clean
clean:
Expand Down
33 changes: 32 additions & 1 deletion types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ module Interfaces = struct
}
end

let to_json x =
let of_arg_list args =
`Assoc (List.map (fun (name, ty) -> name, `String (Type.string_of_t ty)) args) in
let of_interface i =
`Assoc [
"name", `String i.Interface.name;
"description", `String i.Interface.description;
"methods",
`List (List.map
(fun m ->
`Assoc [
"name", `String m.Method.name;
"inputs", of_arg_list m.Method.inputs;
"outputs", of_arg_list m.Method.outputs;
]
) i.Interface.methods)
] in
let of_interfaces i =
`Assoc [
"name", `String i.Interfaces.name;
"description", `String i.Interfaces.description;
"interfaces", `List (List.map of_interface i.Interfaces.interfaces)
] in
let json = of_interfaces x in
Yojson.Basic.to_string json


let to_dbus_xml x =
let open Xmlm in
let buffer = Buffer.create 128 in
Expand Down Expand Up @@ -171,4 +198,8 @@ let smapiv2 =
}

let _ =
print_string (to_dbus_xml smapiv2)
print_string (to_dbus_xml smapiv2);
print_string "";
print_string "\n";
print_string "";
print_string (to_json smapiv2);

0 comments on commit 514f4e3

Please sign in to comment.