Permalink
Browse files

Moving XMPPStream ivar declarations from header file to implementatio…

…n file. Also replacing some global dispatch queues with private queues.
  • Loading branch information...
robbiehanson committed Jul 12, 2012
1 parent 300cb9a commit 0f208eed680c56a1188764657a91fe23559523a3
@@ -117,10 +117,10 @@ - (BOOL)authenticateAnonymously:(NSError **)errPtr
}
}};
- if (dispatch_get_current_queue() == xmppQueue)
+ if (dispatch_get_current_queue() == self.xmppQueue)
block();
else
- dispatch_sync(xmppQueue, block);
+ dispatch_sync(self.xmppQueue, block);
if (errPtr)
*errPtr = err;
@@ -122,18 +122,18 @@ - (BOOL)supportsDeprecatedDigestAuthentication
// The root element can be properly queried for authentication mechanisms anytime after the
// stream:features are received, and TLS has been setup (if required)
- if (state >= STATE_XMPP_POST_NEGOTIATION)
+ if (self.state >= STATE_XMPP_POST_NEGOTIATION)
{
// Search for an iq element within the rootElement.
// Recall that some servers might stupidly add a "jabber:client" namespace which might cause problems
// if we simply used the elementForName method.
NSXMLElement *iq = nil;
- NSUInteger i, count = [rootElement childCount];
+ NSUInteger i, count = [self.rootElement childCount];
for (i = 0; i < count; i++)
{
- NSXMLNode *childNode = [rootElement childAtIndex:i];
+ NSXMLNode *childNode = [self.rootElement childAtIndex:i];
if ([childNode kind] == NSXMLElementKind)
{
@@ -151,10 +151,10 @@ - (BOOL)supportsDeprecatedDigestAuthentication
}
}};
- if (dispatch_get_current_queue() == xmppQueue)
+ if (dispatch_get_current_queue() == self.xmppQueue)
block();
else
- dispatch_sync(xmppQueue, block);
+ dispatch_sync(self.xmppQueue, block);
return result;
}
@@ -116,18 +116,18 @@ - (BOOL)supportsDeprecatedPlainAuthentication
// The root element can be properly queried for authentication mechanisms anytime after the
// stream:features are received, and TLS has been setup (if required)
- if (state >= STATE_XMPP_POST_NEGOTIATION)
+ if (self.state >= STATE_XMPP_POST_NEGOTIATION)
{
// Search for an iq element within the rootElement.
// Recall that some servers might stupidly add a "jabber:client" namespace which might cause problems
// if we simply used the elementForName method.
NSXMLElement *iq = nil;
- NSUInteger i, count = [rootElement childCount];
+ NSUInteger i, count = [self.rootElement childCount];
for (i = 0; i < count; i++)
{
- NSXMLNode *childNode = [rootElement childAtIndex:i];
+ NSXMLNode *childNode = [self.rootElement childAtIndex:i];
if ([childNode kind] == NSXMLElementKind)
{
@@ -145,10 +145,10 @@ - (BOOL)supportsDeprecatedPlainAuthentication
}
}};
- if (dispatch_get_current_queue() == xmppQueue)
+ if (dispatch_get_current_queue() == self.xmppQueue)
block();
else
- dispatch_sync(xmppQueue, block);
+ dispatch_sync(self.xmppQueue, block);
return result;
}
@@ -232,15 +232,15 @@ - (id)initWithFacebookAppId:(NSString *)fbAppId
if ((self = [self init])) // Note: Using [self init], NOT [super init]
{
self.facebookAppId = fbAppId;
- myJID_setByClient = [XMPPJID jidWithString:XMPPFacebookChatHostName];
+ self.myJID = [XMPPJID jidWithString:XMPPFacebookChatHostName];
// As of October 8, 2011, Facebook doesn't have their XMPP SRV records set.
// And, as per the XMPP specification, we MUST check the XMPP SRV records for an IP address,
// before falling back to a traditional A record lookup.
//
// So we're setting the hostname as a minor optimization to avoid the SRV timeout delay.
- hostName = XMPPFacebookChatHostName;
+ self.hostName = XMPPFacebookChatHostName;
}
return self;
}
@@ -253,10 +253,10 @@ - (NSString *)facebookAppId
result = objc_getAssociatedObject(self, &facebookAppIdKey);
};
- if (dispatch_get_current_queue() == xmppQueue)
+ if (dispatch_get_current_queue() == self.xmppQueue)
block();
else
- dispatch_sync(xmppQueue, block);
+ dispatch_sync(self.xmppQueue, block);
return result;
}
@@ -269,10 +269,10 @@ - (void)setFacebookAppId:(NSString *)inFacebookAppId
objc_setAssociatedObject(self, &facebookAppIdKey, newFacebookAppId, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
};
- if (dispatch_get_current_queue() == xmppQueue)
+ if (dispatch_get_current_queue() == self.xmppQueue)
block();
else
- dispatch_async(xmppQueue, block);
+ dispatch_async(self.xmppQueue, block);
}
- (BOOL)supportsXFacebookPlatformAuthentication
@@ -314,10 +314,10 @@ - (BOOL)authenticateWithFacebookAccessToken:(NSString *)accessToken error:(NSErr
}};
- if (dispatch_get_current_queue() == xmppQueue)
+ if (dispatch_get_current_queue() == self.xmppQueue)
block();
else
- dispatch_sync(xmppQueue, block);
+ dispatch_sync(self.xmppQueue, block);
if (errPtr)
*errPtr = err;
View
@@ -48,8 +48,9 @@ typedef enum XMPPStreamState XMPPStreamState;
**/
extern NSString *const XMPPStreamDidChangeMyJIDNotification;
-@interface XMPPStream (Internal)
+@interface XMPPStream (/* Internal */)
+@property (readonly) dispatch_queue_t xmppQueue;
@property (readonly) XMPPStreamState state;
/**
View
@@ -86,7 +86,7 @@ - (BOOL)isChatMessage
- (BOOL)isChatMessageWithBody
{
- if([self isChatMessage])
+ if ([self isChatMessage])
{
return [self isMessageWithBody];
}
View
@@ -15,7 +15,7 @@
**/
@interface XMPPModule : NSObject
{
- __strong XMPPStream *xmppStream;
+ XMPPStream *xmppStream;
dispatch_queue_t moduleQueue;
id multicastDelegate;
View
@@ -39,57 +39,6 @@ typedef enum XMPPStreamErrorCode XMPPStreamErrorCode;
@interface XMPPStream : NSObject <GCDAsyncSocketDelegate>
-{
- dispatch_queue_t xmppQueue;
- dispatch_queue_t parserQueue;
-
- GCDMulticastDelegate <XMPPStreamDelegate> *multicastDelegate;
-
- int state;
-
- GCDAsyncSocket *asyncSocket;
- NSMutableData *socketBuffer;
-
- UInt64 numberOfBytesSent;
- UInt64 numberOfBytesReceived;
-
- XMPPParser *parser;
- NSError *parserError;
-
- Byte flags;
- Byte config;
-
- NSString *hostName;
- UInt16 hostPort;
-
- id <XMPPSASLAuthentication> auth;
-
- XMPPJID *myJID_setByClient;
- XMPPJID *myJID_setByServer;
- XMPPJID *remoteJID;
-
- XMPPPresence *myPresence;
- NSXMLElement *rootElement;
-
- NSTimeInterval keepAliveInterval;
- dispatch_source_t keepAliveTimer;
- NSTimeInterval lastSendReceiveTime;
- NSData *keepAliveData;
-
- NSMutableArray *registeredModules;
- NSMutableDictionary *autoDelegateDict;
-
- XMPPSRVResolver *srvResolver;
- NSArray *srvResults;
- NSUInteger srvResultsIndex;
-
- NSMutableArray *receipts;
-
- NSThread *xmppUtilityThread;
- NSRunLoop *xmppUtilityRunLoop;
-
- id userTag;
-}
/**
* Standard XMPP initialization.
View
@@ -4,7 +4,6 @@
#import "XMPPInternal.h"
#import "XMPPSRVResolver.h"
#import "NSData+XMPP.h"
-#import "DDList.h"
#import <objc/runtime.h>
#import <libkern/OSAtomic.h>
@@ -90,9 +89,63 @@
#pragma mark -
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-@interface XMPPStream (PrivateAPI)
+@interface XMPPStream ()
+{
+ dispatch_queue_t xmppQueue;
+ dispatch_queue_t parserQueue;
+
+ dispatch_queue_t willSendIqQueue;
+ dispatch_queue_t willSendMessageQueue;
+ dispatch_queue_t willSendPresenceQueue;
+
+ GCDMulticastDelegate <XMPPStreamDelegate> *multicastDelegate;
+
+ int state;
+
+ GCDAsyncSocket *asyncSocket;
+ NSMutableData *socketBuffer;
+
+ UInt64 numberOfBytesSent;
+ UInt64 numberOfBytesReceived;
+
+ XMPPParser *parser;
+ NSError *parserError;
+
+ Byte flags;
+ Byte config;
+
+ NSString *hostName;
+ UInt16 hostPort;
+
+ id <XMPPSASLAuthentication> auth;
+
+ XMPPJID *myJID_setByClient;
+ XMPPJID *myJID_setByServer;
+ XMPPJID *remoteJID;
+
+ XMPPPresence *myPresence;
+ NSXMLElement *rootElement;
+
+ NSTimeInterval keepAliveInterval;
+ dispatch_source_t keepAliveTimer;
+ NSTimeInterval lastSendReceiveTime;
+ NSData *keepAliveData;
+
+ NSMutableArray *registeredModules;
+ NSMutableDictionary *autoDelegateDict;
+
+ XMPPSRVResolver *srvResolver;
+ NSArray *srvResults;
+ NSUInteger srvResultsIndex;
+
+ NSMutableArray *receipts;
+
+ NSThread *xmppUtilityThread;
+ NSRunLoop *xmppUtilityRunLoop;
+
+ id userTag;
+}
-- (void)cleanup;
- (void)setIsSecure:(BOOL)flag;
- (void)setIsAuthenticated:(BOOL)flag;
- (void)continueSendIQ:(XMPPIQ *)iq withTag:(long)tag;
@@ -127,8 +180,12 @@ @implementation XMPPStream
**/
- (void)commonInit
{
- xmppQueue = dispatch_queue_create("xmppStreamQueue", NULL);
- parserQueue = dispatch_queue_create("xmppParserQueue", NULL);
+ xmppQueue = dispatch_queue_create("xmpp", NULL);
+ parserQueue = dispatch_queue_create("xmpp.parser", NULL);
+
+ willSendIqQueue = dispatch_queue_create("xmpp.willSendIq", NULL);
+ willSendMessageQueue = dispatch_queue_create("xmpp.willSendMessage", NULL);
+ willSendPresenceQueue = dispatch_queue_create("xmpp.willSendPresence", NULL);
multicastDelegate = (GCDMulticastDelegate <XMPPStreamDelegate> *)[[GCDMulticastDelegate alloc] init];
@@ -207,6 +264,9 @@ - (void)dealloc
#if NEEDS_DISPATCH_RETAIN_RELEASE
dispatch_release(xmppQueue);
dispatch_release(parserQueue);
+ dispatch_release(willSendIqQueue);
+ dispatch_release(willSendMessageQueue);
+ dispatch_release(willSendPresenceQueue);
#endif
[asyncSocket setDelegate:nil delegateQueue:NULL];
@@ -234,6 +294,8 @@ - (void)dealloc
#pragma mark Properties
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+@synthesize xmppQueue;
+
- (XMPPStreamState)state
{
__block XMPPStreamState result = STATE_XMPP_DISCONNECTED;
@@ -1778,8 +1840,7 @@ - (void)sendIQ:(XMPPIQ *)iq withTag:(long)tag
GCDMulticastDelegateEnumerator *delegateEnumerator = [multicastDelegate delegateEnumerator];
- dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_async(concurrentQueue, ^{ @autoreleasepool {
+ dispatch_async(willSendIqQueue, ^{ @autoreleasepool {
// Allow delegates to modify and/or filter outgoing element
@@ -1849,8 +1910,7 @@ - (void)sendMessage:(XMPPMessage *)message withTag:(long)tag
GCDMulticastDelegateEnumerator *delegateEnumerator = [multicastDelegate delegateEnumerator];
- dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_async(concurrentQueue, ^{ @autoreleasepool {
+ dispatch_async(willSendMessageQueue, ^{ @autoreleasepool {
// Allow delegates to modify outgoing element
@@ -1920,8 +1980,7 @@ - (void)sendPresence:(XMPPPresence *)presence withTag:(long)tag
GCDMulticastDelegateEnumerator *delegateEnumerator = [multicastDelegate delegateEnumerator];
- dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_async(concurrentQueue, ^{ @autoreleasepool {
+ dispatch_async(willSendPresenceQueue, ^{ @autoreleasepool {
// Allow delegates to modify outgoing element

0 comments on commit 0f208ee

Please sign in to comment.