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

WiFiManagerParameter API Changes #1773

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

dmadison
Copy link

@dmadison dmadison commented Oct 30, 2024

This PR makes some small API changes to the WiFiManagerParameter class to improve clarity, usability, and encapsulation:

Length to Max Length

  • All length arguments have been changed to maxLength
  • getValueLength() has been changed to getValueMaxLength()

When used as an argument, this refers to the max length of the form and the size of the internal buffer, not the length of the string passed as an argument as expected.

Similarly, the value returned is the max length of the form and the size of the internal buffer, not the length of the value stored.

The internal name (_length) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version.

ID to Name

  • getID() has been changed to getName()

In HTML forms, names and IDs are two different attributes. Although this value is applied to both, when submitted the form data corresponds to the name, not the ID. This causes confusion if we want the name and ID to differ, since we are currently calling the name the ID internally.

The internal name (_id) has not been changed to maintain compatibility with user code, as it's exposed as a protected value. This should be changed in the next major version.

Value Received Function

  • Created a setValueReceived() function to receive data from the server

Currently the user can set the parameter value and max length via the setValue(const char *defaultValue, int maxLength) function, and in WiFiManager::doParamSave() the server sets the value directly to the buffer pointer using the existing max length.

This function provides a standardized way for the server (and any user code) to set a new value while respecting the existing max length value. This is also virtual, so derived parameter classes can intercept the received value and perform additional logic or sanitization if necessary.

WiFiManager friendship removed

There is no reason for the WiFiManager class to have a friendship with the parameter class. The internal calls have been replaced with the corresponding public functions and the friendship has been removed.

Incidental Bugfixes

  • setValue() now checks if a max length argument is negative
  • WiFiManagerParameter's destructor is now virtual

Although PR contains API changes there should be no breaking changes. The few items marked deprecated should be removed on the next major release.

If this is merged, here are the changes to make on the next major release:

  • WiFiManagerParameter::_length should be refactored to _maxLength
  • WiFiManagerParameter::getValueLength() const should be removed
  • WiFiManagerParameter::_id should be refactored to _name
  • WiFiManagerParameter::getID() const should be removed

This is a reworked version of PR #1772 that will serve as a basis for other WiFiManagerParameter related PRs.

This does *not* refer to the length of the string passed in, or the length of the string currently stored. This refers to the maximum length of the HTML form, and the size of the class buffer to hold the value.

Note that this does *not* change the internal _length name, because the variable is exposed as protected and through friendship with WiFiManager. It is however marked deprecated and can be changed on the next major release.
To clarify that the function returns the *max* possible length, and not the length of the current value.

Deprecating getValueLength for removal on next major release.
In HTML forms names and IDs are two different things. Although this value is applied to both attributes, the form data corresponds to the name, *not* the ID. This causes confusion if we want the name and ID to differ, since we are currently calling the name the ID.
For intercepting the value received from the server in derived classes
Preventing a new default value from being assigned if the max length is set to a negative value
Because this is polymorphic, the destructor needs to be virtual to allow for properly clearing data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant