-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathPluginBase.m
executable file
·147 lines (116 loc) · 2.75 KB
/
PluginBase.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// PluginBase.m
// KnockKnock
#import "PluginBase.h"
#import "AppDelegate.h"
#define kErrFormat @"%@ not implemented in subclass %@"
#define kExceptName @"KK Plugin"
@implementation PluginBase
@synthesize icon;
@synthesize name;
@synthesize allItems;
@synthesize description;
@synthesize flaggedItems;
@synthesize unknownItems;
@synthesize untrustedItems;
//init method
-(id)init
{
//super
self = [super init];
if(nil != self)
{
//alloc
allItems = [NSMutableArray array];
//alloc
untrustedItems = [NSMutableArray array];
//alloc
unknownItems = [NSMutableArray array];
//alloc
flaggedItems = [NSMutableArray array];
}
return self;
}
//reset plugin
// ->remove all items
-(void)reset
{
//sync
// ->VT threads might still be accessing
@synchronized(self.allItems)
{
//remove all items
[self.allItems removeAllObjects];
}//sync
//sync
// ->VT threads might still be accessing
@synchronized(self.untrustedItems)
{
//remove unknown items
[self.untrustedItems removeAllObjects];
}//sync
//sync
// ->VT threads might still be accessing
@synchronized(self.unknownItems)
{
//remove flagged items
[self.unknownItems removeAllObjects];
}
//sync
// ->VT threads might still be accessing
@synchronized(self.flaggedItems)
{
//remove flagged items
[self.flaggedItems removeAllObjects];
}
return;
}
//process and item
// save and report (if necessary)
-(void)processItem:(ItemBase*)item
{
//exit if scanner (self) thread was cancelled
// ->will prevent UI from updating after scan is cancelled
if(YES == [[NSThread currentThread] isCancelled])
{
//exit
[NSThread exit];
}
//sync
// ->just to be safe
@synchronized(self.allItems)
{
//save item into 'allItems'
[self.allItems addObject:item];
}
//for unknown items
// ->save seperately as well
if(YES != item.isTrusted)
{
//sync
// ->just to be safe
@synchronized(self.untrustedItems)
{
//save
[self.untrustedItems addObject:item];
}
}
//invoke callback
if(nil != self.callback)
{
//invoke
self.callback(item);
}
return;
}
/* OPTIONAL METHODS */
/* REQUIRED METHODS */
//scan away!
-(void)scan
{
@throw [NSException exceptionWithName:kExceptName
reason:[NSString stringWithFormat:kErrFormat, NSStringFromSelector(_cmd), [self class]]
userInfo:nil];
return;
}
@end