-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
refactor onoff to separate async notification and standardize terminology #23601
refactor onoff to separate async notification and standardize terminology #23601
Conversation
All checks passed. checkpatch (informational only, not a failure)
Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
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.
few comments.
To proactively address some comments from earlier reviews for which I have not made changes:
|
97d2a33
to
c883cf5
Compare
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.
Could you fix 80liners checkpatch complains? Regarding result
field in the async notify. Let's keep it for now as it is. I don't see clearly the use case that needs it so it's hard for me to say if there are other alternatives. If use case is specific to a service then first that comes to my mind is to implement that in the service, in completion callback (before calling async_notify_finalize
) result can be stored in dedicated service struct which contains async notification. This way, it would be supported only for services which implements that but on the other hand it will save 4 bytes for each async notify which does not need it.
c883cf5
to
cf4135d
Compare
I think I got all but the ones where there's no obvious place to break a line. |
@tbursztyka @anangl if any of you could review that? @carlescufi maybe you know someone that would have interest in reviewing that? |
include/sys/async_notify.h
Outdated
* Flag value that overwrites the method field when the operation has | ||
* completed. | ||
*/ | ||
#define ASYNC_NOTIFY_METHOD_COMPLETED 0 |
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.
Again, I disagree with these long names. I really would like to shorten this to something like ANOTIFY_
and anotify_
or something even shorter, if we can come up with one. I will add this to the API meeting.
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 whole namespace would need to change. I don't know if we need to keep async in the name, notify_* only perhaps?
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.
in a way, by default notification is asynchronous in nature so async_
prefix might be redundant.
Some other proposals :
notifier
gnotify
- generic notificationk_notify
- since (a least currently) it is limited to kernel.
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.
gnotify sounds like glib, your are right k_ is strictly used by the kernel only. z_notify maybe? Though it does not "sound" nice.
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.
yeah, i thought about z_notify but z_
indicates internal function.
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 suppose that async_
doesn't add a huge amount of information except that it's intended to be the standard way of notifying of completion of async operations.
Bare notify_
IMO has too large of a conflict with existing and new identifiers that are not part of this API (struct notify_data
, notify_remote_info
).
Since this is in the sys/
include hierarchy sys_notify_
could mitigate that.
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.
API meeting:
sys_notify_
raised no objections.
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.
how to we call the file? notify.h
? since path contains the namespace (sys/notify.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.
yes, as all the other files there. (besides sys_io.h which is a legacy name, and was not part of sys/ at first if I remember well)
No, unfortunately beyond @tbursztyka and @anangl I can't think of anyone else at this point. Perhaps @wentongwu or @pdunaj? |
#define SERVICE_STATE_TRANSITION (ONOFF_SERVICE_INTERNAL_BASE << 1) | ||
#define SERVICE_STATE_TO_ON (SERVICE_STATE_TRANSITION | SERVICE_STATE_ON) | ||
#define SERVICE_STATE_TO_OFF (SERVICE_STATE_TRANSITION | SERVICE_STATE_OFF) | ||
#define ST_OFF 0 |
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.
about naming, I don't know if going to the shortest possible one is relevant (it becomes cryptic then). You'll need to find something in the middle.
besides naming issues, lgtm |
86ee33c
to
2474cba
Compare
Extracted transition functions from onoff structure to external one which allows to keep them in flash. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2474cba
to
c8a3e43
Compare
@carlescufi @tbursztyka naming has been resolved can you look again? |
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.
Some random notes
include/sys/notify.h
Outdated
* @{ | ||
*/ | ||
|
||
/* Forward declaration */ |
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 comment could be removed, it just states the obvious.
/* Forward declaration */ | ||
struct sys_notify; | ||
|
||
/* |
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 looks like a comment that should be in the documentation, so we should put /**
here.
Same comment to other defines below.
Could we replace these defines by enum as they seem to be sequential and related to each other?
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 not public API, but maintainers need to know its intent so it's described. It's also the value of a bitfield in flags so it shouldn't be an enum.
*/ | ||
#define SYS_NOTIFY_METHOD_CALLBACK 3 | ||
|
||
#define SYS_NOTIFY_METHOD_MASK 0x03 |
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 we do not want to document these, they should probably be outside of doxygen group or marked as internal using /** @cond INTERNAL_HIDDEN */
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.
Moved.
*/ | ||
struct sys_notify { | ||
union method { | ||
/* Pointer to signal used to notify client. |
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.
Documentation comment here /**
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 not public API (it's manipulated through accessor functions). And documentation for struct members isn't generated so it wouldn't help.
sys_notify_generic_callback callback; | ||
} method; | ||
|
||
/* |
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.
ditto
*/ | ||
u32_t volatile flags; | ||
|
||
/* |
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.
and here too
int volatile result; | ||
}; | ||
|
||
/** @internal */ |
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.
In other parts of the code, I have used
/** @cond INTERNAL_HIDDEN */
...
/** @endcond */
not sure which is correct
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'm not sure either work, but @internal
is common.
rv = 0; | ||
*result = notify->result; | ||
} | ||
return rv; |
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.
empty line after }
* @param handler a function pointer to use for notification. | ||
*/ | ||
static inline void sys_notify_init_callback(struct sys_notify *notify, | ||
sys_notify_generic_callback handler) |
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 looks like too long line, in this case I would just make sure the line is max 80 chars long even if the indentation would not match. Other option is just to put the 1st parameter to new line.
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.
Generally we don't do that sort of thing just to satisfy the line length test (which is advisory in Zephyr).
tests/lib/notify/testcase.yaml
Outdated
@@ -0,0 +1,3 @@ | |||
tests: | |||
libraries.sys_notify: | |||
tags: sys_notify |
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.
You could also add here notify
tag (easier to remember)
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.
replaced
k_poll() for a signal is often desired for notification of completion of asynchronous operations, but there are APIs where it may be necessary to invoke "asynchronous" operations from contexts where sleep is disallowed, or before the kernel has been initialized. Extract the general notification solution from the on-off service into a utility that can be used for other APIs. Also move documentation out to a resource management section. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
The original API was misnamed, as the intent was to provide a manager that decoupled state management from the service that needed to be turned on or off. Update all the names, shortening them where appropriate removing unncessary internal components like _service. Also remove some API that misled developers into believing that onoff managers are normally expected to be exposed directly to consumers. While this is a use case, in most situations there are service or client-specific actions that need to be coupled to transition events. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
c8a3e43
to
8a96ade
Compare
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.
LGTM
Will merge since the naming has been resolved |
The following PR's zephyrproject-rtos#23941 zephyrproject-rtos#23601 was merged using old boilerplate inclusion. This commit updates those tests to use find_package(Zephyr) Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The following PR's zephyrproject-rtos#23941 zephyrproject-rtos#23601 was merged using old boilerplate inclusion. This commit updates those tests to use find_package(Zephyr) Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This PR separates generic resource management updates that appear to be nearly stable from #23229. The changes are: