Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 868eda0ff -> 878fe2fff


newtmgr - Add New* functions for state req/rsp


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/878fe2ff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/878fe2ff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/878fe2ff

Branch: refs/heads/develop
Commit: 878fe2fffa9c9af182efa6bfc7f105a5200ee504
Parents: 868eda0
Author: Christopher Collins <ccoll...@apache.org>
Authored: Thu Oct 13 14:53:36 2016 -0700
Committer: Christopher Collins <ccoll...@apache.org>
Committed: Thu Oct 13 14:53:36 2016 -0700

----------------------------------------------------------------------
 newtmgr/cli/image.go           | 25 ++++++++++++++++++-------
 newtmgr/protocol/imagestate.go | 17 +++++++++++++++--
 2 files changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/878fe2ff/newtmgr/cli/image.go
----------------------------------------------------------------------
diff --git a/newtmgr/cli/image.go b/newtmgr/cli/image.go
index 7e02407..67a8b8b 100644
--- a/newtmgr/cli/image.go
+++ b/newtmgr/cli/image.go
@@ -90,7 +90,11 @@ func imageStateListCmd(cmd *cobra.Command, args []string) {
 
        var nmr *protocol.NmgrReq
 
-       req := protocol.ImageStateReadReq{}
+       req, err := protocol.NewImageStateReadReq()
+       if err != nil {
+               nmUsage(nil, err)
+       }
+
        nmr, err = req.Encode()
        if err != nil {
                nmUsage(nil, err)
@@ -121,10 +125,14 @@ func imageStateTestCmd(cmd *cobra.Command, args []string) 
{
 
        hex_bytes, _ := hex.DecodeString(args[0])
 
-       req := protocol.ImageStateWriteReq{
-               Hash:    hex_bytes,
-               Confirm: false,
+       req, err := protocol.NewImageStateWriteReq()
+       if err != nil {
+               nmUsage(nil, err)
        }
+
+       req.Hash = hex_bytes
+       req.Confirm = false
+
        nmr, err := req.Encode()
        if err != nil {
                nmUsage(nil, err)
@@ -155,10 +163,13 @@ func imageStateTestCmd(cmd *cobra.Command, args []string) 
{
 }
 
 func imageStateConfirmCmd(cmd *cobra.Command, args []string) {
-       req := protocol.ImageStateWriteReq{
-               Hash:    nil,
-               Confirm: true,
+       req, err := protocol.NewImageStateWriteReq()
+       if err != nil {
+               nmUsage(nil, err)
        }
+
+       req.Confirm = true
+
        nmr, err := req.Encode()
        if err != nil {
                nmUsage(cmd, err)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/878fe2ff/newtmgr/protocol/imagestate.go
----------------------------------------------------------------------
diff --git a/newtmgr/protocol/imagestate.go b/newtmgr/protocol/imagestate.go
index e90109e..3c2feaf 100644
--- a/newtmgr/protocol/imagestate.go
+++ b/newtmgr/protocol/imagestate.go
@@ -50,6 +50,16 @@ type ImageStateWriteReq struct {
        Confirm bool   `codec:"confirm"`
 }
 
+func NewImageStateReadReq() (*ImageStateReadReq, error) {
+       s := &ImageStateReadReq{}
+       return s, nil
+}
+
+func NewImageStateWriteReq() (*ImageStateWriteReq, error) {
+       s := &ImageStateWriteReq{}
+       return s, nil
+}
+
 func NewImageStateRsp() (*ImageStateRsp, error) {
        s := &ImageStateRsp{}
        return s, nil
@@ -76,10 +86,13 @@ func (i *ImageStateWriteReq) Encode() (*NmgrReq, error) {
                return nil, err
        }
 
-       clone := ImageStateWriteReq{
-               Confirm: i.Confirm,
+       clone, err := NewImageStateWriteReq()
+       if err != nil {
+               return nil, err
        }
 
+       clone.Confirm = i.Confirm
+
        if len(i.Hash) != 0 {
                clone.Hash = i.Hash
                if err != nil {

Reply via email to