X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-context.c;h=ba093c375b189fc26a64c11646a2366a971f5d1c;hb=26bca5f8a8c6f9403a84945a5cd914b6da948efd;hp=2f391decee10d41ee108a72579af9517d5e11ae3;hpb=f1b901ed676b2d45ec8e6ae3d6ef2f94d79f9ee6;p=src%2Fapp-framework-binder.git diff --git a/src/afb-context.c b/src/afb-context.c index 2f391dec..ba093c37 100644 --- a/src/afb-context.c +++ b/src/afb-context.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 "IoT.bzh" + * Copyright (C) 2015, 2016 "IoT.bzh" * Author "Fulup Ar Foll" * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,8 +23,7 @@ #include "session.h" #include "afb-context.h" - -void afb_context_init(struct afb_context *context, struct AFB_clientCtx *session, const char *token) +static void init_context(struct afb_context *context, struct AFB_clientCtx *session, const char *token) { assert(session != NULL); @@ -32,6 +31,7 @@ void afb_context_init(struct afb_context *context, struct AFB_clientCtx *session context->session = session; context->flags = 0; context->api_index = -1; + context->loa_in = ctxClientGetLOA(session) & 7; /* check the token */ if (token != NULL) { @@ -42,6 +42,11 @@ void afb_context_init(struct afb_context *context, struct AFB_clientCtx *session } } +void afb_context_init(struct afb_context *context, struct AFB_clientCtx *session, const char *token) +{ + init_context(context, ctxClientAddRef(session), token); +} + int afb_context_connect(struct afb_context *context, const char *uuid, const char *token) { int created; @@ -50,20 +55,31 @@ int afb_context_connect(struct afb_context *context, const char *uuid, const cha session = ctxClientGetSession (uuid, &created); if (session == NULL) return -1; - afb_context_init(context, session, token); - if (created) + init_context(context, session, token); + if (created) { context->created = 1; + /* context->refreshing = 1; */ + } return 0; } void afb_context_disconnect(struct afb_context *context) { if (context->session != NULL) { + if (context->refreshing && !context->refreshed) { + ctxTokenNew (context->session); + context->refreshed = 1; + } + if (context->loa_changing && !context->loa_changed) { + ctxClientSetLOA (context->session, context->loa_out); + context->loa_changed = 1; + } if (context->closing && !context->closed) { - context->closed = 1; ctxClientClose(context->session); + context->closed = 1; } ctxClientUnref(context->session); + context->session = NULL; } } @@ -71,7 +87,7 @@ const char *afb_context_sent_token(struct afb_context *context) { if (context->session == NULL || context->closing) return NULL; - if (!(context->created || context->refreshing)) + if (!context->refreshing) return NULL; if (!context->refreshed) { ctxTokenNew (context->session); @@ -108,6 +124,7 @@ void afb_context_close(struct afb_context *context) void afb_context_refresh(struct afb_context *context) { + assert(context->validated); context->refreshing = 1; } @@ -116,7 +133,24 @@ int afb_context_check(struct afb_context *context) return context->validated; } -int afb_context_create(struct afb_context *context) +int afb_context_check_loa(struct afb_context *context, unsigned loa) +{ + return context->loa_in >= loa; +} + +int afb_context_change_loa(struct afb_context *context, unsigned loa) { - return context->created; + if (!context->validated || loa > 7) + return 0; + + if (loa == context->loa_in && !context->loa_changed) + context->loa_changing = 0; + else { + context->loa_out = loa & 7; + context->loa_changing = 1; + context->loa_changed = 0; + } + return 1; } + +