* [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL
@ 2018-03-26 13:33 Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 2/4] shared/shell: Add export command Luiz Augusto von Dentz
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-03-26 13:33 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If value is NULL there is no point in allocating any data if value is
NULL since bt_shell_get_env would return NULL anyway, also this makes
sure the existing value is freed which means passing NULL can remove
an env like it was intended.
---
src/shared/shell.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/shared/shell.c b/src/shared/shell.c
index 33bc0d980..241878b30 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -1142,6 +1142,8 @@ void bt_shell_set_env(const char *name, void *value)
struct bt_shell_env *env;
if (!data.envs) {
+ if (!value)
+ return;
data.envs = queue_new();
goto done;
}
@@ -1150,6 +1152,10 @@ void bt_shell_set_env(const char *name, void *value)
if (env)
env_destroy(env);
+ /* Don't create an env if value is not set */
+ if (!value)
+ return;
+
done:
env = new0(struct bt_shell_env, 1);
env->name = strdup(name);
--
2.14.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ 2/4] shared/shell: Add export command
2018-03-26 13:33 [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
@ 2018-03-26 13:33 ` Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 3/4] client: Add envs for proxies Luiz Augusto von Dentz
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-03-26 13:33 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds export command to default menu which can be used to print
the environment variables that have been set.
---
src/shared/shell.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/shared/shell.c b/src/shared/shell.c
index 241878b30..552e066d7 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -198,6 +198,17 @@ static bool cmd_back_exists(const struct bt_shell_menu *menu)
return true;
}
+static void cmd_export(int argc, char *argv[])
+{
+ const struct queue_entry *entry;
+
+ for (entry = queue_get_entries(data.envs); entry; entry = entry->next) {
+ struct bt_shell_env *env = entry->data;
+
+ print_text(COLOR_HIGHLIGHT, "%s=%p", env->name, env->value);
+ }
+}
+
static const struct bt_shell_menu_entry default_menu[] = {
{ "back", NULL, cmd_back, "Return to main menu", NULL,
NULL, cmd_back_exists },
@@ -209,6 +220,8 @@ static const struct bt_shell_menu_entry default_menu[] = {
{ "exit", NULL, cmd_quit, "Quit program" },
{ "help", NULL, cmd_help,
"Display help about this program" },
+ { "export", NULL, cmd_export,
+ "Print evironment variables" },
{ }
};
--
2.14.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ 3/4] client: Add envs for proxies
2018-03-26 13:33 [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 2/4] shared/shell: Add export command Luiz Augusto von Dentz
@ 2018-03-26 13:33 ` Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 4/4] client: Attempt to convert the device path to address Luiz Augusto von Dentz
2018-03-29 11:12 ` [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-03-26 13:33 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This adds envs for device and adapter proxies found so other files are
able to access them.
---
client/main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/client/main.c b/client/main.c
index 584217a82..a36e932ac 100644
--- a/client/main.c
+++ b/client/main.c
@@ -456,6 +456,7 @@ static void device_added(GDBusProxy *proxy)
adapter->devices = g_list_append(adapter->devices, proxy);
print_device(proxy, COLORED_NEW);
+ bt_shell_set_env(g_dbus_proxy_get_path(proxy), proxy);
if (default_dev)
return;
@@ -494,6 +495,7 @@ static void adapter_added(GDBusProxy *proxy)
adapter->proxy = proxy;
print_adapter(proxy, COLORED_NEW);
+ bt_shell_set_env(g_dbus_proxy_get_path(proxy), proxy);
}
static void ad_manager_added(GDBusProxy *proxy)
@@ -561,6 +563,7 @@ static void device_removed(GDBusProxy *proxy)
adapter->devices = g_list_remove(adapter->devices, proxy);
print_device(proxy, COLORED_DEL);
+ bt_shell_set_env(g_dbus_proxy_get_path(proxy), NULL);
if (default_dev == proxy)
set_default_device(NULL, NULL);
@@ -575,6 +578,7 @@ static void adapter_removed(GDBusProxy *proxy)
if (adapter->proxy == proxy) {
print_adapter(proxy, COLORED_DEL);
+ bt_shell_set_env(g_dbus_proxy_get_path(proxy), NULL);
if (default_ctrl && default_ctrl->proxy == proxy) {
default_ctrl = NULL;
--
2.14.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH BlueZ 4/4] client: Attempt to convert the device path to address
2018-03-26 13:33 [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 2/4] shared/shell: Add export command Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 3/4] client: Add envs for proxies Luiz Augusto von Dentz
@ 2018-03-26 13:33 ` Luiz Augusto von Dentz
2018-03-29 11:12 ` [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-03-26 13:33 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Printing the object path is not only long but it also may change.
---
client/gatt.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/client/gatt.c b/client/gatt.c
index cbf7adf57..7103c4f83 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -1415,6 +1415,20 @@ static const GDBusPropertyTable chrc_properties[] = {
{ }
};
+static const char *path_to_address(const char *path)
+{
+ GDBusProxy *proxy;
+ DBusMessageIter iter;
+ const char *address = path;
+
+ proxy = bt_shell_get_env(path);
+
+ if (g_dbus_proxy_get_property(proxy, "Address", &iter))
+ dbus_message_iter_get_basic(&iter, &address);
+
+ return address;
+}
+
static int parse_options(DBusMessageIter *iter, uint16_t *offset, uint16_t *mtu,
char **device, char **link)
{
@@ -1539,8 +1553,8 @@ static DBusMessage *chrc_read_value(DBusConnection *conn, DBusMessage *msg,
"org.bluez.Error.InvalidArguments",
NULL);
- bt_shell_printf("ReadValue: %s offset %u link %s\n", device, offset,
- link);
+ bt_shell_printf("ReadValue: %s offset %u link %s\n",
+ path_to_address(device), offset, link);
if (chrc->authorization_req && offset == 0)
chrc->authorized = false;
@@ -1722,7 +1736,8 @@ static DBusMessage *chrc_acquire_write(DBusConnection *conn, DBusMessage *msg,
"org.bluez.Error.InvalidArguments",
NULL);
- bt_shell_printf("AcquireWrite: %s link %s\n", device, link);
+ bt_shell_printf("AcquireWrite: %s link %s\n", path_to_address(device),
+ link);
reply = chrc_create_pipe(chrc, msg);
@@ -1753,7 +1768,8 @@ static DBusMessage *chrc_acquire_notify(DBusConnection *conn, DBusMessage *msg,
"org.bluez.Error.InvalidArguments",
NULL);
- bt_shell_printf("AcquireNotify: %s link %s\n", device, link);
+ bt_shell_printf("AcquireNotify: %s link %s\n", path_to_address(device),
+ link);
reply = chrc_create_pipe(chrc, msg);
@@ -1961,8 +1977,8 @@ static DBusMessage *desc_read_value(DBusConnection *conn, DBusMessage *msg,
"org.bluez.Error.InvalidArguments",
NULL);
- bt_shell_printf("ReadValue: %s offset %u link %s\n", device, offset,
- link);
+ bt_shell_printf("ReadValue: %s offset %u link %s\n",
+ path_to_address(device), offset, link);
if (offset > desc->value_len)
return g_dbus_create_error(msg, "org.bluez.Error.InvalidOffset",
@@ -1993,8 +2009,8 @@ static DBusMessage *desc_write_value(DBusConnection *conn, DBusMessage *msg,
"org.bluez.Error.InvalidArguments",
NULL);
- bt_shell_printf("WriteValue: %s offset %u link %s\n", device, offset,
- link);
+ bt_shell_printf("WriteValue: %s offset %u link %s\n",
+ path_to_address(device), offset, link);
bt_shell_printf("[" COLORED_CHG "] Attribute %s written" , desc->path);
--
2.14.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL
2018-03-26 13:33 [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
` (2 preceding siblings ...)
2018-03-26 13:33 ` [PATCH BlueZ 4/4] client: Attempt to convert the device path to address Luiz Augusto von Dentz
@ 2018-03-29 11:12 ` Luiz Augusto von Dentz
3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2018-03-29 11:12 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
Hi,
On Mon, Mar 26, 2018 at 4:33 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> If value is NULL there is no point in allocating any data if value is
> NULL since bt_shell_get_env would return NULL anyway, also this makes
> sure the existing value is freed which means passing NULL can remove
> an env like it was intended.
> ---
> src/shared/shell.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index 33bc0d980..241878b30 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -1142,6 +1142,8 @@ void bt_shell_set_env(const char *name, void *value)
> struct bt_shell_env *env;
>
> if (!data.envs) {
> + if (!value)
> + return;
> data.envs = queue_new();
> goto done;
> }
> @@ -1150,6 +1152,10 @@ void bt_shell_set_env(const char *name, void *value)
> if (env)
> env_destroy(env);
>
> + /* Don't create an env if value is not set */
> + if (!value)
> + return;
> +
> done:
> env = new0(struct bt_shell_env, 1);
> env->name = strdup(name);
> --
> 2.14.3
Applied.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-03-29 11:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-26 13:33 [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 2/4] shared/shell: Add export command Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 3/4] client: Add envs for proxies Luiz Augusto von Dentz
2018-03-26 13:33 ` [PATCH BlueZ 4/4] client: Attempt to convert the device path to address Luiz Augusto von Dentz
2018-03-29 11:12 ` [PATCH BlueZ 1/4] shared/shell: Don't allocate any data if env value is NULL Luiz Augusto von Dentz
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).