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 void handle_method_call(GDBusConnection
*conn
,
91 const gchar
*obj_path
,
92 const gchar
*interf_name
,
93 const gchar
*method_name
,
95 GDBusMethodInvocation
*invc
,
98 g_printf("%s wants to call %s, at %s with interface %s\n", sender
, method_name
, obj_path
, interf_name
);
100 g_dbus_method_invocation_return_value(invc
, &spect_xml
);
105 static GVariant
* handle_get_property(GDBusConnection
*conn
,
107 const gchar
*obj_path
,
108 const gchar
*interf_name
,
109 const gchar
*prop_name
,
114 ret
= g_variant_new_string("");
115 g_snprintf(ret
, 100, "%s touched property %s at %s", sender
, prop_name
, obj_path
);
120 static gboolean
handle_set_property(GDBusConnection
*conn
,
122 const gchar
*obj_path
,
123 const gchar
*interf_name
,
124 const gchar
*prop_name
,
128 g_dbus_connection_emit_signal(conn
,
131 "org.freedesktop.DBus.Properties",
133 NULL
, /* incorrect */
139 static const GDBusInterfaceVTable interface_vtable
=
148 static void on_bus_acquired(GDBusConnection
*conn
, const gchar
*name
, gpointer user_data
) {
149 g_print("got bus, name: %s\n", name
);
153 reg_id
= g_dbus_connection_register_object (conn
,
154 "/org/freedesktop/hostname1",
155 spect_data
->interfaces
[0],
160 g_assert(reg_id
> 0);
163 static void on_name_acquired(GDBusConnection
*conn
, const gchar
*name
, gpointer user_data
) {
164 g_print("got name %s\n", name
);
167 static void on_name_lost(GDBusConnection
*conn
, const gchar
*name
, gpointer user_data
) {
168 g_print("lost name %s, exiting...\n", name
);
172 void hostnamed_init() {
174 guint bus_descriptor
;
178 spect_data
= g_dbus_node_info_new_for_xml(spect_xml
, NULL
);
180 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SESSION
,
181 (gchar
*)"org.freedesktop.hostname1",
182 G_BUS_NAME_OWNER_FLAGS_NONE
,
189 loop
= g_main_loop_new(NULL
, FALSE
);
190 g_main_loop_run(loop
);
194 g_bus_unown_name(bus_descriptor
);
195 g_dbus_node_info_unref(spect_data
);