Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOMacDebugger.m
Go to the documentation of this file.
1/*
2
3OOMacDebugger.m
4
5
6Oolite Debug Bundle
7
8Copyright (C) 2007 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
30
31#import "OOMacDebugger.h"
32#import "OODebugMonitor.h"
34
35#import "OOLogging.h"
37
38
39@implementation OOMacDebugger
40
41- (id) initWithController:(OOJavaScriptConsoleController *)controller
42{
43 self = [super init];
44 if (self != nil)
45 {
46 _jsConsoleController = controller;
48 }
49 return self;
50}
51
52
53- (void)dealloc
54{
55 [_monitor disconnectDebugger:self message:@"Debugger released."];
56 // _monitor and _jsConsoleController are not retained.
57
58 [_configuration release];
59
60 [super dealloc];
61}
62
63
64#pragma mark -
65
66- (void)performConsoleCommand:(NSString *)command
67{
68 [_monitor performJSConsoleCommand:command];
69}
70
71
72- (id)configurationValueForKey:(NSString *)key
73{
74 return [self configurationValueForKey:key class:Nil defaultValue:nil];
75}
76
77
78- (id)configurationValueForKey:(NSString *)key class:(Class)class defaultValue:(id)value
79{
80 id result = nil;
81
82 if (class == Nil) class = [NSObject class];
83
84 result = [_configuration objectForKey:key];
85 if (![result isKindOfClass:class] && result != [NSNull null]) result = [[value retain] autorelease];
86 if (result == [NSNull null]) result = nil;
87
88 return result;
89}
90
91
92- (long long)configurationIntValueForKey:(NSString *)key defaultValue:(long long)value
93{
94 long long result;
95 id object = nil;
96
97 object = [self configurationValueForKey:key];
98 if ([object respondsToSelector:@selector(longLongValue)]) result = [object longLongValue];
99 else if ([object respondsToSelector:@selector(intValue)]) result = [object intValue];
100 else result = value;
101
102 return result;
103}
104
105
106- (BOOL)configurationBoolValueForKey:(NSString *)key
107{
108 return OOBooleanFromObject([self configurationValueForKey:key], NO);
109}
110
111
112- (void)setConfigurationValue:(id)value forKey:(NSString *)key
113{
114 if (key == nil) return;
115
116 [_monitor setConfigurationValue:value forKey:key];
117}
118
119
120- (NSArray *)configurationKeys
121{
122 return [[_configuration allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
123}
124
125
126#pragma mark -
127
128- (BOOL)connectDebugMonitor:(in OODebugMonitor *)debugMonitor
129 errorMessage:(out NSString **)message
130{
131 if (debugMonitor == _monitor)
132 {
133 if (message != NULL) *message = @"ERROR: attempt to reconnect already-connected debugger!";
134 return NO;
135 }
136
137 if (_monitor != nil)
138 {
139 // Should never happen.
140 [_monitor disconnectDebugger:self message:@"Connected to different monitor."];
141 }
142
143 // Not retained.
144 _monitor = debugMonitor;
145 return YES;
146}
147
148- (void)disconnectDebugMonitor:(in OODebugMonitor *)debugMonitor
149 message:(in NSString *)message
150{
151 NSString *prefix = nil;
152 NSRange emphasisRange;
153
154 if (debugMonitor == _monitor)
155 {
156 prefix = @"Debugger disconnected: ";
157 emphasisRange = NSMakeRange(0, [prefix length] - 1);
158 [_jsConsoleController appendMessage:[prefix stringByAppendingString:message]
159 colorKey:@"console-internal"
160 emphasisRange:emphasisRange];
161
162 _monitor = nil;
163 }
164 else
165 {
166 prefix = @"ERROR: ";
167 emphasisRange = NSMakeRange(0, [prefix length] - 1);
168 message = [NSString stringWithFormat:@"%@attempt to disconnect unconnected debug monitor %@ with message: %@", prefix, debugMonitor, message];
169 [_jsConsoleController appendMessage:message
170 colorKey:@"console-internal"
171 emphasisRange:emphasisRange];
172 }
173}
174
175
176- (oneway void)debugMonitor:(in OODebugMonitor *)debugMonitor
177 jsConsoleOutput:(in NSString *)output
178 colorKey:(in NSString *)colorKey
179 emphasisRange:(in NSRange)emphasisRange
180{
181 [_jsConsoleController appendMessage:output
182 colorKey:colorKey
183 emphasisRange:emphasisRange];
184}
185
186- (oneway void)debugMonitorClearConsole:(in OODebugMonitor *)debugMonitor
187{
188 [_jsConsoleController clearConsole];
189}
190
191- (oneway void)debugMonitorShowConsole:(in OODebugMonitor *)debugMonitor
192{
193 [_jsConsoleController doShowConsole];
194}
195
196- (oneway void)debugMonitor:(in OODebugMonitor *)debugMonitor
197 noteConfiguration:(in NSDictionary *)configuration
198{
199 [_configuration release];
200 _configuration = [configuration mutableCopy];
201
202 [_jsConsoleController noteConfigurationChanged:nil];
203}
204
205
206- (oneway void)debugMonitor:(in OODebugMonitor *)debugMonitor
207noteChangedConfigrationValue:(in id)newValue
208 forKey:(in NSString *)key
209{
210 if (_configuration == nil) _configuration = [[NSMutableDictionary alloc] init];
211 if (newValue != nil) [_configuration setObject:newValue forKey:key];
212 else [_configuration removeObjectForKey:key];
213
214 [_jsConsoleController noteConfigurationChanged:key];
215}
216
217@end
BOOL OOBooleanFromObject(id object, BOOL defaultValue)
return nil
OOJavaScriptConsoleController * _jsConsoleController
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque