Skip to content

Commit

Permalink
event_routing: Add API loading; Begin implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
liviuchircu committed Apr 9, 2020
1 parent 7933e38 commit 07b431d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 23 deletions.
27 changes: 22 additions & 5 deletions modules/event_routing/api.h
Expand Up @@ -25,9 +25,10 @@

#include "ebr_data.h"

typedef struct usr_avp *(*ebr_pack_params_cb) (evi_params_t *params);
typedef void (*ebr_notify_cb) (void);

struct ebr_api {
typedef struct ebr_api {
/**
* get_ebr_event() - look up the ebr_event corresponding to the given @name
*
Expand All @@ -53,9 +54,25 @@ struct ebr_api {
* callback is invoked, so the user can perform some transactional-related
* actions related to the event (for now, only tm.t_inject_branch())
*/
int (*notify_on_event) (const ebr_event *event, const ebr_filter *filters,
struct usr_avp *(*pack_params_cb) (evi_params_t *params),
void (*notify_cb) (void), int timeout);
};
int (*notify_on_event) (ebr_event *event, const ebr_filter *filters,
ebr_pack_params_cb pack_params,
ebr_notify_cb notify, int timeout);
} ebr_api_t;

typedef int (*ebr_bind_f)(ebr_api_t *api);

static inline int load_ebr_api(ebr_api_t *api)
{
ebr_bind_f ebr_bind;

ebr_bind = (ebr_bind_f)find_export("ebr_bind", 0);
if (!ebr_bind) {
LM_ERR("failed to bind EBR API\n");
return -1;
}

ebr_bind(api);
return 0;
}

#endif /* __EBR_API_H__ */
7 changes: 4 additions & 3 deletions modules/event_routing/ebr_data.c
Expand Up @@ -28,8 +28,9 @@
#include "../../route.h"
#include "../../evi/evi_modules.h"
#include "../tm/tm_load.h"
#include "ebr_data.h"

#include "ebr_data.h"
#include "api.h"

/* structure holding all the needed data to be passed via IPC to
* the process that has to run the notification route */
Expand Down Expand Up @@ -59,7 +60,7 @@ static ebr_event *ebr_events = NULL;



ebr_event* search_ebr_event( str *name )
ebr_event* search_ebr_event( const str *name )
{
ebr_event *ev;

Expand All @@ -71,7 +72,7 @@ ebr_event* search_ebr_event( str *name )
return NULL;
}

ebr_event* add_ebr_event( str *name )
ebr_event* add_ebr_event( const str *name )
{
ebr_event *ev;

Expand Down
4 changes: 2 additions & 2 deletions modules/event_routing/ebr_data.h
Expand Up @@ -67,9 +67,9 @@ typedef struct _ebr_event {



ebr_event * search_ebr_event( str *name );
ebr_event * search_ebr_event( const str *name );

ebr_event * add_ebr_event( str *name );
ebr_event * add_ebr_event( const str *name );

int init_ebr_event( ebr_event *ev );

Expand Down
65 changes: 52 additions & 13 deletions modules/event_routing/event_routing.c
Expand Up @@ -25,8 +25,9 @@
#include "../../evi/evi_transport.h"
#include "../../evi/evi_modules.h"
#include "../tm/tm_load.h"
#include "ebr_data.h"

#include "ebr_data.h"
#include "api.h"


/* module API */
Expand All @@ -49,6 +50,11 @@ static evi_reply_sock* ebr_parse(str socket);
static int ebr_match(evi_reply_sock *sock1, evi_reply_sock *sock2);
static str ebr_print(evi_reply_sock *sock);

void ebr_bind(ebr_api_t *api);
ebr_event *get_ebr_event(const str *name);
int api_notify_on_event(ebr_event *event, const ebr_filter *filters,
ebr_pack_params_cb pack_params,
ebr_notify_cb notify, int timeout);

/* IPC type registered with the IPC layer */
ipc_handler_type ebr_ipc_type;
Expand All @@ -72,6 +78,7 @@ static cmd_export_t cmds[]={
{CMD_PARAM_STR, fix_notification_route, 0},
{CMD_PARAM_INT, 0 ,0}, {0,0,0}},
EVENT_ROUTE|REQUEST_ROUTE|ONREPLY_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
{"ebr_bind", (cmd_function)ebr_bind, {{0,0,0}}, 0},
{0,0,{{0,0,0}},0}
};

Expand Down Expand Up @@ -186,6 +193,13 @@ static int mod_init(void)
}


void ebr_bind(ebr_api_t *api)
{
api->get_ebr_event = get_ebr_event;
api->notify_on_event = api_notify_on_event;
}


static int cfg_validate(void)
{
if ( ebr_tmb.t_gett==NULL && is_script_func_used("notify_on_event",-1)) {
Expand All @@ -198,27 +212,34 @@ static int cfg_validate(void)
}


/* Fixes an EBR event (given by name) by coverting to an internal
* structure (if not already found)
*/
int fix_event_name(void** param)
ebr_event *get_ebr_event(const str *name)
{
ebr_event *ev;

/* check if we have the ID in our list */
ev = search_ebr_event((str*)*param);

if (ev==NULL) {
if (!(ev = search_ebr_event(name))) {
/* add the new event into the list */
if ( (ev=add_ebr_event((str*)*param)) == NULL ) {
LM_ERR("failed to add event <%.*s>\n",
((str*)*param)->len, ((str*)*param)->s);
return -1;
if (!(ev = add_ebr_event(name))) {
LM_ERR("failed to add event <%.*s>\n", name->len, name->s);
return NULL;
}
}

*param = ev;
return ev;
}


/* Fix an EBR event (given by name) by converting to an internal structure */
int fix_event_name(void** param)
{
ebr_event *ev;

if (!(ev = get_ebr_event((str *)*param))) {
LM_ERR("failed to fix event name\n");
return -1;
}

*param = ev;
return 0;
}

Expand Down Expand Up @@ -279,6 +300,24 @@ static int notify_on_event(struct sip_msg *msg, ebr_event* event, pv_spec_t *avp
}


int api_notify_on_event(ebr_event *event, const ebr_filter *filters,
ebr_pack_params_cb pack_params,
ebr_notify_cb notify, int timeout)
{
if (event->event_id == -1) {
/* do the init of the event*/
if (init_ebr_event(event)<0) {
LM_ERR("failed to init event\n");
return -1;
}
}

// TODO

return 0;
}


static int wait_for_event(struct sip_msg* msg, async_ctx *ctx,
ebr_event* event, pv_spec_t* avp_filter, int* timeout)
{
Expand Down

0 comments on commit 07b431d

Please sign in to comment.