Make method names more consistent with ObjFW.

This commit is contained in:
Jonathan Schleifer 2012-12-13 22:49:09 +01:00
parent 89b1f86a4d
commit 00a064a4a5
7 changed files with 66 additions and 54 deletions

View file

@ -31,18 +31,21 @@ typedef void(^xmpp_callback_block_t)(XMPPConnection*, XMPPIQ*);
@interface XMPPCallback: OFObject @interface XMPPCallback: OFObject
{ {
id object; id target;
SEL selector; SEL selector;
#ifdef OF_HAVE_BLOCKS
xmpp_callback_block_t block;
#endif
} }
#ifdef OF_HAVE_BLOCKS #ifdef OF_HAVE_BLOCKS
+ callbackWithCallbackBlock: (xmpp_callback_block_t)callback; + callbackWithBlock: (xmpp_callback_block_t)callback;
- initWithCallbackBlock: (xmpp_callback_block_t)callback; - initWithBlock: (xmpp_callback_block_t)callback;
#endif #endif
+ callbackWithCallbackObject: (id)object + callbackWithTarget: (id)target
selector: (SEL)selector; selector: (SEL)selector;
- initWithCallbackObject: (id)object - initWithTarget: (id)target
selector: (SEL)selector; selector: (SEL)selector;
- (void)runWithIQ: (XMPPIQ*)iq - (void)runWithIQ: (XMPPIQ*)iq

View file

