Skip to content

Commit

Permalink
bevent: event filter mask
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Aug 6, 2024
1 parent 0c78103 commit c80dcc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 12 additions & 1 deletion include/baresip.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef BARESIP_H__
#define BARESIP_H__

#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -875,6 +876,16 @@ enum ua_event {
};


enum bevent_class {
BEVENT_CLASS_UA = 1,
BEVENT_CLASS_CALL = 2,
BEVENT_CLASS_SIP = 4,
BEVENT_CLASS_APP = 8,
BEVENT_CLASS_UNDEFINED = 32768,
BEVENT_CLASS_ALL = 65535,
};


struct bevent;


Expand Down Expand Up @@ -1667,7 +1678,7 @@ int odict_encode_bevent(struct odict *od, struct bevent *event);
int event_add_au_jb_stat(struct odict *od_parent, const struct call *call);
int uag_event_register(ua_event_h *eh, void *arg);
void uag_event_unregister(ua_event_h *eh);
int bevent_register(bevent_h *eh, void *arg);
int bevent_register(bevent_h *eh, void *arg, uint16_t mask);
void bevent_unregister(bevent_h *eh);
void ua_event(struct ua *ua, enum ua_event ev, struct call *call,
const char *fmt, ...);
Expand Down
16 changes: 5 additions & 11 deletions src/bevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static void eh_destructor(void *arg)

struct ehe {
struct le le;
uint16_t mask;
bevent_h *h;
void *arg;
};
Expand All @@ -67,15 +68,6 @@ static void ehe_destructor(void *arg)
}


enum bevent_class {
BEVENT_CLASS_UA,
BEVENT_CLASS_CALL,
BEVENT_CLASS_APP,
BEVENT_CLASS_SIP,
BEVENT_CLASS_UNDEFINED
};


static enum bevent_class bevent_class(enum ua_event ev)
{
switch (ev) {
Expand Down Expand Up @@ -631,7 +623,7 @@ void uag_event_unregister(ua_event_h *h)
*
* @return 0 if success, otherwise errorcode
*/
int bevent_register(bevent_h *eh, void *arg)
int bevent_register(bevent_h *eh, void *arg, uint16_t mask)
{
struct ehe *ehe;

Expand All @@ -646,6 +638,7 @@ int bevent_register(bevent_h *eh, void *arg)

ehe->h = eh;
ehe->arg = arg;
ehe->mask = mask;

list_append(&ehel, &ehe->le, ehe);

Expand Down Expand Up @@ -791,7 +784,8 @@ static void bevent_emit_base(struct bevent *event)
struct ehe *ehe = le->data;
le = le->next;

ehe->h(event->ev, event, ehe->arg);
if (ehe->mask & bevent_class(event->ev))
ehe->h(event->ev, event, ehe->arg);

if (event->stop)
return;
Expand Down

0 comments on commit c80dcc6

Please sign in to comment.