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.
20 #include <glib/gprintf.h>
22 #include "localed-gen.h"
24 GPtrArray
*localed_freeable
;
25 GDBusNodeInfo
*spect_data
;
26 localedLocale1
*localed_interf
;
28 /* begin method/property/signal code */
30 /* TODO make sure these guys only work if called by root */
34 on_handle_set_hostname(localedLocale1 *hn1_passed_interf,
35 GDBusMethodInvocation *invoc,
41 /* note: all localed/locale1's properties are read-only,
42 * and do not need set_ functions, gdbus-codegen realized
43 * this from the XML and handled the to-be error of trying
44 * to set a read-only property's value
55 /* end method/property/signal code, begin bus/name handlers */
57 static void localed_on_bus_acquired(GDBusConnection
*conn
,
61 g_print("got bus, name: %s\n", name
);
65 static void localed_on_name_acquired(GDBusConnection
*conn
,
69 g_print("got '%s' on system bus\n", name
);
71 localed_interf
= localed_locale1_skeleton_new();
73 /* attach function pointers to generated struct's method handlers */
74 /*g_signal_connect(localed_interf, "handle-set-hostname", G_CALLBACK(on_handle_set_hostname), NULL);
75 g_signal_connect(localed_interf, "handle-set-static-hostname", G_CALLBACK(on_handle_set_static_hostname), NULL);
76 g_signal_connect(localed_interf, "handle-set-pretty-hostname", G_CALLBACK(on_handle_set_pretty_hostname), NULL);
77 g_signal_connect(localed_interf, "handle-set-chassis", G_CALLBACK(on_handle_set_chassis), NULL);
78 g_signal_connect(localed_interf, "handle-set-icon-name", G_CALLBACK(on_handle_set_icon_name), NULL); */
80 /* set our properties before export */
81 /*localed_locale1_set_hostname(localed_interf, our_get_hostname());
82 localed_locale1_set_static_hostname(localed_interf, our_get_static_hostname());
83 localed_locale1_set_pretty_hostname(localed_interf, our_get_pretty_hostname());
84 localed_locale1_set_chassis(localed_interf, our_get_chassis());
85 localed_locale1_set_icon_name(localed_interf, our_get_icon_name());
86 localed_locale1_set_kernel_name(localed_interf, our_get_kernel_name());
87 localed_locale1_set_kernel_version(localed_interf, our_get_kernel_version());
88 localed_locale1_set_kernel_release(localed_interf, our_get_kernel_release());
89 localed_locale1_set_operating_system_cpename(localed_interf, our_get_os_cpename());
90 localed_locale1_set_operating_system_pretty_name(localed_interf, our_get_os_pretty_name()); */
92 if(!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(localed_interf
),
94 "/org/freedesktop/locale1",
97 g_printf("failed to export locale1's interface on system bus!");
103 void localed_mem_clean() {
105 g_ptr_array_foreach(localed_freeable
, (GFunc
) g_free
, NULL
);
108 static void localed_on_name_lost(GDBusConnection
*conn
,
110 gpointer user_data
) {
112 g_print("lost name %s, exiting...", name
);
115 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(localed_interf
));
117 /* TODO exit through g_main_loop properly... */
120 /* safe call to try and start localed */
121 void localed_init() {
123 guint bus_descriptor
;
125 gchar
**localed_ispect_xml
;
126 gchar
*localed_joined_xml
;
128 localed_freeable
= g_ptr_array_new();
129 localed_ispect_xml
= g_malloc(3000);
131 g_file_get_contents("conf/localed-ispect.xml", localed_ispect_xml
, NULL
, NULL
);
132 localed_joined_xml
= g_strjoinv("\n", localed_ispect_xml
);
133 spect_data
= g_dbus_node_info_new_for_xml(localed_joined_xml
, NULL
);
135 g_free(localed_ispect_xml
);
136 g_ptr_array_add(localed_freeable
, localed_joined_xml
);
138 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
139 "org.freedesktop.locale1",
140 G_BUS_NAME_OWNER_FLAGS_NONE
,
141 localed_on_bus_acquired
,
142 localed_on_name_acquired
,
143 localed_on_name_lost
,
147 /* TODO: malloc and return reference as if a main() closed */
152 GMainLoop
*localed_loop
;
153 localed_loop
= g_main_loop_new(NULL
, TRUE
);
155 /* config stuff here */
159 g_main_loop_run(localed_loop
);
160 g_main_loop_unref(localed_loop
);