* [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter
@ 2013-02-06 21:40 Szymon Janc
2013-02-06 21:40 ` [PATCH v2 2/5] adapter: Mark adapter as default before probing drivers Szymon Janc
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Szymon Janc @ 2013-02-06 21:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Instead of global default_adapter_id variable use is_default field
to indicate if adapter is default one.
---
src/adapter.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 9ddd2fc..3774c77 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -96,7 +96,6 @@ static unsigned int adapter_remaining = 0;
static bool powering_down = false;
static GSList *adapters = NULL;
-static int default_adapter_id = -1;
static struct mgmt *mgmt_master = NULL;
@@ -184,6 +183,8 @@ struct btd_adapter {
unsigned int pair_device_id;
guint pair_device_timeout;
+
+ bool is_default; /* true if adapter is default one */
};
static struct btd_adapter *btd_adapter_lookup(uint16_t index)
@@ -205,14 +206,11 @@ struct btd_adapter *btd_adapter_get_default(void)
{
GList *list;
- if (default_adapter_id < 0)
- return NULL;
-
for (list = g_list_first(adapter_list); list;
list = g_list_next(list)) {
struct btd_adapter *adapter = list->data;
- if (adapter->dev_id == default_adapter_id)
+ if (adapter->is_default)
return adapter;
}
@@ -224,10 +222,7 @@ bool btd_adapter_is_default(struct btd_adapter *adapter)
if (!adapter)
return false;
- if (adapter->dev_id == default_adapter_id)
- return true;
-
- return false;
+ return adapter->is_default;
}
uint16_t btd_adapter_get_index(struct btd_adapter *adapter)
@@ -5506,8 +5501,8 @@ static int adapter_register(struct btd_adapter *adapter)
adapter->initialized = TRUE;
- if (default_adapter_id < 0)
- default_adapter_id = adapter->dev_id;
+ if (g_slist_length(adapters) == 1)
+ adapter->is_default = true;
if (main_opts.did_source)
set_did(adapter, main_opts.did_vendor, main_opts.did_product,
@@ -5524,8 +5519,13 @@ static int adapter_unregister(struct btd_adapter *adapter)
adapters = g_slist_remove(adapters, adapter);
- if (default_adapter_id == adapter->dev_id || default_adapter_id < 0)
- default_adapter_id = hci_get_route(NULL);
+ if (adapter->is_default && adapters != NULL) {
+ struct btd_adapter *new_default;
+
+ new_default = adapter_find_by_id(hci_get_route(NULL));
+ if (new_default)
+ new_default->is_default = true;
+ }
adapter_list = g_list_remove(adapter_list, adapter);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/5] adapter: Mark adapter as default before probing drivers
2013-02-06 21:40 [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Szymon Janc
@ 2013-02-06 21:40 ` Szymon Janc
2013-02-06 21:40 ` [PATCH v2 3/5] adapter: Always set new default adapter if current one is removed Szymon Janc
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2013-02-06 21:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
Drivers may depends on adapter being default or not. This fix hostname
plugin setting default adapter name to 'foo #1' instead of 'foo' if
pretty hostname was received before probing adapter drivers.
---
src/adapter.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 3774c77..3f51fd4 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -5474,6 +5474,9 @@ static int adapter_register(struct btd_adapter *adapter)
return -EINVAL;
}
+ if (adapters == NULL)
+ adapter->is_default = true;
+
adapters = g_slist_append(adapters, adapter);
agent = agent_get(NULL);
@@ -5501,9 +5504,6 @@ static int adapter_register(struct btd_adapter *adapter)
adapter->initialized = TRUE;
- if (g_slist_length(adapters) == 1)
- adapter->is_default = true;
-
if (main_opts.did_source)
set_did(adapter, main_opts.did_vendor, main_opts.did_product,
main_opts.did_version, main_opts.did_source);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 3/5] adapter: Always set new default adapter if current one is removed
2013-02-06 21:40 [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Szymon Janc
2013-02-06 21:40 ` [PATCH v2 2/5] adapter: Mark adapter as default before probing drivers Szymon Janc
@ 2013-02-06 21:40 ` Szymon Janc
2013-02-06 21:40 ` [PATCH v2 4/5] hostname: Fix setting adapter name to empty string Szymon Janc
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2013-02-06 21:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In case hci_get_route() failed mark first adapter on list as default.
This make sure default adapter is always set and that
btd_adapter_get_default will not return NULL if at least one adapter
is registered.
---
src/adapter.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 3f51fd4..7b08425 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -5523,8 +5523,10 @@ static int adapter_unregister(struct btd_adapter *adapter)
struct btd_adapter *new_default;
new_default = adapter_find_by_id(hci_get_route(NULL));
- if (new_default)
- new_default->is_default = true;
+ if (new_default == NULL)
+ new_default = adapters->data;
+
+ new_default->is_default = true;
}
adapter_list = g_list_remove(adapter_list, adapter);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 4/5] hostname: Fix setting adapter name to empty string
2013-02-06 21:40 [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Szymon Janc
2013-02-06 21:40 ` [PATCH v2 2/5] adapter: Mark adapter as default before probing drivers Szymon Janc
2013-02-06 21:40 ` [PATCH v2 3/5] adapter: Always set new default adapter if current one is removed Szymon Janc
@ 2013-02-06 21:40 ` Szymon Janc
2013-02-06 21:40 ` [PATCH v2 5/5] hostname: Fallback to static hostname if pretty hostname is not set Szymon Janc
2013-02-15 10:51 ` [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2013-02-06 21:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
If pretty hostname is not set empty string is received. Don't update
adapters' names is such case.
---
plugins/hostname.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/plugins/hostname.c b/plugins/hostname.c
index 0b75fac..74c25df 100644
--- a/plugins/hostname.c
+++ b/plugins/hostname.c
@@ -117,6 +117,12 @@ static void property_changed(GDBusProxy *proxy, const char *name,
DBG("pretty hostname: %s", str);
+ if (g_str_equal(str, "") == TRUE) {
+ g_free(pretty_hostname);
+ pretty_hostname = NULL;
+ return;
+ }
+
g_free(pretty_hostname);
pretty_hostname = g_strdup(str);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 5/5] hostname: Fallback to static hostname if pretty hostname is not set
2013-02-06 21:40 [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Szymon Janc
` (2 preceding siblings ...)
2013-02-06 21:40 ` [PATCH v2 4/5] hostname: Fix setting adapter name to empty string Szymon Janc
@ 2013-02-06 21:40 ` Szymon Janc
2013-02-15 10:51 ` [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2013-02-06 21:40 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
If pretty hostname is not set fallback to static hostname (if it is
set). If static or pretty hostname is not set appropriate properties
are empty strings not NULLs. This behaviour is recomended by hostnamed.
---
plugins/hostname.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 44 insertions(+), 10 deletions(-)
diff --git a/plugins/hostname.c b/plugins/hostname.c
index 74c25df..92a71e0 100644
--- a/plugins/hostname.c
+++ b/plugins/hostname.c
@@ -53,22 +53,43 @@ static uint8_t major_class = MAJOR_CLASS_MISCELLANEOUS;
static uint8_t minor_class = MINOR_CLASS_UNCATEGORIZED;
static char *pretty_hostname = NULL;
+static char *static_hostname = NULL;
+
+/*
+ * Fallback to static hostname only if empty pretty hostname was already
+ * received.
+ */
+static const char *get_hostname(void)
+{
+ if (pretty_hostname) {
+ if (g_str_equal(pretty_hostname, "") == FALSE)
+ return pretty_hostname;
+
+ if (static_hostname &&
+ g_str_equal(static_hostname, "") == FALSE)
+ return static_hostname;
+ }
+
+ return NULL;
+}
static void update_name(struct btd_adapter *adapter, gpointer user_data)
{
- if (pretty_hostname == NULL)
+ const char *hostname = get_hostname();
+
+ if (hostname == NULL)
return;
if (btd_adapter_is_default(adapter)) {
- DBG("name: %s", pretty_hostname);
+ DBG("name: %s", hostname);
- adapter_set_name(adapter, pretty_hostname);
+ adapter_set_name(adapter, hostname);
} else {
uint16_t index = btd_adapter_get_index(adapter);
char *str;
/* Avoid "some device #0" names, start at #1 */
- str = g_strdup_printf("%s #%u", pretty_hostname, index + 1);
+ str = g_strdup_printf("%s #%u", hostname, index + 1);
DBG("name: %s", str);
@@ -117,17 +138,29 @@ static void property_changed(GDBusProxy *proxy, const char *name,
DBG("pretty hostname: %s", str);
- if (g_str_equal(str, "") == TRUE) {
- g_free(pretty_hostname);
- pretty_hostname = NULL;
- return;
- }
-
g_free(pretty_hostname);
pretty_hostname = g_strdup(str);
adapter_foreach(update_name, NULL);
}
+ } else if (g_str_equal(name, "StaticHostname") == TRUE) {
+ if (iter == NULL) {
+ g_dbus_proxy_refresh_property(proxy, name);
+ return;
+ }
+
+ if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
+ const char *str;
+
+ dbus_message_iter_get_basic(iter, &str);
+
+ DBG("static hostname: %s", str);
+
+ g_free(static_hostname);
+ static_hostname = g_strdup(str);
+
+ adapter_foreach(update_name, NULL);
+ }
} else if (g_str_equal(name, "Chassis") == TRUE) {
if (iter == NULL) {
g_dbus_proxy_refresh_property(proxy, name);
@@ -283,6 +316,7 @@ static void hostname_exit(void)
}
g_free(pretty_hostname);
+ g_free(static_hostname);
}
BLUETOOTH_PLUGIN_DEFINE(hostname, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
--
1.8.1.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter
2013-02-06 21:40 [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Szymon Janc
` (3 preceding siblings ...)
2013-02-06 21:40 ` [PATCH v2 5/5] hostname: Fallback to static hostname if pretty hostname is not set Szymon Janc
@ 2013-02-15 10:51 ` Johan Hedberg
4 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2013-02-15 10:51 UTC (permalink / raw)
To: Szymon Janc; +Cc: linux-bluetooth
Hi Szymon,
On Wed, Feb 06, 2013, Szymon Janc wrote:
> Instead of global default_adapter_id variable use is_default field
> to indicate if adapter is default one.
> ---
> src/adapter.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
All patches in this set have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-02-15 10:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-06 21:40 [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Szymon Janc
2013-02-06 21:40 ` [PATCH v2 2/5] adapter: Mark adapter as default before probing drivers Szymon Janc
2013-02-06 21:40 ` [PATCH v2 3/5] adapter: Always set new default adapter if current one is removed Szymon Janc
2013-02-06 21:40 ` [PATCH v2 4/5] hostname: Fix setting adapter name to empty string Szymon Janc
2013-02-06 21:40 ` [PATCH v2 5/5] hostname: Fallback to static hostname if pretty hostname is not set Szymon Janc
2013-02-15 10:51 ` [PATCH v2 1/5] adapter: Add is_default field to struct btd_adapter Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).