WIP: Clean up zx interface to external programs.

This commit is contained in:
Craig Everett 2020-01-10 12:37:21 +09:00
parent 7e0e4a798d
commit 6f5a829d43

View File

@ -31,10 +31,13 @@
-license("GPL-3.0").
-export([do/0, run/2, not_done/1, done/1]).
-export([subscribe/1, unsubscribe/0]).
-export([list/0, list/1, list/2, list/3, latest/1]).
-export([start/2, stop/1, stop/0, silent_stop/0]).
-export([do/0]).
-export([run/2, not_done/1, done/1,
subscribe/1, unsubscribe/0,
list/0, list/1, list/2, list/3, latest/1,
list_type/2, list_type_ar/2, describe/1, describe_plural/1,
stop/0, silent_stop/0]).
-export([start/2, stop/1]).
-export_type([serial/0, package_id/0, package/0, realm/0, name/0, version/0,
identifier/0,
@ -577,6 +580,54 @@ latest(PackageID) ->
zx_daemon:wait_result(ID).
-spec list_type(Realm, Type) -> Result
when Realm :: realm(),
Type :: package_type(),
Result :: {ok, [package_id()]}.
list_type(Realm, Type) ->
{ok, ID} = zx_daemon:list_type({Realm, Type}),
zx_daemon:wait_result(ID).
-spec list_type_ar(Type) -> Outcome
when Type :: package_type(),
Outcome :: {ok, [Result]}
| {error, Unexpected, [Result]}
| {error, Reason},
Result :: {id(), [package_id()]},
Unexpected :: {unexpected, {result, id(), term()}},
Reason :: bad_realm
| bad_package
| bad_version
| timeout
| network
| {unexpected, Message :: string()}.
%% @doc
%% List all packages from all realms that are of `Type'.
%% The "_ar" suffix to this function is short for "all realms".
list_type_ar(Targets) ->
Realms = zx_lib:list_realms(),
MakeRequest =
fun(Realm) ->
{ok, ID} = zx_daemon:list_type({Realm, Type}),
ID
end,
Index = [{MakeRequest(R), R} || R <- Realms],
IDs = [element(1, I) || I <- Index],
case zx_daemon:wait_results(IDs) of
{ok, Results} -> {ok, scrub_errors(lists:sort(Index), lists:sort(Results), [])};
Error -> Error
end.
-spec describe(Target) -> Result
when Target :: package_id(),
Result ::
%%% Execution of application