Skip to content

Commit 0c38e01

Browse files
committed
Apply pull request review feedback
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
1 parent 141d3e3 commit 0c38e01

File tree

5 files changed

+103
-87
lines changed

5 files changed

+103
-87
lines changed

Core/XMPP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "XMPPMessage.h"
1010
#import "XMPPPresence.h"
1111
#import "XMPPModule.h"
12+
#import "XMPPElementEvent.h"
1213

1314
//
1415
// Authentication

Core/XMPPElementEvent.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#import <Foundation/Foundation.h>
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@class XMPPJID;
6+
7+
/**
8+
* A handle that allows identifying elements sent or received in the stream across different delegates
9+
* and tracking their processing progress.
10+
*
11+
* While the core XMPP specification does not require stanzas to be uniquely identifiable, you may still want to
12+
* identify them internally across different modules or trace the sent ones to the respective send result delegate callbacks.
13+
*
14+
* An instance of this class is provided in the context of execution of any of the @c didSendXXX/didFailToSendXXX/didReceiveXXX
15+
* stream delegate methods. It is retrieved from the @c currentElementEvent property on the calling stream.
16+
* The delegates can then use it to:
17+
* - identify the corresponding XMPP stanzas.
18+
* - be notified of asynchronous processing completion for a given XMPP stanza.
19+
*
20+
* Using @c XMPPElementEvent handles is a more robust approach than relying on pointer equality of @c XMPPElement instances.
21+
*/
22+
@interface XMPPElementEvent : NSObject
23+
24+
/// The universally unique identifier of the event that provides the internal identity of the corresponding XMPP stanza.
25+
@property (nonatomic, copy, readonly) NSString *uniqueID;
26+
27+
/// The value of the stream's @c myJID property at the time when the event occured.
28+
@property (nonatomic, strong, readonly, nullable) XMPPJID *myJID;
29+
30+
/// The local device time when the event occured.
31+
@property (nonatomic, strong, readonly) NSDate *timestamp;
32+
33+
/**
34+
* A flag indicating whether all delegates are done processing the given event.
35+
*
36+
* Supports Key-Value Observing. Change notifications are emitted on the stream queue.
37+
*
38+
* @see beginDelayedProcessing
39+
* @see endDelayedProcessingWithToken
40+
*/
41+
@property (nonatomic, assign, readonly) BOOL isProcessingCompleted;
42+
43+
// Instances are created by the stream only.
44+
- (instancetype)init NS_UNAVAILABLE;
45+
46+
/**
47+
* Marks the event as being asynchronously processed by a delegate and returns a completion token.
48+
*
49+
* Event processing is completed after every @c beginDelayedProcessing call has been followed
50+
* by @c endDelayedProcessingWithToken: with a matching completion token.
51+
*
52+
* Unpaired invocations may lead to undefined behavior or stalled events.
53+
*
54+
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
55+
* after control returns from all callbacks.
56+
*
57+
* @see endDelayedProcessingWithToken:
58+
* @see isProcessingCompleted
59+
*/
60+
- (id)beginDelayedProcessing;
61+
62+
/**
63+
* Marks an end of the previously initiated asynchronous delegate processing.
64+
*
65+
* Event processing is completed after every @c beginDelayedProcessing call has been followed
66+
* by @c endDelayedProcessingWithToken: with a matching completion token.
67+
*
68+
* Unpaired invocations may lead to undefined behavior or stalled events.
69+
*
70+
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
71+
* after control returns from all callbacks.
72+
*
73+
* @see beginDelayedProcessing
74+
* @see isProcessingCompleted
75+
*/
76+
- (void)endDelayedProcessingWithToken:(id)delayedProcessingToken;
77+
78+
@end
79+
80+
NS_ASSUME_NONNULL_END

Core/XMPPStream.h

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
646646
* Even if you close the xmpp stream after this point, the OS will still do everything it can to send the data.
647647
**/
648648
- (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt * _Nullable * _Nullable)receiptPtr;
649-
- (void)sendElement:(NSXMLElement *)element registeringEventWithID:(NSString *)eventID andGetReceipt:(XMPPElementReceipt * _Nullable * _Nullable)receiptPtr;
649+
- (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt * _Nullable * _Nullable)receiptPtr registeringEventWithID:(NSString *)eventID;
650650

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

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

