-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Network interface: Add status callback register #5457
Conversation
The destination branch: Would @hasnainvirk review this, anyone else should be asked for review for this feature?
Let us know once this be ready . |
@0xc0170 Yes, the destination branch is feature-status-callbacks. Possible list of reviewers: |
@SeppoTakalo Note, there are currently some problems with access for reviewers (I can not assign most of the names mentioned here), we are investigating |
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.
Looks okay to me for going into feature-status-callbacks. I would suggest taking all NetworkInterface users in confidence. This is going to effect them mildly.
@SeppoTakalo, @0xc0170 I cannot modify the Reviewers list |
@kjbracey-arm Please review. |
@TeemuKultala what does "Status cb pr1" mean? Could you update your PR title? |
@theotherjimmy "Status cb pr1" means "status callback pull request 1". I try to find a better name for this or for the next pull request |
* | ||
* @param status_cb The callback for status changes | ||
*/ | ||
virtual void register_status_callback(mbed::Callback<void(ConnectionStatusType)> 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.
should this follow attach()
for attaching a callback?
@@ -31,6 +32,11 @@ class NetworkStack; | |||
*/ | |||
class NetworkInterface { | |||
public: | |||
|
|||
enum ConnectionStatusType { | |||
down, local_up, global_up, undefined |
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 should start uppercase Down
, etc, each of them on the new line, good if with doxygen description for each status type.
* | ||
* @return The connection status according to ConnectionStatusType | ||
*/ | ||
virtual ConnectionStatusType get_connection_status(); |
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 is this not connection_status_t
? same as nsapi_error_t
on the line 152
This should be part of this patch, thus this needs some work (not yet complete) ? |
@0xc0170 I have now ethernet and mesh changes available, and also fixes for other things you mentioned, should I make a new pull request for those things, or add them to this same pull request? |
You can add them here, feel free to push updates anytime |
@0xc0170 Ethernet and mesh changes added here now, so should the status change back to needs: review, or how to proceed? |
* | ||
* @param status_cb The callback for status changes | ||
*/ | ||
virtual void register_status_callback(mbed::Callback<void(connection_status_t, int)> 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.
Still not answered, is this regular way how to register a callback? many API in mbed has attach
, shall this be also aligned?
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.
What about how to register callback? I would like to have an alignment if possible or an argument why this is register_status_callback_name
features/netsocket/nsapi_types.h
Outdated
@@ -55,6 +55,14 @@ enum nsapi_error { | |||
NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */ | |||
}; | |||
|
|||
typedef enum connection_status { | |||
DISCONNECTED, |
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 should follow the rest of enumeration values (add prefix NSAPI
), plus more specification (NSAPI_CONNECTION_STATUS
or at least NSAPI_STATUS
). See line 55 and others
@0xc0170 register_status_callback renamed to attach, enum changed too |
@TeemuKultala There are lot of reviewers assigned but only two reviewed so far. @kjbracey-arm @hasnainvirk Review please Update: |
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.
Looks like this is going to work out okay; main issue is that it doesn't seem to have picked up on the main point of the review with @AnttiKauppila and @lauri-piikivi about the callback API, which is to make the "connection status change" just one possible event on the attach, so the new state becomes a subreason of that.
This is going to conflict thoroughly with #5558 - whatever this does is going to have to be reimplemented in line with its style. That needn't worry you excessively, but it may help concentrate the mind with regard to genericity.
{ | ||
} | ||
Callback<void(nsapi_connection_status_t, int)> EthernetInterface::_connection_status_cb = NULL; |
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.
These things mustn't be static. Nothing stopping you having multiple Ethernet interfaces.
* | ||
* @param status_cb The callback for status changes | ||
*/ | ||
virtual void attach(mbed::Callback<void(nsapi_connection_status_t, int)> 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.
The callback here isn't following the discussion we had in that 2017-11-08 meeting - that agreed generalising to be effectively (nsapi_event_t reason, uint32_t parameter)
, so for this initial event the "reason" would be "connection status change", and the parameter would be the nsapi_connection_status_t
.
@@ -111,6 +123,12 @@ class EthernetInterface : public EthInterface | |||
char _ip_address[IPADDR_STRLEN_MAX]; | |||
char _netmask[NSAPI_IPv4_SIZE]; | |||
char _gateway[NSAPI_IPv4_SIZE]; | |||
|
|||
|
|||
static Callback<void(nsapi_connection_status_t, int)> _connection_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.
As mentioned above - nothing should be static
@@ -599,7 +617,12 @@ nsapi_error_t mbed_lwip_bringup_2(bool dhcp, bool ppp, const char *ip, const cha | |||
|
|||
netif_set_default(&lwip_netif); | |||
netif_set_link_callback(&lwip_netif, mbed_lwip_netif_link_irq); | |||
netif_set_status_callback(&lwip_netif, mbed_lwip_netif_status_irq); | |||
if (status_cb) { | |||
netif_set_status_callback(&lwip_netif, 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.
Don't you always need to call our callback to unblock the blocking connect? Oh, you've assuming the person doing the attach will call back in to our status callback.
No that doesn't make sense, and will cause complication with the stack generalisation (#5558). The callback to lwIP should always be mbed_lwip_netif_status_irq. That can call status_cb if set - you'll need to record its setting.
|
||
nsapi_error_t NetworkInterface::set_blocking(bool blocking) | ||
{ | ||
return NSAPI_ERROR_UNSUPPORTED; |
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.
If you're adding this, you should implement it for lwIP and Nanostack, which I don't think you are.
* | ||
* @return The connection status according to ConnectionStatusType | ||
*/ | ||
virtual nsapi_connection_status_t get_connection_status(); |
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 be const.
|
||
/** Set blocking status of connect() | ||
* | ||
* @param blocking true if connect is blocking |
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.
Note that the default is blocking.
@@ -263,9 +263,11 @@ PPPCellularInterface::PPPCellularInterface(FileHandle *fh, bool debug) | |||
_fh = fh; | |||
_debug_trace_on = debug; | |||
_stack = DEFAULT_STACK; | |||
_connection_status_cb = NULL; | |||
_ppp_cb = Callback<void(nsapi_connection_status_t, int)>(this, &PPPCellularInterface::ppp_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.
I think you should be able to simplify this to callback(this, &PPPCellularInterface::ppp_status_cb)
. Although not sure why it's a variable at all? Just pass that straight to the bringup function.
@@ -398,7 +406,11 @@ bool PPPCellularInterface::nwk_registration(uint8_t nwk_type) | |||
|
|||
bool PPPCellularInterface::is_connected() | |||
{ | |||
return dev_info.ppp_connection_up; | |||
if (_connect_status == NSAPI_STATUS_DISCONNECTED) { |
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.
return __connect_status != NSAPI_STATUS_DISCONNECTED;
perhaps?
@TeemuKultala, please take another look. The UDP DTLS handshake test case appears to be failing. |
#5720 should provide a fix for the UDP DTLS handshake issue |
/morph build |
Build : SUCCESSBuild number : 778 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 430 |
Test : FAILUREBuild number : 613 |
/morph build |
Build : SUCCESSBuild number : 784 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 438 |
Test : SUCCESSBuild number : 619 |
This is the original content of feature-status-callbacks, reviewed in ARMmbed#5457
Description
This adds connection status callback registering, and connection status reporting to NetworkInterface, and implementation of these to CellularInterface, mesh and ethernet interfaces
Status
READY
Migrations
YES
In NetworkInterface new APIs:
-attach() for connection status callback registering
-get_connection_status()
-set_blocking()
In PPPCellularInterface:
-connection_status_cb() removed
Related PRs
Todos
Deploy notes
Steps to test or reproduce