Debian Codegraph @

examples/caller/list_names.adb

raw
1 --
2 -- D_Bus/Ada - An Ada binding to D-Bus
3 --
4 -- Copyright (C) 2011, 2012 Reto Buerki <[email protected]>
5 --
6 -- This program is free software; you can redistribute it and/or
7 -- modify it under the terms of the GNU General Public License
8 -- as published by the Free Software Foundation; either version 2
9 -- of the License, or (at your option) any later version.
10 --
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
15 --
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 -- USA.
20 --
21 -- As a special exception, if other files instantiate generics from this
22 -- unit, or you link this unit with other files to produce an
23 -- executable this unit does not by itself cause the resulting
24 -- executable to be covered by the GNU General Public License. This
25 -- exception does not however invalidate any other reasons why the
26 -- executable file might be covered by the GNU Public License.
27 --
28
29 with Ada.Text_IO;
30
31 with D_Bus.Types;
32 with D_Bus.Arguments.Basic;
33 with D_Bus.Arguments.Containers;
34 with D_Bus.Connection;
35
36 pragma Unreferenced (D_Bus.Arguments.Basic);
37 pragma Unreferenced (D_Bus.Arguments.Containers);
38
39 procedure List_Names
40 is
41 use D_Bus;
42 use type D_Bus.Types.Obj_Path;
43
44 -- Connect to the D-Bus session bus
45
46 Conn : constant Connection.Connection_Type := Connection.Connect;
47 Result : Arguments.Argument_List_Type;
48
49 procedure Print (Argument : Arguments.Argument_Type'Class);
50 -- Print out an argument.
51
52 procedure Print (Argument : Arguments.Argument_Type'Class)
53 is
54 begin
55 Ada.Text_IO.Set_Col (To => 1);
56 Ada.Text_IO.Put ("(" & Argument.Get_Code'Img & " )");
57 Ada.Text_IO.Set_Col (To => 10);
58 Ada.Text_IO.Put_Line (Argument.To_String);
59 end Print;
60
61 begin
62
63 -- Request a name on the bus
64
65 Connection.Request_Name
66 (Connection => Conn,
67 Name => "dbus.ada.caller");
68
69 -- Call a method on a remote object
70
71 Result := Connection.Call_Blocking
72 (Connection => Conn,
73 Destination => "org.freedesktop.DBus",
74 Path => +"/",
75 Iface => "org.freedesktop.DBus",
76 Method => "ListNames");
77 Ada.Text_IO.Put_Line ("Method called successfully:");
78
79 Arguments.Iterate (List => Result,
80 Process => Print'Access);
81 end List_Names;