summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-06-23 18:21:23 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-06-23 18:21:23 +0000
commit2cc84f09868d94aad737853b12ab41f4b83a1db9 (patch)
tree316ad981b86d0719858a1025da8fef374147f128
parent5c95755a67bc8653af44996bb2fe9263a3137131 (diff)
Fix storage code.
-rw-r--r--audio/device.c36
-rw-r--r--audio/manager.c42
2 files changed, 27 insertions, 51 deletions
diff --git a/audio/device.c b/audio/device.c
index 8442a87c..785d0115 100644
--- a/audio/device.c
+++ b/audio/device.c
@@ -83,7 +83,7 @@ static DBusHandlerResult device_get_connected(DBusConnection *conn,
&array_iter);
if (device->headset &&
- headset_get_state(device->headset) >= HEADSET_STATE_CONNECTED) {
+ headset_get_state(device) >= HEADSET_STATE_CONNECTED) {
iface = AUDIO_HEADSET_INTERFACE;
dbus_message_iter_append_basic(&array_iter,
DBUS_TYPE_STRING, &iface);
@@ -173,7 +173,6 @@ int device_store(struct device *device, gboolean is_default)
char value[64];
char filename[PATH_MAX + 1];
char src_addr[18], dst_addr[18];
- int err;
if (!device->path)
return -EINVAL;
@@ -185,24 +184,21 @@ int device_store(struct device *device, gboolean is_default)
create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (is_default)
- err = textfile_put(filename, "default", dst_addr);
- else {
- if (device->headset)
- snprintf(value, 64, "headset");
- if (device->gateway)
- snprintf(value, 64, "%s:gateway", value);
- if (device->sink)
- snprintf(value, 64, "%s:sink", value);
- if (device->source)
- snprintf(value, 64, "%s:source", value);
- if (device->control)
- snprintf(value, 64, "%s:control", value);
- if (device->target)
- snprintf(value, 64, "%s:target", value);
- err = textfile_put(filename, dst_addr, value);
- }
-
- return err;
+ textfile_put(filename, "default", dst_addr);
+ if (device->headset)
+ snprintf(value, 64, "headset");
+ else if (device->gateway)
+ snprintf(value, 64, "gateway");
+ else if (device->sink)
+ snprintf(value, 64, "sink");
+ else if (device->source)
+ snprintf(value, 64, "source");
+ else if (device->control)
+ snprintf(value, 64, "control");
+ else
+ snprintf(value, 64, "target");
+
+ return textfile_put(filename, dst_addr, value);
}
void device_finish_sdp_transaction(struct device *device)
diff --git a/audio/manager.c b/audio/manager.c
index aa34c94b..fca8d47a 100644
--- a/audio/manager.c
+++ b/audio/manager.c
@@ -123,17 +123,12 @@ static void remove_device(struct device *device)
static gboolean add_device(struct device *device)
{
- gboolean is_default;
-
/* First device became default */
if (g_slist_length(devices) == 0)
default_dev = device;
devices = g_slist_append(devices, device);
- is_default = default_dev == device ? TRUE : FALSE;
-
- device_store(device, is_default);
return TRUE;
}
@@ -174,6 +169,7 @@ done:
static void handle_record(sdp_record_t *record, struct device *device)
{
+ gboolean is_default;
uint16_t uuid16;
uuid16 = get_service_uuid(record);
@@ -217,6 +213,10 @@ static void handle_record(sdp_record_t *record, struct device *device)
debug("Unrecognized UUID: 0x%04X", uuid16);
break;
}
+
+ is_default = (default_dev == device) ? TRUE : FALSE;
+
+ device_store(device, is_default);
}
static gint record_iface_cmp(gconstpointer a, gconstpointer b)
@@ -1041,6 +1041,7 @@ static DBusHandlerResult am_change_default_device(DBusConnection *conn,
return err_does_not_exist(connection, msg);
default_dev = device;
+ device_store(device, TRUE);
return send_message_and_unref(connection, reply);
}
@@ -1080,20 +1081,17 @@ static DBusSignalVTable manager_signals[] = {
{ NULL, NULL }
};
-#if 0
static void parse_stored_devices(char *key, char *value, void *data)
{
struct device *device;
bdaddr_t dst;
char addr[18];
- char *ptr;
- char ifaces[6][8];
- int len, i;
- if (!key || !value)
+ if (!key || !value || strcmp(key, "default") == 0)
return;
/* Format: XX:XX:XX:XX:XX:XX interface0:interface1:... */
+ info("Loading device %s", key);
memset(addr, 0, 18);
strncpy(addr, key, 17);
str2ba(addr, &dst);
@@ -1101,36 +1099,19 @@ static void parse_stored_devices(char *key, char *value, void *data)
if ((device = create_device(&dst)) == NULL)
return;
- /* Parsing the interface */
- ptr = strchr(value, ':');
-
- if (!ptr) {
- strncpy(ifaces[0], value, 8);
- if (strcmp(ifaces[0], "headset") == 0)
- device->headset = headset_init(device, NULL, 0);
- }
-
- /* FIXME: has more than 1 interface */
- for (i = 0; ptr && i < 6; i++) {
- len = ptr-value;
- strncpy(ifaces[i], value, len);
- value = ptr;
- ptr = strchr(ptr, ':');
- }
+ if (strcmp(value, "headset") == 0)
+ device->headset = headset_init(device, NULL, 0);
add_device(device);
}
-#endif
static void register_devices_stored(const char *adapter)
{
char filename[PATH_MAX + 1];
struct stat s;
bdaddr_t src;
-#if 0
bdaddr_t dst;
char *addr;
-#endif
bdaddr_t default_src;
int dev_id;
@@ -1144,13 +1125,12 @@ static void register_devices_stored(const char *adapter)
hci_devba(dev_id, &default_src);
if (stat(filename, &s) == 0 && (s.st_mode & __S_IFREG)) {
-#if 0
textfile_foreach(filename, parse_stored_devices, &src);
addr = textfile_get(filename, "default");
str2ba(addr, &dst);
default_dev = find_device(&dst);
-#endif
+ free(addr);
}
}