Skip to content

Commit

Permalink
dune fmt with profile = ocamlformat
Browse files Browse the repository at this point in the history
  • Loading branch information
yfyf committed Nov 25, 2024
1 parent 0ec213d commit 2c5996e
Show file tree
Hide file tree
Showing 60 changed files with 1,425 additions and 1,489 deletions.
287 changes: 137 additions & 150 deletions controller/bindings/connman/connman.ml

Large diffs are not rendered by default.

107 changes: 55 additions & 52 deletions controller/bindings/connman/connman.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ module Technology : sig
Note that not all properties are encoded.
*)
type t = {
_proxy : (OBus_proxy.t[@sexp.opaque]);
name : string;
type' : type';
powered : bool;
connected : bool;
}
type t =
{ _proxy: (OBus_proxy.t[@sexp.opaque])
; name: string
; type': type'
; powered: bool
; connected: bool
}
[@@deriving sexp, protocol ~driver:(module Jsonm)]

(** Enable a technology *)
Expand Down Expand Up @@ -72,50 +72,50 @@ module Service : sig

(** IPv4 properties *)
module IPv4 : sig
type t = {
method' : string;
address : string;
netmask : string;
gateway : string option;
}
type t =
{ method': string
; address: string
; netmask: string
; gateway: string option
}
[@@deriving sexp, protocol ~driver:(module Jsonm)]
end

(** IPv6 properties *)
module IPv6 : sig
type t = {
method' : string;
address : string;
prefix_length : int;
gateway : string option;
privacy : string;
}
type t =
{ method': string
; address: string
; prefix_length: int
; gateway: string option
; privacy: string
}
[@@deriving sexp, protocol ~driver:(module Jsonm)]
end

(** Ethernet properties *)
module Ethernet : sig
type t = {
method' : string;
interface : string;
address : string;
mtu : int;
}
type t =
{ method': string
; interface: string
; address: string
; mtu: int
}
[@@deriving sexp, protocol ~driver:(module Jsonm)]
end

module Proxy : sig
type credentials = {
user : string;
password : (string[@sexp.opaque]);
}
type credentials =
{ user: string
; password: (string[@sexp.opaque])
}
[@@deriving sexp, protocol ~driver:(module Jsonm)]

type t = {
host : string;
port : int;
credentials : credentials option;
}
type t =
{ host: string
; port: int
; credentials: credentials option
}
[@@deriving sexp, protocol ~driver:(module Jsonm)]

(** [validate str] returns [t] if [str] is valid.
Expand Down Expand Up @@ -143,36 +143,39 @@ module Service : sig
Note that not all properties are encoded.
*)
type t = {
_proxy : (OBus_proxy.t[@sexp.opaque]);
_manager : (OBus_proxy.t[@sexp.opaque]);
id : string;
name : string;
type' : Technology.type';
security : security list;
state : state;
strength : int option;
favorite : bool;
autoconnect : bool;
ipv4 : IPv4.t option;
ipv6 : IPv6.t option;
ethernet : Ethernet.t;
proxy : Proxy.t option;
nameservers : string list;
}
type t =
{ _proxy: (OBus_proxy.t[@sexp.opaque])
; _manager: (OBus_proxy.t[@sexp.opaque])
; id: string
; name: string
; type': Technology.type'
; security: security list
; state: state
; strength: int option
; favorite: bool
; autoconnect: bool
; ipv4: IPv4.t option
; ipv6: IPv6.t option
; ethernet: Ethernet.t
; proxy: Proxy.t option
; nameservers: string list
}
[@@deriving sexp, protocol ~driver:(module Jsonm)]

(** Helper to decide if service is connected *)
val is_connected : t -> bool

val set_direct_proxy : t -> unit Lwt.t

val set_manual_proxy : t -> Proxy.t -> unit Lwt.t

val set_manual_ipv4 :
t -> address:string -> netmask:string -> gateway:string -> unit Lwt.t

val set_dhcp_ipv4 : t -> unit Lwt.t

val set_nameservers : t -> string list -> unit Lwt.t

val connect : ?input:Agent.input -> t -> unit Lwt.t

