Skip to content

Commit

Permalink
fixup! restarts cloud_manager only when user invokes oc_cloud_manager…
Browse files Browse the repository at this point in the history
…_starts
  • Loading branch information
jkralik committed Dec 28, 2023
1 parent 9f6ca38 commit 9061688
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 12 additions & 10 deletions api/cloud/oc_cloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/oc_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9061688

Please sign in to comment.