Make use of multicast delegates in XMPPRoster.
This commit is contained in:
parent
cb43292ca0
commit
d1dc839333
6 changed files with 41 additions and 42 deletions
|
@ -306,7 +306,7 @@
|
||||||
{
|
{
|
||||||
if (length < 1) {
|
if (length < 1) {
|
||||||
[delegates broadcastSelector: @selector(connectionWasClosed:)
|
[delegates broadcastSelector: @selector(connectionWasClosed:)
|
||||||
forConnection: self];
|
withObject: self];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@
|
||||||
- (void)sendStanza: (OFXMLElement*)element
|
- (void)sendStanza: (OFXMLElement*)element
|
||||||
{
|
{
|
||||||
[delegates broadcastSelector: @selector(connection:didSendElement:)
|
[delegates broadcastSelector: @selector(connection:didSendElement:)
|
||||||
forConnection: self
|
withObject: self
|
||||||
withObject: element];
|
withObject: element];
|
||||||
|
|
||||||
[sock writeString: [element XMLString]];
|
[sock writeString: [element XMLString]];
|
||||||
|
@ -486,7 +486,7 @@
|
||||||
forNamespace: XMPP_NS_STREAM];
|
forNamespace: XMPP_NS_STREAM];
|
||||||
|
|
||||||
[delegates broadcastSelector: @selector(connection:didReceiveElement:)
|
[delegates broadcastSelector: @selector(connection:didReceiveElement:)
|
||||||
forConnection: self
|
withObject: self
|
||||||
withObject: element];
|
withObject: element];
|
||||||
|
|
||||||
if ([[element namespace] isEqual: XMPP_NS_CLIENT])
|
if ([[element namespace] isEqual: XMPP_NS_CLIENT])
|
||||||
|
@ -688,7 +688,7 @@
|
||||||
|
|
||||||
[delegates broadcastSelector: @selector(
|
[delegates broadcastSelector: @selector(
|
||||||
connectionWillUpgradeToTLS:)
|
connectionWillUpgradeToTLS:)
|
||||||
forConnection: self];
|
withObject: self];
|
||||||
|
|
||||||
newSock = [[SSLSocket alloc] initWithSocket: sock
|
newSock = [[SSLSocket alloc] initWithSocket: sock
|
||||||
privateKeyFile: privateKeyFile
|
privateKeyFile: privateKeyFile
|
||||||
|
@ -700,7 +700,7 @@
|
||||||
|
|
||||||
[delegates broadcastSelector: @selector(
|
[delegates broadcastSelector: @selector(
|
||||||
connectionDidUpgradeToTLS:)
|
connectionDidUpgradeToTLS:)
|
||||||
forConnection: self];
|
withObject: self];
|
||||||
|
|
||||||
/* Stream restart */
|
/* Stream restart */
|
||||||
[self XMPP_startStream];
|
[self XMPP_startStream];
|
||||||
|
@ -744,7 +744,7 @@
|
||||||
|
|
||||||
[delegates broadcastSelector: @selector(
|
[delegates broadcastSelector: @selector(
|
||||||
connectionWWasAuthenticated:)
|
connectionWWasAuthenticated:)
|
||||||
forConnection: self];
|
withObject: self];
|
||||||
|
|
||||||
/* Stream restart */
|
/* Stream restart */
|
||||||
[self XMPP_startStream];
|
[self XMPP_startStream];
|
||||||
|
@ -777,7 +777,7 @@
|
||||||
|
|
||||||
handled = [delegates broadcastSelector: @selector(
|
handled = [delegates broadcastSelector: @selector(
|
||||||
connection:didReceiveIQ:)
|
connection:didReceiveIQ:)
|
||||||
forConnection: self
|
withObject: self
|
||||||
withObject: iq];
|
withObject: iq];
|
||||||
|
|
||||||
if (!handled && ![[iq type] isEqual: @"error"] &&
|
if (!handled && ![[iq type] isEqual: @"error"] &&
|
||||||
|
@ -790,14 +790,14 @@
|
||||||
- (void)XMPP_handleMessage: (XMPPMessage*)message
|
- (void)XMPP_handleMessage: (XMPPMessage*)message
|
||||||
{
|
{
|
||||||
[delegates broadcastSelector: @selector(connection:didReceiveMessage:)
|
[delegates broadcastSelector: @selector(connection:didReceiveMessage:)
|
||||||
forConnection: self
|
withObject: self
|
||||||
withObject: message];
|
withObject: message];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)XMPP_handlePresence: (XMPPPresence*)presence
|
- (void)XMPP_handlePresence: (XMPPPresence*)presence
|
||||||
{
|
{
|
||||||
[delegates broadcastSelector: @selector(connection:didReceivePresence:)
|
[delegates broadcastSelector: @selector(connection:didReceivePresence:)
|
||||||
forConnection: self
|
withObject: self
|
||||||
withObject: presence];
|
withObject: presence];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -968,7 +968,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
[delegates broadcastSelector: @selector(connection:wasBoundToJID:)
|
[delegates broadcastSelector: @selector(connection:wasBoundToJID:)
|
||||||
forConnection: self
|
withObject: self
|
||||||
withObject: JID];
|
withObject: JID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -991,7 +991,7 @@
|
||||||
assert(0);
|
assert(0);
|
||||||
|
|
||||||
[delegates broadcastSelector: @selector(connection:wasBoundToJID:)
|
[delegates broadcastSelector: @selector(connection:wasBoundToJID:)
|
||||||
forConnection: self
|
withObject: self
|
||||||
withObject: JID];
|
withObject: JID];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "XMPPConnection.h"
|
#import <ObjFW/OFObject.h>
|
||||||
|
|
||||||
@class OFDataArray;
|
@class OFDataArray;
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@
|
||||||
OFDataArray *delegates;
|
OFDataArray *delegates;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate;
|
- (void)addDelegate: (id)delegate;
|
||||||
- (void)removeDelegate: (id <XMPPConnectionDelegate>)delegate;
|
- (void)removeDelegate: (id)delegate;
|
||||||
- (BOOL)broadcastSelector: (SEL)selector
|
- (BOOL)broadcastSelector: (SEL)selector
|
||||||
forConnection: (XMPPConnection*)connection;
|
|
||||||
- (BOOL)broadcastSelector: (SEL)selector
|
|
||||||
forConnection: (XMPPConnection*)connection
|
|
||||||
withObject: (id)object;
|
withObject: (id)object;
|
||||||
|
- (BOOL)broadcastSelector: (SEL)selector
|
||||||
|
withObject: (id)object1
|
||||||
|
withObject: (id)object2;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -50,12 +50,12 @@
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addDelegate: (id <XMPPConnectionDelegate>)delegate
|
- (void)addDelegate: (id)delegate
|
||||||
{
|
{
|
||||||
[delegates addItem: &delegate];
|
[delegates addItem: &delegate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeDelegate: (id<XMPPConnectionDelegate>)delegate
|
- (void)removeDelegate: (id)delegate
|
||||||
{
|
{
|
||||||
id *cArray = [delegates cArray];
|
id *cArray = [delegates cArray];
|
||||||
size_t i, count = [delegates count];
|
size_t i, count = [delegates count];
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)broadcastSelector: (SEL)selector
|
- (BOOL)broadcastSelector: (SEL)selector
|
||||||
forConnection: (XMPPConnection*)connection
|
withObject: (id)object
|
||||||
{
|
{
|
||||||
id *cArray = [delegates cArray];
|
id *cArray = [delegates cArray];
|
||||||
size_t i, count = [delegates count];
|
size_t i, count = [delegates count];
|
||||||
|
@ -82,15 +82,15 @@
|
||||||
BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
|
BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id))
|
||||||
[cArray[i] methodForSelector: selector];
|
[cArray[i] methodForSelector: selector];
|
||||||
|
|
||||||
handled |= imp(cArray[i], selector, connection);
|
handled |= imp(cArray[i], selector, object);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)broadcastSelector: (SEL)selector
|
- (BOOL)broadcastSelector: (SEL)selector
|
||||||
forConnection: (XMPPConnection*)connection
|
withObject: (id)object1
|
||||||
withObject: (id)object
|
withObject: (id)object2
|
||||||
{
|
{
|
||||||
id *cArray = [delegates cArray];
|
id *cArray = [delegates cArray];
|
||||||
size_t i, count = [delegates count];
|
size_t i, count = [delegates count];
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
|
BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id))
|
||||||
[cArray[i] methodForSelector: selector];
|
[cArray[i] methodForSelector: selector];
|
||||||
|
|
||||||
handled |= imp(cArray[i], selector, connection, object);
|
handled |= imp(cArray[i], selector, object1, object2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
@class XMPPRosterItem;
|
@class XMPPRosterItem;
|
||||||
@class XMPPIQ;
|
@class XMPPIQ;
|
||||||
@class XMPPRoster;
|
@class XMPPRoster;
|
||||||
|
@class XMPPMulticastDelegate;
|
||||||
|
|
||||||
@protocol XMPPRosterDelegate
|
@protocol XMPPRosterDelegate
|
||||||
#ifndef XMPP_ROSTER_M
|
#ifndef XMPP_ROSTER_M
|
||||||
|
@ -49,21 +50,17 @@
|
||||||
{
|
{
|
||||||
XMPPConnection *connection;
|
XMPPConnection *connection;
|
||||||
OFMutableDictionary *rosterItems;
|
OFMutableDictionary *rosterItems;
|
||||||
id <XMPPRosterDelegate, OFObject> delegate;
|
XMPPMulticastDelegate *delegates;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef OF_HAVE_PROPERTIES
|
|
||||||
@property (assign) id <XMPPRosterDelegate> delegate;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
- initWithConnection: (XMPPConnection*)conn;
|
- initWithConnection: (XMPPConnection*)conn;
|
||||||
- (OFDictionary*)rosterItems;
|
- (OFDictionary*)rosterItems;
|
||||||
- (void)requestRoster;
|
- (void)requestRoster;
|
||||||
- (void)addRosterItem: (XMPPRosterItem*)rosterItem;
|
- (void)addRosterItem: (XMPPRosterItem*)rosterItem;
|
||||||
- (void)updateRosterItem: (XMPPRosterItem*)rosterItem;
|
- (void)updateRosterItem: (XMPPRosterItem*)rosterItem;
|
||||||
- (void)deleteRosterItem: (XMPPRosterItem*)rosterItem;
|
- (void)deleteRosterItem: (XMPPRosterItem*)rosterItem;
|
||||||
- (void)setDelegate: (id <XMPPRosterDelegate>)delegate;
|
- (void)addDelegate: (id <XMPPRosterDelegate>)delegate;
|
||||||
- (id <XMPPRosterDelegate>)delegate;
|
- (void)removeDelegate: (id <XMPPRosterDelegate>)delegate;
|
||||||
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem;
|
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem;
|
||||||
- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem;
|
- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem;
|
||||||
- (void)XMPP_deleteRosterItem: (XMPPRosterItem*)rosterItem;
|
- (void)XMPP_deleteRosterItem: (XMPPRosterItem*)rosterItem;
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
rosterItems = [[OFMutableDictionary alloc] init];
|
rosterItems = [[OFMutableDictionary alloc] init];
|
||||||
connection = connection_;
|
connection = connection_;
|
||||||
[connection addDelegate: self];
|
[connection addDelegate: self];
|
||||||
|
delegates = [[XMPPMulticastDelegate alloc] init];
|
||||||
} @catch (id e) {
|
} @catch (id e) {
|
||||||
[self release];
|
[self release];
|
||||||
@throw e;
|
@throw e;
|
||||||
|
@ -57,6 +58,7 @@
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
[connection removeDelegate: self];
|
[connection removeDelegate: self];
|
||||||
|
[delegates release];
|
||||||
[rosterItems release];
|
[rosterItems release];
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
|
@ -107,10 +109,10 @@
|
||||||
else
|
else
|
||||||
[self XMPP_addRosterItem: rosterItem];
|
[self XMPP_addRosterItem: rosterItem];
|
||||||
|
|
||||||
if ([delegate respondsToSelector:
|
[delegates broadcastSelector: @selector(
|
||||||
@selector(roster:didReceiveRosterItem:)])
|
roster:didReceiveRosterItem:)
|
||||||
[delegate roster: self
|
withObject: self
|
||||||
didReceiveRosterItem: rosterItem];
|
withObject: rosterItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
[connection_ sendStanza: [iq resultIQ]];
|
[connection_ sendStanza: [iq resultIQ]];
|
||||||
|
@ -172,14 +174,14 @@
|
||||||
[connection sendStanza: iq];
|
[connection sendStanza: iq];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDelegate: (id <XMPPRosterDelegate>)delegate_
|
- (void)addDelegate: (id <XMPPRosterDelegate>)delegate
|
||||||
{
|
{
|
||||||
delegate = (id <XMPPRosterDelegate, OFObject>)delegate_;
|
[delegates addDelegate: delegate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id <XMPPRosterDelegate>)delegate
|
- (void)removeDelegate: (id <XMPPRosterDelegate>)delegate
|
||||||
{
|
{
|
||||||
return delegate;
|
[delegates removeDelegate: delegate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem
|
- (void)XMPP_addRosterItem: (XMPPRosterItem*)rosterItem
|
||||||
|
@ -258,8 +260,8 @@
|
||||||
[self XMPP_addRosterItem: rosterItem];
|
[self XMPP_addRosterItem: rosterItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([delegate respondsToSelector: @selector(rosterWasReceived:)])
|
[delegates broadcastSelector: @selector(rosterWasReceived:)
|
||||||
[delegate rosterWasReceived: self];
|
withObject: self];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
|
||||||
roster = [[XMPPRoster alloc] initWithConnection: conn];
|
roster = [[XMPPRoster alloc] initWithConnection: conn];
|
||||||
|
|
||||||
[conn addDelegate: self];
|
[conn addDelegate: self];
|
||||||
[roster setDelegate: self];
|
[roster addDelegate: self];
|
||||||
|
|
||||||
if ([arguments count] != 3) {
|
if ([arguments count] != 3) {
|
||||||
of_log(@"Invalid count of command line arguments!");
|
of_log(@"Invalid count of command line arguments!");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue