Diff between c9958f1a3b78bf49f84d2137bd372ad0e9b5177b and 41aed2896c89e82da6b21655f598cf8245b86cb4

Changed Files

File Additions Deletions Status
profiles/thermometer/thermometer.c +5 -24 modified

Full Patch

diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index 909cec0..d7c377d 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -83,6 +83,7 @@ struct thermometer {
 
 	uint16_t			measurement_ccc_handle;
 	uint16_t			intermediate_ccc_handle;
+	uint16_t			interval_val_handle;
 };
 
 struct characteristic {
@@ -240,14 +241,6 @@ static gint cmp_watcher(gconstpointer a, gconstpointer b)
 	return g_strcmp0(watcher->path, match->path);
 }
 
-static gint cmp_char_uuid(gconstpointer a, gconstpointer b)
-{
-	const struct characteristic *ch = a;
-	const char *uuid = b;
-
-	return g_strcmp0(ch->attr.uuid, uuid);
-}
-
 static gint cmp_char_val_handle(gconstpointer a, gconstpointer b)
 {
 	const struct characteristic *ch = a;
@@ -267,18 +260,6 @@ find_thermometer_adapter(struct btd_adapter *adapter)
 	return l->data;
 }
 
-static struct characteristic *get_characteristic(struct thermometer *t,
-							const char *uuid)
-{
-	GSList *l;
-
-	l = g_slist_find_custom(t->chars, uuid, cmp_char_uuid);
-	if (l == NULL)
-		return NULL;
-
-	return l->data;
-}
-
 static void change_property(struct thermometer *t, const char *name,
 							gpointer value) {
 	if (g_strcmp0(name, "Intermediate") == 0) {
@@ -541,6 +522,8 @@ static void process_thermometer_char(struct characteristic *ch)
 		gatt_read_char(ch->t->attrib, ch->attr.value_handle,
 							read_temp_type_cb, ch);
 	} else if (g_strcmp0(ch->attr.uuid, MEASUREMENT_INTERVAL_UUID) == 0) {
+		ch->t->interval_val_handle = ch->attr.value_handle;
+
 		gatt_read_char(ch->t->attrib, ch->attr.value_handle,
 							read_interval_cb, ch);
 	}
@@ -651,14 +634,12 @@ static DBusMessage *write_attr_interval(struct thermometer *t, DBusMessage *msg,
 								uint16_t value)
 {
 	struct tmp_interval_data *data;
-	struct characteristic *ch;
 	uint8_t atval[2];
 
 	if (t->attrib == NULL)
 		return btd_error_not_connected(msg);
 
-	ch = get_characteristic(t, MEASUREMENT_INTERVAL_UUID);
-	if (ch == NULL)
+	if (t->interval_val_handle == 0)
 		return btd_error_not_available(msg);
 
 	if (value < t->min || value > t->max)
@@ -669,7 +650,7 @@ static DBusMessage *write_attr_interval(struct thermometer *t, DBusMessage *msg,
 	data = g_new0(struct tmp_interval_data, 1);
 	data->thermometer = t;
 	data->interval = value;
-	gatt_write_char(t->attrib, ch->attr.value_handle, atval, 2,
+	gatt_write_char(t->attrib, t->interval_val_handle, atval, 2,
 						write_interval_cb, data);
 
 	return dbus_message_new_method_return(msg);