Debian Codegraph @

examples/notify/notify.adb

raw
1 --
2 -- D_Bus/Ada - Example program which does desktop notification on Linux
3 --
4 -- Copyright (C) 2011, 2012 Reto Buerki <[email protected]>
5 -- Copyright (C) 2011 Tero Koskinen <[email protected]>
6 --
7 -- This program is free software; you can redistribute it and/or
8 -- modify it under the terms of the GNU General Public License
9 -- as published by the Free Software Foundation; either version 2
10 -- of the License, or (at your option) any later version.
11 --
12 -- This program is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with this program; if not, write to the Free Software
19 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 -- USA.
21 --
22 -- As a special exception, if other files instantiate generics from this
23 -- unit, or you link this unit with other files to produce an
24 -- executable this unit does not by itself cause the resulting
25 -- executable to be covered by the GNU General Public License. This
26 -- exception does not however invalidate any other reasons why the
27 -- executable file might be covered by the GNU Public License.
28 --
29
30 with Ada.Text_IO;
31
32 with D_Bus.Types;
33 with D_Bus.Arguments.Basic;
34 with D_Bus.Arguments.Containers;
35 with D_Bus.Connection;
36
37 procedure Notify
38 is
39 use D_Bus;
40 use D_Bus.Arguments.Basic;
41 use D_Bus.Arguments.Containers;
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 Nil_Array : Arguments.Containers.Array_Type;
49 begin
50
51 -- Workaround for 'cannot serialize empty array' problem
52
53 Nil_Array.Append (+"");
54
55 -- Request a name on the bus
56
57 Connection.Request_Name
58 (Connection => Conn,
59 Name => "notify.example");
60
61 -- Call a method on a remote object
62
63 Result := Connection.Call_Blocking
64 (Connection => Conn,
65 Destination => "org.freedesktop.Notifications",
66 Path => +"/org/freedesktop/Notifications",
67 Iface => "org.freedesktop.Notifications",
68 Method => "Notify",
69 Args => +"ada.notify" & Unsigned_32'(0) & "" & "Hello"
70 & "Hello, World from Ada!" & Nil_Array & Nil_Array & Signed_32'(-1));
71
72 Ada.Text_IO.Put ("Notify successful with ID ");
73 Ada.Text_IO.Put_Line (U_Int32_Type (Result.First_Element).To_String);
74 end Notify;