752752
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
753753
#pragma mark Utilities
@@ -801,79 +801,6 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
801801

802802
@end
803803

804-
/**
805-
* A handle that allows identifying elements sent or received in the stream across different delegates
806-
* and tracking their processing progress.
807-
*
808-
* While the core XMPP specification does not require stanzas to be uniquely identifiable, you may still want to
809-
* identify them internally across different modules or trace the sent ones to the respective send result delegate callbacks.
810-
*
811-
* An instance of this class is provided in the context of execution of any of the @c didSendXXX/didFailToSendXXX/didReceiveXXX
812-
* stream delegate methods. It is retrieved by calling the @c currentElementEvent method on the calling stream.
813-
* The delegates can then use it to:
814-
* - identify the corresponding XMPP stanzas.
815-
* - be notified of asynchronous processing completion for a given XMPP stanza.
816-
*
817-
* Using @c XMPPElementEvent handles is a more robust approach than relying on pointer equality of @c XMPPElement instances.
818-
*/
819-
@interface XMPPElementEvent : NSObject
820-
821-
/// The universally unique identifier of the event that provides the internal identity of the corresponding XMPP stanza.
822-
@property (nonatomic, copy, readonly) NSString *uniqueID;
823-
824-
/// The value of the stream's @c myJID property at the time when the event occured.
825-
@property (nonatomic, strong, readonly, nullable) XMPPJID *myJID;
826-
827-
/// The local device time when the event occured.
828-
@property (nonatomic, strong, readonly) NSDate *timestamp;
829-
830-
/**
831-
* A flag indicating whether all delegates are done processing the given event.
832-
*
833-
* Supports Key-Value Observing. Change notifications are emitted on the stream queue.
834-
*
835-
* @see beginDelayedProcessing
836-
* @see endDelayedProcessingWithToken
837-
*/
838-
@property (nonatomic, assign, readonly, getter=isProcessingCompleted) BOOL processingCompleted;
839-
840-
// Instances are created by the stream only.
841-
- (instancetype)init NS_UNAVAILABLE;
842-
843-
/**
844-
* Marks the event as being asynchronously processed by a delegate and returns a completion token.
845-
*
846-
* Event processing is completed after every @c beginDelayedProcessing call has been followed
847-
* by @c endDelayedProcessingWithToken: with a matching completion token.
848-
*
849-
* Unpaired invocations may lead to undefined behavior or stalled events.
850-
*
851-
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
852-
* after control returns from all callbacks.
853-
*
854-
* @see endDelayedProcessingWithToken:
855-
* @see processingCompleted
856-
*/
857-
- (id)beginDelayedProcessing;
858-
859-
/**
860-
* Marks an end of the previously initiated asynchronous delegate processing.
861-
*
862-
* Event processing is completed after every @c beginDelayedProcessing call has been followed
863-
* by @c endDelayedProcessingWithToken: with a matching completion token.
864-
*
865-
* Unpaired invocations may lead to undefined behavior or stalled events.
866-
*
867-
* Events that are not marked for asynchronous processing by any of the delegates complete immediately
868-
* after control returns from all callbacks.
869-
*
870-
* @see beginDelayedProcessing
871-
* @see processingCompleted
872-
*/
873-
- (void)endDelayedProcessingWithToken:(id)delayedProcessingToken;
874-
875-
@end
876-
877804
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
878805
#pragma mark -
879806
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1077,7 +1004,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
10771004
* If you have need to modify an element for any reason,
10781005
* you should copy the element first, and then modify and use the copy.
10791006
*
1080-
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
1007+
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
10811008
* from within these callbacks. For more details, please refer to @c XMPPElementEvent documentation.
10821009
**/
10831010
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq;
@@ -1125,7 +1052,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
11251052
* These methods may be used to listen for certain events (such as an unavailable presence having been sent),
11261053
* or for general logging purposes. (E.g. a central history logging mechanism).
11271054
*
1128-
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
1055+
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
11291056
* from within these callbacks. For more details, please refer to @c XMPPElementEvent documentation.
11301057
**/
11311058
- (void)xmppStream:(XMPPStream *)sender didSendIQ:(XMPPIQ *)iq;
@@ -1136,7 +1063,7 @@ extern const NSTimeInterval XMPPStreamTimeoutNone;
11361063
* These methods are called after failing to send the respective XML elements over the stream.
11371064
* This occurs when the stream gets disconnected before the element can get sent out.
11381065
*
1139-
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
1066+
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
11401067
* from within these callbacks.
11411068
* Note that if these methods are called, the event context is incomplete, e.g. the stream might have not been connected
11421069
* and the actual myJID value is not determined. For more details, please refer to @c XMPPElementEvent documentation.
@@ -1244,7 +1171,7 @@ NS_SWIFT_NAME(xmppStream(_:didFinishProcessing:));
12441171
* If you're using custom elements, you must register the custom element name(s).
12451172
* Otherwise the xmppStream will treat non-XMPP elements as errors (xmppStream:didReceiveError:).
12461173
*
1247-
* Delegates can obtain event metadata associated with the respective element by calling @c currentElementEvent on @c sender
1174+
* Delegates can obtain event metadata associated with the respective element by accessing @c currentElementEvent on @c sender
12481175
* from within these callbacks. For more details, please refer to @c XMPPElementEvent documentation.
12491176
*
12501177
* @see registerCustomElementNames (in XMPPInternal.h)

