File: pong.ml

package info (click to toggle)
obus 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,480 kB
  • sloc: ml: 14,675; lisp: 52; makefile: 11; xml: 8
file content (39 lines) | stat: -rw-r--r-- 861 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(*
 * pong.ml
 * -------
 * Copyright : (c) 2008, Jeremie Dimino <jeremie@dimino.org>
 * Licence   : BSD3
 *
 * This file is a part of obus, an ocaml implementation of D-Bus.
 *)

(* Very simple service with one object have a ping method *)

open Lwt
open Lwt_io

let ping obj msg =
  let%lwt () = printlf "received: %s" msg in
  return msg

let interface =
  Ping_pong.Org_foo_bar.make {
    Ping_pong.Org_foo_bar.m_Ping = (fun obj msg -> ping (OBus_object.get obj) msg);
  }

let () = Lwt_main.run begin
  let%lwt bus = OBus_bus.session () in

  (* Request a name *)
  let%lwt _ = OBus_bus.request_name bus "org.plop" in

  (* Create the object *)
  let obj = OBus_object.make ~interfaces:[interface] ["plip"] in
  OBus_object.attach obj ();

  (* Export the object on the connection *)
  OBus_object.export bus obj;

  (* Wait forever *)
  fst (wait ())
end