[glib/wip/kdbus-junk] some sort of actual progress here...



commit 80fbe0b5b7eeb3b5aa8990252f94ef58ed185e7f
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Dec 15 08:00:56 2014 -0500

    some sort of actual progress here...

 gio/gdbusaddress.c    |   14 +++++----
 gio/gdbusconnection.c |   51 ++++++++++++++++++++++-------------
 gio/gdbusnameowning.c |   27 +++++++-----------
 gio/gdbusprivate.c    |    6 ++--
 gio/gdbusprivate.h    |    9 ++----
 gio/gkdbus.c          |   70 +++++++++++++++++++++++++++++++++++-------------
 gio/gkdbus.h          |    4 +--
 gio/kdbus.h           |   23 +++++++++++++---
 8 files changed, 128 insertions(+), 76 deletions(-)
---
diff --git a/gio/gdbusaddress.c b/gio/gdbusaddress.c
index 0b79208..d82a09a 100644
--- a/gio/gdbusaddress.c
+++ b/gio/gdbusaddress.c
@@ -554,7 +554,7 @@ g_dbus_address_connect (const gchar   *address_entry,
     {
     }
 #ifdef G_OS_UNIX
-  else if (kdbus_okay || g_str_equal (transport_name, "kernel"))
+  else if (kdbus_okay && g_str_equal (transport_name, "kernel"))
     {
       GKDBusWorker *worker;
       const gchar *path;
@@ -567,13 +567,15 @@ g_dbus_address_connect (const gchar   *address_entry,
                        _("Error in address '%s' - the kernel transport requires a path"),
                        address_entry);
         }
+      else
+        {
+          worker = g_kdbus_worker_new (path, error);
 
-      worker = g_kdbus_worker_new (path, error);
-
-      if (worker == NULL)
-        return NULL;
+          if (worker == NULL)
+            return NULL;
 
-      return G_OBJECT (worker);
+          return G_OBJECT (worker);
+        }
     }
   else if (g_strcmp0 (transport_name, "unix") == 0)
     {
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c
index 354764e..da706bc 100644
--- a/gio/gdbusconnection.c
+++ b/gio/gdbusconnection.c
@@ -1162,8 +1162,12 @@ g_dbus_connection_start_message_processing (GDBusConnection *connection)
   if (!check_initialized (connection))
     return;
 
-  g_assert (connection->worker != NULL);
-  _g_dbus_worker_unfreeze (connection->worker);
+  g_assert (connection->worker || connection->kdbus_worker);
+
+  if (connection->kdbus_worker)
+    g_kdbus_worker_unfreeze (connection->kdbus_worker);
+  else
+    _g_dbus_worker_unfreeze (connection->worker);
 }
 
 /**
@@ -2754,8 +2758,7 @@ typedef struct
 
 /* Called in GDBusWorker's thread - we must not block - with no lock held */
 static void
