Skip to content

Commit

Permalink
Apply pull request review feedback
Browse files Browse the repository at this point in the history
Squashed commits:
[73bf7ae] Rename XMPPElementEvent processingCompleted property
[d1bbfce] Move XMPPElementEvent interface declaration to a separate header file
[b7ac0a7] Use property syntax for XMPPStream currentElementEvent
[ba381c4] Reorder XMPPStream sendElement method parameters
  • Loading branch information
pwetrifork committed Nov 29, 2017
1 parent 3327290 commit 613183a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 87 deletions.
1 change: 1 addition & 0 deletions Core/XMPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "XMPPMessage.h"
#import "XMPPPresence.h"
#import "XMPPModule.h"
#import "XMPPElementEvent.h"

//
// Authentication
Expand Down
80 changes: 80 additions & 0 deletions Core/XMPPElementEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@class XMPPJID;

/**
* A handle that allows identifying elements sent or received in the stream across different delegates
* and tracking their processing progress.
*
* While the core XMPP specification does not require stanzas to be uniquely identifiable, you may still want to
* identify them internally across different modules or trace the sent ones to the respective send result delegate callbacks.
*
* An instance of this class is provided in the context of execution of any of the @c didSendXXX/didFailToSendXXX/didReceiveXXX
* stream delegate methods. It is retrieved from the @c currentElementEvent property on the calling stream.
* The delegates can then use it to:
* - identify the corresponding XMPP stanzas.
* - be notified of asynchronous processing completion for a given XMPP stanza.
*
* Using @c XMPPElementEvent handles is a more robust approach than relying on pointer equality of @c XMPPElement instances.
*/
@interface XMPPElementEvent : NSObject

/// The universally unique identifier of the event that provides the internal identity of the corresponding XMPP stanza.
@property (nonatomic, copy, readonly) NSString *uniqueID;

/// The value of the stream's @c myJID property at the time when the event occured.
@property (nonatomic, strong, readonly, nullable) XMPPJID *myJID;

/// The local device time when the event occured.
@property (nonatomic, strong, readonly) NSDate *timestamp;

/**
* A flag indicating whether all delegates are done processing the given event.
*
* Supports Key-Value Observing. Change notifications are emitted on the stream queue.
*
* @see beginDelayedProcessing
* @see endDelayedProcessingWithToken
*/
@property (nonatomic, assign, readonly) BOOL isProcessingCompleted;

// Instances are created by the stream only.
- (instancetype)init NS_UNAVAILABLE;

/**
* Marks the event as being asynchronously processed by a delegate and returns a completion token.
*
* Event processing is completed after every @c beginDelayedProcessing call has been followed
* by @c endDelayedProcessingWithToken: with a matching completion token.
*
* Unpaired invocations may lead to undefined behavior or stalled events.
*
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
* after control returns from all callbacks.
*
* @see endDelayedProcessingWithToken:
* @see isProcessingCompleted
*/
- (id)beginDelayedProcessing;

/**
* Marks an end of the previously initiated asynchronous delegate processing.
*
* Event processing is completed after every @c beginDelayedProcessing call has been followed
* by @c endDelayedProcessingWithToken: with a matching completion token.
*
* Unpaired invocations may lead to undefined behavior or stalled events.
*
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
* after control returns from all callbacks.
*
* @see beginDelayedProcessing
* @see isProcessingCompleted
*/
- (void)endDelayedProcessingWithToken:(id)delayedProcessingToken;

@end

NS_ASSUME_NONNULL_END
89 changes: 8 additions & 81 deletions Core/XMPPStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
* Even if you close the xmpp stream after this point, the OS will still do everything it can to send the data.
**/
- (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt * _Nullable * _Nullable)receiptPtr;
- (void)sendElement:(NSXMLElement *)element registeringEventWithID:(NSString *)eventID andGetReceipt:(XMPPElementReceipt * _Nullable * _Nullable)receiptPtr;
- (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt * _Nullable * _Nullable)receiptPtr registeringEventWithID:(NSString *)eventID;

