Skip to content

Commit 1164af4

Browse files
committed
MSRP/MRP: remove application event handlers
1 parent cdc4697 commit 1164af4

File tree

3 files changed

+7
-61
lines changed

3 files changed

+7
-61
lines changed

Sources/MRP/Applications/MSRP/MSRPApplication.swift

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ struct MSRPPortState<P: AVBPort>: Sendable {
137137
}
138138

139139
public final class MSRPApplication<P: AVBPort>: BaseApplication, BaseApplicationEventObserver,
140-
BaseApplicationContextObserver,
141-
ApplicationEventHandler, CustomStringConvertible, @unchecked Sendable where P == P
140+
BaseApplicationContextObserver, CustomStringConvertible, @unchecked Sendable where P == P
142141
{
143142
private typealias TalkerRegistration = (Participant<MSRPApplication>, any MSRPTalkerValue)
144143

@@ -397,49 +396,6 @@ public final class MSRPApplication<P: AVBPort>: BaseApplication, BaseApplication
397396
.normalParticipant
398397
}
399398

400-
// If an MSRP message is received from a Port with an event value specifying
401-
// the JoinIn or JoinMt message, and if the StreamID (35.2.2.8.2,
402-
// 35.2.2.10.2), and Direction (35.2.1.2) all match those of an attribute
403-
// already registered on that Port, and the Attribute Type (35.2.2.4) or
404-
// FourPackedEvent (35.2.2.7.2) has changed, then the Bridge should behave as
405-
// though an rLv! event (with immediate leavetimer expiration in the
406-
// Registrar state table) was generated for the MAD in the Received MSRP
407-
// Attribute Declarations before the rJoinIn! or rJoinMt! event for the
408-
// attribute in the received message is processed
409-
public func willHandleEvent(
410-
context: EventContext<MSRPApplication>
411-
) async throws {
412-
guard context.eventSource != .application else { return } // don't recurse
413-
guard context.event == .rJoinIn || context.event == .rJoinMt else { return }
414-
415-
let contextAttributeType = MSRPAttributeType(rawValue: context.attributeType)!
416-
guard let contextDirection = contextAttributeType.direction else { return }
417-
418-
let contextStreamID = (context.attributeValue as! MSRPStreamIDRepresentable).streamID
419-
420-
try await context.participant.leaveNow { attributeType, attributeSubtype, attributeValue in
421-
let attributeType = MSRPAttributeType(rawValue: attributeType)!
422-
guard let direction = attributeType.direction else { return false }
423-
let streamID = (attributeValue as! MSRPStreamIDRepresentable).streamID
424-
425-
// force immediate leave if the streamID and direction match and the
426-
// attribute type has changed
427-
let isIncluded = contextStreamID == streamID &&
428-
contextDirection == direction &&
429-
(contextAttributeType != attributeType || context.attributeSubtype != attributeSubtype)
430-
431-
if isIncluded {
432-
_logger
433-
.debug(
434-
"MSRP: forcing immediate leave for stream \(streamID) owing to attribute change: \(attributeType)->\(contextAttributeType)"
435-
)
436-
}
437-
return isIncluded
438-
}
439-
}
440-
441-
public func didHandleEvent(context: EventContext<MSRPApplication>) {}
442-
443399
// On receipt of a REGISTER_STREAM.request the MSRP Participant shall issue a
444400
// MAD_Join.request service primitive (10.2, 10.3). The attribute_type (10.2)
445401
// parameter of the request shall carry the appropriate Talker Attribute Type
@@ -904,12 +860,12 @@ extension MSRPApplication {
904860

905861
// Leave the opposite talker declaration type to ensure mutual exclusion
906862
// (per spec, only one talker declaration type should exist per stream)
907-
try await participant.leaveNow { attributeType, _, attributeValue in
908-
let attributeType = MSRPAttributeType(rawValue: attributeType)!
909-
return attributeType.direction == .talker && attributeType != declarationType
910-
.attributeType &&
911-
(attributeValue as! MSRPStreamIDRepresentable).streamID == talkerValue.streamID
912-
}
863+
let oppositeType: MSRPAttributeType = declarationType == .talkerAdvertise ? .talkerFailed : .talkerAdvertise
864+
try? await participant.leave(
865+
attributeType: oppositeType.rawValue,
866+
attributeValue: talkerValue,
867+
eventSource: eventSource
868+
)
913869

914870
if declarationType == .talkerAdvertise {
915871
do {

Sources/MRP/Model/Application.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,3 @@ extension Application {
214214
try await apply(for: contextIdentifier) { try await $0.redeclare() }
215215
}
216216
}
217-
218-
public protocol ApplicationEventHandler<A>: Application {
219-
associatedtype A: Application
220-
221-
func willHandleEvent(context: EventContext<A>) async throws
222-
func didHandleEvent(context: EventContext<A>)
223-
}

Sources/MRP/Model/Participant.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,9 @@ Sendable, Hashable, Equatable,
951951
isolation participant: isolated P
952952
) async throws {
953953
let context = try _getEventContext(for: event, eventSource: eventSource, isolation: participant)
954-
let applicationEventHandler = context.participant.application as? any ApplicationEventHandler<A>
955954

956-
try await applicationEventHandler?.willHandleEvent(context: context)
957955
try await _handleRegistrar(context: context, isolation: context.participant)
958956
try await _handleApplicant(context: context, isolation: context.participant)
959-
applicationEventHandler?.didHandleEvent(context: context)
960957

961958
// remove attribute entirely if it is no longer declared or registered
962959
if canGC { participant._gcAttributeValue(self) }

0 commit comments

Comments
 (0)