-
Notifications
You must be signed in to change notification settings - Fork 429
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
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 |
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: |
2affce8
to
9542c48
Compare
The tests are green now. Now everything is backwards compatible, the old functions are marked as deprecated and a warning is printed if they are used. The unit tests already use the new event handler. In order to keep the PR as small as possible I will
|
Regarding this:
I would prefer names |
include/baresip.h
Outdated
struct call *call; | ||
const struct sip_msg *msg; | ||
void *arg; | ||
} 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.
union means that only one of the pointers are valid, for example ua OR call.
you cannot cast a ua pointer to a call pointer, or msg pointer etc.
is it better to use a struct here ?
most of the events have a valid UA pointer
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 also thought about the choice between union and struct. And decided to try first a union. Reasons for that:
- In the current UA event API we often pass a
call
and itsua
which is redundant. - Then we had often UA events where
ua
was set, butcall
was NULL. - The new events which add a
sip_msg
pointer should be used before a call is allocated.
It seems to work with a union. An application would have no benefit to have multiple of these pointers.
include/baresip.h
Outdated
int event_ua_emit(enum ua_event ev, struct ua *ua, const char *fmt, ...); | ||
int event_call_emit(enum ua_event ev, struct call *call, const char *fmt, ...); | ||
int event_sip_msg_emit(enum ua_event ev, const struct sip_msg *msg, | ||
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.
is the call
valid in this case ?
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. Here the table from above extended with the function names:
function name | event class | union field |
---|---|---|
event_ua_emit | EVENT_CLASS_UA | event.u.ua |
event_call_emit | EVENT_CLASS_CALL | event.u.call |
event_app_emit | EVENT_CLASS_APP | event.u.arg |
event_sip_msg_emit | EVENT_CLASS_SIP | event.u.msg |
It is more the type of the second parameter we want to address with the name. If we had C++ it would be best like this: int event_emit(enum ua_event ev, void *arg, const char *fmt, ...);
int event_emit(enum ua_event ev, struct ua *ua, const char *fmt, ...);
int event_emit(enum ua_event ev, struct call *call, const char *fmt, ...);
int event_emit(enum ua_event ev, const struct sip_msg *msg, const char *fmt, ...); And it is not only for incoming SIP requests. For the event I tried to keep it short with |
src/ua.c
Outdated
if (uag_dnd()) { | ||
(void)sip_treply(NULL, uag_sip(), msg, | ||
480,"Temporarily Unavailable"); | ||
err = event_sip_msg_emit(UA_EVENT_SIP_INCOMING, msg, ""); |
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.
UA_EVENT_SIPSESS_CONN
include/baresip.h
Outdated
|
||
UA_EVENT_MAX, | ||
}; | ||
|
||
|
||
struct event { |
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 add a one or two letter prefix to "event", like xxevent
.
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.
okay, this time it should more general than ua
. Maybe bs
for baresip? --> bsevent
?
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.
Or bevent
?
Currently there are a lot of deprecated warnings when the unit tests are ran. Thus before I'll set this PR green, I will remove the calls to the deprecated API in the baresip core. |
OK, but I would prefer the same as in the event_sip_msg_emit, i.e., UA_EVENT_SIP_MSG_INCOMING. |
The "emit" function names are related to event classes and to the union fields. |
In my opinion event_handler should return false only in case of error. Otherwise it simply handles the event and returns true. As result of the handling, e.g., call_state, can change. |
Please compare with We don't have a The err code of the "emit" function can be used to have influence on further processing after the event was emitted and processed by the handler list. As an example see Dnd commit: 881af62 |
Christian Spielberger writes:
The err code of the "emit" function can be used to have influence on
further processing after the event was emitted and processed by the
handler list. As an example see Dnd commit:
881af62
My point is that the information regarding possible further processing
should be carried by some other means than the boolean result, e.g., by
call state change. So, for example, in case of DnD, after event
processing, the call state could be either CALL_STATE_TERMINATED
or CALL_STATE_RINGING.
|
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 |
aae140c
to
82049cd
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
?
src/event.c
Outdated
} 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
include/baresip.h
Outdated
@@ -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
|
8ce80f0
to
6349946
Compare
This is the first commit of a series that introduce new baresip events.
6349946
to
2c44d85
Compare
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.