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
event refactoring #3018
base: main
Are you sure you want to change the base?
event refactoring #3018
Conversation
src/event.c
Outdated
@@ -333,29 +424,27 @@ void uag_event_unregister(ua_event_h *h) | |||
* @param fmt Formatted arguments | |||
* @param ... Variable arguments | |||
*/ | |||
void ua_event(struct ua *ua, enum ua_event ev, struct call *call, | |||
const char *fmt, ...) | |||
void ua_event(enum ua_event ev, const char *fmt, ...) |
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.
Unsure if mixing formatting args and optional args is a good idea. It's very confusing.
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.
SInce this is ua_event
, I would prefer to keep struct ua *ua
param and add event_param
(without struct ua *ua;
in union).
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.
And maybe we should not directly drop the current API.
I'll try a multi function solution for emitting events:
/**
* @deprecated
*/
void ua_event(struct ua *ua, enum ua_event ev, struct call *call, const char *fmt, ...);
void ua_event_app(enum ua_event ev, const char *fmt, ...);
void ua_event_ua(enum ua_event ev, struct ua *ua, const char *fmt, ...);
void ua_event_call(enum ua_event ev, struct call *call, const char *fmt, ...);
void ua_event_sip_msg(enum ua_event ev, struct sip_msg *msg, const char *fmt, ...);
This could be extended without breaking the API.
ee1fd6e
to
d355985
Compare
I completely replaced the commits |
559faa7
to
f129576
Compare
f129576
to
7915e5a
Compare
This commit shows how DnD could be solved: 881af62 |
8b5c3b1
to
881af62
Compare
Still don't understand why new event (UA_EVENT_SIP_INCOMING) is needed. Also, better name would be UA_EVENT_INVITE_INCOMING. Now when I read ua.c code, I noticed that call blocking based on contacts does not belong to core either and should be moved to menu. |
src/event.c
Outdated
va_list ap; | ||
int err; | ||
|
||
if (event_class(ev) != EVENT_CLASS_CALL) |
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.
Is EVENT_CLASS_CALL
right 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.
Good point!
if (event_class(ev) != EVENT_CLASS_SIP)
return EINVAL;
is correct.
Explanation
@juha-h
The event class selects the union field.
event class | union field |
---|---|
EVENT_CLASS_UA | event.u.ua |
EVENT_CLASS_CALL | event.u.call |
EVENT_CLASS_APP | event.nothing |
EVENT_CLASS_SIP | event.u.msg |
Problem
The function ua_event_class_name()
returns some incongruous class names
register
, better would beua
mwi
--> betterua
UA_EVENT_CREATE
returnsapplication
--> betterua
VU_REPORT
--> bettercall
But maybe there are already applications which event parsing rely on the current texts. Thus I didn't touch this function. The function is used in event_encode_dict()
which I would mark as deprecated.
The new function odict_encode_event()
uses event_class_name()
that returns logical fitting class names. This should also make parsing of events simpler for applications.
Module eventsThe commit 9542c48 should be discussed, and maybe dropped. A replacement for function /* new module event */
event_module_emit("ctrl_dbus", modev->event, NULL, "%s", modev->txt);
/* or we use the other event functions, like */
event_app_emit(UA_EVENT_MODULE, NULL, "ctrl_dbus,%s,%s",
modev->event, modev->txt); Note: |
If an incoming INVITE is rejected by an event handler, then no further event handler should process the event. My proposition is to return true if the event processing should be stopped. We could also add a stop flag to Isn't it possible to return a bool from a Kotlin callback function? |
Instead of the return value I put the stop flag to
|
Christian Spielberger writes:
If an incoming INVITE is rejected by an event handler, then no further
event handler should process the event. My proposition is to return
true if the event processing should be stopped. We could also add a
stop flag to `struct bevent`.
That doesn't change the situation. If event processing should be
stopped (for example when the handler rejects the INVITE due to dnd),
the state will be CALL_STATE_TERMINATED. Why checking of the state is
not enough? Why do you need a return value or stopped flag, which in my
opinion is bad design and breaks the idea of handler? After short
search I have not found in baresip any other handler that returns a
value or has stopped flag.
Isn't it possible to return a bool from a Kotlin callback function?
Yes it could be possible, but see above.
|
Why these are not done before
|
Why can't there be |
So when INVITE comes in, |
... but I'm ready to give up as long there API documentation is clear. |
I'll add Doxygen to the API |
a379ef4
to
aae140c
Compare
Once you move these #3018 (comment), I can add new API function |
Yes, this would be possible from App side. |
updated the description |
Could you move this
down after all checks? |
Yes, it can be moved to line 760. Also in following PRs we could move the max_calls check to the application e.g. module menu. We could discuss this. |
include/baresip.h
Outdated
@@ -881,6 +886,7 @@ enum answer_method { | |||
/** Defines the User-Agent event handler */ | |||
typedef void (ua_event_h)(struct ua *ua, enum ua_event ev, | |||
struct call *call, const char *prm, void *arg); | |||
typedef void (bevent_h)(struct bevent *event, void *arg); |
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.
suggested signature:
typedef void (bevent_h)(struct ua_event ev, struct bevent_payload *event, void *arg);
All events must have a valid EV event set.
The payload is optional and type dependent.
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'll try this.
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.
Do you mean?
typedef void (bevent_h)(enum ua_event ev, struct bevent_payload *event, void *arg);
Rename struct bevent
-> struct bevent_payload
?
} u; | ||
}; | ||
|
||
|
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.
perhaps rename this file to bevent.c ?
@alfredh Now I changed to typedef void (bevent_h)(enum ua_event ev, struct bevent *event, void *arg); Can we keep the shorter name
The |
I would like to suggest that we split this up into logical blocks (many PRs).
For example a small PR can be to just rename event.c to bevent.c Is there a need to update all the calls that are sending the event ? |
@@ -167,7 +167,7 @@ set(SRCS | |||
src/custom_hdrs.c | |||
src/descr.c | |||
src/dial_number.c | |||
src/event.c | |||
src/bevent.c |
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 can be a separate PR
@@ -866,10 +866,15 @@ enum ua_event { | |||
UA_EVENT_MODULE, | |||
UA_EVENT_END_OF_FILE, | |||
UA_EVENT_CUSTOM, | |||
UA_EVENT_SIPSESS_CONN, |
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 change and related changes can be separate PR
Idea got from:
This PR involved now to a backwards compatible solution. Old and new event API exist in parallel.
For now only updated three modules.