Skip to content

Conversation

@ndrs-pst
Copy link
Contributor

@ndrs-pst ndrs-pst commented Dec 8, 2024

This PR aims to eliminate the dependency on ctx_shell in the Bluetooth audio/shell/*, mesh/shell/*, and classic/shell/* directories, making the code more maintainable.
The shell_* functions that depended on ctx_shell have been replaced with the appropriate bt_shell_* functions.

@ndrs-pst
Copy link
Contributor Author

ndrs-pst commented Dec 8, 2024

@Thalley Hi, the follow-up PR after #74652 get merged. 🚀

jhedberg
jhedberg previously approved these changes Dec 8, 2024
Copy link
Member

@jhedberg jhedberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no idea we had this much shell code. Especially on the audio side.

Thalley
Thalley previously approved these changes Dec 8, 2024
@ndrs-pst ndrs-pst dismissed stale reviews from Thalley and jhedberg via 047694e December 9, 2024 04:34
@ndrs-pst ndrs-pst force-pushed the pr_bt_shell_2024-12-08 branch from f7073b0 to 047694e Compare December 9, 2024 04:34
jhedberg
jhedberg previously approved these changes Dec 9, 2024
@PavelVPV PavelVPV added the DNM This PR should not be merged (Do Not Merge) label Dec 9, 2024
@PavelVPV
Copy link
Contributor

PavelVPV commented Dec 9, 2024

Putting DNM to review mesh changes.

Thalley
Thalley previously approved these changes Dec 9, 2024
Comment on lines 8 to 10
Copy link
Contributor

@PavelVPV PavelVPV Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this API is being used not just by host, then I think it should be moved to common/ folder.

This zephyr_library_sources_ifndef part can be fixed by a hidden Kconfig option (added to common/Kconfig) which is selected by BT_MESH_SHELL or BT_SHELL Kconfig options. If I'm not missing anything, this will also solve the _ifndef part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion. Here's the updated approach:

common/Kconfig

config BT_PRIVATE_SHELL
    bool
    default y if BT_MESH_SHELL || BT_SHELL

common/CMakeList

zephyr_library_sources_ifdef(CONFIG_BT_PRIVATE_SHELL bt_shell_private.c)

Then move bt_shell_private.c and bt_shell_private.h into the common folder instead.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. But I'd add select BT_PRIVATE_SHELL to BT_MESH_SHELL and BT_SHELL so it is unconditionally selected when one of these options is enabled. This also makes visible dependency of host and mesh shell on that API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case where BT_MESH_SHELL=y and BT_SHELL=n?

Shouldn't BT_MESH_SHELL depend on BT_SHELL, so that bt_shell_private is always compiled for BT_MESH_SHELL?

Do we need BT_MESH_SHELL at all, or should it just be similar to LE, LL and Classic and enable the mesh shell if BT_SHELL && BT_MESH?

Copy link
Contributor

@PavelVPV PavelVPV Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BT_MESH_SHELL is completely independent of BT_SHELL:

menuconfig BT_MESH_SHELL
bool "Bluetooth Mesh shell"
select SHELL
help
Activate shell module that provides Bluetooth Mesh commands to
the console.

And currently they can't work together. Mesh must be initialized before settings are loaded. The the shell's bt init function doesn't do this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And currently they can't work together. Mesh must be initialized before settings are loaded. The the shell's bt init function doesn't do this.

That sounds fairly trivial to implement.

Would it make sense to get rid of BT_MESH_SHELL (not in this PR of course)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not trivial as it depends on composition data and provisioning context.

There is no such request from users/customers/PMT. Also, 2 shells seem to have different purpose. For mesh most of the code is embedded into an application and the application can enable the mesh shell only for a certain model. For example, you can enable shell commands for client models without changing code in your application by toggling few Kconfig options. The host's shell adds a lot of code which is not needed in most (if not all) mesh applications.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Thalley, according to @PavelVPV's response, can I move forward with the changes as per his suggestion?
Also, I need to resolve the merge conflict too. 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sure :)

Relocated `bt_shell_private.c` to the `common` folder to enable
independent use between `BT_SHELL` and `BT_MESH_SHELL`.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
This change aims to eliminate the dependency on `ctx_shell` in
the Bluetooth `audio/shell/*`, making the code more maintainable.
Replaced `shell_*` functions that depended on `ctx_shell` with
the appropriate `bt_shell_*` functions.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
This change aims to eliminate the dependency on `ctx_shell` in
the Bluetooth `mesh/shell/*`, making the code more maintainable.
Replaced `shell_*` functions that depended on `ctx_shell` with
the appropriate `bt_shell_*` functions.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
@ndrs-pst ndrs-pst dismissed stale reviews from Thalley and jhedberg via 5ef5eaf January 3, 2025 09:13
@ndrs-pst ndrs-pst force-pushed the pr_bt_shell_2024-12-08 branch from 047694e to 5ef5eaf Compare January 3, 2025 09:13
@zephyrbot zephyrbot added area: Bluetooth Controller area: Bluetooth ISO Bluetooth LE Isochronous Channels labels Jan 3, 2025
This change aims to eliminate the dependency on `ctx_shell` in
the Bluetooth `classic/shell/*`, making the code more maintainable.
Replaced `shell_*` functions that depended on `ctx_shell` with
the appropriate `bt_shell_*` functions.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
This commit removes the `ctx_shell` declaration from the Bluetooth shell,
marking a milestone in eliminating this dependency.

Signed-off-by: Pisit Sawangvonganan <[email protected]>
@ndrs-pst ndrs-pst force-pushed the pr_bt_shell_2024-12-08 branch from 5ef5eaf to 48cff96 Compare January 3, 2025 09:58
Comment on lines +247 to +249
config BT_PRIVATE_SHELL
bool
default n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I suggest an alternative here?

Suggested change
config BT_PRIVATE_SHELL
bool
default n
config BT_PRIVATE_SHELL
def_bool BT_SHELL || BT_MESH_SHELL

select should be used sparingly: https://docs.zephyrproject.org/latest/build/kconfig/tips.html#select-pitfalls, and while this specific use is one of the "safe" uses of select, defaulting to the values that would otherwise select it is more flexible (works with ints too), and avoids any future issues with select, while achieving the same.

That being said, it could also be argued that BT_PRIVATE_SHELL is a bit overkill, and that

zephyr_library_sources_ifdef(CONFIG_BT_PRIVATE_SHELL bt_shell_private.c)

could just be modified to

if (CONFIG_BT_SHELL OR CONFIG_BT_MESH_SHELL)
	zephyr_library_sources(bt_shell_private.c)
endif()

If you want to keep it as is, then I my only suggestion would be to

Suggested change
config BT_PRIVATE_SHELL
bool
default n
config BT_PRIVATE_SHELL
bool

as bool Kconfigs always default to false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment. May I also get a suggestion from @PavelVPV?
Additionally, I'm waiting for the CI to turn green first.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to keep Kconfig option, then I think it is exactly the case for select. It won't cause issues described in the doc as these functions don't bring new dependencies.

It can be a bit more clear to have a Kconfig option rather than including bt_shell_private.c by explicitly checking bt shell o rmesh shell Kconfig options state as it won't require CMakeLists.txt change if these functions need to be enabled in some other cases. But I leave it to you here.

@PavelVPV PavelVPV removed the DNM This PR should not be merged (Do Not Merge) label Jan 14, 2025
@kartben kartben merged commit bd92494 into zephyrproject-rtos:main Jan 14, 2025
27 of 28 checks passed
@ndrs-pst ndrs-pst deleted the pr_bt_shell_2024-12-08 branch January 14, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants