diff options
author | Julien Puydt <jpuydt@debian.org> | 2022-10-14 09:02:49 +0200 |
---|---|---|
committer | Julien Puydt <jpuydt@debian.org> | 2022-10-14 09:02:49 +0200 |
commit | cc997a6ac46d5c8be431a622a06ef27487f82024 (patch) | |
tree | 07150d70c9e5cd71db106864d7b982f9ce20f65d /examples/list_services.ml |
Import obus_1.2.4.orig.tar.gz
[dgit import orig obus_1.2.4.orig.tar.gz]
Diffstat (limited to 'examples/list_services.ml')
-rw-r--r-- | examples/list_services.ml | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/list_services.ml b/examples/list_services.ml new file mode 100644 index 0000000..44b7da1 --- /dev/null +++ b/examples/list_services.ml @@ -0,0 +1,33 @@ +(* + * list_services.ml + * ---------------- + * Copyright : (c) 2008, Jeremie Dimino <jeremie@dimino.org> + * Licence : BSD3 + * + * This file is a part of obus, an ocaml implementation of D-Bus. + *) + +(* List services with their owner *) + +open Lwt +open Lwt_io + +let list name get_bus = + let%lwt () = printlf "service name mapping on %s bus:" name in + let%lwt bus = get_bus () in + + (* Get the list of all names on the session bus *) + let%lwt names = OBus_bus.list_names bus in + + Lwt_list.iter_p + (fun name -> + let%lwt owner = OBus_bus.get_name_owner bus name in + printlf " %s -> %s" owner name) + + (* Select only names which are not connection unique names *) + (List.filter (fun s -> s.[0] <> ':') names) + +let () = Lwt_main.run begin + let%lwt () = list "session" OBus_bus.session in + list "system" OBus_bus.system +end |