/**
* Fetches and resends the myPresence element (if available) in a single atomic operation.
Expand Down Expand Up @@ -741,13 +741,13 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
* Returns the stream metadata corresponding to the currently processed XMPP stanza.
* The stream metadata corresponding to the currently processed XMPP stanza.
*
* Event information is only available in the context of @c didSendXXX/didFailToSendXXX/didReceiveXXX delegate callbacks.
* This method returns nil if called outside of those callbacks.
* This property is nil if accessed outside of those callbacks.
* For more details, please refer to @c XMPPElementEvent documentation.
*/
- (nullable XMPPElementEvent *)currentElementEvent;
@property (nonatomic, readonly, nullable) XMPPElementEvent *currentElementEvent;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Utilities
Expand Down Expand Up @@ -801,79 +801,6 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;

@end

/**
* A handle that allows identifying elements sent or received in the stream across different delegates
* and tracking their processing progress.
*
* While the core XMPP specification does not require stanzas to be uniquely identifiable, you may still want to
* identify them internally across different modules or trace the sent ones to the respective send result delegate callbacks.
*
* An instance of this class is provided in the context of execution of any of the @c didSendXXX/didFailToSendXXX/didReceiveXXX
* stream delegate methods. It is retrieved by calling the @c currentElementEvent method on the calling stream.
* The delegates can then use it to:
* - identify the corresponding XMPP stanzas.
* - be notified of asynchronous processing completion for a given XMPP stanza.
*
* Using @c XMPPElementEvent handles is a more robust approach than relying on pointer equality of @c XMPPElement instances.
*/
@interface XMPPElementEvent : NSObject

/// The universally unique identifier of the event that provides the internal identity of the corresponding XMPP stanza.
@property (nonatomic, copy, readonly) NSString *uniqueID;

/// The value of the stream's @c myJID property at the time when the event occured.
@property (nonatomic, strong, readonly, nullable) XMPPJID *myJID;

/// The local device time when the event occured.
@property (nonatomic, strong, readonly) NSDate *timestamp;

/**
* A flag indicating whether all delegates are done processing the given event.
*
* Supports Key-Value Observing. Change notifications are emitted on the stream queue.
*
* @see beginDelayedProcessing
* @see endDelayedProcessingWithToken
*/
@property (nonatomic, assign, readonly, getter=isProcessingCompleted) BOOL processingCompleted;

// Instances are created by the stream only.
- (instancetype)init NS_UNAVAILABLE;

/**
* Marks the event as being asynchronously processed by a delegate and returns a completion token.
*
* Event processing is completed after every @c beginDelayedProcessing call has been followed
* by @c endDelayedProcessingWithToken: with a matching completion token.
*
* Unpaired invocations may lead to undefined behavior or stalled events.
*
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
* after control returns from all callbacks.
*
* @see endDelayedProcessingWithToken:
* @see processingCompleted
*/
- (id)beginDelayedProcessing;

/**
* Marks an end of the previously initiated asynchronous delegate processing.
*
* Event processing is completed after every @c beginDelayedProcessing call has been followed
* by @c endDelayedProcessingWithToken: with a matching completion token.
*
* Unpaired invocations may lead to undefined behavior or stalled events.
*
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
* after control returns from all callbacks.
*
* @see beginDelayedProcessing
* @see processingCompleted
*/
- (void)endDelayedProcessingWithToken:(id)delayedProcessingToken;

@end

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark -
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1077,7 +1004,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
* If you have need to modify an element for any reason,
* you should copy the element first, and then modify and use the copy.
*
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
* from within these callbacks. For more details, please refer to @c XMPPElementEvent documentation.
**/
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq;
Expand Down Expand Up @@ -1125,7 +1052,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
* These methods may be used to listen for certain events (such as an unavailable presence having been sent),
* or for general logging purposes. (E.g. a central history logging mechanism).
*
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
* from within these callbacks. For more details, please refer to @c XMPPElementEvent documentation.
**/
- (void)xmppStream:(XMPPStream *)sender didSendIQ:(XMPPIQ *)iq;
Expand All @@ -1136,7 +1063,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
* These methods are called after failing to send the respective XML elements over the stream.
* This occurs when the stream gets disconnected before the element can get sent out.
*
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
* from within these callbacks.
* Note that if these methods are called, the event context is incomplete, e.g. the stream might have not been connected
* and the actual myJID value is not determined. For more details, please refer to @c XMPPElementEvent documentation.
Expand Down Expand Up @@ -1244,7 +1171,7 @@ NS_SWIFT_NAME(xmppStream(_:didFinishProcessing:));
* If you're using custom elements, you must register the custom element name(s).
* Otherwise the xmppStream will treat non-XMPP elements as errors (xmppStream:didReceiveError:).
*
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
* from within these callbacks. For more details, please refer to @c XMPPElementEvent documentation.
*
* @see registerCustomElementNames (in XMPPInternal.h)
Expand Down
12 changes: 6 additions & 6 deletions Core/XMPPStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ - (void)signalFailure;
@interface XMPPElementEvent ()

