-
Notifications
You must be signed in to change notification settings - Fork 3k
Allows multiple network status listeners #9424
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
Conversation
@SeppoTakalo, thank you for your changes. |
} | ||
} | ||
|
||
void NetworkInterface::add_event_listener(void (*status_cb)(nsapi_event_t, intptr_t)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about if you give NULL here as status_cb?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you?
It is not acceptable value and leads to HardFault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being protective on your API and checking for NULL values can seriously hide bugs where your data types or pointers gets corrupted and are overwritten with zeros.
Then when that data is fed to here, it will be silently ignored, and device keeps running, but actually never receives callbacks.
Opposite would be that data corruption would immediately lead to HardFault when fed into APIs that try to access the value.
These Hardfault are quickly catched in the testing whereas silently ignoring carbage might lead to very hard to debug issues, as it might take long time to capture your failure and there is no knowledge anymore where it went wrong.
You should only do protective programming in external interfaces where you can expect carbage.
2384b68
to
95f311c
Compare
This work is now complete and no blocker issues. Can be tested and merged in. |
Why |
Can you try 'deregister'? |
No. I'll bend the system to my will. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve, but if the PR is not urgent, I think that two simple checkes could be added to unit tests:
- Check that an empty listeners list causes no callbacks if the event is sent:
iface->event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, 0);
EXPECT_EQ(callback_is_called, true);
- Perform the same check after the list got emptied (in case someone, intentionally or by mistake, adds a mechanism that would prevent the last listener from being removed from the list)
Allow more than one callback to be register to NetworkInterfaces. This introduces new APIs: void NetworkInterface::add_event_listener(...); void NetworkInterface::remove_event_listener(...); Which internally calls interfaces attach() functions.
->move() operator was not touching unused data fields, therefore leaving uninitialised data and failing the comparison. Fixed by initialising all fields to zero before moving.
d6c6248
to
e9f5ed4
Compare
@michalpasztamobica Added the unittest that you proposed. |
Thank you, review reapproved after changes.. |
Standard new operator already calls MBED_ERROR in failure.
@kjbracey-arm Is this error coming from ns_list.h? |
0f5bfc0
to
26c57fc
Compare
Checked with Kevin.B. |
@0xc0170 can be tested now. |
Actually.. Don't test yet.. |
26c57fc
to
43a53df
Compare
Now should pass the IAR tests. Verified in https://mbed-os.mbedcloudtesting.com/job/mbed-os-ci_fork-test/88/ |
@michalpasztamobica @kjbracey-arm @VeijoPesonen @KariHaapalehto could you please re-review the latest updates from Seppo. |
CI started |
Requested adding release notes section (@AnotherButler to review once added) |
Test run: FAILEDSummary: 1 of 12 test jobs failed Failed test jobs:
|
I can see that within the failing test job there is
What does this mean? It did not run anything... |
The greentea-test was restarted and not commented here as restarted, my bad. |
@alekla01 Thanks for the clarification. |
Description
Allow more than one callback to be register to NetworkInterfaces.
This introduces new APIs:
Which internally calls
NetworkInterface::attach()
function.Also contains fix for: #9423
Target: Mbed OS 5.12
Release notes
NetworkInterface API is extended with two new functions regarding status callbacks. Applications now have possibility to use these new APIs to register more than one callback per network interface. New APIs are as follows:
Earlier
NetworkInterface::attach()
is still functional, and it is a porting API that each interface should provide. The new API uses internallyNetworkInterface::attach()
so application cannot use both APIs at the same time. Application should either be completely refactored to new API by replacingNetworkInterface::attach()
calls withNetworkInterface::add_event_listener()
or remain using theNetworkInterface::attach()
both APIs are still supported but usage is limited to either one of these.Pull request type
Reviewers
@kjbracey-arm @yogpan01 @teetak01