From 906168812c81c491f6fc09ee4a69289ab84ca73b Mon Sep 17 00:00:00 2001 From: Jozef Kralik Date: Thu, 28 Dec 2023 09:36:10 +0000 Subject: [PATCH] fixup! restarts cloud_manager only when user invokes oc_cloud_manager_starts --- api/cloud/oc_cloud.c | 22 ++++++++++++---------- include/oc_cloud.h | 2 ++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/api/cloud/oc_cloud.c b/api/cloud/oc_cloud.c index 26e9924a1..fb4284475 100644 --- a/api/cloud/oc_cloud.c +++ b/api/cloud/oc_cloud.c @@ -79,6 +79,10 @@ start_manager(void *user_data) static void cloud_manager_restart(oc_cloud_context_t *ctx) { + if (!ctx->cloud_manager) { + OC_CLOUD_ERR("cloud manager is not running"); + return; + } cloud_manager_stop(ctx); cloud_deregister_stop(ctx); oc_remove_delayed_callback(ctx, start_manager); @@ -229,12 +233,7 @@ cloud_update_by_resource(oc_cloud_context_t *ctx, ctx->store.cps = OC_CPS_READYTOREGISTER; if (ctx->cloud_manager) { oc_cloud_manager_restart(ctx); - return; } - - // if (oc_cloud_manager_start(ctx, ctx->callback, ctx->user_data) != 0) { - // OC_CLOUD_ERR("cannot start cloud manager"); - // } } #ifdef OC_SESSION_EVENTS @@ -255,9 +254,9 @@ cloud_ep_session_event_handler(const oc_endpoint_t *endpoint, } ctx->cloud_ep_state = state; - if (ctx->cloud_ep_state == OC_SESSION_DISCONNECTED && ctx->cloud_manager) { + if (ctx->cloud_ep_state == OC_SESSION_DISCONNECTED) { OC_CLOUD_INFO("Session disconnected"); - if ((ctx->store.status & OC_CLOUD_REGISTERED) != 0) { + if ((ctx->store.status & OC_CLOUD_REGISTERED) != 0 && ctx->cloud_manager) { cloud_manager_restart(ctx); } } @@ -270,7 +269,7 @@ static void cloud_interface_up_event_handler(oc_cloud_context_t *ctx, void *user_data) { (void)user_data; - if (ctx->store.status == OC_CLOUD_INITIALIZED) { + if (ctx->store.status == OC_CLOUD_INITIALIZED && ctx->cloud_manager) { cloud_manager_restart(ctx); } } @@ -329,6 +328,10 @@ cloud_is_deregistering(const oc_cloud_context_t *ctx) void oc_cloud_manager_restart(oc_cloud_context_t *ctx) { + if (!ctx->cloud_manager) { + OC_CLOUD_ERR("cloud manager is not running"); + return; + } OC_CLOUD_DBG("oc_cloud_manager_restart"); #ifdef OC_SESSION_EVENTS if (ctx->cloud_ep_state == OC_SESSION_CONNECTED) { @@ -339,8 +342,7 @@ oc_cloud_manager_restart(oc_cloud_context_t *ctx) } } #endif /* OC_SESSION_EVENTS */ - oc_remove_delayed_callback(ctx, restart_manager); - oc_set_delayed_callback(ctx, restart_manager, 0); + oc_reset_delayed_callback(ctx, restart_manager, 0); } int diff --git a/include/oc_cloud.h b/include/oc_cloud.h index f30eec10c..8a5ec184d 100644 --- a/include/oc_cloud.h +++ b/include/oc_cloud.h @@ -234,6 +234,8 @@ int oc_cloud_manager_stop(oc_cloud_context_t *ctx); /** * @brief Restart cloud registration process with the current configuration. * + * @note The cloud manager must be started before calling this function. + * * @param ctx cloud context (cannot be NULL) */ OC_API