(1) updated ispect xml to reflect recent undocumented changes in hostnamed
[systembsd.git] / src / interfaces / hostnamed / hostnamed.c
index 522d750959eadf90b853d641b74c299b422232f4..dff5115875f1e03b1ab01e5f07655aa6e9be8404 100644 (file)
 
 GPtrArray *hostnamed_freeable;
 GDBusNodeInfo *spect_data;
+Hostname1 *hostnamed_interf;
+
+static gboolean
+on_handle_set_hostname(Hostname1 *hn1_passed_interf,
+                       GDBusMethodInvocation *invoc,
+                       const gchar *greet,
+                       gpointer data) {
+    return FALSE;
+}
+
+static gboolean
+on_handle_set_static_hostname(Hostname1 *hn1_passed_interf,
+                              GDBusMethodInvocation *invoc,
+                              const gchar *greet,
+                              gpointer data) {
+    return FALSE;
+}
+
+static gboolean
+on_handle_set_pretty_hostname(Hostname1 *hn1_passed_interf,
+                              GDBusMethodInvocation *invoc,
+                              const gchar *greet,
+                              gpointer data) {
+    return FALSE;
+}
+
+static gboolean
+on_handle_set_chassis(Hostname1 *hn1_passed_interf,
+                      GDBusMethodInvocation *invoc,
+                      const gchar *greet,
+                      gpointer data) {
+    return FALSE;
+}
+
+static gboolean
+on_handle_set_icon_name(Hostname1 *hn1_passed_interf,
+                        GDBusMethodInvocation *invoc,
+                        const gchar *greet,
+                        gpointer data) {
+    return FALSE;
+}
+
+/* end method/property/signal code, begin bus/name handlers */
 
 static void on_bus_acquired(GDBusConnection *conn,
                             const gchar *name,
                             gpointer user_data) {
 
-    GError *err;
-
     g_print("got bus, name: %s\n", name);   
 
 }
@@ -40,7 +81,25 @@ static void on_name_acquired(GDBusConnection *conn,
                              const gchar *name,
                              gpointer user_data) {
 
-    g_print("got name %s\n", name);
+    g_print("got '%s' on system bus\n", name);
+
+    hostnamed_interf = hostname1_skeleton_new();
+
+    /* attach function pointers to generated vfunc table struct */
+    g_signal_connect(hostnamed_interf, "handle-set-hostname", G_CALLBACK(on_handle_set_hostname), NULL);
+    g_signal_connect(hostnamed_interf, "handle-set-static-hostname", G_CALLBACK(on_handle_set_static_hostname), NULL);
+    g_signal_connect(hostnamed_interf, "handle-set-pretty-hostname", G_CALLBACK(on_handle_set_pretty_hostname), NULL);
+    g_signal_connect(hostnamed_interf, "handle-set-chassis", G_CALLBACK(on_handle_set_chassis), NULL);
+    g_signal_connect(hostnamed_interf, "handle-set-icon-name", G_CALLBACK(on_handle_set_icon_name), NULL);
+
+    if(!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(hostnamed_interf),
+                                                                   conn,
+                                                                   "/org/freedesktop/hostname1",
+                                                                   NULL)) {
+
+        g_printf("failed to export hostname1's interface on system bus!");
+    }
+
 }
 
 static void on_name_lost(GDBusConnection *conn,
@@ -50,8 +109,9 @@ static void on_name_lost(GDBusConnection *conn,
     g_print("lost name %s, exiting...", name);
 
     hostnamed_mem_clean();
+    g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(hostnamed_interf));
 
-    //TODO exit through g_main_loop properly...
+    /* TODO exit through g_main_loop properly... */
 }
 
 /* safe call to try and start hostnamed */
@@ -81,7 +141,7 @@ GError *hostnamed_init() {
                                     NULL,
                                     NULL);
 
-    //TODO: malloc and return reference as if a main() closed 
+    /* TODO: malloc and return reference as if a main() closed */
     return err;
 }
 
@@ -91,14 +151,12 @@ void hostnamed_mem_clean() {
     g_ptr_array_foreach(hostnamed_freeable, (GFunc) g_free, NULL);
 }
 
-//TODO figure out DMI variables on obsd
+/* TODO figure out DMI variables on obsd */
 /*static gchar *guess_icon_name() {
 
     gchar *filebuf = NULL;
     gchar *ret = NULL;
 
-    //TODO vm check
-
     #if defined(__i386__) || defined(__x86_64__)
     
        Taken with a few minor changes from systemd's hostnamed.c,