From 6f5a829d43d5d0814d3189f1d40d0f5254cdf431 Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Fri, 10 Jan 2020 12:37:21 +0900 Subject: [PATCH] WIP: Clean up zx interface to external programs. --- zomp/lib/otpr/zx/0.7.2/src/zx.erl | 59 ++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/zomp/lib/otpr/zx/0.7.2/src/zx.erl b/zomp/lib/otpr/zx/0.7.2/src/zx.erl index 85a57ab..784fb29 100644 --- a/zomp/lib/otpr/zx/0.7.2/src/zx.erl +++ b/zomp/lib/otpr/zx/0.7.2/src/zx.erl @@ -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