/*
- * 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");
context->session = session;
context->flags = 0;
context->api_index = -1;
+ context->loa_in = ctxClientGetLOA(session) & 7;
/* check the token */
if (token != NULL) {
if (session == NULL)
return -1;
init_context(context, session, token);
- if (created)
+ 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;
}
}
{
if (context->session == NULL || context->closing)
return NULL;
- if (!(context->created || context->refreshing))
+ if (!context->refreshing)
return NULL;
if (!context->refreshed) {
ctxTokenNew (context->session);
void afb_context_refresh(struct afb_context *context)
{
+ assert(context->validated);
context->refreshing = 1;
}
return context->validated;
}
-int afb_context_create(struct afb_context *context)
+int afb_context_check_loa(struct afb_context *context, unsigned loa)
{
- return context->created;
+ return context->loa_in >= loa;
}
+
+int afb_context_change_loa(struct afb_context *context, unsigned loa)
+{
+ 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;
+}
+
+