ObjXMPP  Diff

Differences From Artifact [aac405c1ea]:

To Artifact [1ccfe848fa]:


1
2

3
4
5
6
7
8
9
1
2
3
4
5
6
7
8
9
10


+







/*
 * Copyright (c) 2011, Florian Zeitz <florob@babelmonkeys.de>
 * Copyright (c) 2021, Jonathan Schleifer <js@nil.im>
 *
 * https://heap.zone/objxmpp/
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice is present in all copies.
 *
22
23
24
25
26
27
28
29

30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
23
24
25
26
27
28
29

30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51

52
53
54
55
56

57

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

77

78
79
80
81
82
83
84
85
86
87
88







-
+





-
+














-
+
-





-
+
-



















-
+
-












#include "config.h"

#import "XMPPCallback.h"

@implementation XMPPCallback
#ifdef OF_HAVE_BLOCKS
+ (instancetype)callbackWithBlock: (xmpp_callback_block_t)block
+ (instancetype)callbackWithBlock: (XMPPCallbackBlock)block
{
	return [[(XMPPCallback *)[self alloc]
	    initWithBlock: block] autorelease];
}

- (instancetype)initWithBlock: (xmpp_callback_block_t)block
- (instancetype)initWithBlock: (XMPPCallbackBlock)block
{
	self = [super init];

	@try {
		_block = [block copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif

+ (instancetype)callbackWithTarget: (id)target
+ (instancetype)callbackWithTarget: (id)target selector: (SEL)selector
			  selector: (SEL)selector
{
	return [[[self alloc] initWithTarget: target
				    selector: selector] autorelease];
}

- (instancetype)initWithTarget: (id)target
- (instancetype)initWithTarget: (id)target selector: (SEL)selector
		      selector: (SEL)selector
{
	self = [super init];

	_target = [target retain];
	_selector = selector;

	return self;
}

- (void)dealloc
{
	[_target release];
#ifdef OF_HAVE_BLOCKS
	[_block release];
#endif

	[super dealloc];
}

- (void)runWithIQ: (XMPPIQ *)IQ
- (void)runWithIQ: (XMPPIQ *)IQ connection: (XMPPConnection *)connection
       connection: (XMPPConnection *)connection
{
#ifdef OF_HAVE_BLOCKS
	if (_block != NULL)
		_block(connection, IQ);
	else
#endif
		[_target performSelector: _selector
			      withObject: connection
			      withObject: IQ];
}
@end