5 GDBusNodeInfo
*spect_data
;
7 static void handle_method_call(GDBusConnection
*conn
,
10 const gchar
*interf_name
,
11 const gchar
*method_name
,
13 GDBusMethodInvocation
*invc
,
16 //g_printf("%s wants to call %s, at %s with interface %s\n", sender, method_name, obj_path, interf_name);
18 if(g_strcmp0(method_name
, "Introspect"
20 GVariant
*xml_ret_gvar
;
23 g_dbus_interface_info_generate_xml(spect_data
->interfaces
[0], (guint
)0, xml_ret
);
24 xml_ret_gvar
= g_variant_new_string(xml_ret
->str
);
25 g_dbus_method_invocation_return_value(invc
, xml_ret_gvar
);
29 static GVariant
* handle_get_property(GDBusConnection
*conn
,
31 const gchar
*obj_path
,
32 const gchar
*interf_name
,
33 const gchar
*prop_name
,
42 static gboolean
handle_set_property(GDBusConnection
*conn
,
44 const gchar
*obj_path
,
45 const gchar
*interf_name
,
46 const gchar
*prop_name
,
51 g_dbus_connection_emit_signal(conn
,
54 "org.freedesktop.DBus.Properties",
62 /* "hot" functions initially passed to gdbus */
63 static const GDBusInterfaceVTable interface_vtable
=
70 /* end method/property functions, begin bus name handlers
71 * TODO: these should be intertwined as to handle edge cases
72 * for when the system cannot immediately grab the name, as
73 * well as cases where the system unintendedly loses the name
75 static void on_bus_acquired(GDBusConnection
*conn
,
78 g_print("got bus, name: %s\n", name
);
82 reg_id
= g_dbus_connection_register_object(conn
,
83 "/org/freedesktop/hostname1",
84 spect_data
->interfaces
[0],
91 static void on_name_acquired(GDBusConnection
*conn
,
95 g_print("got name %s\n", name
);
98 static void on_name_lost(GDBusConnection
*conn
,
100 gpointer user_data
) {
102 g_print("lost name %s, exiting...\n", name
);
103 //g_print("you might need to run hacks/punch_config.sh\n");
104 g_main_loop_quit(loop
);
107 /* safe call to try and start hostnamed */
108 GError
* hostnamed_init() {
110 guint bus_descriptor
;
113 spect_data
= g_dbus_node_info_new_for_xml(SYSTEMD_HOSTNAMED_XML
, &err
);
114 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
115 (gchar
*)"org.freedesktop.hostname1",
116 G_BUS_NAME_OWNER_FLAGS_NONE
,
123 loop
= g_main_loop_new(NULL
, FALSE
);
124 g_main_loop_run(loop
);
126 //TODO: malloc and return reference as if a main() closed