Index: uspace/srv/audio/hound/hound.c
===================================================================
--- uspace/srv/audio/hound/hound.c	(revision 737b4c0c17bd4b9485d683e5c0802d801e3543e1)
+++ uspace/srv/audio/hound/hound.c	(revision 1df3018aba16e9a26b7b9df22c85eb411795797c)
@@ -39,4 +39,5 @@
 
 #include "hound.h"
+#include "audio_client.h"
 #include "audio_device.h"
 #include "audio_sink.h"
@@ -46,15 +47,45 @@
 #include "str_error.h"
 
+#define FIND_BY_NAME(type) \
+do { \
+	assert(list); \
+	assert(name); \
+	list_foreach(*list, it) { \
+		audio_ ## type ## _t *dev = \
+		    audio_ ## type ## _list_instance(it); \
+		if (str_cmp(name, dev->name) == 0) { \
+			log_debug("%s with name %s is already present", \
+			    #type, name); \
+			return NULL; \
+		} \
+	} \
+	return NULL; \
+} while (0)
+
+static audio_device_t * find_device_by_name(list_t *list, const char *name)
+{
+	FIND_BY_NAME(device);
+}
+static audio_source_t * find_source_by_name(list_t *list, const char *name)
+{
+	FIND_BY_NAME(source);
+}
+static audio_sink_t * find_sink_by_name(list_t *list, const char *name)
+{
+	FIND_BY_NAME(sink);
+}
+
 int hound_init(hound_t *hound)
 {
 	assert(hound);
+	fibril_mutex_initialize(&hound->list_guard);
 	list_initialize(&hound->devices);
+	list_initialize(&hound->sources);
 	list_initialize(&hound->available_sources);
 	list_initialize(&hound->sinks);
-	list_initialize(&hound->clients);
 	return EOK;
 }
 
-int hound_add_device(hound_t *hound, service_id_t id, const char* name)
+int hound_add_device(hound_t *hound, service_id_t id, const char *name)
 {
 	log_verbose("Adding device \"%s\", service: %zu", name, id);
@@ -67,5 +98,5 @@
 
 	list_foreach(hound->devices, it) {
-		audio_device_t *dev = list_audio_device_instance(it);
+		audio_device_t *dev = audio_device_list_instance(it);
 		if (dev->id == id) {
 			log_debug("Device with id %zu is already present", id);
@@ -74,5 +105,11 @@
 	}
 
-	audio_device_t *dev = malloc(sizeof(audio_device_t));
+	audio_device_t *dev = find_device_by_name(&hound->devices, name);
+	if (dev) {
+		log_debug("Device with name %s is already present", name);
+		return EEXISTS;
+	}
+
+	dev = malloc(sizeof(audio_device_t));
 	if (!dev) {
 		log_debug("Failed to malloc device structure.");
@@ -80,4 +117,5 @@
 	}
 	const int ret = audio_device_init(dev, id, name);
+	free(name);
 	if (ret != EOK) {
 		log_debug("Failed to initialize new audio device: %s",
@@ -88,16 +126,28 @@
 
 	list_append(&dev->link, &hound->devices);
-	log_info("Added new device: '%s'", name);
+	log_info("Added new device: '%s'", dev->name);
 
 	audio_source_t *source = audio_device_get_source(dev);
 	if (source) {
+		const int ret = hound_add_source(hound, source);
+		if (ret != EOK) {
+			log_debug("Failed to add device source: %s",
+			    str_error(ret));
+			audio_device_fini(dev);
+			return ret;
+		}
 		log_verbose("Added source: '%s'.", source->name);
-		list_append(&source->link, &hound->available_sources);
 	}
 
 	audio_sink_t *sink = audio_device_get_sink(dev);
 	if (sink) {
+		const int ret = hound_add_sink(hound, sink);
+		if (ret != EOK) {
+			log_debug("Failed to add device sink: %s",
+			    str_error(ret));
+			audio_device_fini(dev);
+			return ret;
+		}
 		log_verbose("Added sink: '%s'.", sink->name);
-		list_append(&sink->link, &hound->sinks);
 	}
 
@@ -108,4 +158,48 @@
 }
 
+int hound_add_source(hound_t *hound, audio_source_t *source)
+{
+	assert(hound);
+	if (!source || !source->name) {
+		log_debug("Invalid source specified.");
+		return EINVAL;
+	}
+	fibril_mutex_lock(&hound->list_guard);
+	if (find_source_by_name(&hound->sources, source->name)) {
+		log_debug("Source by that name already exists");
+		fibril_mutex_unlock(&hound->list_guard);
+		return EEXISTS;
+	}
+	list_foreach(hound->sinks, it) {
+		audio_sink_t *sink = audio_sink_list_instance(it);
+		if (find_source_by_name(&sink->sources, source->name)) {
+			log_debug("Source by that name already exists");
+			fibril_mutex_unlock(&hound->list_guard);
+			return EEXISTS;
+		}
+	}
+	list_append(&source->link, &hound->sources);
+	fibril_mutex_unlock(&hound->list_guard);
+	return EOK;
+}
+
+int hound_add_sink(hound_t *hound, audio_sink_t *sink)
+{
+	assert(hound);
+	if (!sink || !sink->name) {
+		log_debug("Invalid source specified.");
+		return EINVAL;
+	}
+	fibril_mutex_lock(&hound->list_guard);
+	if (find_sink_by_name(&hound->sinks, sink->name)) {
+		log_debug("Sink by that name already exists");
+		fibril_mutex_unlock(&hound->list_guard);
+		return EEXISTS;
+	}
+	list_append(&sink->link, &hound->sinks);
+	fibril_mutex_unlock(&hound->list_guard);
+	return EOK;
+}
+
 /**
  * @}
