Skip to content

Commit

Permalink
Merge pull request #524 from NordicSemiconductor/message-callbacks
Browse files Browse the repository at this point in the history
Breaking: Message callbacks
  • Loading branch information
philips77 authored Jun 27, 2023
2 parents 45b4b07 + d220b41 commit 4ddb2a0
Show file tree
Hide file tree
Showing 288 changed files with 1,035 additions and 691 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class GenericDefaultTransitionTimeClientDelegate: ModelDelegate {
}

init() {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
GenericDefaultTransitionTimeStatus.self
]
messageTypes = types.toMap()
Expand All @@ -67,18 +67,18 @@ class GenericDefaultTransitionTimeClientDelegate: ModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) throws -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) throws -> MeshResponse {
fatalError("Not possible")
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
// The status message may be received here if the Generic Default
// Transition Time Server model has been configured to publish.
// Ignore this message.
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
// Ignore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class GenericDefaultTransitionTimeServerDelegate: ModelDelegate {
private let defaults: UserDefaults

init(_ meshNetwork: MeshNetwork) {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
GenericDefaultTransitionTimeGet.self,
GenericDefaultTransitionTimeSet.self,
GenericDefaultTransitionTimeSetUnacknowledged.self
Expand All @@ -63,7 +63,7 @@ class GenericDefaultTransitionTimeServerDelegate: ModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) throws -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) throws -> MeshResponse {
switch request {

case let request as GenericDefaultTransitionTimeSet:
Expand All @@ -85,7 +85,7 @@ class GenericDefaultTransitionTimeServerDelegate: ModelDelegate {
return GenericDefaultTransitionTimeStatus(transitionTime: defaultTransitionTime)
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
switch message {

Expand All @@ -103,7 +103,7 @@ class GenericDefaultTransitionTimeServerDelegate: ModelDelegate {
}
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
// Not possible.
Expand Down
8 changes: 4 additions & 4 deletions Example/Source/Mesh Network/GenericLevelClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GenericLevelClientDelegate: ModelDelegate {
}

init() {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
GenericLevelStatus.self
]
messageTypes = types.toMap()
Expand All @@ -62,17 +62,17 @@ class GenericLevelClientDelegate: ModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) -> MeshResponse {
fatalError("Not possible")
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
// The status message may be received here if the Generic Level Server model
// has been configured to publish. Ignore this message.
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address){
// Ignore.
Expand Down
8 changes: 4 additions & 4 deletions Example/Source/Mesh Network/GenericLevelServerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class GenericLevelServerDelegate: StoredWithSceneModelDelegate {
init(_ meshNetwork: MeshNetwork,
defaultTransitionTimeServer delegate: GenericDefaultTransitionTimeServerDelegate,
elementIndex: UInt8) {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
GenericLevelGet.self,
GenericLevelSet.self,
GenericLevelSetUnacknowledged.self,
Expand Down Expand Up @@ -145,7 +145,7 @@ class GenericLevelServerDelegate: StoredWithSceneModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) -> MeshResponse {
switch request {
case let request as GenericLevelSet:
// Ignore a repeated request (with the same TID) from the same source
Expand Down Expand Up @@ -228,7 +228,7 @@ class GenericLevelServerDelegate: StoredWithSceneModelDelegate {
}
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
switch message {
case let request as GenericLevelSetUnacknowledged:
Expand Down Expand Up @@ -301,7 +301,7 @@ class GenericLevelServerDelegate: StoredWithSceneModelDelegate {
}
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
// Not possible.
Expand Down
8 changes: 4 additions & 4 deletions Example/Source/Mesh Network/GenericOnOffClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GenericOnOffClientDelegate: ModelDelegate {
}

init() {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
GenericOnOffStatus.self
]
messageTypes = types.toMap()
Expand All @@ -63,17 +63,17 @@ class GenericOnOffClientDelegate: ModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) -> MeshResponse {
fatalError("Not possible")
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
// The status message may be received here if the Generic OnOff Server model
// has been configured to publish. Ignore this message.
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
// Ignore.
Expand Down
8 changes: 4 additions & 4 deletions Example/Source/Mesh Network/GenericOnOffServerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class GenericOnOffServerDelegate: StoredWithSceneModelDelegate {
init(_ meshNetwork: MeshNetwork,
defaultTransitionTimeServer delegate: GenericDefaultTransitionTimeServerDelegate,
elementIndex: UInt8) {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
GenericOnOffGet.self,
GenericOnOffSet.self,
GenericOnOffSetUnacknowledged.self
Expand Down Expand Up @@ -141,7 +141,7 @@ class GenericOnOffServerDelegate: StoredWithSceneModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) -> MeshResponse {
switch request {
case let request as GenericOnOffSet:
// Ignore a repeated request (with the same TID) from the same source
Expand Down Expand Up @@ -179,7 +179,7 @@ class GenericOnOffServerDelegate: StoredWithSceneModelDelegate {
}
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
switch message {
case let request as GenericOnOffSetUnacknowledged:
Expand Down Expand Up @@ -207,7 +207,7 @@ class GenericOnOffServerDelegate: StoredWithSceneModelDelegate {
}
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
// Not possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GenericPowerOnOffClientDelegate: ModelDelegate {
}

init() {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
GenericOnPowerUpStatus.self
]
messageTypes = types.toMap()
Expand All @@ -62,17 +62,17 @@ class GenericPowerOnOffClientDelegate: ModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) -> MeshResponse {
fatalError("Message not supported: \(request)")
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
// The status message may be received here if the Generic Power OnOff Server model
// has been configured to publish. Ignore this message.
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
// Ignore.
Expand Down
8 changes: 4 additions & 4 deletions Example/Source/Mesh Network/SceneServerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class SceneServerDelegate: SceneServerModelDelegate {

init(_ meshNetwork: MeshNetwork,
defaultTransitionTimeServer delegate: GenericDefaultTransitionTimeServerDelegate) {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
SceneGet.self,
SceneRegisterGet.self,
SceneRecall.self,
Expand All @@ -112,7 +112,7 @@ class SceneServerDelegate: SceneServerModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) throws -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) throws -> MeshResponse {
switch request {
case is SceneRegisterGet:
// When a Scene Server receives a Scene Register Get message, it shall respond
Expand Down Expand Up @@ -190,7 +190,7 @@ class SceneServerDelegate: SceneServerModelDelegate {
return SceneStatus(report: currentScene)
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
switch message {
case let request as SceneRecallUnacknowledged:
Expand Down Expand Up @@ -254,7 +254,7 @@ class SceneServerDelegate: SceneServerModelDelegate {
}
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage, from source: Address) {
// Not possible.
}
Expand Down
8 changes: 4 additions & 4 deletions Example/Source/Mesh Network/SceneSetupServerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SceneSetupServerDelegate: ModelDelegate {
let publicationMessageComposer: MessageComposer? = nil

init(server delegate: SceneServerDelegate) {
let types: [GenericMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
SceneStore.self,
SceneStoreUnacknowledged.self,
SceneDelete.self,
Expand All @@ -56,7 +56,7 @@ class SceneSetupServerDelegate: ModelDelegate {
// MARK: - Message handlers

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) throws -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) throws -> MeshResponse {
switch request {
case let request as SceneStore:
// Little validation.
Expand Down Expand Up @@ -103,7 +103,7 @@ class SceneSetupServerDelegate: ModelDelegate {
return SceneRegisterStatus(report: currentScene, and: storedScenes)
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
switch message {
case let request as SceneStoreUnacknowledged:
Expand Down Expand Up @@ -144,7 +144,7 @@ class SceneSetupServerDelegate: ModelDelegate {
}
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
// Not possible.
Expand Down
8 changes: 4 additions & 4 deletions Example/Source/Mesh Network/SensorClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SensorClientDelegate: ModelDelegate {
let publicationMessageComposer: MessageComposer? = nil

init() {
let types: [SensorMessage.Type] = [
let types: [StaticMeshMessage.Type] = [
SensorDescriptorStatus.self,
SensorCadenceStatus.self,
SensorSettingsStatus.self,
Expand All @@ -52,20 +52,20 @@ class SensorClientDelegate: ModelDelegate {
}

func model(_ model: Model, didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) throws -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) throws -> MeshResponse {
switch request {
// No acknowledged message supported by this Model.
default:
fatalError("Message not supported: \(request)")
}
}

func model(_ model: Model, didReceiveUnacknowledgedMessage message: MeshMessage,
func model(_ model: Model, didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
handle(message, sentFrom: source)
}

func model(_ model: Model, didReceiveResponse response: MeshMessage,
func model(_ model: Model, didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address) {
handle(response, sentFrom: source)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct SimpleOnOffGet: AcknowledgedStaticVendorMessage {
// 0x00-5900 - Nordic Semiconductor ASA company ID (in Little Endian) as defined here:
// https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers/
static let opCode: UInt32 = 0xC25900
static let responseType: StaticMeshMessage.Type = SimpleOnOffStatus.self
static let responseType: StaticMeshResponse.Type = SimpleOnOffStatus.self

var parameters: Data? {
return Data()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct SimpleOnOffSet: AcknowledgedStaticVendorMessage {
// 0x00-5900 - Nordic Semiconductor ASA company ID (in Little Endian) as defined here:
// https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers/
static let opCode: UInt32 = 0xC15900
static let responseType: StaticMeshMessage.Type = SimpleOnOffStatus.self
static let responseType: StaticMeshResponse.Type = SimpleOnOffStatus.self

var parameters: Data? {
return Data([isOn ? 0x01 : 0x00])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import Foundation
import nRFMeshProvision

struct SimpleOnOffStatus: StaticVendorMessage {
struct SimpleOnOffStatus: StaticVendorResponse {
// The Op Code consists of:
// 0xC0-0000 - Vendor Op Code bitmask
// 0x04-0000 - The Op Code defined by...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ class SimpleOnOffClientDelegate: ModelDelegate {

func model(_ model: Model,
didReceiveAcknowledgedMessage request: AcknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) -> MeshMessage {
from source: Address, sentTo destination: MeshAddress) -> MeshResponse {
// This method will never be called for this Model, as the single message
// type it supports (defines in `messageTypes`) is unacknowledged.
fatalError("What has just happened?")
}

func model(_ model: Model,
didReceiveUnacknowledgedMessage message: MeshMessage,
didReceiveUnacknowledgedMessage message: UnacknowledgedMeshMessage,
from source: Address, sentTo destination: MeshAddress) {
// A Simple OnOff Server may send status messages that do not reply
// to any acknowledged messages, for example may publish the state
Expand All @@ -109,7 +109,7 @@ class SimpleOnOffClientDelegate: ModelDelegate {
}

func model(_ model: Model,
didReceiveResponse response: MeshMessage,
didReceiveResponse response: MeshResponse,
toAcknowledgedMessage request: AcknowledgedMeshMessage, from source: Address) {
// This message for sure did not change the state.
let stateNotChanged = request is SimpleOnOffGet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protocol ModelViewCellDelegate: AnyObject {
///
/// - parameter message: The message to be sent.
/// - parameter description: The message to be displayed for the user.
func send(_ message: ConfigMessage, description: String)
func send(_ message: AcknowledgedConfigMessage, description: String)

/// Whether the view is being refreshed with Pull-to-Refresh or not.
var isRefreshing: Bool { get }
Expand Down
Loading

0 comments on commit 4ddb2a0

Please sign in to comment.