Core/XMPPStream.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ - (void)signalFailure;
156156
@interface XMPPElementEvent ()
157157

158158
@property (nonatomic, unsafe_unretained, readonly) XMPPStream *xmppStream;
159-
@property (nonatomic, assign, readwrite, getter=isProcessingCompleted) BOOL processingCompleted;
159+
@property (nonatomic, assign, readwrite) BOOL isProcessingCompleted;
160160

161161
@end
162162

@@ -2639,12 +2639,12 @@ - (void)sendElement:(NSXMLElement *)element withTag:(long)tag registeringEventWi
26392639
**/
26402640
- (void)sendElement:(NSXMLElement *)element
26412641
{
2642-
[self sendElement:element registeringEventWithID:[self generateUUID] andGetReceipt:nil];
2642+
[self sendElement:element andGetReceipt:nil registeringEventWithID:[self generateUUID]];
26432643
}
26442644

26452645
- (void)sendElement:(NSXMLElement *)element andGetReceipt:(XMPPElementReceipt **)receiptPtr
26462646
{
2647-
[self sendElement:element registeringEventWithID:[self generateUUID] andGetReceipt:receiptPtr];
2647+
[self sendElement:element andGetReceipt:receiptPtr registeringEventWithID:[self generateUUID]];
26482648
}
26492649

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

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

51575157
dispatch_group_notify(eventProcessingDelegateInvocationContext.continuityGroup, self.xmppQueue, ^{
5158-
event.processingCompleted = YES;
5158+
event.isProcessingCompleted = YES;
51595159
[multicastDelegate xmppStream:self didFinishProcessingElementEvent:event];
51605160
});
51615161
}
@@ -5265,7 +5265,7 @@ - (BOOL)isProcessingCompleted
52655265
__block BOOL result;
52665266

52675267
dispatch_block_t block = ^{
5268-
result = _processingCompleted;
5268+
result = _isProcessingCompleted;
52695269
};
52705270

52715271
if (dispatch_get_specific(self.xmppStream.xmppQueueTag))

