Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[controller] Create ControllerInitParams class init params #5747

Merged
merged 2 commits into from
Apr 1, 2021

Conversation

erjiaqing
Copy link
Contributor

@erjiaqing erjiaqing commented Apr 1, 2021

Problem

The arguments for calling Controller::Init looks not clean.

Summary of Changes

Wrap them in seperare struct.

Further considerations: The SystemLayer, the InetLayer are singleton infact and their life cycle should be the same as the program and we wrap them in classes just for convenience,

However, there do exist some seneros that we don't use full device layer, for example, the Android app.

Anyway, when using a wrapper class, we can reduce the work for adding / removing params in the future.

System::Layer * systemLayer = nullptr, Inet::InetLayer * inetLayer = nullptr);
CHIP_ERROR Init(NodeId localDeviceId, ControllerInitParams params);

[[deprecated("Use ControllerInitParams instead")]] CHIP_ERROR Init(NodeId localDeviceId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't add this without re-enabling -Wdeprecated-declarations:
https://github.com/project-chip/connectedhomeip/blob/master/build/config/compiler/BUILD.gn#L147

(i.e., We should not use our own deprecated interfaces. To do so breaks any project that includes CHIP, enables -Wdeprecated-declarations, and prohibits non-fatal diagnostics using -Werror)

To be honest, I don't think we need to worry about using [[deprecated]] at all prior to 1.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So maybe we can just left this function as is, with a comment to indicate future changes to Init should use ControllerInitParams?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, that sounds good. My concern is just breaking builds.

System::Layer * systemLayer = nullptr;
Inet::InetLayer * inetLayer = nullptr;

ControllerInitParams() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize this pattern is elsewhere, but I don't understand why we need all this.

What's wrong with

struct ControllerInitParams
{
    PersistentStorageDelegate * storageDelegate = nullptr;
    System::Layer * systemLayer                 = nullptr;
    Inet::InetLayer * inetLayer                 = nullptr;
};

?

(maybe I just don't understand the desire to build a whole object as a one-liner. Personally, I think the lack of line breaks is a negative for readability)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found even if we dont use the setter, we can still write code in one-liner style.
Since this is just a wrapper of several params (and to avoid merge conflicts), I think the bare struct without getter/setter is ok.

Copy link
Contributor

@mspang mspang left a comment

Choose a reason for hiding this comment

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

This init style was not standard until C++20.

But it was an extension long before that, so maybe we are OK with it.

@andy31415 andy31415 merged commit 3cb69ff into project-chip:master Apr 1, 2021
kghost added a commit to kghost/connectedhomeip that referenced this pull request Apr 7, 2021
kghost added a commit to kghost/connectedhomeip that referenced this pull request Apr 8, 2021
jimlyall-q pushed a commit to jimlyall-q/connectedhomeip that referenced this pull request Apr 13, 2021
…hip#5747)

* [controller] Create InitParams class

* Remove Setter and Deprecated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants