- Now phantom connection is created once for unique name, not for each well-known name,
- Fixed sending NameLost signal to disconected client
Change-Id: I33f856c56a8fbb8c865b023aa1e773ffd1f3343e
Signed-off-by: Radoslaw Pajak <r.pajak@samsung.com>
foreach_inactive (connections, function, data);
}
+DBusConnection*
+bus_connections_find_conn_by_name(BusConnections *connections, const char* name)
+{
+ DBusList *link;
+
+ link = _dbus_list_get_first_link (&connections->completed);
+ while (link != NULL)
+ {
+ DBusConnection *connection = link->data;
+ DBusList *next = _dbus_list_get_next_link (&connections->completed, link);
+
+ if (!strcmp(bus_connection_get_name(connection), name))
+ return connection;
+
+ link = next;
+ }
+
+ return NULL;
+}
+
BusContext*
bus_connections_get_context (BusConnections *connections)
{
void bus_connections_foreach_active (BusConnections *connections,
BusConnectionForeachFunction function,
void *data);
+DBusConnection* bus_connections_find_conn_by_name (BusConnections *connections,
+ const char* name);
BusContext* bus_connections_get_context (BusConnections *connections);
void bus_connections_increment_stamp (BusConnections *connections);
BusContext* bus_connection_get_context (DBusConnection *connection);
return retval;
}
+/*
static dbus_bool_t remove_conn_if_name_match (DBusConnection *connection, void *data)
{
if(!strcmp(bus_connection_get_name(connection), (char*)data))
{
bus_connection_disconnected(connection);
-// return FALSE; //needed to break foreach function
- /* todo should we brake? Now we create phantom for each name, so if someone acquire more than
- * one name he will have more than one phantom. I think that there should be one phantom for one name
- * but if so, name acquiring and releasing must be changed
- */
+ return FALSE; //this is to break foreach function
}
return TRUE;
-}
+}*/
void handleNameOwnerChanged(DBusMessage *msg, BusTransaction *transaction, DBusConnection *connection)
{
return;
}
+ _dbus_verbose ("Got NameOwnerChanged signal:\nName: %s\nOld: %s\nNew: %s\n", name, old, new);
+
if(!strncmp(name, ":1.", 3))/*if it starts from :1. it is unique name - this might be IdRemoved info*/
{
if(!strcmp(name, old)) //yes it is - someone has disconnected
- {
- _dbus_verbose ("Connection %s has disconnected. Removing.\n", name); //todo to remove at the end of development
- bus_connections_foreach_active(bus_connection_get_connections(connection), remove_conn_if_name_match, (void*)name);
- }
+ bus_connection_disconnected(bus_connections_find_conn_by_name(bus_connection_get_connections(connection), name));
}
else //it is well-known name
{
{
DBusMessage *message;
+ if(bus_connections_find_conn_by_name(bus_connection_get_connections(connection), old) == NULL)
+ goto next;
+
_dbus_verbose ("Owner '%s' lost name '%s'. Sending NameLost.\n", old, name);
message = dbus_message_new_signal (DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "NameLost");
if((*result == DBUS_REQUEST_NAME_REPLY_IN_QUEUE) || (*result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER))
{
DBusConnection* phantom;
+ const char* name;
- //todo what if we already have phantom for that sender?
- phantom = create_phantom_connection(connection, dbus_message_get_sender(message), error);
+ name = dbus_message_get_sender(message);
+ phantom = bus_connections_find_conn_by_name(bus_connection_get_connections(connection), name);
+ if(phantom == NULL)
+ phantom = create_phantom_connection(connection, name, error);
if(phantom == NULL)
goto failed2;
if (!bus_service_add_owner (service, phantom, flags, transaction, error))
- {
- bus_connection_disconnected(phantom);
goto failed2;
- }
if(*result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
{
/* Here we are removing DBus daemon as an owner of the service,
if(phantom)
{
bus_service_remove_owner (service, phantom, transaction, NULL);
- dbus_connection_unref_phantom(phantom); //todo if there will be one phantom for one id not for one name, than it must be changed
+ /* todo we could remove phantom if he doesn't own any name
+ * to do this we should write function in connection.c to check if
+ * _dbus_list_get_last (&d->services_owned) returns not NULL
+ * or we can leave phantom - he will be removed when he disconnects from the bus
+ */
}
else
_dbus_verbose ("Didn't find phantom connection for released name!\n");