-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
@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. |
@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. |
@kjbracey-arm Upon quick inspection the failures in travis look legit. Let us know if something is amis. |
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). |
533d2c9
to
105d860
Compare
#include "EthInterface.h" | ||
#include "WiFiInterface.h" | ||
#include "CellularBase.h" | ||
#include "MeshInterface.h" |
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.
Having #include lines in the middle of a C file looks a bit weird, is this a leftover from rebasing?
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.
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?
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 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 |
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.
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.
Moved new code from |
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.
This is definitely 2^63 times better than anything we currently have.
/morph build |
Build : SUCCESSBuild number : 2056 Triggering tests/morph test |
Test : SUCCESSBuild number : 1865 |
Exporter Build : FAILUREBuild number : 1698 |
/morph export-build |
Exporter Build : FAILUREBuild number : 1702 |
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/ |
/morph export-build |
Exporter Build : FAILUREBuild number : 1707 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 1710 |
* Returns the default on-board NanostackRfPhy - this will be target-specific, and | ||
* may not be available on all targets. | ||
*/ | ||
static NanostackRfPhy &get_default_instance(); |
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.
curiosity why is this a reference and the rest pointers?
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.
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.
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