Debian Codegraph @

examples/service/server.adb

raw
1 --
2 -- D_Bus/Ada - An Ada binding to D-Bus
3 --
4 -- Copyright (C) 2011 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 D_Bus.Messages;
30 with D_Bus.Arguments.Basic;
31
32 package body Server is
33
34 use D_Bus;
35
36 procedure Get_Name
37 (Request : Messages.Message_Type;
38 Reply : out Messages.Message_Type);
39 -- Get server name.
40
41 procedure Introspect
42 (Request : Messages.Message_Type;
43 Reply : out Messages.Message_Type);
44 -- Return introspection data of this service.
45
46 Intro_Spect : constant String :=
47 "<!DOCTYPE node PUBLIC ""-//freedesktop//DTD D-BUS Object " &
48 "Introspection 1.0//EN""" & ASCII.LF &
49 """http://www.freedesktop.org/standards/dbus/" &
50 "1.0/introspect.dtd"">" & ASCII.LF &
51 "<node>" & ASCII.LF &
52 " <interface name=""org.freedesktop.DBus.Introspectable"">" & ASCII.LF &
53 " <method name=""Introspect"">" & ASCII.LF &
54 " <arg name=""introspection_xml"" direction=""out"" type=""s""/>"
55 & ASCII.LF &
56 " </method>" & ASCII.LF &
57 " </interface>" & ASCII.LF &
58 " <interface name=""dbus.ada.service"">" & ASCII.LF &
59 " <method name=""GetName"">" & ASCII.LF &
60 " <arg name=""name"" direction=""out"" type=""s""/>" & ASCII.LF &
61 " </method>" & ASCII.LF &
62 " </interface>" & ASCII.LF &
63 "</node>";
64 -- Introspection data.
65
66 -------------------------------------------------------------------------
67
68 procedure Get_Name
69 (Request : Messages.Message_Type;
70 Reply : out Messages.Message_Type)
71 is
72 use D_Bus.Arguments.Basic;
73 begin
74 Reply := Messages.New_Method_Return (Method_Call => Request);
75 Messages.Add_Arguments (Msg => Reply,
76 Args => +"Lovelace");
77 end Get_Name;
78
79 -------------------------------------------------------------------------
80
81 procedure Initialize (Server : in out Server_Type)
82 is
83 begin
84 Server.Register (Name => "Introspect",
85 Method => Introspect'Access);
86 Server.Register (Name => "GetName",
87 Method => Get_Name'Access);
88 end Initialize;
89
90 -------------------------------------------------------------------------
91
92 procedure Introspect
93 (Request : Messages.Message_Type;
94 Reply : out Messages.Message_Type)
95 is
96 use D_Bus.Arguments.Basic;
97 begin
98 Reply := Messages.New_Method_Return (Method_Call => Request);
99 Messages.Add_Arguments (Msg => Reply,
100 Args => +Intro_Spect);
101 end Introspect;
102
103 end Server;