summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-04-04 09:50:53 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-04-04 09:50:53 +0200
commitf9f80fd77b5a6a9b50fac3026fae088823a23dc1 (patch)
tree94baedaa21a66c93423c225c8eaa7524a223a5e7
parent074410d68f46148370b793eff8f34cf4724e3e31 (diff)
Introduce subcontext for subcalls
Change-Id: I5460e9c502cee814c59a0ee60c2be001385e7b4a Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-context.c33
-rw-r--r--src/afb-context.h2
2 files changed, 29 insertions, 6 deletions
diff --git a/src/afb-context.c b/src/afb-context.c
index 6eb29f0d..174ac163 100644
--- a/src/afb-context.c
+++ b/src/afb-context.c
@@ -31,6 +31,7 @@ static void init_context(struct afb_context *context, struct afb_session *sessio
/* reset the context for the session */
context->session = session;
context->flags = 0;
+ context->super = NULL;
context->api_key = NULL;
context->loa_in = afb_session_get_LOA(session) & 7;
@@ -48,6 +49,12 @@ void afb_context_init(struct afb_context *context, struct afb_session *session,
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;
@@ -66,7 +73,7 @@ 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) {
afb_session_new_token (context->session);
context->refreshed = 1;
@@ -86,7 +93,7 @@ void afb_context_disconnect(struct afb_context *context)
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;
@@ -99,7 +106,7 @@ const char *afb_context_sent_token(struct afb_context *context)
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;
@@ -122,27 +129,41 @@ void afb_context_set(struct afb_context *context, void *value, void (*free_value
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;
diff --git a/src/afb-context.h b/src/afb-context.h
index 3eb49742..40adeb5b 100644
--- a/src/afb-context.h
+++ b/src/afb-context.h
@@ -39,9 +39,11 @@ struct afb_context
};
};
void *api_key;
+ struct afb_context *super;
};
extern void afb_context_init(struct afb_context *context, struct afb_session *session, const char *token);
+extern void afb_context_subinit(struct afb_context *context, struct afb_context *super);
extern int afb_context_connect(struct afb_context *context, const char *uuid, const char *token);
extern void afb_context_disconnect(struct afb_context *context);
extern const char *afb_context_sent_token(struct afb_context *context);