Commit 40ab50a9 authored by Kishen Maloor's avatar Kishen Maloor

oc_cloud:persist cloud provisioning status

Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parent 7c50703a
......@@ -113,7 +113,7 @@ cloud_deregister_on_reset_internal(oc_cloud_context_t *ctx,
cloud_store_initialize(&ctx->store);
cloud_manager_stop(ctx);
ctx->last_error = 0;
ctx->cps = 0;
ctx->store.cps = 0;
}
#endif /* OC_SECURITY */
......@@ -137,7 +137,7 @@ oc_cloud_reset_context(size_t device)
cloud_store_initialize(&ctx->store);
cloud_manager_stop(ctx);
ctx->last_error = 0;
ctx->cps = 0;
ctx->store.cps = 0;
return 0;
}
......@@ -168,7 +168,7 @@ oc_cloud_provision_conf_resource(oc_cloud_context_t *ctx, const char *server,
}
ctx->store.status = OC_CLOUD_INITIALIZED;
ctx->cps = OC_CPS_READYTOREGISTER;
ctx->store.cps = OC_CPS_READYTOREGISTER;
cloud_store_dump_async(&ctx->store);
......@@ -204,7 +204,7 @@ cloud_update_by_resource(oc_cloud_context_t *ctx,
cloud_set_string(&ctx->store.sid, data->sid, data->sid_len);
}
ctx->store.status = OC_CLOUD_INITIALIZED;
ctx->cps = OC_CPS_READYTOREGISTER;
ctx->store.cps = OC_CPS_READYTOREGISTER;
if (ctx->cloud_manager) {
cloud_reconnect(ctx);
}
......
......@@ -109,7 +109,7 @@ oc_cloud_register(oc_cloud_context_t *ctx, oc_cloud_cb_t cb, void *data)
oc_string(ctx->store.uid), oc_string(ctx->store.access_token),
ctx->device, oc_cloud_register_handler, p)) {
cannotConnect = false;
ctx->cps = OC_CPS_REGISTERING;
ctx->store.cps = OC_CPS_REGISTERING;
}
if (cannotConnect) {
cloud_set_last_error(ctx, CLOUD_ERROR_CONNECT);
......@@ -241,7 +241,7 @@ cloud_deregistered_internal(oc_client_response_t *data)
ctx->store.status = OC_CLOUD_DEREGISTERED;
}
ctx->cps = OC_CPS_READYTOREGISTER;
ctx->store.cps = OC_CPS_READYTOREGISTER;
if (p->cb) {
p->cb(ctx, ctx->store.status, p->data);
......
......@@ -146,8 +146,6 @@ _register_handler(oc_cloud_context_t *ctx, oc_client_response_t *data)
oc_rep_t *payload = data->payload;
ctx->store.status = 0;
char *value = NULL;
size_t size = 0;
......@@ -195,12 +193,12 @@ _register_handler(oc_cloud_context_t *ctx, oc_client_response_t *data)
cloud_set_last_error(ctx, CLOUD_OK);
ctx->store.status |= OC_CLOUD_REGISTERED;
ctx->cps = OC_CPS_REGISTERED;
ctx->store.cps = OC_CPS_REGISTERED;
return 0;
error:
ctx->cps = OC_CPS_FAILED;
ctx->store.cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_RESPONSE);
......@@ -259,7 +257,7 @@ cloud_register(void *data)
oc_string(ctx->store.uid), oc_string(ctx->store.access_token),
ctx->device, cloud_register_handler, data)) {
cannotConnect = false;
ctx->cps = OC_CPS_REGISTERING;
ctx->store.cps = OC_CPS_REGISTERING;
}
if (cannotConnect) {
cloud_set_last_error(ctx, CLOUD_ERROR_CONNECT);
......@@ -297,7 +295,7 @@ _login_handler(oc_cloud_context_t *ctx, oc_client_response_t *data)
return 0;
error:
ctx->cps = OC_CPS_FAILED;
ctx->store.cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_RESPONSE);
......@@ -430,7 +428,7 @@ error:
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_REFRESH_ACCESS_TOKEN);
}
ctx->cps = OC_CPS_FAILED;
ctx->store.cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
return -1;
}
......
......@@ -66,7 +66,7 @@ cloud_response(oc_cloud_context_t *ctx)
root, sid, (oc_string(ctx->store.sid) ? oc_string(ctx->store.sid) : ""));
oc_rep_set_int(root, clec, (int)ctx->last_error);
const char *cps = cps_to_str(ctx->cps);
const char *cps = cps_to_str(ctx->store.cps);
if (cps) {
oc_rep_set_text_string(root, cps, cps);
}
......@@ -145,7 +145,7 @@ post_cloud(oc_request_t *request, oc_interface_mask_t interface,
OC_DBG("POST request received");
(void)interface;
switch (ctx->cps) {
switch (ctx->store.cps) {
case OC_CPS_UNINITIALIZED:
case OC_CPS_READYTOREGISTER:
case OC_CPS_FAILED:
......
......@@ -68,6 +68,7 @@ encode_cloud_with_map(CborEncoder *object_map, const oc_cloud_store_t *store)
oc_rep_set_text_string(*object, refresh_token,
oc_string(store->refresh_token));
oc_rep_set_int(*object, status, store->status);
oc_rep_set_int(*object, cps, store->cps);
}
static void
......@@ -168,6 +169,8 @@ cloud_store_decode(oc_rep_t *rep, oc_cloud_store_t *store)
case OC_REP_INT:
if (len == 6 && memcmp(oc_string(t->name), "status", 6) == 0) {
store->status = (uint8_t)t->value.integer;
} else if (len == 3 && memcmp(oc_string(t->name), "cps", 3) == 0) {
store->cps = (uint8_t)t->value.integer;
} else {
OC_ERR("[CLOUD_STORE] Unknown property %s", oc_string(t->name));
return -1;
......
......@@ -62,6 +62,7 @@ typedef struct oc_cloud_store_t
oc_string_t refresh_token;
oc_string_t sid;
uint8_t status;
oc_cps_t cps;
size_t device;
} oc_cloud_store_t;
......@@ -104,8 +105,6 @@ typedef struct oc_cloud_context_t
oc_link_t *rd_delete_resources;
bool rd_delete_all;
oc_cps_t cps;
oc_resource_t *cloud_conf;
bool cloud_manager;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment