#include <pthread.h>
#include <json-c/json.h>
+
#define AFB_BINDING_VERSION 0
#include <afb/afb-binding.h>
{
int refcount; /* reference count */
pthread_mutex_t mutex; /* concurrency management */
- struct afb_daemon *daemon; /* daemon */
+ const char *apiname; /* api name for events */
struct afb_session *bound; /* bound to session */
struct event *events; /* list of events */
struct tag *tags; /* list of tags */
*/
static struct event *trace_get_event(struct afb_trace *trace, const char *name, int alloc)
{
- struct afb_event e;
struct event *event;
/* search the event */
if (!event && alloc) {
event = malloc(sizeof * event);
if (event) {
- e = afb_daemon_make_event_v1(*trace->daemon, name);
- event->evtid = afb_evt_eventid_to_evtid(afb_event_to_eventid(e));
+ event->evtid = afb_evt_evtid_create2(trace->apiname, name);
if (event->evtid) {
event->next = trace->events;
trace->events = event;
/* create the hook handler */
switch (type) {
case Trace_Type_Xreq:
- if (desc->session) {
+ if (!desc->session)
+ session = afb_session_addref(bind);
+ else {
session = trace_get_session_by_uuid(trace, desc->session, 1);
if (!session) {
ctxt_error(&desc->context->errors, "allocation of session failed");
free(hook);
return;
}
- bind = session;
}
- hook->handler = afb_hook_create_xreq(desc->api, desc->verb, bind,
+ hook->handler = afb_hook_create_xreq(desc->api, desc->verb, session,
desc->flags[type], &hook_xreq_itf, hook);
+ afb_session_unref(session);
break;
case Trace_Type_Ditf:
hook->handler = afb_hook_create_ditf(desc->api, desc->flags[type], &hook_ditf_itf, hook);
session = trace_get_session_by_uuid(context->trace, uuid, 0);
if (!session)
ctxt_error(&context->errors, "session %s not found", uuid);
- else
+ else {
trace_unhook(context->trace, NULL, NULL, session);
+ afb_session_unref(session);
+ }
}
}
/*******************************************************************************/
/* allocates an afb_trace instance */
-struct afb_trace *afb_trace_create(struct afb_daemon *daemon, struct afb_session *bound)
+struct afb_trace *afb_trace_create(const char *apiname, struct afb_session *bound)
{
struct afb_trace *trace;
- assert(daemon);
+ assert(apiname);
trace = calloc(1, sizeof *trace);
if (trace) {
trace->refcount = 1;
trace->bound = bound;
- trace->daemon = daemon;
+ trace->apiname = apiname;
pthread_mutex_init(&trace->mutex, NULL);
}
return trace;