2 * Copyright (c) 2014 Ian Sutton <ian@kremlin.cc>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include "localed-gen.c"
26 GPtrArray
*localed_freeable
;
27 GDBusNodeInfo
*spect_data
;
28 localedLocale1
*localed_interf
;
30 /* begin method/property/signal code */
32 /* TODO make sure these guys only work if called by root */
36 on_handle_set_hostname(localedLocale1 *hn1_passed_interf,
37 GDBusMethodInvocation *invoc,
43 /* note: all localed/locale1's properties are read-only,
44 * and do not need set_ functions, gdbus-codegen realized
45 * this from the XML and handled the to-be error of trying
46 * to set a read-only property's value
57 /* end method/property/signal code, begin bus/name handlers */
59 static void localed_on_bus_acquired(GDBusConnection
*conn
,
63 g_print("got bus, name: %s\n", name
);
67 static void localed_on_name_acquired(GDBusConnection
*conn
,
71 g_print("got '%s' on system bus\n", name
);
73 localed_interf
= localed_locale1_skeleton_new();
75 /* attach function pointers to generated struct's method handlers */
76 /*g_signal_connect(localed_interf, "handle-set-hostname", G_CALLBACK(on_handle_set_hostname), NULL);
77 g_signal_connect(localed_interf, "handle-set-static-hostname", G_CALLBACK(on_handle_set_static_hostname), NULL);
78 g_signal_connect(localed_interf, "handle-set-pretty-hostname", G_CALLBACK(on_handle_set_pretty_hostname), NULL);
79 g_signal_connect(localed_interf, "handle-set-chassis", G_CALLBACK(on_handle_set_chassis), NULL);
80 g_signal_connect(localed_interf, "handle-set-icon-name", G_CALLBACK(on_handle_set_icon_name), NULL); */
82 /* set our properties before export */
83 /*localed_locale1_set_hostname(localed_interf, our_get_hostname());
84 localed_locale1_set_static_hostname(localed_interf, our_get_static_hostname());
85 localed_locale1_set_pretty_hostname(localed_interf, our_get_pretty_hostname());
86 localed_locale1_set_chassis(localed_interf, our_get_chassis());
87 localed_locale1_set_icon_name(localed_interf, our_get_icon_name());
88 localed_locale1_set_kernel_name(localed_interf, our_get_kernel_name());
89 localed_locale1_set_kernel_version(localed_interf, our_get_kernel_version());
90 localed_locale1_set_kernel_release(localed_interf, our_get_kernel_release());
91 localed_locale1_set_operating_system_cpename(localed_interf, our_get_os_cpename());
92 localed_locale1_set_operating_system_pretty_name(localed_interf, our_get_os_pretty_name()); */
94 if(!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(localed_interf
),
96 "/org/freedesktop/locale1",
99 g_printf("failed to export locale1's interface on system bus!");
104 static void localed_on_name_lost(GDBusConnection
*conn
,
106 gpointer user_data
) {
108 g_print("lost name %s, exiting...", name
);
111 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(localed_interf
));
113 /* TODO exit through g_main_loop properly... */
116 /* safe call to try and start localed */
117 void localed_init() {
119 guint bus_descriptor
;
121 gchar
**localed_ispect_xml
;
122 gchar
*localed_joined_xml
;
124 localed_freeable
= g_ptr_array_new();
125 localed_ispect_xml
= g_malloc(3000);
127 g_file_get_contents("conf/localed-ispect.xml", localed_ispect_xml
, NULL
, NULL
);
128 localed_joined_xml
= g_strjoinv("\n", localed_ispect_xml
);
129 spect_data
= g_dbus_node_info_new_for_xml(localed_joined_xml
, NULL
);
131 g_free(localed_ispect_xml
);
132 g_ptr_array_add(localed_freeable
, localed_joined_xml
);
134 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
135 "org.freedesktop.locale1",
136 G_BUS_NAME_OWNER_FLAGS_NONE
,
137 localed_on_bus_acquired
,
138 localed_on_name_acquired
,
139 localed_on_name_lost
,
143 /* TODO: malloc and return reference as if a main() closed */
147 void localed_mem_clean() {
149 g_ptr_array_foreach(localed_freeable
, (GFunc
) g_free
, NULL
);
152 /* TODO figure out DMI variables on obsd */
153 /*static gchar *guess_icon_name() {
155 gchar *filebuf = NULL;
158 #if defined(__i386__) || defined(__x86_64__)
160 Taken with a few minor changes from systemd's localed.c,
161 copyright 2011 Lennart Poettering.
163 See the SMBIOS Specification 2.7.1 section 7.4.1 for
164 details about the values listed here:
166 http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
169 if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
170 switch (g_ascii_strtoull (filebuf, NULL, 10)) {
176 ret = g_strdup ("computer-desktop");
181 ret = g_strdup ("computer-laptop");
187 ret = g_strdup ("computer-server");
192 ret = g_strdup ("computer");