XMPPFramework.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
0D44BB721E537110000930E0 /* XMPPStringPrep.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D44BB641E537110000930E0 /* XMPPStringPrep.m */; };
6666
0D44BB731E537110000930E0 /* XMPPTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D44BB651E537110000930E0 /* XMPPTimer.h */; settings = {ATTRIBUTES = (Public, ); }; };
6767
0D44BB741E537110000930E0 /* XMPPTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D44BB661E537110000930E0 /* XMPPTimer.m */; };
68+
249704751FC0680900D25EC6 /* XMPPElementEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 249704731FC0680900D25EC6 /* XMPPElementEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
69+
249704761FC0680900D25EC6 /* XMPPElementEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 249704731FC0680900D25EC6 /* XMPPElementEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
70+
249704771FC0680900D25EC6 /* XMPPElementEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 249704731FC0680900D25EC6 /* XMPPElementEvent.h */; settings = {ATTRIBUTES = (Public, ); }; };
6871
D96D6E7D1F8D9701006DEC58 /* XMPPPushModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */; };
6972
D96D6E7E1F8D9701006DEC58 /* XMPPPushModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */; };
7073
D96D6E7F1F8D9701006DEC58 /* XMPPPushModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */; };
@@ -1261,6 +1264,7 @@
12611264
0D44BB641E537110000930E0 /* XMPPStringPrep.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPStringPrep.m; sourceTree = "<group>"; };
12621265
0D44BB651E537110000930E0 /* XMPPTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPTimer.h; sourceTree = "<group>"; };
12631266
0D44BB661E537110000930E0 /* XMPPTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPTimer.m; sourceTree = "<group>"; };
1267+
249704731FC0680900D25EC6 /* XMPPElementEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XMPPElementEvent.h; sourceTree = "<group>"; };
12641268
D96D6E6C1F8D9700006DEC58 /* XMPPPushModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XMPPPushModule.h; sourceTree = "<group>"; };
12651269
D96D6E7C1F8D9701006DEC58 /* XMPPPushModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XMPPPushModule.m; sourceTree = "<group>"; };
12661270
D9DCD11F1E6250920010D1C7 /* XMPPBandwidthMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPBandwidthMonitor.h; sourceTree = "<group>"; };
@@ -1617,6 +1621,7 @@
16171621
0D44BB0A1E5370ED000930E0 /* XMPPPresence.m */,
16181622
0D44BB0B1E5370ED000930E0 /* XMPPStream.h */,
16191623
0D44BB0C1E5370ED000930E0 /* XMPPStream.m */,
1624+
249704731FC0680900D25EC6 /* XMPPElementEvent.h */,
16201625
);
16211626
path = Core;
16221627
sourceTree = SOURCE_ROOT;
@@ -2557,6 +2562,7 @@
25572562
D9DCD3241E6250930010D1C7 /* XMPPMessage+XEP_0334.h in Headers */,
25582563
D96D6E801F8D970E006DEC58 /* XMPPPushModule.h in Headers */,
25592564
D9DCD3281E6250930010D1C7 /* NSXMLElement+XEP_0352.h in Headers */,
2565+
249704751FC0680900D25EC6 /* XMPPElementEvent.h in Headers */,
25602566
D9DCD2541E6250930010D1C7 /* XMPPOutgoingFileTransfer.h in Headers */,
25612567
D9DCD2561E6250930010D1C7 /* XMPPGoogleSharedStatus.h in Headers */,
25622568
D9DCD2B61E6250930010D1C7 /* XMPPvCardTemp.h in Headers */,
@@ -2718,6 +2724,7 @@
27182724
D9DCD4A51E6256D90010D1C7 /* XMPPMessage+XEP_0334.h in Headers */,
27192725
D96D6E811F8D970E006DEC58 /* XMPPPushModule.h in Headers */,
27202726
D9DCD4A61E6256D90010D1C7 /* NSXMLElement+XEP_0352.h in Headers */,
2727+
249704761FC0680900D25EC6 /* XMPPElementEvent.h in Headers */,
27212728
D9DCD4A71E6256D90010D1C7 /* XMPPOutgoingFileTransfer.h in Headers */,
27222729
D9DCD4A81E6256D90010D1C7 /* XMPPGoogleSharedStatus.h in Headers */,
27232730
D9DCD4A91E6256D90010D1C7 /* XMPPvCardTemp.h in Headers */,
@@ -2879,6 +2886,7 @@
28792886
D9DCD6081E6258CF0010D1C7 /* XMPPMessage+XEP_0334.h in Headers */,
28802887
D96D6E821F8D970F006DEC58 /* XMPPPushModule.h in Headers */,
28812888
D9DCD6091E6258CF0010D1C7 /* NSXMLElement+XEP_0352.h in Headers */,
2889+
249704771FC0680900D25EC6 /* XMPPElementEvent.h in Headers */,
28822890
D9DCD60A1E6258CF0010D1C7 /* XMPPOutgoingFileTransfer.h in Headers */,
28832891
D9DCD60B1E6258CF0010D1C7 /* XMPPGoogleSharedStatus.h in Headers */,
28842892
D9DCD60C1E6258CF0010D1C7 /* XMPPvCardTemp.h in Headers */,

0 commit comments

Comments
 (0)