4 static GDBusNodeInfo
*spect_data
= NULL
;
5 static const gchar spect_xml
[] =
7 " <interface name='org.freedesktop.DBus.Peer'>"
8 " <method name='Ping'/>"
9 " <method name='GetMachineId'>"
10 " <arg type='s' name='machine_uuid' direction='out'/>"
13 " <interface name='org.freedesktop.DBus.Introspectable'>"
14 " <method name='Introspect'>"
15 " <arg name='data' type='s' direction='out'/>"
18 " <interface name='org.freedesktop.DBus.Properties'>"
19 " <method name='Get'>"
20 " <arg name='interface' direction='in' type='s'/>"
21 " <arg name='property' direction='in' type='s'/>"
22 " <arg name='value' direction='out' type='v'/>"
24 " <method name='GetAll'>"
25 " <arg name='interface' direction='in' type='s'/>"
26 " <arg name='properties' direction='out' type='a{sv}'/>"
28 " <method name='Set'>"
29 " <arg name='interface' direction='in' type='s'/>"
30 " <arg name='property' direction='in' type='s'/>"
31 " <arg name='value' direction='in' type='v'/>"
33 " <signal name='PropertiesChanged'>"
34 " <arg type='s' name='interface'/>"
35 " <arg type='a{sv}' name='changed_properties'/>"
36 " <arg type='as' name='invalidated_properties'/>"
39 " <interface name='org.freedesktop.hostname1'>"
40 " <property name='Hostname' type='s' access='read'>"
41 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='false'/>"
43 " <property name='StaticHostname' type='s' access='read'>"
45 " <property name='PrettyHostname' type='s' access='read'>"
47 " <property name='IconName' type='s' access='read'>"
49 " <property name='Chassis' type='s' access='read'>"
51 " <property name='KernelName' type='s' access='read'>"
52 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
54 " <property name='KernelRelease' type='s' access='read'>"
55 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
57 " <property name='KernelVersion' type='s' access='read'>"
58 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
60 " <property name='OperatingSystemPrettyName' type='s' access='read'>"
61 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
63 " <property name='OperatingSystemCPEName' type='s' access='read'>"
64 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
66 " <method name='SetHostname'>"
67 " <arg type='s' direction='in'/>"
68 " <arg type='b' direction='in'/>"
70 " <method name='SetStaticHostname'>"
71 " <arg type='s' direction='in'/>"
72 " <arg type='b' direction='in'/>"
74 " <method name='SetPrettyHostname'>"
75 " <arg type='s' direction='in'/>"
76 " <arg type='b' direction='in'/>"
78 " <method name='SetIconName'>"
79 " <arg type='s' direction='in'/>"
80 " <arg type='b' direction='in'/>"
82 " <method name='SetChassis'>"
83 " <arg type='s' direction='in'/>"
84 " <arg type='b' direction='in'/>"
89 static const GDBusInterfaceVTable interface_vtable
=
96 static void handle_method_call(GDBusConnection
*conn
,
98 const gchar
*obj_path
,
99 const gchar
*interf_name
,
100 const gchar
*method_name
,
102 GDBusMethodInvocation
*invc
,
105 g_printf("%s wants to call %s, at %s with interface %s\n", sender
, method_name
, obj_path
, interf_name
);
107 g_dbus_method_invocation_return_value(invc
, &spect_xml
);
112 static GVariant
* handle_get_property(GDBusConnection
*conn
,
114 const gchar
*obj_path
,
115 const gchar
*interf_name
,
116 const gchar
*prop_name
,
121 ret
= g_variant_new_string("");
122 g_snprintf(ret
, 100, "%s touched property %s at %s", sender
, prop_name
, obj_path
);
127 static gboolean
handle_set_property(GDBusConnection
*conn
,
129 const gchar
*obj_path
,
130 const gchar
*interf_name
,
131 const gchar
*prop_name
,
135 g_dbus_connection_emit_signal(conn
,
138 "org.freedesktop.DBus.Properties",
140 NULL
, /* incorrect */
146 /* end method/property functions, begin bus name handlers
147 * TODO: these should be intertwined as to handle edge cases
148 * for when the system cannot immediately grab the name, as
149 * well as cases where the system unintendedly loses the name
153 static void on_bus_acquired(GDBusConnection
*conn
, const gchar
*name
, gpointer user_data
) {
154 g_print("got bus, name: %s\n", name
);
158 reg_id
= g_dbus_connection_register_object (conn
,
159 "/org/freedesktop/hostname1",
160 spect_data
->interfaces
[0],
165 g_assert(reg_id
> 0);
168 static void on_name_acquired(GDBusConnection
*conn
, const gchar
*name
, gpointer user_data
) {
169 g_print("got name %s\n", name
);
172 static void on_name_lost(GDBusConnection
*conn
, const gchar
*name
, gpointer user_data
) {
173 g_print("lost name %s, exiting...\n", name
);
177 /* safe call to try and start hostnamed */
178 GError
hostnamed_init() {
180 guint bus_descriptor
;
184 /* TODO: there is a correct way to generate introspection XML, switch to that */
185 spect_data
= g_dbus_node_info_new_for_xml(spect_xml
, NULL
);
187 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SESSION
,
188 (gchar
*)"org.freedesktop.hostname1",
189 G_BUS_NAME_OWNER_FLAGS_NONE
,
196 loop
= g_main_loop_new(NULL
, FALSE
);
197 g_main_loop_run(loop
);
199 /* i am not sure what the system state is once g_main_loop exits */
201 g_bus_unown_name(bus_descriptor
);
202 g_dbus_node_info_unref(spect_data
);