4 GDBusNodeInfo
*spect_data
;
6 static void handle_method_call(GDBusConnection
*conn
,
9 const gchar
*interf_name
,
10 const gchar
*method_name
,
12 GDBusMethodInvocation
*invc
,
15 //g_printf("%s wants to call %s, at %s with interface %s\n", sender, method_name, obj_path, interf_name);
17 if(g_strcmp0(method_name
, "Introspect"
19 GVariant
*xml_ret_gvar
;
22 g_dbus_interface_info_generate_xml(spect_data
->interfaces
[0], (guint
)0, xml_ret
);
23 xml_ret_gvar
= g_variant_new_string(xml_ret
->str
);
24 g_dbus_method_invocation_return_value(invc
, xml_ret_gvar
);
28 static GVariant
* handle_get_property(GDBusConnection
*conn
,
30 const gchar
*obj_path
,
31 const gchar
*interf_name
,
32 const gchar
*prop_name
,
41 static gboolean
handle_set_property(GDBusConnection
*conn
,
43 const gchar
*obj_path
,
44 const gchar
*interf_name
,
45 const gchar
*prop_name
,
50 g_dbus_connection_emit_signal(conn
,
53 "org.freedesktop.DBus.Properties",
61 /* "hot" functions initially passed to gdbus */
62 static const GDBusInterfaceVTable interface_vtable
=
69 /* end method/property functions, begin bus name handlers
70 * TODO: these should be intertwined as to handle edge cases
71 * for when the system cannot immediately grab the name, as
72 * well as cases where the system unintendedly loses the name
74 static void on_bus_acquired(GDBusConnection
*conn
,
77 g_print("got bus, name: %s\n", name
);
81 reg_id
= g_dbus_connection_register_object(conn
,
82 "/org/freedesktop/hostname1",
83 spect_data
->interfaces
[0],
90 static void on_name_acquired(GDBusConnection
*conn
,
94 g_print("got name %s\n", name
);
97 static void on_name_lost(GDBusConnection
*conn
,
101 g_print("lost name %s, exiting...\n", name
);
102 //g_print("you might need to run hacks/punch_config.sh\n");
103 g_main_loop_quit(loop
);
106 /* safe call to try and start hostnamed */
107 GError
* hostnamed_init() {
109 guint bus_descriptor
;
112 spect_data
= g_dbus_node_info_new_for_xml(SYSTEMD_HOSTNAMED_XML
, &err
);
113 bus_descriptor
= g_bus_own_name(G_BUS_TYPE_SYSTEM
,
114 (gchar
*)"org.freedesktop.hostname1",
115 G_BUS_NAME_OWNER_FLAGS_NONE
,
122 loop
= g_main_loop_new(NULL
, FALSE
);
123 g_main_loop_run(loop
);
125 //TODO: malloc and return reference as if a main() closed