Skip to content

refactor(RemoteServ): Reduce nesting #291

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thekurtovic
Copy link
Collaborator

@thekurtovic thekurtovic commented Jan 13, 2025

  • Adds parameter out to retrieveCharacteristics, default value works as the original method.
    • out: if not nullptr, will allow caller to obtain the characteristic
  • Add check to retrieveCharacteristics, return if found the last handle
  • Rename characteristicDiscCB to chrDiscCB
  • General cleanup

@thekurtovic
Copy link
Collaborator Author

thekurtovic commented Jan 13, 2025

Same treatment as previous PR. I assumed similar rules apply here, but let me know if it's wrong.
NimBLEClient also has a similar section of code. I was thinking of making a class which the other 3 classes will be derived from, then move the retrieve function into the new class and make it a template.
Would look something like this

NimBLERemoteCharacteristic* NimBLERemoteService::getCharacteristic(const NimBLEUUID& uuid) const {
    NIMBLE_LOGD(LOG_TAG, ">> getCharacteristic: uuid: %s", uuid.toString().c_str());
    NimBLERemoteCharacteristic* pChar = nullptr;

    retrieve(uuid, pChar, m_vChars, [this](const NimBLEUUID* u, void* o) {
        return retrieveCharacteristics(u, (NimBLERemoteCharacteristic*)o);
    });

Might have to roll back to bool retrieveDescriptors(const NimBLEUUID* uuidFilter = nullptr, NimBLERemoteDescriptor* out = nullptr) const; in NimBLERemoteCharacteristic to make it work though.

@h2zero
Copy link
Owner

h2zero commented Jan 14, 2025

Looks good and I agree with the consolidation thought. Not sure if creating/inheriting from a class for this purpose is the way to go because the client class would also need to inherit from it. Maybe a utility function instead?

@thekurtovic
Copy link
Collaborator Author

Sure, that works too.

@thekurtovic
Copy link
Collaborator Author

Does retrieveCharacteristics need a check similar to 8158a16?

@h2zero
Copy link
Owner

h2zero commented Jan 26, 2025

Probably not, unless it's an empty service, which would be weird. Wouldn't be the worst idea to add it anyway though.

@thekurtovic thekurtovic force-pushed the refactor-remote-svc branch 3 times, most recently from f5aca05 to 75d77d9 Compare January 26, 2025 21:58
@thekurtovic thekurtovic marked this pull request as draft January 26, 2025 22:32
@thekurtovic thekurtovic force-pushed the refactor-remote-svc branch 3 times, most recently from eec32d5 to 2c909ff Compare January 27, 2025 04:31
* Adds parameter out to retrieveCharacteristics, default value works as
  the original method.
    * out: if not nullptr, will allow caller to obtain the characteristic
* Add check to retrieveCharacteristics, return if found the last handle
* General cleanup
}

NIMBLE_LOGE(LOG_TAG, "<< retrieveCharacteristics() rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
return false;
if (out) {
Copy link
Owner

Choose a reason for hiding this comment

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

💯

Copy link
Owner

Choose a reason for hiding this comment

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

You have to love those mysterious compiler warnings when it comes to pointers, been there done that lol!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could have swore the consolidation PR omits the nullptr check and was able to pass.
Wasted so much time on this stupid error lol, especially since it was building fine on my end.
I'm assuming the build check uses more pedantic flags or something, would be nice to have a similar setup locally.

@thekurtovic
Copy link
Collaborator Author

I introduced some minor changes since the previous successful build. Let me know if I should revert.
Since characteristicDiscCB doesn't mention the function name in the log messages, I shortened the name so that the multi-line function calls could be avoided in retrieveCharacteristics.
Also tried thinking of a more compact way to write connHandle, endHandle, etc. Settled on hdleConn, hdlEnd, but considered using h as a prefix to signify handles.

Btw when a PR gets merged, does it use the message from the OP or the message from the commit?

@thekurtovic thekurtovic marked this pull request as ready for review January 27, 2025 04:50
@h2zero
Copy link
Owner

h2zero commented Jan 27, 2025

I'm not concerned with the naming, as long as it's somewhat consistent throughout the library and obvious/readable for casual observers as to what they represent, in this case the original naming suits but I'm happy to entertain changes.

Btw when a PR gets merged, does it use the message from the OP or the message from the commit?

The title/message on github for each commit in a PR is what will be seen in git log when pulled by anyone else.

@thekurtovic
Copy link
Collaborator Author

thekurtovic commented Jan 27, 2025

Some of the BLE jargon just adds so much bloat when written in full like characteristic, descriptor, etc.; which then causes the need to break function calls up with one parameter per line.

I definitely think some standardization should be established which will make things more concise while still having a clear meaning. Though that's probably a 3.0 discussion.

The title/message on github for each commit in a PR is what will be seen in git log when pulled by anyone else.

Good to know. Sometimes I mess up the message in the terminal and wasn't sure if I need to bother repushing.

@h2zero
Copy link
Owner

h2zero commented Jan 27, 2025

Some of the BLE jargon just adds so much bloat when written in full like characteristic, descriptor, etc.; which then causes the need to break function calls up with one parameter per line.

Yeah, drives me crazy sometimes.

I definitely think some standardization should be established which will make things more concise while still having a clear meaning. Though that's probably a 3.0 discussion.

Absolutely

Good to know. Sometimes I mess up the message in the terminal and wasn't sure if I need to bother repushing

No promises lol, it comes down to the person merging, it can all be edited.

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.

2 participants