When another adapter is found, the default adapter would be changed,
which is not expected. Default adapter can only be changed by select
command.
---
client/main.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/client/main.c b/client/main.c
index 75696c2c1..29b3978e1 100644
--- a/client/main.c
+++ b/client/main.c
@@ -67,6 +67,7 @@ struct adapter {
};
static struct adapter *default_ctrl;
+static struct adapter *cache_ctrl;
static GDBusProxy *default_dev;
static GDBusProxy *default_attr;
static GList *ctrl_list;
@@ -151,7 +152,7 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
g_list_free_full(ctrl_list, proxy_leak);
ctrl_list = NULL;
-
+ cache_ctrl = NULL;
default_ctrl = NULL;
}
@@ -521,15 +522,21 @@ static void device_added(GDBusProxy *proxy)
static void adapter_added(GDBusProxy *proxy)
{
- default_ctrl = g_malloc0(sizeof(struct adapter));
- default_ctrl->proxy = proxy;
- ctrl_list = g_list_append(ctrl_list, default_ctrl);
+ struct adapter *adapter = g_malloc0(sizeof(struct adapter));
+
+ adapter->proxy = proxy;
+ cache_ctrl = adapter;
+ ctrl_list = g_list_append(ctrl_list, adapter);
+
+ if (!default_ctrl)
+ default_ctrl = adapter;
+
print_adapter(proxy, COLORED_NEW);
}
static void ad_manager_added(GDBusProxy *proxy)
{
- default_ctrl->ad_proxy = proxy;
+ cache_ctrl->ad_proxy = proxy;
}
static void proxy_added(GDBusProxy *proxy, void *user_data)
@@ -602,7 +609,6 @@ static void adapter_removed(GDBusProxy *proxy)
print_adapter(proxy, COLORED_DEL);
if (default_ctrl && default_ctrl->proxy == proxy) {
- default_ctrl = NULL;
set_default_device(NULL, NULL);
}
--
2.14.1.581.gf28d330327-goog
VGhhbmtzIFl1bmhhbiwgDQoNCldlIGhhdmUgZmlndXJlZCBvdXQgaG93IHRvIHVzZSB0aG9zZSBj
b21tYW5kcyBpbiBibHVldG9vdGhjdGwuIEFsc28gd2UgYnVpbHQgMiBoaWdoIGxldmVsIHRvb2xz
LCBnYXR0LWNsaWVudCBhbm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j4+ICAgICAgICAgICAgICAgICAgICAgICBwcmludF9h
ZGFwdGVyKHByb3h5LCBDT0xPUkVEX0RFTCk7DQo+Pj4NCj4+PiAgICAgICAgICAgICAgICAgICAg
ICAgaWYgKGRlZmF1bHRfY3RybCAmJiBkZWZhdWx0X2N0cmwtPnByb3h5ID09IHByb3h5KSB7DQo+
Pj4gLSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGVmYXVsdF9jdHJsID0gTlVMTDsNCj4+
PiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzZXRfZGVmYXVsdF9kZXZpY2UoTlVMTCwg
TlVMTCk7DQo+Pj4gICAgICAgICAgICAgICAgICAgICAgIH0NCj4+Pg0KPj4+DQo+Pg0KPiAtLQ0K
PiBUbyB1bnN1YnNjcmliZSBmcm9tIHRoaXMgbGlzdDogc2VuZCB0aGUgbGluZSAidW5zdWJzY3Jp
YmUgDQo+IGxpbnV4LWJsdWV0b290aCIgaW4gdGhlIGJvZHkgb2YgYSBtZXNzYWdlIHRvIG1ham9y
ZG9tb0B2Z2VyLmtlcm5lbC5vcmcgDQo+IE1vcmUgbWFqb3Jkb21vIGluZm8gYXQgIA0KPiBodHRw
czovL25hMDEuc2FmZWxpbmtzLnByb3RlY3Rpb24ub3V0bG9vay5jb20vP3VybD1odHRwJTNBJTJG
JTJGdmdlci5rDQo+IGVybmVsLm9yZyUyRm1ham9yZG9tby1pbmZvLmh0bWwmZGF0YT0wMSU3QzAx
JTdDTWluZy5aaGFuZyU0MGFycmlzLmNvbSUNCj4gN0NkMDE2M2U2YmQ4NTQ0NDZjYWY2ZDA4ZDRm
MTBkMDQ0NCU3Q2YyNzkyOWFkZTU1NDRkNTU4MzdhYzU2MTUxOWMzMDkxJQ0KPiA3QzEmc2RhdGE9
aklpUlRZaG5CNGtkR0FuSVBSMmRQdG04aTZpYWxMUUZmeUdmVVMxQnhFbyUzRCZyZXNlcnZlZD0w
DQo=
Hi, Ming
Could you post your command from your peripheral and central? Usually
when you set the attribute with read,write permission in peripheral,
then in central, you can select-attribute the characteristic path, and
read/write.
thanks
best wishes
yunhan
On Fri, Sep 1, 2017 at 2:06 PM, Zhang, Ming <[email protected]> wrote:
> Hello,
>
> Can anybody give a help with BlueZ utility bluetoothctl?
> - "read" and "write" commands seem not working? always report "no attribu=
te selected", using "select-attribute" first doesn't help.
>
> Thanks,
> Ming
>
> -----Original Message-----
> From: [email protected] [mailto:linux-bluetooth-owner=
@vger.kernel.org] On Behalf Of Yunhan Wang
> Sent: Friday, September 01, 2017 12:43 AM
> To: ERAMOTO Masaya <[email protected]>
> Cc: [email protected]
> Subject: Re: [PATCH BlueZ] client: Fix default_ctrl change when new adapt=
er is found
>
> Hi, ERAMOTO
>
> cache_ctrl is not advertising manager, cache_ctrl is temporary adapter th=
at store newest adapter info(see the below structure info). When you use se=
lect, find_ctrl_by_address would filter your preferred adapter by your addr=
ess, then if it is default, return, otherwise, it would update default_ctrl=
.
>
> struct adapter {
> GDBusProxy *proxy;
> GDBusProxy *ad_proxy;
> GList *devices;
> };
>
> when new adapter is found, the proxy handler would add adapter proxy, pro=
file proxy, advertising proxy sequentially, in this procedure, cache_ctrl w=
ould update advertising manager.
>
> thanks
> best wishes
> yunhan
>
> On Fri, Sep 1, 2017 at 12:28 AM, ERAMOTO Masaya <[email protected]=
u.com> wrote:
>> Hi Yunhan,
>>
>> Your patch have a regression, since select command can not update the
>> current advertising manager (cache_ctrl) when it chooses another adapter=
.
>>
>> I think that it is better to use proxy->obj_path below:
>>
>> ---
>> client/main.c | 57
>> +++++++++++++++++++++++++++++++++++++++------------------
>> 1 file changed, 39 insertions(+), 18 deletions(-)
>>
>> diff --git a/client/main.c b/client/main.c index 825647d..c6cb995
>> 100644
>> --- a/client/main.c
>> +++ b/client/main.c
>> @@ -525,17 +525,52 @@ static void device_added(GDBusProxy *proxy)
>> }
>> }
>>
>> +static struct adapter *find_ctrl(GList *source, const char *path) {
>> + GList *list;
>> +
>> + for (list =3D g_list_first(source); list; list =3D g_list_next(l=
ist)) {
>> + struct adapter *adapter =3D list->data;
>> +
>> + if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), p=
ath))
>> + return adapter;
>> + }
>> +
>> + return NULL;
>> +}
>> +
>> +static struct adapter *adapter_new(GDBusProxy *proxy) {
>> + struct adapter *adapter =3D g_malloc0(sizeof(struct adapter));
>> +
>> + ctrl_list =3D g_list_append(ctrl_list, adapter);
>> +
>> + if (!default_ctrl)
>> + default_ctrl =3D adapter;
>> +
>> + return adapter;
>> +}
>> +
>> static void adapter_added(GDBusProxy *proxy) {
>> - default_ctrl =3D g_malloc0(sizeof(struct adapter));
>> - default_ctrl->proxy =3D proxy;
>> - ctrl_list =3D g_list_append(ctrl_list, default_ctrl);
>> + struct adapter *ctrl;
>> + ctrl =3D find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
>> + if (!ctrl)
>> + ctrl =3D adapter_new(proxy);
>> +
>> + ctrl->proxy =3D proxy;
>> +
>> print_adapter(proxy, COLORED_NEW); }
>>
>> static void ad_manager_added(GDBusProxy *proxy) {
>> - default_ctrl->ad_proxy =3D proxy;
>> + struct adapter *ctrl;
>> + ctrl =3D find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
>> + if (!ctrl)
>> + ctrl =3D adapter_new(proxy);
>> +
>> + ctrl->ad_proxy =3D proxy;
>> }
>>
>> static void proxy_added(GDBusProxy *proxy, void *user_data) @@
>> -661,20 +696,6 @@ static void proxy_removed(GDBusProxy *proxy, void *use=
r_data)
>> }
>> }
>>
>> -static struct adapter *find_ctrl(GList *source, const char *path) -{
>> - GList *list;
>> -
>> - for (list =3D g_list_first(source); list; list =3D g_list_next(l=
ist)) {
>> - struct adapter *adapter =3D list->data;
>> -
>> - if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), p=
ath))
>> - return adapter;
>> - }
>> -
>> - return NULL;
>> -}
>> -
>> static void property_changed(GDBusProxy *proxy, const char *name,
>> DBusMessageIter *iter, void
>> *user_data) {
>> --
>> 2.7.4
>>
>>
>> Regards,
>> Eramoto
>>
>> On 09/01/2017 12:56 PM, Yunhan Wang wrote:
>>> When another adapter is found, the default adapter would be changed,
>>> which is not expected. Default adapter can only be changed by select
>>> command.
>>> ---
>>> client/main.c | 18 ++++++++++++------
>>> 1 file changed, 12 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/client/main.c b/client/main.c index 75696c2c1..29b3978e1
>>> 100644
>>> --- a/client/main.c
>>> +++ b/client/main.c
>>> @@ -67,6 +67,7 @@ struct adapter {
>>> };
>>>
>>> static struct adapter *default_ctrl;
>>> +static struct adapter *cache_ctrl;
>>> static GDBusProxy *default_dev;
>>> static GDBusProxy *default_attr;
>>> static GList *ctrl_list;
>>> @@ -151,7 +152,7 @@ static void disconnect_handler(DBusConnection
>>> *connection, void *user_data)
>>>
>>> g_list_free_full(ctrl_list, proxy_leak);
>>> ctrl_list =3D NULL;
>>> -
>>> + cache_ctrl =3D NULL;
>>> default_ctrl =3D NULL;
>>> }
>>>
>>> @@ -521,15 +522,21 @@ static void device_added(GDBusProxy *proxy)
>>>
>>> static void adapter_added(GDBusProxy *proxy) {
>>> - default_ctrl =3D g_malloc0(sizeof(struct adapter));
>>> - default_ctrl->proxy =3D proxy;
>>> - ctrl_list =3D g_list_append(ctrl_list, default_ctrl);
>>> + struct adapter *adapter =3D g_malloc0(sizeof(struct adapter));
>>> +
>>> + adapter->proxy =3D proxy;
>>> + cache_ctrl =3D adapter;
>>> + ctrl_list =3D g_list_append(ctrl_list, adapter);
>>> +
>>> + if (!default_ctrl)
>>> + default_ctrl =3D adapter;
>>> +
>>> print_adapter(proxy, COLORED_NEW); }
>>>
>>> static void ad_manager_added(GDBusProxy *proxy) {
>>> - default_ctrl->ad_proxy =3D proxy;
>>> + cache_ctrl->ad_proxy =3D proxy;
>>> }
>>>
>>> static void proxy_added(GDBusProxy *proxy, void *user_data) @@
>>> -602,7 +609,6 @@ static void adapter_removed(GDBusProxy *proxy)
>>> print_adapter(proxy, COLORED_DEL);
>>>
>>> if (default_ctrl && default_ctrl->proxy =3D=3D pr=
oxy) {
>>> - default_ctrl =3D NULL;
>>> set_default_device(NULL, NULL);
>>> }
>>>
>>>
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth=
" in the body of a message to [email protected] More majordomo info=
at https://na01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fvger=
.kernel.org%2Fmajordomo-info.html&data=3D01%7C01%7CMing.Zhang%40arris.com%7=
Cd0163e6bd854446caf6d08d4f10d0444%7Cf27929ade5544d55837ac561519c3091%7C1&sd=
ata=3DjIiRTYhnB4kdGAnIPR2dPtm8i6ialLQFfyGfUS1BxEo%3D&reserved=3D0
Hi, ERAMOTO
On Sun, Sep 3, 2017 at 5:48 PM, ERAMOTO Masaya
<[email protected]> wrote:
> Hi Yunhan,
>
> On 09/02/2017 12:54 PM, Yunhan Wang wrote:
>> Hi, ERAMOTO
>>
>> On Fri, Sep 1, 2017 at 12:59 AM, ERAMOTO Masaya
>> <[email protected]> wrote:
>>> Hi Yunhan,
>>>
>>> Thanks for your explanation.
>>>
>>> Btw, could you also tell me about the following fix.
>>
>> default_ctrl would be set as NULL in disconnect_handler. Therefore I
>> remove this redundant one.
>>
>
> It seems g_dbus_client_unref() calls disconnect_handler() when g_main_loop_run()
> is exited by quit command etc.. So I think here defautl_ctrl should be set as
> NULL in interactive mode.
>
Yes, just send patch to fix it.
>>
>>> bluetoothclt sometimes do core dump when I detach the adapter of default_ctrl
>>> and run show command.
>>
>> Could you share your reproduce step for this issue? Could it be
>> constantly reproduced?
>
> It is always reproduced with the following steps:
>
> 1. Attach an adapter.
> 2. Run bluetoothctl.
> 3. Detach this adapter.
> 4. Run device command in bluetootctl.
>
With the new fix, when you detach adapter, the default_ctrl become
NULL, you should not see the devices via running devices cmd.
>
> Regards,
> Eramoto
>
>>
>> thanks
>> best wishes
>> yunhan
>>
>>
>
thanks
best wishes
yunhan
Hi Yunhan,
On 09/02/2017 12:54 PM, Yunhan Wang wrote:
> Hi, ERAMOTO
>
> On Fri, Sep 1, 2017 at 12:59 AM, ERAMOTO Masaya
> <[email protected]> wrote:
>> Hi Yunhan,
>>
>> Thanks for your explanation.
>>
>> Btw, could you also tell me about the following fix.
>
> default_ctrl would be set as NULL in disconnect_handler. Therefore I
> remove this redundant one.
>
It seems g_dbus_client_unref() calls disconnect_handler() when g_main_loop_run()
is exited by quit command etc.. So I think here defautl_ctrl should be set as
NULL in interactive mode.
>
>> bluetoothclt sometimes do core dump when I detach the adapter of default_ctrl
>> and run show command.
>
> Could you share your reproduce step for this issue? Could it be
> constantly reproduced?
It is always reproduced with the following steps:
1. Attach an adapter.
2. Run bluetoothctl.
3. Detach this adapter.
4. Run device command in bluetootctl.
Regards,
Eramoto
>
> thanks
> best wishes
> yunhan
>
>
Hi, ERAMOTO
On Fri, Sep 1, 2017 at 12:59 AM, ERAMOTO Masaya
<[email protected]> wrote:
> Hi Yunhan,
>
> Thanks for your explanation.
>
> Btw, could you also tell me about the following fix.
default_ctrl would be set as NULL in disconnect_handler. Therefore I
remove this redundant one.
> bluetoothclt sometimes do core dump when I detach the adapter of default_ctrl
> and run show command.
Could you share your reproduce step for this issue? Could it be
constantly reproduced?
thanks
best wishes
yunhan
SGVsbG8sIA0KDQpDYW4gYW55Ym9keSBnaXZlIGEgaGVscCB3aXRoIEJsdWVaIHV0aWxpdHkgYmx1
ZXRvb3RoY3RsPyANCi0gInJlYWQiIGFuZCAid3JpdGUiIGNvbW1hbmRzIHNlZW0gbm90IHdvcmtp
bmc/IGFsd2F5cyByZXBvcnQgIm5vIGF0dHJpYnV0ZSBzZWxlY3RlZCIsIHVzaW5nICJzZWxlY3Qt
YXR0cmlidXRlIiBmaXJzdCBkb2Vzbid0IGhlbHAuIA0KDQpUaGFua3MsIA0KTWluZw0KDQotLS0t
LU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KRnJvbTogbGludXgtYmx1ZXRvb3RoLW93bmVyQHZnZXIu
a2Vybm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SU3QzAxJTdDTWlu
Zy5aaGFuZyU0MGFycmlzLmNvbSU3Q2QwMTYzZTZiZDg1NDQ0NmNhZjZkMDhkNGYxMGQwNDQ0JTdD
ZjI3OTI5YWRlNTU0NGQ1NTgzN2FjNTYxNTE5YzMwOTElN0MxJnNkYXRhPWpJaVJUWWhuQjRrZEdB
bklQUjJkUHRtOGk2aWFsTFFGZnlHZlVTMUJ4RW8lM0QmcmVzZXJ2ZWQ9MA0K
Hi Yunhan,
Thanks for your explanation.
Btw, could you also tell me about the following fix.
bluetoothclt sometimes do core dump when I detach the adapter of default_ctrl
and run show command.
>>> @@ -602,7 +609,6 @@ static void adapter_removed(GDBusProxy *proxy)
>>> print_adapter(proxy, COLORED_DEL);
>>>
>>> if (default_ctrl && default_ctrl->proxy == proxy) {
>>> - default_ctrl = NULL;
>>> set_default_device(NULL, NULL);
Regards,
Eramoto
On 09/01/2017 04:42 PM, Yunhan Wang wrote:
> Hi, ERAMOTO
>
> cache_ctrl is not advertising manager, cache_ctrl is temporary adapter
> that store newest adapter info(see the below structure info). When you
> use select, find_ctrl_by_address would filter your preferred adapter
> by your address, then if it is default, return, otherwise, it would
> update default_ctrl.
>
> struct adapter {
> GDBusProxy *proxy;
> GDBusProxy *ad_proxy;
> GList *devices;
> };
>
> when new adapter is found, the proxy handler would add adapter proxy,
> profile proxy, advertising proxy sequentially, in this procedure,
> cache_ctrl would update advertising manager.
>
> thanks
> best wishes
> yunhan
>
> On Fri, Sep 1, 2017 at 12:28 AM, ERAMOTO Masaya
> <[email protected]> wrote:
>> Hi Yunhan,
>>
>> Your patch have a regression, since select command can not update the current
>> advertising manager (cache_ctrl) when it chooses another adapter.
>>
>> I think that it is better to use proxy->obj_path below:
>>
>> ---
>> client/main.c | 57 +++++++++++++++++++++++++++++++++++++++------------------
>> 1 file changed, 39 insertions(+), 18 deletions(-)
>>
>> diff --git a/client/main.c b/client/main.c
>> index 825647d..c6cb995 100644
>> --- a/client/main.c
>> +++ b/client/main.c
>> @@ -525,17 +525,52 @@ static void device_added(GDBusProxy *proxy)
>> }
>> }
>>
>> +static struct adapter *find_ctrl(GList *source, const char *path)
>> +{
>> + GList *list;
>> +
>> + for (list = g_list_first(source); list; list = g_list_next(list)) {
>> + struct adapter *adapter = list->data;
>> +
>> + if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), path))
>> + return adapter;
>> + }
>> +
>> + return NULL;
>> +}
>> +
>> +static struct adapter *adapter_new(GDBusProxy *proxy)
>> +{
>> + struct adapter *adapter = g_malloc0(sizeof(struct adapter));
>> +
>> + ctrl_list = g_list_append(ctrl_list, adapter);
>> +
>> + if (!default_ctrl)
>> + default_ctrl = adapter;
>> +
>> + return adapter;
>> +}
>> +
>> static void adapter_added(GDBusProxy *proxy)
>> {
>> - default_ctrl = g_malloc0(sizeof(struct adapter));
>> - default_ctrl->proxy = proxy;
>> - ctrl_list = g_list_append(ctrl_list, default_ctrl);
>> + struct adapter *ctrl;
>> + ctrl = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
>> + if (!ctrl)
>> + ctrl = adapter_new(proxy);
>> +
>> + ctrl->proxy = proxy;
>> +
>> print_adapter(proxy, COLORED_NEW);
>> }
>>
>> static void ad_manager_added(GDBusProxy *proxy)
>> {
>> - default_ctrl->ad_proxy = proxy;
>> + struct adapter *ctrl;
>> + ctrl = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
>> + if (!ctrl)
>> + ctrl = adapter_new(proxy);
>> +
>> + ctrl->ad_proxy = proxy;
>> }
>>
>> static void proxy_added(GDBusProxy *proxy, void *user_data)
>> @@ -661,20 +696,6 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
>> }
>> }
>>
>> -static struct adapter *find_ctrl(GList *source, const char *path)
>> -{
>> - GList *list;
>> -
>> - for (list = g_list_first(source); list; list = g_list_next(list)) {
>> - struct adapter *adapter = list->data;
>> -
>> - if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), path))
>> - return adapter;
>> - }
>> -
>> - return NULL;
>> -}
>> -
>> static void property_changed(GDBusProxy *proxy, const char *name,
>> DBusMessageIter *iter, void *user_data)
>> {
>> --
>> 2.7.4
>>
>>
>> Regards,
>> Eramoto
>>
>> On 09/01/2017 12:56 PM, Yunhan Wang wrote:
>>> When another adapter is found, the default adapter would be changed,
>>> which is not expected. Default adapter can only be changed by select
>>> command.
>>> ---
>>> client/main.c | 18 ++++++++++++------
>>> 1 file changed, 12 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/client/main.c b/client/main.c
>>> index 75696c2c1..29b3978e1 100644
>>> --- a/client/main.c
>>> +++ b/client/main.c
>>> @@ -67,6 +67,7 @@ struct adapter {
>>> };
>>>
>>> static struct adapter *default_ctrl;
>>> +static struct adapter *cache_ctrl;
>>> static GDBusProxy *default_dev;
>>> static GDBusProxy *default_attr;
>>> static GList *ctrl_list;
>>> @@ -151,7 +152,7 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
>>>
>>> g_list_free_full(ctrl_list, proxy_leak);
>>> ctrl_list = NULL;
>>> -
>>> + cache_ctrl = NULL;
>>> default_ctrl = NULL;
>>> }
>>>
>>> @@ -521,15 +522,21 @@ static void device_added(GDBusProxy *proxy)
>>>
>>> static void adapter_added(GDBusProxy *proxy)
>>> {
>>> - default_ctrl = g_malloc0(sizeof(struct adapter));
>>> - default_ctrl->proxy = proxy;
>>> - ctrl_list = g_list_append(ctrl_list, default_ctrl);
>>> + struct adapter *adapter = g_malloc0(sizeof(struct adapter));
>>> +
>>> + adapter->proxy = proxy;
>>> + cache_ctrl = adapter;
>>> + ctrl_list = g_list_append(ctrl_list, adapter);
>>> +
>>> + if (!default_ctrl)
>>> + default_ctrl = adapter;
>>> +
>>> print_adapter(proxy, COLORED_NEW);
>>> }
>>>
>>> static void ad_manager_added(GDBusProxy *proxy)
>>> {
>>> - default_ctrl->ad_proxy = proxy;
>>> + cache_ctrl->ad_proxy = proxy;
>>> }
>>>
>>> static void proxy_added(GDBusProxy *proxy, void *user_data)
>>> @@ -602,7 +609,6 @@ static void adapter_removed(GDBusProxy *proxy)
>>> print_adapter(proxy, COLORED_DEL);
>>>
>>> if (default_ctrl && default_ctrl->proxy == proxy) {
>>> - default_ctrl = NULL;
>>> set_default_device(NULL, NULL);
>>> }
>>>
>>>
>>
>
>
Hi, ERAMOTO
cache_ctrl is not advertising manager, cache_ctrl is temporary adapter
that store newest adapter info(see the below structure info). When you
use select, find_ctrl_by_address would filter your preferred adapter
by your address, then if it is default, return, otherwise, it would
update default_ctrl.
struct adapter {
GDBusProxy *proxy;
GDBusProxy *ad_proxy;
GList *devices;
};
when new adapter is found, the proxy handler would add adapter proxy,
profile proxy, advertising proxy sequentially, in this procedure,
cache_ctrl would update advertising manager.
thanks
best wishes
yunhan
On Fri, Sep 1, 2017 at 12:28 AM, ERAMOTO Masaya
<[email protected]> wrote:
> Hi Yunhan,
>
> Your patch have a regression, since select command can not update the current
> advertising manager (cache_ctrl) when it chooses another adapter.
>
> I think that it is better to use proxy->obj_path below:
>
> ---
> client/main.c | 57 +++++++++++++++++++++++++++++++++++++++------------------
> 1 file changed, 39 insertions(+), 18 deletions(-)
>
> diff --git a/client/main.c b/client/main.c
> index 825647d..c6cb995 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -525,17 +525,52 @@ static void device_added(GDBusProxy *proxy)
> }
> }
>
> +static struct adapter *find_ctrl(GList *source, const char *path)
> +{
> + GList *list;
> +
> + for (list = g_list_first(source); list; list = g_list_next(list)) {
> + struct adapter *adapter = list->data;
> +
> + if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), path))
> + return adapter;
> + }
> +
> + return NULL;
> +}
> +
> +static struct adapter *adapter_new(GDBusProxy *proxy)
> +{
> + struct adapter *adapter = g_malloc0(sizeof(struct adapter));
> +
> + ctrl_list = g_list_append(ctrl_list, adapter);
> +
> + if (!default_ctrl)
> + default_ctrl = adapter;
> +
> + return adapter;
> +}
> +
> static void adapter_added(GDBusProxy *proxy)
> {
> - default_ctrl = g_malloc0(sizeof(struct adapter));
> - default_ctrl->proxy = proxy;
> - ctrl_list = g_list_append(ctrl_list, default_ctrl);
> + struct adapter *ctrl;
> + ctrl = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
> + if (!ctrl)
> + ctrl = adapter_new(proxy);
> +
> + ctrl->proxy = proxy;
> +
> print_adapter(proxy, COLORED_NEW);
> }
>
> static void ad_manager_added(GDBusProxy *proxy)
> {
> - default_ctrl->ad_proxy = proxy;
> + struct adapter *ctrl;
> + ctrl = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
> + if (!ctrl)
> + ctrl = adapter_new(proxy);
> +
> + ctrl->ad_proxy = proxy;
> }
>
> static void proxy_added(GDBusProxy *proxy, void *user_data)
> @@ -661,20 +696,6 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
> }
> }
>
> -static struct adapter *find_ctrl(GList *source, const char *path)
> -{
> - GList *list;
> -
> - for (list = g_list_first(source); list; list = g_list_next(list)) {
> - struct adapter *adapter = list->data;
> -
> - if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), path))
> - return adapter;
> - }
> -
> - return NULL;
> -}
> -
> static void property_changed(GDBusProxy *proxy, const char *name,
> DBusMessageIter *iter, void *user_data)
> {
> --
> 2.7.4
>
>
> Regards,
> Eramoto
>
> On 09/01/2017 12:56 PM, Yunhan Wang wrote:
>> When another adapter is found, the default adapter would be changed,
>> which is not expected. Default adapter can only be changed by select
>> command.
>> ---
>> client/main.c | 18 ++++++++++++------
>> 1 file changed, 12 insertions(+), 6 deletions(-)
>>
>> diff --git a/client/main.c b/client/main.c
>> index 75696c2c1..29b3978e1 100644
>> --- a/client/main.c
>> +++ b/client/main.c
>> @@ -67,6 +67,7 @@ struct adapter {
>> };
>>
>> static struct adapter *default_ctrl;
>> +static struct adapter *cache_ctrl;
>> static GDBusProxy *default_dev;
>> static GDBusProxy *default_attr;
>> static GList *ctrl_list;
>> @@ -151,7 +152,7 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
>>
>> g_list_free_full(ctrl_list, proxy_leak);
>> ctrl_list = NULL;
>> -
>> + cache_ctrl = NULL;
>> default_ctrl = NULL;
>> }
>>
>> @@ -521,15 +522,21 @@ static void device_added(GDBusProxy *proxy)
>>
>> static void adapter_added(GDBusProxy *proxy)
>> {
>> - default_ctrl = g_malloc0(sizeof(struct adapter));
>> - default_ctrl->proxy = proxy;
>> - ctrl_list = g_list_append(ctrl_list, default_ctrl);
>> + struct adapter *adapter = g_malloc0(sizeof(struct adapter));
>> +
>> + adapter->proxy = proxy;
>> + cache_ctrl = adapter;
>> + ctrl_list = g_list_append(ctrl_list, adapter);
>> +
>> + if (!default_ctrl)
>> + default_ctrl = adapter;
>> +
>> print_adapter(proxy, COLORED_NEW);
>> }
>>
>> static void ad_manager_added(GDBusProxy *proxy)
>> {
>> - default_ctrl->ad_proxy = proxy;
>> + cache_ctrl->ad_proxy = proxy;
>> }
>>
>> static void proxy_added(GDBusProxy *proxy, void *user_data)
>> @@ -602,7 +609,6 @@ static void adapter_removed(GDBusProxy *proxy)
>> print_adapter(proxy, COLORED_DEL);
>>
>> if (default_ctrl && default_ctrl->proxy == proxy) {
>> - default_ctrl = NULL;
>> set_default_device(NULL, NULL);
>> }
>>
>>
>
Hi Yunhan,
Your patch have a regression, since select command can not update the current
advertising manager (cache_ctrl) when it chooses another adapter.
I think that it is better to use proxy->obj_path below:
---
client/main.c | 57 +++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 39 insertions(+), 18 deletions(-)
diff --git a/client/main.c b/client/main.c
index 825647d..c6cb995 100644
--- a/client/main.c
+++ b/client/main.c
@@ -525,17 +525,52 @@ static void device_added(GDBusProxy *proxy)
}
}
+static struct adapter *find_ctrl(GList *source, const char *path)
+{
+ GList *list;
+
+ for (list = g_list_first(source); list; list = g_list_next(list)) {
+ struct adapter *adapter = list->data;
+
+ if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), path))
+ return adapter;
+ }
+
+ return NULL;
+}
+
+static struct adapter *adapter_new(GDBusProxy *proxy)
+{
+ struct adapter *adapter = g_malloc0(sizeof(struct adapter));
+
+ ctrl_list = g_list_append(ctrl_list, adapter);
+
+ if (!default_ctrl)
+ default_ctrl = adapter;
+
+ return adapter;
+}
+
static void adapter_added(GDBusProxy *proxy)
{
- default_ctrl = g_malloc0(sizeof(struct adapter));
- default_ctrl->proxy = proxy;
- ctrl_list = g_list_append(ctrl_list, default_ctrl);
+ struct adapter *ctrl;
+ ctrl = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
+ if (!ctrl)
+ ctrl = adapter_new(proxy);
+
+ ctrl->proxy = proxy;
+
print_adapter(proxy, COLORED_NEW);
}
static void ad_manager_added(GDBusProxy *proxy)
{
- default_ctrl->ad_proxy = proxy;
+ struct adapter *ctrl;
+ ctrl = find_ctrl(ctrl_list, g_dbus_proxy_get_path(proxy));
+ if (!ctrl)
+ ctrl = adapter_new(proxy);
+
+ ctrl->ad_proxy = proxy;
}
static void proxy_added(GDBusProxy *proxy, void *user_data)
@@ -661,20 +696,6 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
}
}
-static struct adapter *find_ctrl(GList *source, const char *path)
-{
- GList *list;
-
- for (list = g_list_first(source); list; list = g_list_next(list)) {
- struct adapter *adapter = list->data;
-
- if (!strcasecmp(g_dbus_proxy_get_path(adapter->proxy), path))
- return adapter;
- }
-
- return NULL;
-}
-
static void property_changed(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter, void *user_data)
{
--
2.7.4
Regards,
Eramoto
On 09/01/2017 12:56 PM, Yunhan Wang wrote:
> When another adapter is found, the default adapter would be changed,
> which is not expected. Default adapter can only be changed by select
> command.
> ---
> client/main.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/client/main.c b/client/main.c
> index 75696c2c1..29b3978e1 100644
> --- a/client/main.c
> +++ b/client/main.c
> @@ -67,6 +67,7 @@ struct adapter {
> };
>
> static struct adapter *default_ctrl;
> +static struct adapter *cache_ctrl;
> static GDBusProxy *default_dev;
> static GDBusProxy *default_attr;
> static GList *ctrl_list;
> @@ -151,7 +152,7 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
>
> g_list_free_full(ctrl_list, proxy_leak);
> ctrl_list = NULL;
> -
> + cache_ctrl = NULL;
> default_ctrl = NULL;
> }
>
> @@ -521,15 +522,21 @@ static void device_added(GDBusProxy *proxy)
>
> static void adapter_added(GDBusProxy *proxy)
> {
> - default_ctrl = g_malloc0(sizeof(struct adapter));
> - default_ctrl->proxy = proxy;
> - ctrl_list = g_list_append(ctrl_list, default_ctrl);
> + struct adapter *adapter = g_malloc0(sizeof(struct adapter));
> +
> + adapter->proxy = proxy;
> + cache_ctrl = adapter;
> + ctrl_list = g_list_append(ctrl_list, adapter);
> +
> + if (!default_ctrl)
> + default_ctrl = adapter;
> +
> print_adapter(proxy, COLORED_NEW);
> }
>
> static void ad_manager_added(GDBusProxy *proxy)
> {
> - default_ctrl->ad_proxy = proxy;
> + cache_ctrl->ad_proxy = proxy;
> }
>
> static void proxy_added(GDBusProxy *proxy, void *user_data)
> @@ -602,7 +609,6 @@ static void adapter_removed(GDBusProxy *proxy)
> print_adapter(proxy, COLORED_DEL);
>
> if (default_ctrl && default_ctrl->proxy == proxy) {
> - default_ctrl = NULL;
> set_default_device(NULL, NULL);
> }
>
>