Skip to content

Commit

Permalink
Merge pull request #244 from NordicSemiconductor/suitlistresponse
Browse files Browse the repository at this point in the history
SuitListResponse
  • Loading branch information
dinesharjani authored Jul 9, 2024
2 parents 30a701c + cd4d7bb commit 169a999
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Source/Managers/SuitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class SuitManager: McuManager {
private var state: SuitManagerState = .none
private weak var uploadDelegate: SuitManagerDelegate?

private var callback: ManifestCallback?
private var callback: McuMgrCallback<SuitListResponse>?
private var roleIndex: Int?
private var roles: [McuMgrManifestListResponse.Manifest.Role] = []
private var responses: [McuMgrManifestStateResponse] = []
Expand All @@ -77,16 +77,16 @@ public class SuitManager: McuManager {

// MARK: List

public typealias ManifestCallback = ([McuMgrManifestStateResponse], Error?) -> Void
/**
Command allows to get information about roles of manifests supported by the device.
*/
public func listManifest(callback: @escaping ManifestCallback) {
public func listManifest(callback: @escaping McuMgrCallback<SuitListResponse>) {
self.callback = callback
roleIndex = 0
roles = []
responses = []
send(op: .read, commandId: SuitID.manifestList, payload: nil, callback: listManifestCallback)
send(op: .read, commandId: SuitID.manifestList, payload: nil,
callback: listManifestCallback)
}

private func validateNext() {
Expand All @@ -97,7 +97,9 @@ public class SuitManager: McuManager {
atLevel: .verbose)
getManifestState(for: role, callback: roleStateCallback)
} else {
callback?(responses, nil)
let suitResponse = try? SuitListResponse(cbor: nil)
suitResponse?.states = responses
callback?(suitResponse, nil)
}
}

Expand All @@ -108,7 +110,7 @@ public class SuitManager: McuManager {

guard error == nil, let response, response.rc != 8 else {
self.logDelegate?.log("List Manifest Callback not Supported.", ofCategory: .suit, atLevel: .error)
self.callback?([], error)
self.callback?(nil, error)
return
}

Expand Down
17 changes: 17 additions & 0 deletions Source/McuMgrResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,23 @@ public final class McuMgrManifestStateResponse: McuMgrResponse {
}
}

// MARK: - SuitListResponse

/**
This response type is not a part of the McuMgr/SUIT Protocol. We've added it to make the library API side match what most other APIs do, which is to return a ``McuMgrResponse`` for List in ``SuitManager``.
*/
public final class SuitListResponse: McuMgrResponse {

public var states: [McuMgrManifestStateResponse]?

public required init(cbor: CBOR?) throws {
try super.init(cbor: cbor)
if case let CBOR.array(states)? = cbor?["states"] {
self.states = try CBOR.toObjectArray(array: states) ?? []
}
}
}

// MARK: - McuMgrPollResponse

public final class McuMgrPollResponse: McuMgrResponse {
Expand Down

0 comments on commit 169a999

Please sign in to comment.