You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2019/03/21 16:39:24 UTC

[mynewt-core] branch master updated: imgrmgr: dfu callback fixes (#1708)

This is an automated email from the ASF dual-hosted git repository.

vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 1fa9d9f  imgrmgr: dfu callback fixes (#1708)
1fa9d9f is described below

commit 1fa9d9fa47d2c55a1863f4eda4651664bb2b20e0
Author: JustineKH <35...@users.noreply.github.com>
AuthorDate: Thu Mar 21 09:39:19 2019 -0700

    imgrmgr: dfu callback fixes (#1708)
    
    
    - coding standard fixes
---
 mgmt/imgmgr/include/imgmgr/imgmgr.h | 12 ++++++-----
 mgmt/imgmgr/src/imgmgr.c            | 40 ++++++++++++++++++++-----------------
 mgmt/imgmgr/src/imgmgr_state.c      |  2 ++
 3 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/mgmt/imgmgr/include/imgmgr/imgmgr.h b/mgmt/imgmgr/include/imgmgr/imgmgr.h
index d1cbb2f..ff6c1f4 100644
--- a/mgmt/imgmgr/include/imgmgr/imgmgr.h
+++ b/mgmt/imgmgr/include/imgmgr/imgmgr.h
@@ -52,7 +52,8 @@ typedef struct
 {
     imgrmgr_dfu_cb dfu_started_cb;
     imgrmgr_dfu_cb dfu_stopped_cb;
-    imgrmgr_dfu_cb dfu_complete_cb;
+    imgrmgr_dfu_cb dfu_pending_cb;
+    imgrmgr_dfu_cb dfu_confirmed_cb;
 } imgmgr_dfu_callbacks_t;
 
 /** @typedef imgr_upload_fn
@@ -122,10 +123,11 @@ int imgmgr_state_slot_in_use(int slot);
 int imgmgr_state_set_pending(int slot, int permanent);
 int imgmgr_state_confirm(void);
 int imgmgr_find_best_area_id(void);
-int imgmgr_register_callbacks(const imgmgr_dfu_callbacks_t *cb_struct);
-void imgr_dfu_stopped(void);
-void imgr_dfu_started(void);
-void imgr_dfu_complete(void);
+void imgmgr_register_callbacks(const imgmgr_dfu_callbacks_t *cb_struct);
+void imgmgr_dfu_stopped(void);
+void imgmgr_dfu_started(void);
+void imgmgr_dfu_pending(void);
+void imgmgr_dfu_confirmed(void);
 #ifdef __cplusplus
 }
 #endif
diff --git a/mgmt/imgmgr/src/imgmgr.c b/mgmt/imgmgr/src/imgmgr.c
index 3cef6e5..072fe15 100644
--- a/mgmt/imgmgr/src/imgmgr.c
+++ b/mgmt/imgmgr/src/imgmgr.c
@@ -739,7 +739,7 @@ imgr_upload(struct mgmt_cbuf *cb)
     /* Determine what actions to take as a result of this request. */
     rc = imgr_upload_inspect(&req, &action, &errstr);
     if (rc != 0) {
-        imgr_dfu_stopped();
+        imgmgr_dfu_stopped();
         return rc;
     }
 
@@ -756,7 +756,7 @@ imgr_upload(struct mgmt_cbuf *cb)
     if (imgr_upload_cb != NULL) {
         rc = imgr_upload_cb(req.off, action.size, imgr_upload_arg);
         if (rc != 0) {
-            imgr_dfu_stopped();
+            imgmgr_dfu_stopped();
             return imgr_error_rsp(cb, rc, imgmgr_err_str_app_reject);
         }
     }
@@ -767,7 +767,7 @@ imgr_upload(struct mgmt_cbuf *cb)
 
     rc = flash_area_open(imgr_state.area_id, &fa);
     if (rc != 0) {
-        imgr_dfu_stopped();
+        imgmgr_dfu_stopped();
         return imgr_error_rsp(cb, MGMT_ERR_EUNKNOWN,
                               imgmgr_err_str_flash_open_failed);
     }
@@ -778,7 +778,7 @@ imgr_upload(struct mgmt_cbuf *cb)
          */
         imgr_state.off = 0;
 
-        imgr_dfu_started();
+        imgmgr_dfu_started();
 
         /*
          * We accept SHA trimmed to any length by client since it's up to client
@@ -828,14 +828,14 @@ imgr_upload(struct mgmt_cbuf *cb)
 #endif
         rc = flash_area_write(fa, req.off, req.img_data, action.write_bytes);
         if (rc != 0) {
-            imgr_dfu_stopped();
+            imgmgr_dfu_stopped();
             rc = MGMT_ERR_EUNKNOWN;
             errstr = imgmgr_err_str_flash_write_failed;
         } else {
             imgr_state.off += action.write_bytes;
             if (imgr_state.off == imgr_state.size) {
                 /* Done */
-                imgr_dfu_complete();
+                imgmgr_dfu_pending();
                 imgr_state.area_id = -1;
             }
         }
@@ -854,29 +854,34 @@ end:
 }
 
 void
-imgr_dfu_stopped(void)
+imgmgr_dfu_stopped(void)
 {
-    if (imgmgr_dfu_callbacks_fn->dfu_stopped_cb != NULL)
-    {
+    if (imgmgr_dfu_callbacks_fn && imgmgr_dfu_callbacks_fn->dfu_stopped_cb) {
         imgmgr_dfu_callbacks_fn->dfu_stopped_cb();
     }
 }
 
 void
-imgr_dfu_started(void)
+imgmgr_dfu_started(void)
 {
-    if (imgmgr_dfu_callbacks_fn->dfu_started_cb != NULL)
-    {
+    if (imgmgr_dfu_callbacks_fn && imgmgr_dfu_callbacks_fn->dfu_started_cb) {
         imgmgr_dfu_callbacks_fn->dfu_started_cb();
     }
 }
 
 void
-imgr_dfu_complete(void)
+imgmgr_dfu_pending(void)
 {
-    if (imgmgr_dfu_callbacks_fn->dfu_complete_cb != NULL)
-    {
-        imgmgr_dfu_callbacks_fn->dfu_complete_cb();
+    if (imgmgr_dfu_callbacks_fn && imgmgr_dfu_callbacks_fn->dfu_pending_cb) {
+        imgmgr_dfu_callbacks_fn->dfu_pending_cb();
+    }
+}
+
+void
+imgmgr_dfu_confirmed(void)
+{
+    if (imgmgr_dfu_callbacks_fn && imgmgr_dfu_callbacks_fn->dfu_confirmed_cb) {
+        imgmgr_dfu_callbacks_fn->dfu_confirmed_cb();
     }
 }
 
@@ -887,11 +892,10 @@ imgr_set_upload_cb(imgr_upload_fn *cb, void *arg)
     imgr_upload_arg = arg;
 }
 
-int
+void
 imgmgr_register_callbacks(const imgmgr_dfu_callbacks_t *cb_struct)
 {
     imgmgr_dfu_callbacks_fn = cb_struct;
-    return 0;
 }
 
 void
diff --git a/mgmt/imgmgr/src/imgmgr_state.c b/mgmt/imgmgr/src/imgmgr_state.c
index d7fd89a..48f6b2b 100644
--- a/mgmt/imgmgr/src/imgmgr_state.c
+++ b/mgmt/imgmgr/src/imgmgr_state.c
@@ -230,6 +230,8 @@ imgmgr_state_confirm(void)
 #endif
     }
 
+    imgmgr_dfu_confirmed();
+
     return 0;
 }