Diff between d4477e8fc3dc5b06ba6068741c082d7b4c3f084c and 85cb255b462da360d4712f8b9ff9b5ee398f7c1c

Changed Files

File Additions Deletions Status
doc/advertising-api.txt +4 -0 modified
src/advertising.c +30 -3 modified

Full Patch

diff --git a/doc/advertising-api.txt b/doc/advertising-api.txt
index 8207b59..7a29b70 100644
--- a/doc/advertising-api.txt
+++ b/doc/advertising-api.txt
@@ -112,3 +112,7 @@ Methods		RegisterAdvertisement(object advertisement, dict options)
 
 			Possible errors: org.bluez.Error.InvalidArguments
 					 org.bluez.Error.DoesNotExist
+
+Properties	byte AdvertisementInstaces
+
+			Number of available advertisement instances.
diff --git a/src/advertising.c b/src/advertising.c
index 1bea0d1..10d8d01 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -160,11 +160,16 @@ static void client_remove(void *data)
 	queue_remove(client->manager->clients, client);
 
 	g_idle_add(client_free_idle_cb, client);
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(),
+				adapter_get_path(client->manager->adapter),
+				LE_ADVERTISING_MGR_IFACE,
+				"AdvertisementInstances");
 }
 
 static void client_disconnect_cb(DBusConnection *conn, void *user_data)
 {
-	DBG("Client disconnected");
+	DBG("Client dis:b connected");
 
 	client_remove(user_data);
 }
@@ -446,6 +451,11 @@ static void add_adv_callback(uint8_t status, uint16_t length,
 									client);
 	DBG("Advertisement registered: %s", client->path);
 
+	g_dbus_emit_property_changed(btd_get_dbus_connection(),
+				adapter_get_path(client->manager->adapter),
+				LE_ADVERTISING_MGR_IFACE,
+				"AdvertisementInstances");
+
 done:
 	add_client_complete(client, status);
 }
@@ -715,6 +725,23 @@ static DBusMessage *unregister_advertisement(DBusConnection *conn,
 	return dbus_message_new_method_return(msg);
 }
 
+static gboolean get_instances(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct btd_adv_manager *manager = data;
+	uint8_t instances;
+
+	instances = manager->max_ads - queue_length(manager->clients);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &instances);
+
+	return TRUE;
+}
+
+static const GDBusPropertyTable properties[] = {
+	{ "AdvertisementInstances", "y", get_instances },
+};
+
 static const GDBusMethodTable methods[] = {
 	{ GDBUS_EXPERIMENTAL_ASYNC_METHOD("RegisterAdvertisement",
 					GDBUS_ARGS({ "advertisement", "o" },
@@ -763,8 +790,8 @@ static void read_adv_features_callback(uint8_t status, uint16_t length,
 
 	if (!g_dbus_register_interface(btd_get_dbus_connection(),
 					adapter_get_path(manager->adapter),
-					LE_ADVERTISING_MGR_IFACE,
-					methods, NULL, NULL, manager, NULL))
+					LE_ADVERTISING_MGR_IFACE, methods,
+					NULL, properties, manager, NULL))
 		error("Failed to register " LE_ADVERTISING_MGR_IFACE);
 }