@@ -42,6 +42,7 @@ static void handle_init_state(device_runtime_sm_t* pt_dr_sm)
4242 if (!is_token_empty (pt_dr_sm ))
4343 {
4444 dr_state_machine_execute_transition (pt_dr_sm , SUCCESS_AUTH );
45+
4546 }
4647 else
4748 {
@@ -111,6 +112,8 @@ static void handle_get_ecf_address_state(device_runtime_sm_t* pt_dr_sm)
111112 {
112113 COGNIT_LOG_DEBUG ("Cognit Frontend Client disconnected, re-authenticating..." );
113114 dr_state_machine_execute_transition (pt_dr_sm , TOKEN_NOT_VALID_ADDRESS );
115+ dr_state_machine_execute_transition (pt_dr_sm , TOKEN_UPDATED );
116+
114117 }
115118}
116119
@@ -188,18 +191,10 @@ e_status_code_t dr_sm_offload_function(device_runtime_sm_t* pt_dr_sm, faas_t* pt
188191
189192 COGNIT_LOG_DEBUG ("State is not READY. Handling transitions..." );
190193 handle_transitions (pt_dr_sm );
191- if (pt_dr_sm -> current_state == READY )
194+
195+ if (pt_dr_sm -> current_state != READY )
192196 {
193- COGNIT_LOG_DEBUG ("Retrying function offload after state transitions..." );
194- e_status_code_t ret = exec_offload_func (pt_dr_sm , pt_faas , pt_exec_response );
195- if (ret != E_ST_CODE_SUCCESS )
196- {
197- COGNIT_LOG_DEBUG ("Offload failed, re-authenticating..." );
198- dr_state_machine_execute_transition (pt_dr_sm , TOKEN_NOT_VALID_READY );
199- dr_state_machine_execute_transition (pt_dr_sm , TOKEN_UPDATED );
200- if (pt_dr_sm -> current_state == READY )
201- exec_offload_func (pt_dr_sm , pt_faas , pt_exec_response );
202- }
197+ return E_ST_CODE_ERROR ;
203198 }
204199
205200 COGNIT_LOG_DEBUG ("Retrying function offload after state transitions..." );
@@ -278,6 +273,19 @@ static int success_auth_condition(device_runtime_sm_t* pt_dr_sm)
278273 }
279274}
280275
276+ static int token_updated_condition (device_runtime_sm_t * pt_dr_sm )
277+ {
278+ if (!is_token_empty (pt_dr_sm ) && is_cfc_connected (pt_dr_sm ) && pt_dr_sm -> app_req_id != 0 )
279+ {
280+ return 1 ;
281+ }
282+ else
283+ {
284+ return 0 ;
285+ }
286+ }
287+
288+
281289static int repeat_auth_condition (device_runtime_sm_t * pt_dr_sm )
282290{
283291 if (is_token_empty (pt_dr_sm ))
@@ -419,7 +427,7 @@ sm_transition_t transitions[] = {
419427 { GET_ECF_ADDRESS , ADDRESS_UPDATE_REQUIREMENTS , SEND_INIT_REQUEST , address_update_requirements_condition },
420428 { INIT , SUCCESS_AUTH , SEND_INIT_REQUEST , success_auth_condition },
421429 { INIT , REPEAT_AUTH , INIT , repeat_auth_condition },
422- { INIT , TOKEN_UPDATED , READY , success_auth_condition },
430+ { INIT , TOKEN_UPDATED , READY , token_updated_condition },
423431 { READY , RESULT_GIVEN , READY , result_given_condition },
424432 { READY , TOKEN_NOT_VALID_READY , INIT , token_not_valid_ready_condition },
425433 { READY , TOKEN_NOT_VALID_READY_2 , INIT , token_not_valid_ready_2_condition },
@@ -568,6 +576,13 @@ static bool check_reqs(const scheduling_t* old_reqs, const scheduling_t* new_req
568576 return true;
569577 }
570578
579+ if (old_reqs -> provider == NULL && new_reqs -> provider == NULL ) {
580+ return false; // los consideramos iguales
581+ }
582+ else if (old_reqs -> provider == NULL || new_reqs -> provider == NULL ) {
583+ return true; // uno NULL y el otro no -> distintos
584+ }
585+
571586 if (strcmp (old_reqs -> provider , new_reqs -> provider ) != 0 )
572587 {
573588 return true;
0 commit comments