X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-context.c;h=174ac163813db051c3796deadfbb1422870827f1;hb=f9f80fd77b5a6a9b50fac3026fae088823a23dc1;hp=0bcc79c37f5bea924786e255da87db05a653e074;hpb=a38382e89710db2c298f7f101e3ba0cf3681287c;p=src%2Fapp-framework-binder.git diff --git a/src/afb-context.c b/src/afb-context.c index 0bcc79c3..174ac163 100644 --- a/src/afb-context.c +++ b/src/afb-context.c @@ -21,39 +21,46 @@ #include #include -#include "session.h" +#include "afb-session.h" #include "afb-context.h" -static void init_context(struct afb_context *context, struct AFB_clientCtx *session, const char *token) +static void init_context(struct afb_context *context, struct afb_session *session, const char *token) { assert(session != NULL); /* reset the context for the session */ context->session = session; context->flags = 0; - context->api_index = -1; - context->loa_in = ctxClientGetLOA(session) & 7; + context->super = NULL; + context->api_key = NULL; + context->loa_in = afb_session_get_LOA(session) & 7; /* check the token */ if (token != NULL) { - if (ctxTokenCheck(session, token)) + if (afb_session_check_token(session, token)) context->validated = 1; else context->invalidated = 1; } } -void afb_context_init(struct afb_context *context, struct AFB_clientCtx *session, const char *token) +void afb_context_init(struct afb_context *context, struct afb_session *session, const char *token) { - init_context(context, ctxClientAddRef(session), token); + init_context(context, afb_session_addref(session), token); +} + +void afb_context_subinit(struct afb_context *context, struct afb_context *super) +{ + *context = *super; + context->super = super; } int afb_context_connect(struct afb_context *context, const char *uuid, const char *token) { int created; - struct AFB_clientCtx *session; + struct afb_session *session; - session = ctxClientGetSession (uuid, &created); + session = afb_session_get (uuid, &created); if (session == NULL) return -1; init_context(context, session, token); @@ -66,81 +73,97 @@ int afb_context_connect(struct afb_context *context, const char *uuid, const cha void afb_context_disconnect(struct afb_context *context) { - if (context->session != NULL) { + if (context->session && !context->super) { if (context->refreshing && !context->refreshed) { - ctxTokenNew (context->session); + afb_session_new_token (context->session); context->refreshed = 1; } if (context->loa_changing && !context->loa_changed) { - ctxClientSetLOA (context->session, context->loa_out); + afb_session_set_LOA (context->session, context->loa_out); context->loa_changed = 1; } if (context->closing && !context->closed) { - ctxClientClose(context->session); + afb_session_close(context->session); context->closed = 1; } - ctxClientUnref(context->session); + afb_session_unref(context->session); context->session = NULL; } } const char *afb_context_sent_token(struct afb_context *context) { - if (context->session == NULL || context->closing) + if (context->session == NULL || context->closing || context->super) return NULL; if (!context->refreshing) return NULL; if (!context->refreshed) { - ctxTokenNew (context->session); + afb_session_new_token (context->session); context->refreshed = 1; } - return ctxClientGetToken(context->session); + return afb_session_token(context->session); } const char *afb_context_sent_uuid(struct afb_context *context) { - if (context->session == NULL || context->closing) + if (context->session == NULL || context->closing || context->super) return NULL; if (!context->created) return NULL; - return ctxClientGetUuid(context->session); + return afb_session_uuid(context->session); } void *afb_context_get(struct afb_context *context) { assert(context->session != NULL); - return ctxClientValueGet(context->session, context->api_index); + return afb_session_get_cookie(context->session, context->api_key); } void afb_context_set(struct afb_context *context, void *value, void (*free_value)(void*)) { + int rc; assert(context->session != NULL); - return ctxClientValueSet(context->session, context->api_index, value, free_value); + rc = afb_session_set_cookie(context->session, context->api_key, value, free_value); + (void)rc; /* TODO */ } void afb_context_close(struct afb_context *context) { - context->closing = 1; + if (context->super) + afb_context_close(context->super); + else + context->closing = 1; } void afb_context_refresh(struct afb_context *context) { - assert(context->validated); - context->refreshing = 1; + if (context->super) + afb_context_refresh(context->super); + else { + assert(context->validated); + context->refreshing = 1; + } } int afb_context_check(struct afb_context *context) { + if (context->super) + return afb_context_check(context); return context->validated; } int afb_context_check_loa(struct afb_context *context, unsigned loa) { + if (context->super) + return afb_context_check_loa(context->super, loa); return context->loa_in >= loa; } int afb_context_change_loa(struct afb_context *context, unsigned loa) { + if (context->super) + return afb_context_change_loa(context, loa); + if (!context->validated || loa > 7) return 0;