Skip to content
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

Merged
merged 16 commits into from Jan 3, 2018
Merged

Network interface: Add status callback register #5457

merged 16 commits into from Jan 3, 2018

Conversation

ghost
Copy link

@ghost ghost commented Nov 8, 2017

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

  • Documentation needs to be updated

Deploy notes

Steps to test or reproduce

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 8, 2017

The destination branch: feature-status-callbacks . Is that correct?

Would @hasnainvirk review this, anyone else should be asked for review for this feature?

IN DEVELOPMENT

Let us know once this be ready .

@ghost
Copy link
Author

ghost commented Nov 8, 2017

@0xc0170 Yes, the destination branch is feature-status-callbacks.

Possible list of reviewers:
@hasnainvirk, @SeppoTakalo, @kjbracey-arm, @mikaleppanen, @mikter, @AnttiKauppila

@SeppoTakalo
Copy link
Contributor

@TeemuKultala
Please add reviewers here:
image

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 8, 2017

@SeppoTakalo Note, there are currently some problems with access for reviewers (I can not assign most of the names mentioned here), we are investigating

Copy link
Contributor

@hasnainvirk hasnainvirk left a 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.

@ghost
Copy link
Author

ghost commented Nov 9, 2017

@SeppoTakalo, @0xc0170 I cannot modify the Reviewers list

@SeppoTakalo
Copy link
Contributor

@kjbracey-arm Please review.

@theotherjimmy
Copy link
Contributor

@TeemuKultala what does "Status cb pr1" mean? Could you update your PR title?

@ghost
Copy link
Author

ghost commented Nov 15, 2017

@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);
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 follow attach() for attaching a callback?

@@ -31,6 +32,11 @@ class NetworkStack;
*/
class NetworkInterface {
public:

enum ConnectionStatusType {
down, local_up, global_up, undefined
Copy link
Contributor

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();
Copy link
Contributor

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

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 16, 2017

Implementations needs to be still added to mesh and ethernet interfaces

This should be part of this patch, thus this needs some work (not yet complete) ?

@ghost
Copy link
Author

ghost commented Nov 16, 2017

@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?

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 16, 2017

You can add them here, feel free to push updates anytime

@0xc0170 0xc0170 changed the title Status cb pr1 Network interface: Add status callback register Nov 16, 2017
@ghost
Copy link
Author

ghost commented Nov 20, 2017

@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);
Copy link
Contributor

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?

Copy link
Contributor

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

@@ -55,6 +55,14 @@ enum nsapi_error {
NSAPI_ERROR_CONNECTION_TIMEOUT = -3017, /*!< connection timed out */
};

typedef enum connection_status {
DISCONNECTED,
Copy link
Contributor

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

@ghost
Copy link
Author

ghost commented Nov 21, 2017

@0xc0170 register_status_callback renamed to attach, enum changed too

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 21, 2017

@TeemuKultala There are lot of reviewers assigned but only two reviewed so far.
I restarted jenkins PR , if it fails , please review the results

@kjbracey-arm @hasnainvirk Review please

Update: attach now , I see. Thanks

Copy link
Contributor

@kjbracey kjbracey left a 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;
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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);
Copy link
Contributor

@kjbracey kjbracey Nov 23, 2017

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;
Copy link
Contributor

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();
Copy link
Contributor

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
Copy link
Contributor

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);
Copy link
Contributor

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) {
Copy link
Contributor

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?

@cmonr
Copy link
Contributor

cmonr commented Dec 28, 2017

@TeemuKultala, please take another look. The UDP DTLS handshake test case appears to be failing.

@ghost
Copy link
Author

ghost commented Jan 2, 2018

#5720 should provide a fix for the UDP DTLS handshake issue

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 2, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Jan 2, 2018

Build : SUCCESS

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

Triggering tests

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

@mbed-ci
Copy link

mbed-ci commented Jan 2, 2018

@mbed-ci
Copy link

mbed-ci commented Jan 2, 2018

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 3, 2018

/morph build

@mbed-ci
Copy link

mbed-ci commented Jan 3, 2018

Build : SUCCESS

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

Triggering tests

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

@mbed-ci
Copy link

mbed-ci commented Jan 3, 2018

@mbed-ci
Copy link

mbed-ci commented Jan 3, 2018

@0xc0170 0xc0170 merged commit 469d74f into ARMmbed:feature-status-callbacks Jan 3, 2018
@jarlamsa jarlamsa mentioned this pull request Feb 7, 2018
jarlamsa pushed a commit to jarlamsa/mbed-os that referenced this pull request Feb 9, 2018
This is the original content of feature-status-callbacks, reviewed in
ARMmbed#5457
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.

8 participants