Skip to content

Add NetworkInterface::get_default_instance() #6855

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 1 commit into from
May 21, 2018

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented May 9, 2018

Description

Provide a framework to make it easier to find a default network
interface.

New version of #6108

Envisaged use:

NetworkInterface &net = NetworkInterface::get_default_instance();
net.connect();

// for advanced users:
WiFiInterface *wifi = net.wifiInterface();
if (wifi) {
wifi->do_something_wifiy();
}

Pull request type

[ ] Fix
[ ] Refactor
[ ] New target
[X] Feature
[ ] Breaking change

@kjbracey kjbracey changed the base branch from master to feature-emac May 9, 2018 14:11
@cmonr
Copy link
Contributor

cmonr commented May 9, 2018

@kjbracey-arm I don't think the CI tools work well with changing the target base branch in a PR. Going to close and reopen this PR to see if the issues fix themselves.

@cmonr cmonr closed this May 9, 2018
@cmonr cmonr reopened this May 9, 2018
@cmonr cmonr closed this May 9, 2018
@cmonr cmonr reopened this May 9, 2018
@cmonr
Copy link
Contributor

cmonr commented May 9, 2018

@ARMmbed/mbed-os-maintainers FYI, if a PR has it's base branch changed, waiting for current tests to complete, closing, and reopening should fix testing issues. If a PR is closed and reopened too quickly, the merge checks won't update their base branch.

@cmonr
Copy link
Contributor

cmonr commented May 9, 2018

@kjbracey-arm Upon quick inspection the failures in travis look legit. Let us know if something is amis.

@kjbracey
Copy link
Contributor Author

Thanks for fiddling with the CI - my fault for messing up the branch. Will recreate PR if problems turn out to be CI related. (I suspect this does need some more work).

#include "EthInterface.h"
#include "WiFiInterface.h"
#include "CellularBase.h"
#include "MeshInterface.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Having #include lines in the middle of a C file looks a bit weird, is this a leftover from rebasing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possibly a sign that the thing should be split into two files. Everything above this point is the "core" NetworkInterface stuff which knows nothing about derived types.

This point and below is the "dispatch to known derived types" logic. Which arguably is a piece of "system" code providing the built-in behaviour for the 4 core types.

Possibly move this half of the file to NetworkInterfaceDefaults.cpp?

Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

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

I like this.
We are finally going to the right direction and getting rid of the easy-connect's #ifdef jungle.

@@ -231,3 +231,13 @@ mesh_error_t Nanostack::ThreadInterface::device_pskd_set(const char *pskd)
{
return (mesh_error_t)thread_tasklet_device_pskd_set(pskd);
}

#define THREAD 0x2345
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this macro comparison magic be commented somewhere, eg. here? On #6108 (comment) there was a good explanation for it.

Provide an initial framework to make it easier to find a default network
interface.
@kjbracey
Copy link
Contributor Author

Moved new code from NetworkInterface.cpp to a new NetworkInterfaceDefaults.cpp.

Copy link
Contributor

@TeroJaasko TeroJaasko left a comment

Choose a reason for hiding this comment

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

This is definitely 2^63 times better than anything we currently have.

@cmonr
Copy link
Contributor

cmonr commented May 17, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented May 17, 2018

Build : SUCCESS

Build number : 2056
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/6855/

Triggering tests

/morph test
/morph uvisor-test
/morph export-build
/morph mbed2-build

@mbed-ci
Copy link

mbed-ci commented May 18, 2018

@mbed-ci
Copy link

mbed-ci commented May 18, 2018

@cmonr
Copy link
Contributor

cmonr commented May 18, 2018

/morph export-build

@mbed-ci
Copy link

mbed-ci commented May 18, 2018

@kjbracey
Copy link
Contributor Author

Exporter build passed after retriggering the one spurious failure. Guess individual triggers don't work for updating the status though?

https://mbed-os.mbedcloudtesting.com/job/exporter-build-matrix/1706/
http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/exporter/6855/

@kjbracey
Copy link
Contributor Author

/morph export-build

@mbed-ci
Copy link

mbed-ci commented May 18, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented May 18, 2018

/morph export-build

@mbed-ci
Copy link

mbed-ci commented May 18, 2018

* Returns the default on-board NanostackRfPhy - this will be target-specific, and
* may not be available on all targets.
*/
static NanostackRfPhy &get_default_instance();
Copy link
Contributor

Choose a reason for hiding this comment

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

curiosity why is this a reference and the rest pointers?

Copy link
Contributor Author

@kjbracey kjbracey May 21, 2018

Choose a reason for hiding this comment

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

Slightly different approach to "does it exist" handling.

This version aligns with what EMAC::get_default_instance() does, which says that it must exist, if DEVICE_XXX is defined. There's no "null" possibility, hence a reference. It's kind of the "HAL" end.

For all the app-level end - NetworkInterface and similar, there is no controlling macro, but there is the possibility to override at link or run time (including a runtime check for a module being fitted!). In that case, there are underlying weak definitions that return NULL if the thing isn't provided.

So:

#if DEVICE_EMAC
EMAC &emac = EMAC::get_default_instance(); // must work
#else  
#error "No default EMAC"
#endif

WiFiInterface *wifi = WiFiInterface::get_default_instance();
if (!wifi) {
    error("Wifi not available");
}

This doesn't quite align - the upper style is closer to what the "HAL" does, but the lower is more flexible. First approach was the initial, and is long-existing on feature-emac. We ultimately had to do the second to solve various build problems for the higher levels, and it didn't seem worth going back to change the EMAC form.

@cmonr cmonr merged commit 80f228a into ARMmbed:feature-emac May 21, 2018
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.

7 participants