Commit 82502811 authored by Kishen Maloor's avatar Kishen Maloor

Add support for Cloud registration status

Change-Id: Ib7aedf9790d01820592530b97e708772c9c9e727
Signed-off-by: Kishen Maloor's avatarKishen Maloor <kishen.maloor@intel.com>
parent 727086bc
......@@ -111,6 +111,7 @@ cloud_deregister_on_reset_internal(oc_cloud_context_t *ctx,
cloud_store_deinit(&ctx->store);
cloud_manager_stop(ctx);
ctx->last_error = 0;
ctx->cps = 0;
}
#endif /* OC_SECURITY */
......@@ -134,6 +135,7 @@ oc_cloud_reset_context(size_t device)
cloud_store_deinit(&ctx->store);
cloud_manager_stop(ctx);
ctx->last_error = 0;
ctx->cps = 0;
return 0;
}
......@@ -160,6 +162,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;
if (ctx->cloud_manager) {
cloud_reconnect(ctx);
}
......
......@@ -96,6 +96,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;
}
if (cannotConnect) {
cloud_set_last_error(ctx, CLOUD_ERROR_CONNECT);
......@@ -229,6 +230,8 @@ cloud_deregistered_internal(oc_client_response_t *data)
ctx->store.status = OC_CLOUD_DEREGISTERED;
}
ctx->cps = OC_CPS_READYTOREGISTER;
if (p->cb) {
p->cb(ctx, ctx->store.status, p->data);
}
......
......@@ -193,10 +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;
return 0;
error:
ctx->cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_RESPONSE);
......@@ -257,6 +259,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;
}
if (cannotConnect) {
cloud_set_last_error(ctx, CLOUD_ERROR_CONNECT);
......@@ -294,6 +297,7 @@ _login_handler(oc_cloud_context_t *ctx, oc_client_response_t *data)
return 0;
error:
ctx->cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_RESPONSE);
......@@ -427,6 +431,7 @@ error:
if (ctx->last_error == 0) {
cloud_set_last_error(ctx, CLOUD_ERROR_REFRESH_ACCESS_TOKEN);
}
ctx->cps = OC_CPS_FAILED;
ctx->store.status |= OC_CLOUD_FAILURE;
return -1;
}
......
......@@ -30,6 +30,26 @@
#define OC_RSRVD_SERVERID "sid"
#define OC_RSRVD_LAST_ERROR_CODE "clec"
static const char *
cps_to_str(oc_cps_t cps)
{
switch (cps) {
case OC_CPS_UNINITIALIZED:
return "uninitialized";
case OC_CPS_READYTOREGISTER:
return "readytoregister";
case OC_CPS_REGISTERING:
return "registering";
case OC_CPS_REGISTERED:
return "registered";
case OC_CPS_FAILED:
return "failed";
default:
break;
}
return NULL;
}
static void
cloud_response(oc_cloud_context_t *ctx)
{
......@@ -46,6 +66,10 @@ cloud_response(oc_cloud_context_t *ctx)
oc_rep_set_text_string(root, at, "");
oc_rep_set_int(root, clec, (int)ctx->last_error);
const char *cps = cps_to_str(ctx->cps);
if (cps) {
oc_rep_set_text_string(root, cps, cps);
}
oc_rep_end_root_object();
}
......@@ -113,6 +137,24 @@ post_cloud(oc_request_t *request, oc_interface_mask_t interface,
OC_DBG("POST request received");
(void)interface;
switch (ctx->cps) {
case OC_CPS_UNINITIALIZED:
case OC_CPS_READYTOREGISTER:
case OC_CPS_FAILED:
break;
default: {
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
}
}
char *cps;
size_t cps_len = 0;
if (oc_rep_get_string(request->request_payload, "cps", &cps, &cps_len)) {
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
}
bool changed = cloud_update_from_request(ctx, request);
cloud_response(ctx);
oc_send_response(request,
......
......@@ -42,6 +42,14 @@ typedef enum {
OC_CLOUD_DEREGISTERED = 64
} oc_cloud_status_t;
typedef enum oc_cps_t {
OC_CPS_UNINITIALIZED = 0,
OC_CPS_READYTOREGISTER,
OC_CPS_REGISTERING,
OC_CPS_REGISTERED,
OC_CPS_FAILED
} oc_cps_t;
typedef struct oc_cloud_store_t
{
oc_string_t ci_server;
......@@ -93,6 +101,8 @@ 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