forked from amaxwell/tlutility
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TLMLogMessage.m
147 lines (130 loc) · 5.16 KB
/
TLMLogMessage.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
//
// TLMLogMessage.m
// TeX Live Utility
//
// Created by Adam Maxwell on 12/12/08.
/*
This software is Copyright (c) 2008-2016
Adam Maxwell. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
- Neither the name of Adam Maxwell nor the names of any
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "TLMLogMessage.h"
@implementation TLMLogMessage
@synthesize date = _date;
@synthesize message = _message;
@synthesize sender = _sender;
@synthesize pid = _pid;
@synthesize level = _level;
@synthesize flags = _flags;
@synthesize identifier = _identifier;
- (void)dealloc
{
[_date release];
[_sender release];
[_message release];
[_level release];
[super dealloc];
}
// only encoded by NSPortCoder, which doesn't support key/value coding
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:_date];
[coder encodeObject:_message];
[coder encodeObject:_sender];
[coder encodeObject:_level];
/*
Encode objects since old-style coding doesn't support primitive types directly,
and I don't want to worry about endianness (which should not be a problem on
the same host...but still).
*/
[coder encodeObject:[NSNumber numberWithUnsignedLong:_identifier]];
[coder encodeObject:[NSNumber numberWithInt:_pid]];
[coder encodeObject:[NSNumber numberWithUnsignedInteger:_flags]];
}
- (id)initWithCoder:(NSCoder *)coder
{
self = [super init];
if (self) {
_date = [[coder decodeObject] copy];
_message = [[coder decodeObject] copy];
_sender = [[coder decodeObject] copy];
_level = [[coder decodeObject] copy];
_identifier = [[coder decodeObject] unsignedLongValue];
_pid = [[coder decodeObject] intValue];
_flags = [[coder decodeObject] unsignedIntegerValue];
}
return self;
}
- (id)initWithPropertyList:(NSDictionary *)plist
{
self = [super init];
if (self) {
_date = [[plist objectForKey:@"_date"] copy];
_message = [[plist objectForKey:@"_message"] copy];
_sender = [[plist objectForKey:@"_sender"] copy];
_level = [[plist objectForKey:@"_level"] copy];
_pid = [[plist objectForKey:@"_pid"] intValue];
_flags = [[plist objectForKey:@"_flags"] unsignedIntegerValue];
}
return self;
}
- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
{
#pragma clang diagnostic push
// Apple can stick NSXPCConnection where the sun don't shine
#pragma clang diagnostic ignored "-Wdeprecated"
return [encoder isByref] ? (id)[NSDistantObject proxyWithLocal:self connection:[encoder connection]] : (id)self;
#pragma clang diagnostic pop
}
- (id)propertyList
{
NSMutableDictionary *plist = [NSMutableDictionary dictionary];
[plist setObject:_date forKey:@"_date"];
[plist setObject:_message forKey:@"_message"];
[plist setObject:_sender forKey:@"_sender"];
[plist setObject:_level forKey:@"_level"];
[plist setObject:[NSNumber numberWithUnsignedInteger:_pid] forKey:@"_pid"];
[plist setObject:[NSNumber numberWithUnsignedInteger:_flags] forKey:@"_flags"];
return plist;
}
- (NSUInteger)hash { return [_date hash]; }
- (BOOL)isEqual:(id)other
{
if ([other isKindOfClass:[self class]] == NO)
return NO;
if ([other pid] != _pid)
return NO;
if ([[other message] isEqualToString:_message] == NO)
return NO;
if ([(NSString *)[other sender] isEqualToString:_sender] == NO)
return NO;
if ([[other date] compare:_date] != NSOrderedSame)
return NO;
return YES;
}
- (NSString *)description { return [NSString stringWithFormat:@"%@ %@ %@[%lu]\t%@", _date, _level, _sender, (unsigned long)_pid, _message]; }
- (NSComparisonResult)compare:(TLMLogMessage *)other { return [_date compare:[other date]]; }
- (BOOL)matchesSearchString:(NSString *)searchTerm { return [[self description] rangeOfString:searchTerm options:NSCaseInsensitiveSearch].length; }
@end