5
// Created by John M McIntosh on 01/02/09.
6
// Copyright 2009 Corporate Smalltalk Consulting Ltd. All rights reserved.
10
http://www.squeaksource.com/ObjectiveCBridge.html
11
developers and contributors
12
Creator: Alain Fischer
13
Admin: Avi Bryant, Alain Fischer
14
Developer: Todd Blanchard
17
Permission is hereby granted, free of charge, to any person
18
obtaining a copy of this software and associated documentation
19
files (the "Software"), to deal in the Software without
20
restriction, including without limitation the rights to use,
21
copy, modify, merge, publish, distribute, sublicense, and/or sell
22
copies of the Software, and to permit persons to whom the
23
Software is furnished to do so, subject to the following
26
The above copyright notice and this permission notice shall be
27
included in all copies or substantial portions of the Software.
29
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
31
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
36
OTHER DEALINGS IN THE SOFTWARE.
38
The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
39
"This product includes software developed by Corporate Smalltalk Consulting Ltd (http://www.smalltalkconsulting.com)
40
and its contributors", in the same place and form as other third-party acknowledgments.
41
Alternately, this acknowledgment may appear in the software itself, in the same form and location as other
42
such third-party acknowledgments.
46
#import "squeakProxy.h"
49
@implementation SqueakProxy
52
@synthesize invocation;
53
@synthesize lockForSqueak;
57
@synthesize callbackid;
59
- (id) initWithSemaphore: (sqInt) squeakSem protocolNSString: (NSString *) nameString target: aTarget
63
protocol = objc_getProtocol([nameString UTF8String]);
68
[self setTarget: aTarget];
70
NSObject *dummy = [[NSObject alloc] init];
71
[self setTarget: dummy];
75
lockForSqueak = [[NSConditionLock alloc] initWithCondition: 0];
76
sigs = [[NSMutableDictionary alloc] initWithCapacity: 10];
84
- (void) forwardInvocation: (NSInvocation*) anInvocation
87
// NSLog(@"forwardInvocation: %@", anInvocation);
88
// NSLog(@"currentThread: %@", [NSThread currentThread]);
89
SEL selector = [anInvocation selector];
90
NSString *selectorString = NSStringFromSelector(selector);
91
if (![sigs objectForKey: selectorString]) {
92
[anInvocation invokeWithTarget: target];
96
if([lockForSqueak lockWhenCondition: 0 beforeDate: (timeout = [[NSDate alloc] initWithTimeIntervalSinceNow: 3.0])])
98
// NSLog(@"inside lock 0");
99
[lockForSqueak unlockWithCondition: 1];
101
invocation = [anInvocation retain];
103
// NSLog(@"signalling squeak");
104
interpreterProxy->signalSemaphoreWithIndex(sem);
107
interpreterProxy->callbackEnter(&callbackid);
109
if([lockForSqueak lockWhenCondition: 2 beforeDate: (timeout = [[NSDate alloc] initWithTimeIntervalSinceNow: 5.0])])
111
// NSLog(@"inside lock 2");
113
[invocation release];
115
[lockForSqueak unlockWithCondition: 0];
119
// NSLog(@"failed lock 2");
121
[invocation release];
123
[lockForSqueak unlockWithCondition: 0];
125
//NSLog(@"returning");
130
//NSLog(@"failed lock 0");
134
- (NSMethodSignature *) methodSignatureForSelector: (SEL) selector
136
NSMethodSignature* sig;
137
NSString* sigAsString;
138
sig = [target methodSignatureForSelector: selector];
142
sig = [super methodSignatureForSelector: selector];
146
NSString *selectorString = NSStringFromSelector (selector);
148
if (sigAsString = [sigs objectForKey: selectorString]) {
151
struct objc_method_description methodDescription;
152
methodDescription = protocol_getMethodDescription(protocol, selector, YES, YES);
153
if(methodDescription.name == NULL) {
154
methodDescription = protocol_getMethodDescription(protocol, selector, NO, YES);
157
if(methodDescription.name != NULL) {
158
NSMethodSignature *foo = [NSMethodSignature signatureWithObjCTypes:methodDescription.types];
162
NSMethodSignature *foo = [NSMethodSignature signatureWithObjCTypes: [sigAsString cStringUsingEncoding: NSASCIIStringEncoding]];
169
- (BOOL) respondsToSelector: (SEL) selector
171
if([super respondsToSelector: selector])
174
if ([target respondsToSelector: selector])
177
NSString *which = NSStringFromSelector(selector);
179
if ([sigs objectForKey: which])
185
- (void) setReturnValue: (void*) pointer {
186
[invocation setReturnValue: &pointer];
189
- (BOOL) isDataTypeAware {
193
- (void) setIsCarbonVM {
199
[lockForSqueak release];