@ -28,34 +28,39 @@
@implementation XMPPCallback @implementation XMPPCallback
#ifdef OF_HAVE_BLOCKS #ifdef OF_HAVE_BLOCKS
+ callbackWithCallbackBlock: (xmpp_callback_block_t)callback + callbackWithBlock: (xmpp_callback_block_t)block
{ {
return [[[self alloc] initWithCallbackBlock: callback] autorelease]; return [[(XMPPCallback*)[self alloc] initWithBlock: block] autorelease];
} }
- initWithCallbackBlock: (xmpp_callback_block_t)callback - initWithBlock: (xmpp_callback_block_t)block_
{ {
self = [super init]; self = [super init];
object = [callback copy]; @try {
block = [block_ copy];
} @catch (id e) {
[self release];
@throw e;
}
return self; return self;
} }
#endif #endif
+ callbackWithCallbackObject: (id)object_ + callbackWithTarget: (id)target
selector: (SEL)selector_ selector: (SEL)selector
{ {
return [[[self alloc] initWithCallbackObject: object_ return [[[self alloc] initWithTarget: target
selector: selector_] autorelease]; selector: selector] autorelease];
} }
- initWithCallbackObject: (id)object_ - initWithTarget: (id)target_
selector: (SEL)selector_ selector: (SEL)selector_
{ {
self = [super init]; self = [super init];
object = object_; target = [target_ retain];
selector = selector_; selector = selector_;
return self; return self;
@ -63,6 +68,11 @@
- (void)dealloc - (void)dealloc
{ {
[target release];
#ifdef OF_HAVE_BLOCKS
[block release];
#endif
[super dealloc]; [super dealloc];
} }
@ -70,11 +80,11 @@
connection: (XMPPConnection*)connection connection: (XMPPConnection*)connection
{ {
#ifdef OF_HAVE_BLOCKS #ifdef OF_HAVE_BLOCKS
if ([object isKindOfClass: [OFBlock class]]) if (block != NULL)
((xmpp_callback_block_t)object)(connection, iq); block(connection, iq);
else else
#endif #endif
[object performSelector: selector [target performSelector: selector
withObject: connection withObject: connection
withObject: iq]; withObject: iq];
} }

View file

@ -316,7 +316,7 @@
* must take exactly one parameter of type XMPPIQ* * must take exactly one parameter of type XMPPIQ*
*/ */
- (void)sendIQ: (XMPPIQ*)iq - (void)sendIQ: (XMPPIQ*)iq
withCallbackObject: (id)object callbackTarget: (id)target
selector: (SEL)selector; selector: (SEL)selector;
#ifdef OF_HAVE_BLOCKS #ifdef OF_HAVE_BLOCKS
@ -326,7 +326,7 @@
* \param callback The callback block * \param callback The callback block
*/ */
- (void)sendIQ: (XMPPIQ*)iq - (void)sendIQ: (XMPPIQ*)iq
withCallbackBlock: (xmpp_callback_block_t)block; callbackBlock: (xmpp_callback_block_t)block;
#endif #endif
/** /**
@ -370,10 +370,10 @@
- (void)XMPP_handlePresence: (XMPPPresence*)presence; - (void)XMPP_handlePresence: (XMPPPresence*)presence;
- (void)XMPP_handleFeatures: (OFXMLElement*)element; - (void)XMPP_handleFeatures: (OFXMLElement*)element;
- (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection - (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection
withIQ: (XMPPIQ*)iq; IQ: (XMPPIQ*)iq;
- (void)XMPP_sendSession; - (void)XMPP_sendSession;
- (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection - (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection
withIQ: (XMPPIQ*)iq; IQ: (XMPPIQ*)iq;
- (OFString*)XMPP_IDNAToASCII: (OFString*)domain; - (OFString*)XMPP_IDNAToASCII: (OFString*)domain;
- (XMPPMulticastDelegate*)XMPP_delegates; - (XMPPMulticastDelegate*)XMPP_delegates;
/// \endcond /// \endcond

View file

@ -470,7 +470,7 @@
} }
- (void)sendIQ: (XMPPIQ*)iq - (void)sendIQ: (XMPPIQ*)iq
withCallbackObject: (id)object callbackTarget: (id)target
selector: (SEL)selector selector: (SEL)selector
{ {
OFAutoreleasePool *pool; OFAutoreleasePool *pool;
@ -480,7 +480,7 @@
[iq setID: [self generateStanzaID]]; [iq setID: [self generateStanzaID]];
pool = [[OFAutoreleasePool alloc] init]; pool = [[OFAutoreleasePool alloc] init];
callback = [XMPPCallback callbackWithCallbackObject: object callback = [XMPPCallback callbackWithTarget: target
selector: selector]; selector: selector];
[callbacks setObject: callback [callbacks setObject: callback
forKey: [iq ID]]; forKey: [iq ID]];
@ -491,7 +491,7 @@
#ifdef OF_HAVE_BLOCKS #ifdef OF_HAVE_BLOCKS
- (void)sendIQ: (XMPPIQ*)iq - (void)sendIQ: (XMPPIQ*)iq
withCallbackBlock: (xmpp_callback_block_t)block; callbackBlock: (xmpp_callback_block_t)block
{ {
OFAutoreleasePool *pool; OFAutoreleasePool *pool;
XMPPCallback *callback; XMPPCallback *callback;
@ -500,7 +500,7 @@
[iq setID: [self generateStanzaID]]; [iq setID: [self generateStanzaID]];
pool = [[OFAutoreleasePool alloc] init]; pool = [[OFAutoreleasePool alloc] init];
callback = [XMPPCallback callbackWithCallbackBlock: block]; callback = [XMPPCallback callbackWithBlock: block];
[callbacks setObject: callback [callbacks setObject: callback
forKey: [iq ID]]; forKey: [iq ID]];
[pool release]; [pool release];
@ -1039,9 +1039,9 @@
[iq addChild: bind]; [iq addChild: bind];
[self sendIQ: iq [self sendIQ: iq
withCallbackObject: self callbackTarget: self
selector: @selector(XMPP_handleResourceBindForConnection: selector: @selector(XMPP_handleResourceBindForConnection:
withIQ:)]; IQ:)];
} }
- (void)XMPP_sendStreamError: (OFString*)condition - (void)XMPP_sendStreamError: (OFString*)condition
@ -1065,7 +1065,7 @@
} }
- (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection - (void)XMPP_handleResourceBindForConnection: (XMPPConnection*)connection
withIQ: (XMPPIQ*)iq IQ: (XMPPIQ*)iq
{ {
OFXMLElement *bindElement; OFXMLElement *bindElement;
OFXMLElement *jidElement; OFXMLElement *jidElement;
@ -1100,13 +1100,12 @@
[iq addChild: [OFXMLElement elementWithName: @"session" [iq addChild: [OFXMLElement elementWithName: @"session"
namespace: XMPP_NS_SESSION]]; namespace: XMPP_NS_SESSION]];
[self sendIQ: iq [self sendIQ: iq
withCallbackObject: self callbackTarget: self
selector: @selector( selector: @selector(XMPP_handleSessionForConnection:IQ:)];
XMPP_handleSessionForConnection:withIQ:)];
} }
- (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection - (void)XMPP_handleSessionForConnection: (XMPPConnection*)connection
withIQ: (XMPPIQ*)iq IQ: (XMPPIQ*)iq
{ {
if (![[iq type] isEqual: @"result"]) if (![[iq type] isEqual: @"result"])
assert(0); assert(0);

View file

@ -156,7 +156,7 @@
/// \cond internal /// \cond internal
- (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem; - (void)XMPP_updateRosterItem: (XMPPRosterItem*)rosterItem;
- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection - (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection
withIQ: (XMPPIQ*)iq; IQ: (XMPPIQ*)iq;
- (XMPPRosterItem*)XMPP_rosterItemWithXMLElement: (OFXMLElement*)element; - (XMPPRosterItem*)XMPP_rosterItemWithXMLElement: (OFXMLElement*)element;
/// \endcond /// \endcond
@end @end

View file

@ -98,9 +98,9 @@
[iq addChild: query]; [iq addChild: query];
[connection sendIQ: iq [connection sendIQ: iq
withCallbackObject: self callbackTarget: self
selector: @selector(XMPP_handleInitialRosterForConnection: selector: @selector(XMPP_handleInitialRosterForConnection:
withIQ:)]; IQ:)];
} }
- (BOOL)connection: (XMPPConnection*)connection_ - (BOOL)connection: (XMPPConnection*)connection_
@ -306,7 +306,7 @@
} }
- (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection_ - (void)XMPP_handleInitialRosterForConnection: (XMPPConnection*)connection_
withIQ: (XMPPIQ*)iq IQ: (XMPPIQ*)iq
{ {
OFXMLElement *rosterElement; OFXMLElement *rosterElement;
OFEnumerator *enumerator; OFEnumerator *enumerator;

View file

@ -170,7 +170,7 @@ OF_APPLICATION_DELEGATE(AppDelegate)
[iq addChild: [OFXMLElement elementWithName: @"ping" [iq addChild: [OFXMLElement elementWithName: @"ping"
namespace: @"urn:xmpp:ping"]]; namespace: @"urn:xmpp:ping"]];
[conn sendIQ: iq [conn sendIQ: iq
withCallbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) { callbackBlock: ^ (XMPPConnection *c, XMPPIQ *resp) {
of_log(@"Ping response: %@", resp); of_log(@"Ping response: %@", resp);
}]; }];
#endif #endif