Lines Matching full:instance

206 static void set_sw_update_state(struct lwm2m_swmgmt_data *instance, uint8_t state)  in set_sw_update_state()  argument
210 instance->obj_inst_id, in set_sw_update_state()
219 static void set_sw_update_result(struct lwm2m_swmgmt_data *instance, uint8_t result) in set_sw_update_result() argument
223 instance->obj_inst_id, in set_sw_update_result()
232 static void set_sw_update_act_state(struct lwm2m_swmgmt_data *instance, bool state) in set_sw_update_act_state() argument
236 instance->obj_inst_id, in set_sw_update_act_state()
257 LOG_DBG("No instance found for obj id %u", obj_inst_id); in find_index()
263 struct lwm2m_swmgmt_data *instance = NULL; in lwm2m_swmgmt_set_activate_cb() local
265 instance = find_index(obj_inst_id); in lwm2m_swmgmt_set_activate_cb()
266 if (!instance) { in lwm2m_swmgmt_set_activate_cb()
274 instance->activate_cb = cb; in lwm2m_swmgmt_set_activate_cb()
280 struct lwm2m_swmgmt_data *instance = NULL; in lwm2m_swmgmt_set_deactivate_cb() local
282 instance = find_index(obj_inst_id); in lwm2m_swmgmt_set_deactivate_cb()
283 if (!instance) { in lwm2m_swmgmt_set_deactivate_cb()
291 instance->deactivate_cb = cb; in lwm2m_swmgmt_set_deactivate_cb()
297 struct lwm2m_swmgmt_data *instance = NULL; in lwm2m_swmgmt_set_install_package_cb() local
299 instance = find_index(obj_inst_id); in lwm2m_swmgmt_set_install_package_cb()
300 if (!instance) { in lwm2m_swmgmt_set_install_package_cb()
308 instance->install_package_cb = cb; in lwm2m_swmgmt_set_install_package_cb()
314 struct lwm2m_swmgmt_data *instance = NULL; in lwm2m_swmgmt_set_delete_package_cb() local
316 instance = find_index(obj_inst_id); in lwm2m_swmgmt_set_delete_package_cb()
317 if (!instance) { in lwm2m_swmgmt_set_delete_package_cb()
325 instance->delete_package_cb = cb; in lwm2m_swmgmt_set_delete_package_cb()
331 struct lwm2m_swmgmt_data *instance = NULL; in lwm2m_swmgmt_set_write_package_cb() local
333 instance = find_index(obj_inst_id); in lwm2m_swmgmt_set_write_package_cb()
334 if (!instance) { in lwm2m_swmgmt_set_write_package_cb()
342 instance->write_package_cb = cb; in lwm2m_swmgmt_set_write_package_cb()
348 struct lwm2m_swmgmt_data *instance = NULL; in lwm2m_swmgmt_set_read_package_version_cb() local
350 instance = find_index(obj_inst_id); in lwm2m_swmgmt_set_read_package_version_cb()
351 if (!instance) { in lwm2m_swmgmt_set_read_package_version_cb()
359 instance->read_package_cb = cb; in lwm2m_swmgmt_set_read_package_version_cb()
366 struct lwm2m_swmgmt_data *instance = NULL; in state_read_pkg_version() local
369 instance = find_index(obj_inst_id); in state_read_pkg_version()
370 if (!instance) { in state_read_pkg_version()
374 if (instance->read_package_cb) { in state_read_pkg_version()
375 result = instance->read_package_cb(obj_inst_id, res_id, res_inst_id, data_len); in state_read_pkg_version()
381 static int handle_event(struct lwm2m_swmgmt_data *instance, uint8_t event) in handle_event() argument
385 if (!instance) { in handle_event()
389 switch (instance->update_state) { in handle_event()
393 set_sw_update_state(instance, UPD_STATE_DOWNLOAD_STARTED); in handle_event()
394 set_sw_update_result(instance, UPD_RES_DOWNLOADING); in handle_event()
405 set_sw_update_state(instance, UPD_STATE_DOWNLOADED); in handle_event()
406 set_sw_update_result(instance, UPD_RES_INITIAL); in handle_event()
409 set_sw_update_state(instance, UPD_STATE_INITIAL); in handle_event()
411 /* Inform the instance of DOWNLOAD_FAILED by calling in handle_event()
414 instance->write_package_cb(instance->obj_inst_id, 0, 0, NULL, 0, false, 0); in handle_event()
424 set_sw_update_state(instance, UPD_STATE_DELIVERED); in handle_event()
425 set_sw_update_result(instance, UPD_RES_INITIAL); in handle_event()
428 set_sw_update_state(instance, UPD_STATE_INITIAL); in handle_event()
429 set_sw_update_result(instance, UPD_RES_PACKAGE_INTEGRITY_CHECK_FAILURE); in handle_event()
439 if (instance->next_package_is_upgrade) { in handle_event()
440 ret = instance->upgrade_package_cb(instance->obj_inst_id); in handle_event()
444 ret = instance->install_package_cb(instance->obj_inst_id, NULL, 0); in handle_event()
450 set_sw_update_state(instance, UPD_STATE_INSTALLED); in handle_event()
451 set_sw_update_result(instance, UPD_RES_SW_SUCCESSFULLY_INSTALLED); in handle_event()
452 instance->next_package_is_upgrade = false; in handle_event()
456 set_sw_update_state(instance, UPD_STATE_DELIVERED); in handle_event()
457 set_sw_update_result(instance, UPD_RES_SW_INSTALLATION_FAILURE); in handle_event()
461 ret = instance->delete_package_cb(instance->obj_inst_id, NULL, 0); in handle_event()
463 set_sw_update_state(instance, UPD_STATE_INITIAL); in handle_event()
476 ret = instance->activate_cb(instance->obj_inst_id, NULL, 0); in handle_event()
478 set_sw_update_act_state(instance, true); in handle_event()
482 ret = instance->deactivate_cb(instance->obj_inst_id, NULL, 0); in handle_event()
484 set_sw_update_act_state(instance, false); in handle_event()
488 instance->next_package_is_upgrade = true; in handle_event()
489 set_sw_update_state(instance, UPD_STATE_INITIAL); in handle_event()
490 set_sw_update_result(instance, UPD_RES_INITIAL); in handle_event()
492 ret = instance->delete_package_cb(instance->obj_inst_id, NULL, 0); in handle_event()
494 set_sw_update_state(instance, UPD_STATE_INITIAL); in handle_event()
495 set_sw_update_result(instance, UPD_RES_INITIAL); in handle_event()
513 struct lwm2m_swmgmt_data *instance = NULL; in install_cb() local
515 instance = find_index(obj_inst_id); in install_cb()
517 return handle_event(instance, EVENT_INSTALL); in install_cb()
522 struct lwm2m_swmgmt_data *instance = NULL; in lwm2m_swmgmt_install_completed() local
524 instance = find_index(obj_inst_id); in lwm2m_swmgmt_install_completed()
527 error_code = handle_event(instance, EVENT_INSTALL_FAIL); in lwm2m_swmgmt_install_completed()
529 error_code = handle_event(instance, EVENT_INSTALL_SUCCESSFUL); in lwm2m_swmgmt_install_completed()
537 struct lwm2m_swmgmt_data *instance = NULL; in uninstall_cb() local
539 instance = find_index(obj_inst_id); in uninstall_cb()
541 return handle_event(instance, EVENT_DELETE_PACKAGE); in uninstall_cb()
546 struct lwm2m_swmgmt_data *instance = NULL; in activate_cb() local
548 instance = find_index(obj_inst_id); in activate_cb()
550 return handle_event(instance, EVENT_ACTIVATE); in activate_cb()
555 struct lwm2m_swmgmt_data *instance = NULL; in deactivate_cb() local
557 instance = find_index(obj_inst_id); in deactivate_cb()
559 return handle_event(instance, EVENT_DEACTIVATE); in deactivate_cb()
568 struct lwm2m_swmgmt_data *instance = NULL; in package_write_cb() local
570 instance = find_index(obj_inst_id); in package_write_cb()
572 ret = handle_event(instance, EVENT_PKG_URI_WRITE); in package_write_cb()
578 ret = instance->write_package_cb(obj_inst_id, res_id, res_inst_id, data, data_len, in package_write_cb()
582 handle_event(instance, EVENT_DOWNLOAD_FAILED); in package_write_cb()
585 set_sw_update_result(instance, UPD_RES_OUT_OF_MEMORY_DURING_DOWNLOAD); in package_write_cb()
588 set_sw_update_result(instance, UPD_RES_NOT_ENOUGH_STORAGE); in package_write_cb()
592 set_sw_update_result(instance, UPD_RES_PACKAGE_INTEGRITY_CHECK_FAILURE); in package_write_cb()
595 set_sw_update_result(instance, UPD_RES_LOST_CONNECTION_DURING_DOWNLOAD); in package_write_cb()
603 handle_event(instance, EVENT_PKG_WRITTEN); in package_write_cb()
612 struct lwm2m_swmgmt_data *instance; in set_update_result() local
614 instance = find_index(obj_inst_id); in set_update_result()
617 handle_event(instance, EVENT_PKG_WRITTEN); in set_update_result()
627 handle_event(instance, EVENT_PKG_INTEGRITY_VERIFIED); in set_update_result()
629 handle_event(instance, EVENT_PKG_INTEGRITY_FAILED); in set_update_result()
635 handle_event(instance, EVENT_DOWNLOAD_FAILED); in set_update_result()
637 set_sw_update_result(instance, UPD_RES_OUT_OF_MEMORY_DURING_DOWNLOAD); in set_update_result()
639 set_sw_update_result(instance, UPD_RES_NOT_ENOUGH_STORAGE); in set_update_result()
641 set_sw_update_result(instance, UPD_RES_PACKAGE_INTEGRITY_CHECK_FAILURE); in set_update_result()
643 set_sw_update_result(instance, UPD_RES_INVALID_URI); in set_update_result()
645 set_sw_update_result(instance, UPD_RES_LOST_CONNECTION_DURING_DOWNLOAD); in set_update_result()
656 struct lwm2m_swmgmt_data *instance = NULL; in package_uri_write_cb() local
658 instance = find_index(obj_inst_id); in package_uri_write_cb()
663 .write_cb = instance->write_package_cb, in package_uri_write_cb()
668 error_code = lwm2m_pull_context_start_transfer(instance->package_uri, req, K_NO_WAIT); in package_uri_write_cb()
674 return handle_event(instance, EVENT_PKG_URI_WRITE); in package_uri_write_cb()
683 struct lwm2m_swmgmt_data *instance = NULL; in swmgmt_create() local
686 /* Check that there is no other instance with this ID */ in swmgmt_create()
689 LOG_ERR("Can not create instance - " in swmgmt_create()
703 LOG_ERR("Can not create instance - no more room: %u", obj_inst_id); in swmgmt_create()
707 instance = &swmgmt_data[index]; in swmgmt_create()
713 (void)memset(instance->package_name, 0, PACKAGE_NAME_LEN); in swmgmt_create()
714 (void)memset(instance->package_version, 0, PACKAGE_VERSION_LEN); in swmgmt_create()
716 instance->obj_inst_id = obj_inst_id; in swmgmt_create()
717 instance->update_state = 0; in swmgmt_create()
718 instance->update_result = 0; in swmgmt_create()
719 instance->activation_state = false; in swmgmt_create()
721 instance->next_package_is_upgrade = false; in swmgmt_create()
723 instance->install_package_cb = callback_execute_not_defined; in swmgmt_create()
724 instance->delete_package_cb = callback_execute_not_defined; in swmgmt_create()
725 instance->activate_cb = callback_execute_not_defined; in swmgmt_create()
726 instance->deactivate_cb = callback_execute_not_defined; in swmgmt_create()
727 instance->write_package_cb = callback_write_not_defined; in swmgmt_create()
730 (void)memset(instance->package_uri, 0, PACKAGE_URI_LEN); in swmgmt_create()
733 /* initialize instance resource data */ in swmgmt_create()
735 res_inst_idx, &instance->package_name, PACKAGE_NAME_LEN, 0); in swmgmt_create()
738 res_inst_idx, 1, false, true, &instance->package_version, in swmgmt_create()
746 false, true, instance->package_uri, PACKAGE_URI_LEN, NULL, NULL, NULL, in swmgmt_create()
761 res_inst_idx, &instance->update_state, sizeof(uint8_t)); in swmgmt_create()
767 res_inst_idx, &instance->update_result, sizeof(uint8_t)); in swmgmt_create()
773 res_inst_idx, &instance->activation_state, sizeof(bool)); in swmgmt_create()