-on_worker_message_received (GDBusWorker  *worker,
-                            GDBusMessage *message,
+on_worker_message_received (GDBusMessage *message,
                             gpointer      user_data)
 {
   GDBusConnection *connection;
@@ -2856,8 +2859,7 @@ on_worker_message_received (GDBusWorker  *worker,
 
 /* Called in GDBusWorker's thread, lock is not held */
 static GDBusMessage *
-on_worker_message_about_to_be_sent (GDBusWorker  *worker,
-                                    GDBusMessage *message,
+on_worker_message_about_to_be_sent (GDBusMessage *message,
                                     gpointer      user_data)
 {
   GDBusConnection *connection;
@@ -2933,10 +2935,9 @@ cancel_method_on_close (gpointer key, gpointer value, gpointer user_data)
 
 /* Called in GDBusWorker's thread - we must not block - without lock held */
 static void
-on_worker_closed (GDBusWorker *worker,
-                  gboolean     remote_peer_vanished,
-                  GError      *error,
-                  gpointer     user_data)
+on_worker_closed (gboolean  remote_peer_vanished,
+                  GError   *error,
+                  gpointer  user_data)
 {
   GDBusConnection *connection;
   gboolean alive;
@@ -2998,6 +2999,7 @@ initable_init (GInitable     *initable,
                GError       **error)
 {
   GDBusConnection *connection = G_DBUS_CONNECTION (initable);
+  gboolean initially_frozen;
   gboolean ret;
 
   /* This method needs to be idempotent to work with the singleton
@@ -3052,7 +3054,6 @@ initable_init (GInitable     *initable,
       ret = g_dbus_address_get_stream_internal (connection->address, TRUE,
                                                 NULL, /* TODO: out_guid */
                                                 cancellable, &connection->initialization_error);
-
       if (ret == NULL)
         goto out;
 
@@ -3138,14 +3139,23 @@ authenticated:
   g_hash_table_insert (alive_connections, connection, connection);
   G_UNLOCK (message_bus_lock);
 
-  if (!connection->kdbus_worker)
-  connection->worker = _g_dbus_worker_new (connection->stream,
-                                           connection->capabilities,
-                                           ((connection->flags & 
G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING) != 0),
-                                           on_worker_message_received,
-                                           on_worker_message_about_to_be_sent,
-                                           on_worker_closed,
-                                           connection);
+  initially_frozen = (connection->flags & G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING) != 0;
+
+  if (connection->kdbus_worker)
+   g_kdbus_worker_associate (connection->kdbus_worker,
+                             connection->capabilities,
+                             on_worker_message_received,
+                             on_worker_message_about_to_be_sent,
+                             on_worker_closed,
+                             connection);
+  else
+    connection->worker = _g_dbus_worker_new (connection->stream,
+                                             connection->capabilities,
+                                             initially_frozen,
+                                             on_worker_message_received,
+                                             on_worker_message_about_to_be_sent,
+                                             on_worker_closed,
+                                             connection);
 
   /* if a bus connection, call org.freedesktop.DBus.Hello - this is how we're getting a name */
   if (connection->flags & G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION)
@@ -3189,6 +3199,9 @@ authenticated:
       //g_debug ("unique name is '%s'", connection->bus_unique_name);
     }
 
+  if (connection->kdbus_worker && !initially_frozen)
+    g_kdbus_worker_unfreeze (connection->kdbus_worker);
+
   ret = TRUE;
  out:
   if (!ret)
diff --git a/gio/gdbusnameowning.c b/gio/gdbusnameowning.c
index 5314f0a..aa7b110 100644
--- a/gio/gdbusnameowning.c
+++ b/gio/gdbusnameowning.c
@@ -436,28 +436,20 @@ has_connection (Client *client)
                                                              "closed",
                                                              G_CALLBACK (on_connection_disconnected),
                                                              client);
-#if 0
   /* attempt to acquire the name */
-  if (G_IS_KDBUS_CONNECTION (g_dbus_connection_get_stream (client->connection)))
+  if (1)
     {
-      GVariant *result;
+      GError *error = NULL;
       guint32 request_name_reply;
 
       request_name_reply = 0;
-      result = NULL;
 
-      result = _g_kdbus_RequestName (client->connection, client->name, client->flags, NULL);
-
-      if (result != NULL)
-        {
-          g_variant_get (result, "(u)", &request_name_reply);
-          g_variant_unref (result);
-        }
+      request_name_reply = g_dbus_request_name (client->connection, client->name, client->flags, &error);
+      g_assert_no_error (error);
 
       process_request_name_reply (client, request_name_reply);
     }
   else
-#endif
     {
       g_dbus_connection_call (client->connection,
                               "org.freedesktop.DBus",  /* bus name */
@@ -945,11 +937,14 @@ g_bus_unown_name (guint owner_id)
            * I believe this is a bug in the bus daemon.
            */
           error = NULL;
-#if 0
-          if (G_IS_KDBUS_CONNECTION (g_dbus_connection_get_stream (client->connection)))
-            result = _g_kdbus_ReleaseName (client->connection, client->name, &error);
+          if (1)
+            {
+              g_dbus_release_name (client->connection, client->name, &error);
+              g_assert_no_error (error);
+
+              result = g_variant_ref_sink (g_variant_new_uint32 (1));
+            }
           else
-#endif
             result = g_dbus_connection_call_sync (client->connection,
                                                   "org.freedesktop.DBus",  /* bus name */
                                                   "/org/freedesktop/DBus", /* object path */
diff --git a/gio/gdbusprivate.c b/gio/gdbusprivate.c
index 54659c1..730ee3f 100644
--- a/gio/gdbusprivate.c
+++ b/gio/gdbusprivate.c
@@ -477,7 +477,7 @@ _g_dbus_worker_emit_disconnected (GDBusWorker  *worker,
                                   GError       *error)
 {
   if (!g_atomic_int_get (&worker->stopped))
-    worker->disconnected_callback (worker, remote_peer_vanished, error, worker->user_data);
+    worker->disconnected_callback (remote_peer_vanished, error, worker->user_data);
 }
 
 static void
@@ -485,7 +485,7 @@ _g_dbus_worker_emit_message_received (GDBusWorker  *worker,
                                       GDBusMessage *message)
 {
   if (!g_atomic_int_get (&worker->stopped))
-    worker->message_received_callback (worker, message, worker->user_data);
+    worker->message_received_callback (message, worker->user_data);
 }
 
 static GDBusMessage *
@@ -494,7 +494,7 @@ _g_dbus_worker_emit_message_about_to_be_sent (GDBusWorker  *worker,
 {
   GDBusMessage *ret;
   if (!g_atomic_int_get (&worker->stopped))
-    ret = worker->message_about_to_be_sent_callback (worker, message, worker->user_data);
+    ret = worker->message_about_to_be_sent_callback (message, worker->user_data);
   else
     ret = message;
   return ret;
diff --git a/gio/gdbusprivate.h b/gio/gdbusprivate.h
index bbebb79..094891e 100644
--- a/gio/gdbusprivate.h
+++ b/gio/gdbusprivate.h
@@ -33,16 +33,13 @@ G_BEGIN_DECLS
 
 typedef struct GDBusWorker GDBusWorker;
 
-typedef void (*GDBusWorkerMessageReceivedCallback) (GDBusWorker   *worker,
-                                                    GDBusMessage  *message,
+typedef void (*GDBusWorkerMessageReceivedCallback) (GDBusMessage  *message,
                                                     gpointer       user_data);
 
-typedef GDBusMessage *(*GDBusWorkerMessageAboutToBeSentCallback) (GDBusWorker   *worker,
-                                                                  GDBusMessage  *message,
+typedef GDBusMessage *(*GDBusWorkerMessageAboutToBeSentCallback) (GDBusMessage  *message,
                                                                   gpointer       user_data);
 
-typedef void (*GDBusWorkerDisconnectedCallback)    (GDBusWorker   *worker,
-                                                    gboolean       remote_peer_vanished,
+typedef void (*GDBusWorkerDisconnectedCallback)    (gboolean       remote_peer_vanished,
                                                     GError        *error,
                                                     gpointer       user_data);
 
diff --git a/gio/gkdbus.c b/gio/gkdbus.c
index b8fcf7c..95fe311 100644
--- a/gio/gkdbus.c
+++ b/gio/gkdbus.c
@@ -120,6 +120,12 @@ struct _GKDBusWorker
   guint              timed_out : 1;
 
   guchar             bus_id[16];
+
+  GDBusCapabilityFlags                     capabilities;
+  GDBusWorkerMessageReceivedCallback       message_received_callback;
+  GDBusWorkerMessageAboutToBeSentCallback  message_about_to_be_sent_callback;
+  GDBusWorkerDisconnectedCallback          disconnected_callback;
+  gpointer                                 user_data;
 };
 
 static gssize _g_kdbus_receive (GKDBusWorker  *kdbus,
@@ -197,9 +203,9 @@ kdbus_ready (gint         fd,
 }
 
 gboolean
-_g_kdbus_open (GKDBusWorker       *worker,
-               const gchar  *address,
-               GError      **error)
+_g_kdbus_open (GKDBusWorker  *worker,
+               const gchar   *address,
+               GError       **error)
 {
   g_return_val_if_fail (G_IS_KDBUS_WORKER (worker), FALSE);
 
@@ -212,11 +218,6 @@ _g_kdbus_open (GKDBusWorker       *worker,
 
   worker->closed = FALSE;
 
-  worker->context = g_main_context_ref_thread_default ();
-  worker->source = g_unix_fd_source_new (worker->fd, G_IO_IN);
-  g_source_set_callback (worker->source, (GSourceFunc) kdbus_ready, worker, NULL);
-  g_source_attach (worker->source, worker->context);
-
   return TRUE;
 }
 
@@ -372,8 +373,8 @@ _g_kdbus_Hello (GKDBusWorker *worker,
   asprintf(&worker->unique_name, ":1.%llu", (unsigned long long) hello->id);
 
   /* read bloom filters parameters */
-  worker->bloom_size = (gsize) hello->bloom.size;
-  worker->bloom_n_hash = (guint) hello->bloom.n_hash;
+  //worker->bloom_size = (gsize) hello->bloom.size;
+  //worker->bloom_n_hash = (guint) hello->bloom.n_hash;
 
   return g_variant_new ("(s)", worker->unique_name);
 }
@@ -1577,7 +1578,11 @@ g_kdbus_decode_dbus_msg (GKDBusWorker           *worker,
 
   g_print ("Received:\n%s\n", g_dbus_message_print (message, 2));
 
-  return message;
+  (* worker->message_received_callback) (message, worker->user_data);
+
+  g_object_unref (message);
+
+  return 0;
 }
 
 
@@ -1608,6 +1613,10 @@ again:
         if (errno == EAGAIN)
           return 0;
 
+        g_warning ("in holding pattern over %d %d\n", kdbus->fd, errno);
+        while (1)
+          sleep(1);
+
         g_set_error (error, G_IO_ERROR,
                      g_io_error_from_errno (errno),
                      _("Error while receiving message: %s"),
@@ -1615,6 +1624,8 @@ again:
         return -1;
       }
 
+    g_print ("but sometimes that's okay\n");
+
    msg = (struct kdbus_msg *)((guint8 *)kdbus->kdbus_buffer + recv.reply.offset);
 
    if (msg->payload_type == KDBUS_PAYLOAD_DBUS)
@@ -2083,14 +2094,6 @@ need_compact:
 GKDBusWorker *
 g_kdbus_worker_new (const gchar  *address,
                     GError      **error)
-#if 0
-                    GDBusCapabilityFlags                     capabilities,
-                    gboolean                                 initially_frozen,
-                    GDBusWorkerMessageReceivedCallback       message_received_callback,
-                    GDBusWorkerMessageAboutToBeSentCallback  message_about_to_be_sent_callback,
-                    GDBusWorkerDisconnectedCallback          disconnected_callback,
-                    gpointer                                 user_data)
-#endif
 {
   GKDBusWorker *worker;
 
@@ -2105,8 +2108,37 @@ g_kdbus_worker_new (const gchar  *address,
 }
 
 void
+g_kdbus_worker_associate (GKDBusWorker                            *worker,
+                          GDBusCapabilityFlags                     capabilities,
+                          GDBusWorkerMessageReceivedCallback       message_received_callback,
+                          GDBusWorkerMessageAboutToBeSentCallback  message_about_to_be_sent_callback,
+                          GDBusWorkerDisconnectedCallback          disconnected_callback,
+                          gpointer                                 user_data)
+{
+  worker->capabilities = capabilities;
+  worker->message_received_callback = message_received_callback;
+  worker->message_about_to_be_sent_callback = message_about_to_be_sent_callback;
+  worker->disconnected_callback = disconnected_callback;
+  worker->user_data = user_data;
+}
+
+void
 g_kdbus_worker_unfreeze (GKDBusWorker *worker)
 {
+  gchar *name;
+
+  if (worker->source != NULL)
+    return;
+
+  worker->context = g_main_context_ref_thread_default ();
+  worker->source = g_unix_fd_source_new (worker->fd, G_IO_IN);
+
+  g_source_set_callback (worker->source, (GSourceFunc) kdbus_ready, worker, NULL);
+  name = g_strdup_printf ("kdbus worker");
+  g_source_set_name (worker->source, name);
+  g_free (name);
+
+  g_source_attach (worker->source, worker->context);
 }
 
 gboolean
diff --git a/gio/gkdbus.h b/gio/gkdbus.h
index e27880c..5878bb3 100644
--- a/gio/gkdbus.h
+++ b/gio/gkdbus.h
@@ -50,14 +50,12 @@ GType                   g_kdbus_worker_get_type                         (void);
 GKDBusWorker *          g_kdbus_worker_new                              (const gchar  *address,
                                                                          GError      **error);
 
-#if 0
+void                    g_kdbus_worker_associate                        (GKDBusWorker                        
    *worker,
                                                                          GDBusCapabilityFlags                
     capabilities,
-                                                                         gboolean                            
     initially_frozen,
                                                                          GDBusWorkerMessageReceivedCallback  
     message_received_callback,
                                                                          
GDBusWorkerMessageAboutToBeSentCallback  message_about_to_be_sent_callback,
                                                                          GDBusWorkerDisconnectedCallback     
     disconnected_callback,
                                                                          gpointer                            
     user_data);
-#endif
 
 void                    g_kdbus_worker_unfreeze                         (GKDBusWorker *worker);
 
diff --git a/gio/kdbus.h b/gio/kdbus.h
index 93ef0d3..d7680f7 100644
--- a/gio/kdbus.h
+++ b/gio/kdbus.h
@@ -384,6 +384,16 @@ struct kdbus_item {
 };
 
 /**
+ * struct kdbus_item_list - A list of items
+ * @size:              The total size of the structure
+ * @items:             Array of items
+ */
+struct kdbus_item_list {
+       __u64 size;
+       struct kdbus_item items[0];
+};
+
+/**
  * enum kdbus_msg_flags - type of message
  * @KDBUS_MSG_EXPECT_REPLY:    Expect a reply message, used for
  *                             method calls. The userspace-supplied
@@ -705,8 +715,10 @@ enum kdbus_attach_flags {
  * @id:                        The ID of this connection (kernel → userspace)
  * @pool_size:         Size of the connection's buffer where the received
  *                     messages are placed
- * @bloom:             The bloom properties of the bus, specified
- *                     by the bus creator (kernel → userspace)
+ * @offset:            Pool offset where additional items of type
+ *                     kdbus_item_list are stored. They contain information
+ *                     about the bus and the newly created connection.
+ * @items_size:                Copy of item_list.size stored in @offset.
  * @id128:             Unique 128-bit ID of the bus (kernel → userspace)
  * @items:             A list of items
  *
@@ -722,7 +734,8 @@ struct kdbus_cmd_hello {
        __u64 bus_flags;
        __u64 id;
        __u64 pool_size;
-       struct kdbus_bloom_parameter bloom;
+       __u64 offset;
+       __u64 items_size;
        __u8 id128[16];
        struct kdbus_item items[0];
 } __attribute__((aligned(8)));
@@ -846,7 +859,9 @@ enum kdbus_name_list_flags {
  * @offset:            The returned offset in the caller's pool buffer.
  *                     The user must use KDBUS_CMD_FREE to free the
  *                     allocated memory.
+ * @list_size:         Returned size of list in bytes
  * @size:              Output buffer to report size of data at @offset.
+ * @items:             Items for the command. Reserved for future use.
  *
  * This structure is used with the KDBUS_CMD_NAME_LIST ioctl.
  */
@@ -1021,7 +1036,7 @@ struct kdbus_cmd_match {
 #define KDBUS_CMD_BYEBYE               _IO(KDBUS_IOCTL_MAGIC, 0x21)    \
 
 #define KDBUS_CMD_SEND                 _IOWR(KDBUS_IOCTL_MAGIC, 0x30,  \
-                                             struct kdbus_msg)
+                                             struct kdbus_cmd_send)
 #define KDBUS_CMD_RECV                 _IOWR(KDBUS_IOCTL_MAGIC, 0x31,  \
                                              struct kdbus_cmd_recv)
 #define KDBUS_CMD_CANCEL               _IOW(KDBUS_IOCTL_MAGIC, 0x32,   \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]