[lib-opt] optimization of kdbus add-on to libdbus
authorRadoslaw Pajak <r.pajak@samsung.com>
Fri, 6 Sep 2013 08:22:02 +0000 (10:22 +0200)
committerRadoslaw Pajak <r.pajak@samsung.com>
Mon, 9 Sep 2013 12:40:05 +0000 (14:40 +0200)
Change-Id: I0f79fe0f1514e7ddbc7354a3e35b641257c15723

dbus/dbus-bus.c
dbus/dbus-connection.c
dbus/dbus-connection.h
dbus/dbus-transport-kdbus.c
dbus/dbus-transport-kdbus.h

index 8fc60a7..b639385 100644 (file)
@@ -698,7 +698,7 @@ dbus_bus_register (DBusConnection *connection,
       retval = TRUE;
       goto out;
     }
-  if(dbus_transport_is_kdbus(connection))
+  if(dbus_connection_is_kdbus(connection))
   {
          name = malloc(snprintf(name, 0, "%llu", ULLONG_MAX) + 1);
          if(!bus_register_kdbus(name, connection, error))
@@ -708,6 +708,20 @@ dbus_bus_register (DBusConnection *connection,
                goto out;
 
          dbus_connection_set_is_authenticated(connection);
+
+         /* Set sender for messages.
+          * If not kdbus - daemon does this. */
+         sender = malloc (strlen(name) + 4);
+         if(sender)
+         {
+                 sprintf(sender, ":1.%s", name);
+                 dbus_connection_set_sender(connection, sender);
+         }
+         else
+         {
+                 _DBUS_SET_OOM (error);
+                 goto out;
+         }
   }
   else
   {
@@ -735,16 +749,6 @@ dbus_bus_register (DBusConnection *connection,
 
   bd->unique_name = _dbus_strdup (name);
 
-  /* determine sender once, not for every message */
-  sender = malloc (strlen(name) + 4);
-  if(sender)
-  {
-    strcpy(sender,":1.");
-    strcpy(&sender[3], name);
-    _dbus_verbose ("Message sender: %s\n", sender);
-    dbus_connection_set_sender(connection, sender);             
-  }
-
   if (bd->unique_name == NULL)
     {
       _DBUS_SET_OOM (error);
@@ -1164,7 +1168,7 @@ dbus_bus_request_name (DBusConnection *connection,
        _dbus_return_val_if_fail (_dbus_check_is_valid_bus_name (name), 0);
        _dbus_return_val_if_error_is_set (error, 0);
 
-       if(!dbus_transport_is_kdbus(connection))
+       if(!dbus_connection_is_kdbus(connection))
        {
                DBusMessage *message, *reply;
 
@@ -1582,7 +1586,7 @@ dbus_bus_add_match (DBusConnection *connection,
 {
        _dbus_return_if_fail (rule != NULL);
 
-       if(!dbus_transport_is_kdbus(connection))
+       if(!dbus_connection_is_kdbus(connection))
        {
                DBusMessage *msg;
 
@@ -1635,7 +1639,7 @@ dbus_bus_remove_match (DBusConnection *connection,
                        const char     *rule,
                        DBusError      *error)
 {
-       if(!dbus_transport_is_kdbus(connection))
+       if(!dbus_connection_is_kdbus(connection))
        {
                DBusMessage *msg;
 
index 8e02394..b3cc1bb 100644 (file)
@@ -335,8 +335,8 @@ struct DBusConnection
 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
   int generation; /**< _dbus_current_generation that should correspond to this connection */
 #endif 
-  unsigned int is_kdbus; /* Samsung change: to spare comparing address too often. 0 - uninitialized, 1 - not kdbus, 2 - kdbus */
-  char* sender; /* Samsung change: to spare building sender name for each message sent */
+  unsigned int is_kdbus : 1; /* Samsung change for kdbus: sometimes it's needed to check do we use kdbus*/
+  char* sender; /* Samsung change for kdbus: sender has to be added to message by libdbus because there is no daemon to do this*/
 };
 
 static DBusDispatchStatus _dbus_connection_get_dispatch_status_unlocked      (DBusConnection     *connection);
@@ -1260,6 +1260,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
   DBusMessage *disconnect_message;
   DBusCounter *outgoing_counter;
   DBusObjectTree *objects;
+  const char* address;
   
   watch_list = NULL;
   connection = NULL;
@@ -1350,6 +1351,14 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
   connection->route_peer_messages = FALSE;
   connection->disconnected_message_arrived = FALSE;
   connection->disconnected_message_processed = FALSE;
+  connection->is_kdbus = FALSE;
+
+  address = _dbus_transport_get_address (connection->transport);
+  if(address)
+  {
+         if(address == strstr(address, "kdbus:path="))
+                 connection->is_kdbus = TRUE;
+  }
   
 #if defined(DBUS_ENABLE_CHECKS) || defined(DBUS_ENABLE_ASSERT)
   connection->generation = _dbus_current_generation;
@@ -2004,16 +2013,6 @@ char* dbus_connection_get_sender(DBusConnection *connection)
   return connection->sender;
 }
 
-unsigned int dbus_connection_get_is_kdbus(DBusConnection *connection)
-{
-  return connection->is_kdbus;
-}
-
-void dbus_connection_set_is_kdbus(DBusConnection *connection, unsigned int value)
-{
-  connection->is_kdbus = value;
-}
-
 /* Called with lock held, does not update dispatch status */
 static void
 _dbus_connection_send_preallocated_unlocked_no_update (DBusConnection       *connection,
@@ -2022,7 +2021,6 @@ _dbus_connection_send_preallocated_unlocked_no_update (DBusConnection       *con
                                                        dbus_uint32_t        *client_serial)
 {
   dbus_uint32_t serial;
-  char* sender;
 
   preallocated->queue_link->data = message;
   _dbus_list_prepend_link (&connection->outgoing_messages,
@@ -2075,11 +2073,8 @@ _dbus_connection_send_preallocated_unlocked_no_update (DBusConnection       *con
   _dbus_verbose ("Message %p serial is %u\n",
                  message, dbus_message_get_serial (message));
   
-  if(dbus_transport_is_kdbus(connection))
-  {
-         sender = dbus_connection_get_sender(connection);
-                dbus_message_set_sender(message, sender);
-  }
+  if(dbus_connection_is_kdbus(connection))
+         dbus_message_set_sender(message, dbus_connection_get_sender(connection));
 
   dbus_message_lock (message);
 
@@ -6348,5 +6343,9 @@ dbus_connection_get_transport(DBusConnection *connection)
        return connection->transport;
 }
 
+dbus_bool_t dbus_connection_is_kdbus(DBusConnection *connection)
+{
+       return (dbus_bool_t) connection->is_kdbus;
+}
 
 /** @} */
index 04afe3e..b2e86ef 100644 (file)
@@ -189,9 +189,7 @@ void               dbus_connection_close                        (DBusConnection
 DBUS_EXPORT
 dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection             *connection);
 DBUS_EXPORT
-unsigned int       dbus_connection_get_is_kdbus                 (DBusConnection             *connection);
-DBUS_EXPORT
-void               dbus_connection_set_is_kdbus                 (DBusConnection             *connection, unsigned int value);
+dbus_bool_t               dbus_connection_is_kdbus                                             (DBusConnection *connection);
 DBUS_EXPORT
 void               dbus_connection_set_sender                   (DBusConnection             *connection, char *value);
 DBUS_EXPORT
index 20c3887..3f4b876 100644 (file)
@@ -2750,42 +2750,6 @@ int bus_request_name_kdbus(DBusConnection *connection, const char *name, const u
 }
 
 /**
- * Checks if the connection's transport is kdbus on the basis of its address
- * saves result in DBusConnection for performance.
- *
- * @param pointer to the connection
- * @returns TRUE if kdbus transport, otherwise FALSE
- */
-dbus_bool_t dbus_transport_is_kdbus(DBusConnection *connection)
-{
-       unsigned int is_kdbus;
-
-       is_kdbus = dbus_connection_get_is_kdbus(connection);
-       if(is_kdbus == 0) 
-       {
-               const char* address = _dbus_connection_get_address(connection);
-
-               if(address)
-               {
-                       if(address == strstr(address, "kdbus:path=")) 
-                       {
-                               dbus_connection_set_is_kdbus(connection, 2);
-                               return TRUE;
-                       } else {
-                               dbus_connection_set_is_kdbus(connection, 1);
-                               return FALSE;
-                       }
-               }
-       } 
-       
-       if(is_kdbus == 2) return TRUE;
-       if(is_kdbus == 1) return FALSE;
-       
-       _dbus_verbose("is_kdbus is not 0 or 1 or 2. Should not happen! \n");
-       return FALSE;
-}
-
-/**
  * Seeks key in rule string, and duplicates value of the key into pValue.
  * If value is "org.freedesktop.DBus" it is indicated by returning -1, because it
  * needs to be handled in different manner.
index 8b97af4..4a99767 100644 (file)
@@ -5,7 +5,6 @@
 #include "dbus-errors.h"
 #include "dbus-types.h"
 
-dbus_bool_t dbus_transport_is_kdbus(DBusConnection *connection);
 DBusTransportOpenResult _dbus_transport_open_kdbus(DBusAddressEntry *entry, DBusTransport **transport_p, DBusError *error);
 dbus_bool_t bus_register_kdbus(char* name, DBusConnection *connection, DBusError *error);
 dbus_bool_t bus_register_policy_kdbus(const char* name, DBusConnection *connection, DBusError *error);