2008-12-04 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / droute / introspect-loader.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Codethink Ltd.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library 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 GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <glib.h>
24
25 /*
26  * This file contains utilities for loading introspection XML
27  * from the local file system.
28  *
29  * There is an installation directory with files containing introspection xml.
30  * Each file is named after the interface it describes.
31  */
32
33 /*
34  * Provides the path for the introspection directory.
35  */
36 #if !defined ATSPI_INTROSPECTION_PATH
37     #error "No introspection XML directory defined"
38 #endif
39
40 const char *spi_introspection_header =
41 "<?xml version=\"1.0\"?>\n";
42
43 const char *spi_introspection_node_element =
44 "<node name=\"%s\">\n";
45
46 const char *spi_introspection_footer =
47 "</node>";
48
49 void
50 spi_append_interface (GString *str, const char *interface)
51 {
52   char *filename;
53   char *contents;
54   char *introspection_directory;
55   gsize len;
56
57   GError *err = NULL;
58
59   introspection_directory = (char *) g_getenv("ATSPI_INTROSPECTION_PATH");
60   if (introspection_directory == NULL)
61       introspection_directory = ATSPI_INTROSPECTION_PATH;
62
63   filename = g_build_filename(introspection_directory, interface, NULL);
64
65   if (g_file_get_contents(filename, &contents, &len, &err))
66     {
67       g_string_append_len(str, contents, len);
68     }
69   else
70     {
71       g_warning("AT-SPI: Cannot find introspection XML file %s - %s",
72                 filename, err->message);
73       g_error_free(err);
74     }
75
76   g_string_append(str, "\n");
77   g_free(filename);
78   g_free(contents);
79 }