(** Disconnect service. *)
Expand Down
57 changes: 28 additions & 29 deletions controller/bindings/curl/curl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,47 +49,46 @@ let http_code_marker = '|'

let parse_status_code_and_body str =
let open Base.Option in
Base.String.rsplit2 ~on:http_code_marker str >>= fun (body, code_str) ->
Base.String.rsplit2 ~on:http_code_marker str
>>= fun (body, code_str) ->
safe_int_of_string code_str >>= fun code -> return (code, body)

let request ?proxy ?(headers = []) ?data ?(options = []) url =
let cmd =
( "",
(* path to Curl executable (uses PATH if empty string) *)
( ""
, (* path to Curl executable (uses PATH if empty string) *)
Array.concat
[
[|
"curl";
Uri.to_string url;
"--silent";
"--show-error";
"--write-out";
Char.escaped http_code_marker ^ "%{http_code}";
|];
( match proxy with
| Some p -> [| "--proxy"; Uri.to_string p; "--proxy-anyauth" |]
[ [| "curl"
; Uri.to_string url
; "--silent"
; "--show-error"
; "--write-out"
; Char.escaped http_code_marker ^ "%{http_code}"
|]
; ( match proxy with
| Some p -> [|"--proxy"; Uri.to_string p; "--proxy-anyauth"|]
| None -> [||]
);
headers
|> List.map (fun (k, v) -> [| "--header"; k ^ ":" ^ v |])
|> Array.concat;
( match data with
| Some d -> [| "--data"; d |]
)
; headers
|> List.map (fun (k, v) -> [|"--header"; k ^ ":" ^ v|])
|> Array.concat
; ( match data with
| Some d -> [|"--data"; d|]
| None -> [||]
);
Base.List.to_array options;
)
; Base.List.to_array options
]
)
in
match%lwt Lwt_result.catch (fun () -> exec cmd) with
| Ok (Unix.WEXITED 0, stdout, _) -> (
match parse_status_code_and_body stdout with
| Some (code, body) ->
if Cohttp.Code.is_success code then
Lwt.return (RequestSuccess (code, body))
else Lwt.return (RequestFailure (UnsuccessfulStatus (code, body)))
| None -> Lwt.return (RequestFailure (UnreadableStatus stdout))
)
match parse_status_code_and_body stdout with
| Some (code, body) ->
if Cohttp.Code.is_success code then
Lwt.return (RequestSuccess (code, body))
else Lwt.return (RequestFailure (UnsuccessfulStatus (code, body)))
| None -> Lwt.return (RequestFailure (UnreadableStatus stdout))
)
| Ok (Unix.WEXITED n, _, stderr) ->
Lwt.return (RequestFailure (ProcessExit (n, stderr)))
| Ok (Unix.WSIGNALED signal, _, _stderr) ->
Expand Down
12 changes: 6 additions & 6 deletions controller/bindings/curl/curl.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type result =
val pretty_print_error : error -> string

val request :
?proxy:Uri.t ->
?headers:(string * string) list ->
?data:string ->
?options:string list ->
Uri.t ->
result Lwt.t
?proxy:Uri.t
-> ?headers:(string * string) list
-> ?data:string
-> ?options:string list
-> Uri.t
-> result Lwt.t
3 changes: 3 additions & 0 deletions controller/bindings/locale/locale.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
val get_lang : unit -> string option Lwt.t

val set_lang : string -> unit Lwt.t

val get_keymap : unit -> string option Lwt.t

val set_keymap : string -> unit Lwt.t
70 changes: 40 additions & 30 deletions controller/bindings/rauc/rauc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ module Slot = struct
| SystemA -> "system.a"
| SystemB -> "system.b"

type status = {
device : string;
class' : string;
state : string;
version : string;
installed_timestamp : string;
}
type status =
{ device: string
; class': string
; state: string
; version: string
; installed_timestamp: string
}
[@@deriving sexp]
end

Expand All @@ -58,12 +58,13 @@ let mark_slot daemon slot status =
else Lwt.fail_with "Wrong slot marked."

let mark_good daemon slot = mark_slot daemon slot "good"

let mark_active daemon slot = mark_slot daemon slot "active"

type status = {
a : Slot.status;
b : Slot.status;
}
type status =
{ a: Slot.status
; b: Slot.status
}
[@@deriving sexp]

let json_of_status status = status |> sexp_of_status |> Ezjsonm.t_of_sexp
Expand All @@ -77,22 +78,20 @@ let slot_status_of_obus (o : (string * OBus_value.V.single) list) : Slot.status
| Some (Basic (String s)) -> s
| _ -> failwith (Format.sprintf "could not get string from field %s" key)
in
{
device = get_string "device" o;
class' = get_string "class" o;
state = get_string "state" o;
version = get_string "bundle.version" o;
installed_timestamp = get_string "installed.timestamp" o;
{ device= get_string "device" o
; class'= get_string "class" o
; state= get_string "state" o
; version= get_string "bundle.version" o
; installed_timestamp= get_string "installed.timestamp" o
}

let get_status daemon =
let%lwt status_assoc =
OBus_method.call De_pengutronix_rauc_Installer.m_GetSlotStatus
(proxy daemon) ()
in
{
a = slot_status_of_obus (List.assoc "system.a" status_assoc);
b = slot_status_of_obus (List.assoc "system.b" status_assoc);
{ a= slot_status_of_obus (List.assoc "system.a" status_assoc)
; b= slot_status_of_obus (List.assoc "system.b" status_assoc)
}
|> return

Expand Down Expand Up @@ -128,38 +127,46 @@ let install daemon source =
(* Auto generated with obus-gen-client *)
module De_pengutronix_rauc_Installer : sig
val install : OBus_proxy.t -> source:string -> unit Lwt.t

val info : OBus_proxy.t -> bundle:string -> (string * string) Lwt.t

val mark :
OBus_proxy.t ->
state:string ->
slot_identifier:string ->
(string * string) Lwt.t
OBus_proxy.t
-> state:string
-> slot_identifier:string
-> (string * string) Lwt.t

val get_slot_status :
OBus_proxy.t -> (string * (string * OBus_value.V.single) list) list Lwt.t

val get_primary : OBus_proxy.t -> string Lwt.t

val completed : OBus_proxy.t -> int OBus_signal.t
val operation : OBus_proxy.t -> (string, [ `readable ]) OBus_property.t
val last_error : OBus_proxy.t -> (string, [ `readable ]) OBus_property.t

val operation : OBus_proxy.t -> (string, [`readable]) OBus_property.t

val last_error : OBus_proxy.t -> (string, [`readable]) OBus_property.t

val progress :
OBus_proxy.t -> (int * string * int, [ `readable ]) OBus_property.t
OBus_proxy.t -> (int * string * int, [`readable]) OBus_property.t

val compatible : OBus_proxy.t -> (string, [ `readable ]) OBus_property.t
val variant : OBus_proxy.t -> (string, [ `readable ]) OBus_property.t
val boot_slot : OBus_proxy.t -> (string, [ `readable ]) OBus_property.t
val compatible : OBus_proxy.t -> (string, [`readable]) OBus_property.t

val variant : OBus_proxy.t -> (string, [`readable]) OBus_property.t

val boot_slot : OBus_proxy.t -> (string, [`readable]) OBus_property.t
end = struct
open De_pengutronix_rauc_Installer

let install proxy ~source = OBus_method.call m_Install proxy source

let info proxy ~bundle = OBus_method.call m_Info proxy bundle

let mark proxy ~state ~slot_identifier =
OBus_method.call m_Mark proxy (state, slot_identifier)

let get_slot_status proxy = OBus_method.call m_GetSlotStatus proxy ()

let get_primary proxy = OBus_method.call m_GetPrimary proxy ()

let completed proxy =
Expand All @@ -171,6 +178,7 @@ end = struct
(OBus_signal.make s_Completed proxy)

let operation proxy = OBus_property.make p_Operation proxy

let last_error proxy = OBus_property.make p_LastError proxy

let progress proxy =
Expand All @@ -179,6 +187,8 @@ end = struct
(OBus_property.make p_Progress proxy)

let compatible proxy = OBus_property.make p_Compatible proxy

let variant proxy = OBus_property.make p_Variant proxy

let boot_slot proxy = OBus_property.make p_BootSlot proxy
end
Loading

0 comments on commit 2c5996e

Please sign in to comment.