@property (nonatomic, unsafe_unretained, readonly) XMPPStream *xmppStream;
@property (nonatomic, assign, readwrite, getter=isProcessingCompleted) BOOL processingCompleted;
@property (nonatomic, assign, readwrite) BOOL isProcessingCompleted;

@end

Expand Down Expand Up @@ -2639,12 +2639,12 @@ - (void)sendElement:(NSXMLElement *)element withTag:(long)tag registeringEventWi
**/
- (void)sendElement:(NSXMLElement *)element
{
[self sendElement:element registeringEventWithID:[self generateUUID] andGetReceipt:nil];
[self sendElement:element andGetReceipt:nil registeringEventWithID:[self generateUUID]];
}

- (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt **)receiptPtr
{
[self sendElement:element registeringEventWithID:[self generateUUID] andGetReceipt:receiptPtr];
[self sendElement:element andGetReceipt:receiptPtr registeringEventWithID:[self generateUUID]];
}

/**
Expand All @@ -2654,7 +2654,7 @@ - (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt **
* After the element has been successfully sent,
* the xmppStream:didSendElementWithTag: delegate method is called.
**/
- (void)sendElement:(NSXMLElement *)element registeringEventWithID:(NSString *)eventID andGetReceipt:(XMPPElementReceipt **)receiptPtr
- (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt **)receiptPtr registeringEventWithID:(NSString *)eventID
{
if (element == nil) return;

Expand Down Expand Up @@ -5155,7 +5155,7 @@ - (void)performDelegateActionWithElementEvent:(XMPPElementEvent *)event block:(d
[eventProcessingDelegateInvocationContext becomeCurrentOnQueue:self.xmppQueue forActionWithBlock:block];

dispatch_group_notify(eventProcessingDelegateInvocationContext.continuityGroup, self.xmppQueue, ^{
event.processingCompleted = YES;
event.isProcessingCompleted = YES;
[multicastDelegate xmppStream:self didFinishProcessingElementEvent:event];
});
}
Expand Down Expand Up @@ -5265,7 +5265,7 @@ - (BOOL)isProcessingCompleted
__block BOOL result;

dispatch_block_t block = ^{
result = _processingCompleted;
result = _isProcessingCompleted;
};

if (dispatch_get_specific(self.xmppStream.xmppQueueTag))
Expand Down
8 changes: 8 additions & 0 deletions XMPPFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
D95367E61FB90F0E0075502D /* XMPPBookmarksStorageElement.m in Sources */ = {isa = PBXBuildFile; fileRef = D95367E21FB90F0E0075502D /* XMPPBookmarksStorageElement.m */; };
D95367E71FB90F0E0075502D /* XMPPBookmarksStorageElement.m in Sources */ = {isa = PBXBuildFile; fileRef = D95367E21FB90F0E0075502D /* XMPPBookmarksStorageElement.m */; };
D95367E81FB90F0E0075502D /* XMPPBookmarksStorageElement.m in Sources */ = {isa = PBXBuildFile; fileRef = D95367E21FB90F0E0075502D /* XMPPBookmarksStorageElement.m */; };
249704751FC0680900D25EC6 /* XMPPElementEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 249704731FC0680900D25EC6 /* XMPPElementEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
249704761FC0680900D25EC6 /* XMPPElementEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 249704731FC0680900D25EC6 /* XMPPElementEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
249704771FC0680900D25EC6 /* XMPPElementEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 249704731FC0680900D25EC6 /* XMPPElementEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
D96D6E7D1F8D9701006DEC58 /* XMPPPushModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */; };
D96D6E7E1F8D9701006DEC58 /* XMPPPushModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */; };
D96D6E7F1F8D9701006DEC58 /* XMPPPushModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */; };
Expand Down Expand Up @@ -1489,6 +1492,7 @@
D95367DA1FB90DA00075502D /* XMPPBookmark.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XMPPBookmark.m; sourceTree = "<group>"; };
D95367E11FB90F0E0075502D /* XMPPBookmarksStorageElement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XMPPBookmarksStorageElement.h; sourceTree = "<group>"; };
D95367E21FB90F0E0075502D /* XMPPBookmarksStorageElement.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XMPPBookmarksStorageElement.m; sourceTree = "<group>"; };
249704731FC0680900D25EC6 /* XMPPElementEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XMPPElementEvent.h; sourceTree = "<group>"; };
D96D6E6C1F8D9700006DEC58 /* XMPPPushModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XMPPPushModule.h; sourceTree = "<group>"; };
D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XMPPPushModule.m; sourceTree = "<group>"; };
D96D6E981F8D9D7E006DEC58 /* XMPPMessage+XEP_0359.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XMPPMessage+XEP_0359.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1924,6 +1928,7 @@
0D44BB0A1E5370ED000930E0 /* XMPPPresence.m */,
0D44BB0B1E5370ED000930E0 /* XMPPStream.h */,
0D44BB0C1E5370ED000930E0 /* XMPPStream.m */,
249704731FC0680900D25EC6 /* XMPPElementEvent.h */,
);
path = Core;
sourceTree = SOURCE_ROOT;
Expand Down Expand Up @@ -2959,6 +2964,7 @@
D9DCD3241E6250930010D1C7 /* XMPPMessage+XEP_0334.h in Headers */,
D96D6E801F8D970E006DEC58 /* XMPPPushModule.h in Headers */,
D9DCD3281E6250930010D1C7 /* NSXMLElement+XEP_0352.h in Headers */,
249704751FC0680900D25EC6 /* XMPPElementEvent.h in Headers */,
D9DCD2541E6250930010D1C7 /* XMPPOutgoingFileTransfer.h in Headers */,
D9DCD2561E6250930010D1C7 /* XMPPGoogleSharedStatus.h in Headers */,
D9DCD2B61E6250930010D1C7 /* XMPPvCardTemp.h in Headers */,
Expand Down Expand Up @@ -3155,6 +3161,7 @@
D9DCD4A51E6256D90010D1C7 /* XMPPMessage+XEP_0334.h in Headers */,
D96D6E811F8D970E006DEC58 /* XMPPPushModule.h in Headers */,
D9DCD4A61E6256D90010D1C7 /* NSXMLElement+XEP_0352.h in Headers */,
249704761FC0680900D25EC6 /* XMPPElementEvent.h in Headers */,
D9DCD4A71E6256D90010D1C7 /* XMPPOutgoingFileTransfer.h in Headers */,
D9DCD4A81E6256D90010D1C7 /* XMPPGoogleSharedStatus.h in Headers */,
D9DCD4A91E6256D90010D1C7 /* XMPPvCardTemp.h in Headers */,
Expand Down Expand Up @@ -3327,6 +3334,7 @@
D9DCD6081E6258CF0010D1C7 /* XMPPMessage+XEP_0334.h in Headers */,
D96D6E821F8D970F006DEC58 /* XMPPPushModule.h in Headers */,
D9DCD6091E6258CF0010D1C7 /* NSXMLElement+XEP_0352.h in Headers */,
249704771FC0680900D25EC6 /* XMPPElementEvent.h in Headers */,
D9DCD60A1E6258CF0010D1C7 /* XMPPOutgoingFileTransfer.h in Headers */,
D9DCD60B1E6258CF0010D1C7 /* XMPPGoogleSharedStatus.h in Headers */,
D9DCD60C1E6258CF0010D1C7 /* XMPPvCardTemp.h in Headers */,
Expand Down

0 comments on commit 613183a

Please sign in to comment.