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 "localed-gen.h"
22 GPtrArray
*localed_freeable
;
23 GDBusNodeInfo
*spect_data
;
24 localedLocale1
*localed_interf
;
26 /* begin method/property/signal code */
28 /* TODO make sure these guys only work if called by root */
32 on_handle_set_hostname(localedLocale1 *hn1_passed_interf,
33 GDBusMethodInvocation *invoc,
39 /* note: all localed/locale1's properties are read-only,
40 * and do not need set_ functions, gdbus-codegen realized
41 * this from the XML and handled the to-be error of trying
42 * to set a read-only property's value
53 /* end method/property/signal code, begin bus/name handlers */
55 static void localed_on_bus_acquired(GDBusConnection
*conn
,
59 g_print("got bus, name: %s\n", name
);
63 static void localed_on_name_acquired(GDBusConnection
*conn
,
67 g_print("got '%s' on system bus\n", name
);
69 localed_interf
= localed_locale1_skeleton_new();
71 /* attach function pointers to generated struct's method handlers */
72 /*g_signal_connect(localed_interf, "handle-set-hostname", G_CALLBACK(on_handle_set_hostname), NULL);
73 g_signal_connect(localed_interf, "handle-set-static-hostname", G_CALLBACK(on_handle_set_static_hostname), NULL);
74 g_signal_connect(localed_interf, "handle-set-pretty-hostname", G_CALLBACK(on_handle_set_pretty_hostname), NULL);
75 g_signal_connect(localed_interf, "handle-set-chassis", G_CALLBACK(on_handle_set_chassis), NULL);
76 g_signal_connect(localed_interf, "handle-set-icon-name", G_CALLBACK(on_handle_set_icon_name), NULL); */
78 /* set our properties before export */
79 /*localed_locale1_set_hostname(localed_interf, our_get_hostname());
80 localed_locale1_set_static_hostname(localed_interf, our_get_static_hostname());
81 localed_locale1_set_pretty_hostname(localed_interf, our_get_pretty_hostname());
82 localed_locale1_set_chassis(localed_interf, our_get_chassis());
83 localed_locale1_set_icon_name(localed_interf, our_get_icon_name());
84 localed_locale1_set_kernel_name(localed_interf, our_get_kernel_name());
85 localed_locale1_set_kernel_version(localed_interf, our_get_kernel_version());
86 localed_locale1_set_kernel_release(localed_interf, our_get_kernel_release());
87 localed_locale1_set_operating_system_cpename(localed_interf, our_get_os_cpename());
88 localed_locale1_set_operating_system_pretty_name(localed_interf, our_get_os_pretty_name()); */
90 if(!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(localed_interf
),
92 "/org/freedesktop/locale1",
95 g_printf("failed to export locale1's interface on system bus!");
101 void localed_mem_clean() {
103 g_ptr_array_foreach(localed_freeable
, (GFunc
) g_free
, NULL
);
106 static void localed_on_name_lost(GDBusConnection
*conn
,
108 gpointer user_data
) {
110 g_print("lost name %s, exiting...", name
);
113 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(localed_interf
));
115 /* TODO exit through g_main_loop properly... */
118 /* safe call to try and start localed */
119 void localed_init() {
121 guint bus_descriptor
;
123 gchar
**localed_ispect_xml
;
124 gchar
*localed_joined_xml
;
126 localed_freeable
= g_ptr_array_new();
127 localed_ispect_xml
= g_malloc(3000);
129 g_file_get_contents("conf/localed-ispect.xml", localed_ispect_xml
, NULL
, NULL
);
130 localed_joined_xml
= g_strjoinv("\n", localed_ispect_xml
);
131 spect_data
= g_dbus_node_info_new_for_xml(localed_joined_xml
, NULL
);
133 g_free(localed_ispect_xml
);
134 g_ptr_array_add(localed_freeable
, localed_joined_xml
);
136 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
137 "org.freedesktop.locale1",
138 G_BUS_NAME_OWNER_FLAGS_NONE
,
139 localed_on_bus_acquired
,
140 localed_on_name_acquired
,
141 localed_on_name_lost
,
145 /* TODO: malloc and return reference as if a main() closed */
150 GMainLoop
*localed_loop
;
151 localed_loop
= g_main_loop_new(NULL
, TRUE
);
153 /* config stuff here */
157 g_main_loop_run(localed_loop
);
158 g_main_loop_unref(localed_loop
);