Skip to content

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

Merged
merged 7 commits into from
Feb 11, 2019
Merged

Conversation

SeppoTakalo
Copy link
Contributor

@SeppoTakalo SeppoTakalo commented Jan 18, 2019

Description

Allow more than one callback to be register to NetworkInterfaces.
This introduces new APIs:

void NetworkInterface::add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
void NetworkInterface::remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);

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:

void NetworkInterface::add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
void NetworkInterface::remove_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);

Earlier NetworkInterface::attach() is still functional, and it is a porting API that each interface should provide. The new API uses internally NetworkInterface::attach() so application cannot use both APIs at the same time. Application should either be completely refactored to new API by replacing NetworkInterface::attach() calls with NetworkInterface::add_event_listener() or remain using the NetworkInterface::attach() both APIs are still supported but usage is limited to either one of these.

Pull request type

[ ] Fix
[ ] Refactor
[ ] Target update
[X] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@kjbracey-arm @yogpan01 @teetak01

@ciarmcom
Copy link
Member

@SeppoTakalo, thank you for your changes.
@yogpan01 @teetak01 @kjbracey-arm @ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-maintainers please review.

}
}

void NetworkInterface::add_event_listener(void (*status_cb)(nsapi_event_t, intptr_t))
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@SeppoTakalo SeppoTakalo changed the title WIP: Allows multiple network status listeners Allows multiple network status listeners Jan 29, 2019
@SeppoTakalo
Copy link
Contributor Author

This work is now complete and no blocker issues.

Can be tested and merged in.

@SeppoTakalo
Copy link
Contributor Author

features/netsocket/NetworkInterface.h
=================================
Errors: 
246: unregister
272: unregister

Why unregister is not a word according to our language check?
https://en.wiktionary.org/wiki/unregister

@michalpasztamobica
Copy link
Contributor

Why `unregister` is not a word according to our language check?
https://en.wiktionary.org/wiki/unregister

Can you try 'deregister'?

@SeppoTakalo
Copy link
Contributor Author

Why `unregister` is not a word according to our language check?
https://en.wiktionary.org/wiki/unregister

Can you try 'deregister'?

No.

I'll bend the system to my will.

Copy link
Contributor

@michalpasztamobica michalpasztamobica left a 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:

  1. 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);
  1. 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)

Seppo Takalo added 3 commits January 31, 2019 15:04
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.
@SeppoTakalo
Copy link
Contributor Author

@michalpasztamobica Added the unittest that you proposed.

@michalpasztamobica
Copy link
Contributor

Thank you, review reapproved after changes..

Standard new operator already calls MBED_ERROR in failure.
@cmonr cmonr removed the needs: CI label Feb 2, 2019
@SeppoTakalo
Copy link
Contributor Author

@kjbracey-arm Is this error coming from ns_list.h?

@SeppoTakalo
Copy link
Contributor Author

Checked with Kevin.B.
Should be fixed now.

@SeppoTakalo
Copy link
Contributor Author

@0xc0170 can be tested now.

@SeppoTakalo
Copy link
Contributor Author

Actually.. Don't test yet..
I can still see the failure in
https://mbed-os.mbedcloudtesting.com/job/mbed-os-ci_build-IAR/1404/

@SeppoTakalo
Copy link
Contributor Author

Now should pass the IAR tests. Verified in https://mbed-os.mbedcloudtesting.com/job/mbed-os-ci_fork-test/88/

@SeppoTakalo
Copy link
Contributor Author

@cmonr or @0xc0170 This can be now tested. Thanks.

@adbridge
Copy link
Contributor

adbridge commented Feb 7, 2019

@michalpasztamobica @kjbracey-arm @VeijoPesonen @KariHaapalehto could you please re-review the latest updates from Seppo.

@adbridge
Copy link
Contributor

adbridge commented Feb 7, 2019

CI started

@0xc0170 0xc0170 requested a review from AnotherButler February 7, 2019 13:54
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 7, 2019

Requested adding release notes section (@AnotherButler to review once added)

@mbed-ci
Copy link

mbed-ci commented Feb 7, 2019

Test run: FAILED

Summary: 1 of 12 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@SeppoTakalo
Copy link
Contributor Author

I can see that within the failing test job there is 1060 / SKIP / NUCLEO_F429ZI /and within those log files, it looks like this:

...
	tests-mbed_hal-rtc
	test filtered out 'tests-mbed_hal-rtc'
	tests-integration-basic
	test filtered out 'tests-integration-basic'
	tests-mbed_functional-functionpointer
	test filtered out 'tests-mbed_functional-functionpointer'
	tests-mbed_drivers-sleep_lock
	test filtered out 'tests-mbed_drivers-sleep_lock'
mbedgt: invalid test case names (specified with 'skip-test' option)
mbedgt: test name 'tests-usb_device-*' not found in 'runtime_load' (specified with --test-spec option)
	note: test case names are case sensitive
	note: see list of available test cases below
mbedgt: available tests for build 'NUCLEO_F429ZI-GCC_ARM', location 'BUILD/tests/NUCLEO_F429ZI/GCC_ARM'
mbedgt: running 0 tests for platform 'NUCLEO_F429ZI' and toolchain 'GCC_ARM'
	use 1 instance of execution threads for testing
mbedgt: all tests finished!
mbedgt: shuffle seed: 0.1498677645
mbedgt: exporting to JUNIT file 'results/report_test_greentea_NUCLEO_F429ZI_GCC_ARM.xml'...
mbedgt: exporting to HTML file 'results/report_test_greentea_NUCLEO_F429ZI_GCC_ARM.html'...
mbedgt: no platform/target matching tests were found!
mbedgt: completed in 0.13 sec
mbedgt: exited with code -10

What does this mean? It did not run anything...

@alekla01
Copy link
Contributor

alekla01 commented Feb 8, 2019

The greentea-test was restarted and not commented here as restarted, my bad.
@SeppoTakalo it was skipped, because all the test binaries (with the same hash) had already passed previously, no reason to retest.

@SeppoTakalo
Copy link
Contributor Author

@alekla01 Thanks for the clarification.

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.