Re: Vending a proxy problems
Re: Vending a proxy problems
- Subject: Re: Vending a proxy problems
- From: Ondra Cada <email@hidden>
- Date: Thu, 25 Mar 2004 22:11:09 +0100
Jonathan,
On Thursday, Mar 25, 2004, at 20:44 Europe/Prague, Jonathan Wight wrote:
So now I'm trying to use Distributed Objects to vend the protected
object over an NSConnection. Unfortunately there's a problem...
I am sorry I don't have the time to pursue that, but I do remember I've
bumped into a strange forwarding&DO-related problem a couple of years
ago. Have a look--might it perhaps be related?
From: Ondra Cada <email@hidden>
Date: Thu Aug 8, 2002 17:59:50 Europe/Prague
To: email@hidden
Subject: [Cocoa-Pro] DO+forwarding: needs undocumented (?) methods!
Hi,
answering a question in cocoa I've bumped into something which seemed
to me to be a strange behaviour -- forwarding which worked perfectly
locally did not work via DO.
If someone can shed more light on that, I'd be grateful -- so far as I
have been able to find, so as forwarding+DO works together, you have to
use two methods whose documentation (or even declarations) I've not
been able to find.
#import <Foundation/Foundation.h>
#import <objc/Object.h>
#import <objc/Protocol.h>
@interface NSObject (NowhereDeclaredSoFarAsIKnow)
-(struct objc_method_description*)methodDescriptionForSelector:(SEL)sel;
+(struct
objc_method_description*)instanceMethodDescriptionForSelector:(SEL)sel;
@end
@interface Embedded:NSObject @end
@implementation Embedded
-(void)foobar { NSLog(@"foobar"); }
@end
@interface Server:NSObject {
@public Embedded *embedded;
}
@end
@implementation Server
// without this, it would not work via DO (that's AFAIK undocumented)
-(struct objc_method_description*)methodDescriptionForSelector:(SEL)sel
{
struct objc_method_description *desc=[[self class]
instanceMethodDescriptionForSelector:sel];
if (!desc) desc=[embedded methodDescriptionForSelector:sel];
return desc;
}
// without this, it would not work locally (that's all right and fully
documented)
-(NSMethodSignature*)methodSignatureForSelector:(SEL)sel {
NSMethodSignature *sig=[[self class]
instanceMethodSignatureForSelector:sel];
if (!sig) sig=[embedded methodSignatureForSelector:sel];
return sig;
}
-(void)forwardInvocation:(NSInvocation*)inv {
[inv invokeWithTarget:embedded];
}
@end
int main() {
id p=[NSAutoreleasePool new];
id v=[NSConnection rootProxyForConnectionWithRegisteredName:@"SNAFU"
host:nil];
if (v) {
NSLog(@"client mode");
[v foobar];
NSLog(@"done");
} else {
id conn=[NSConnection defaultConnection];
NSLog(@"server mode");
[conn setRootObject:v=[Server new]];
((Server*)v)->embedded=[Embedded new];
if ([conn registerName:@"SNAFU"]) {
[conn runInNewThread];
NSLog(@"enter 'q' to quit");
while (getchar()!='q');
}
}
[p release];
return 0;
}
Did I overlook something, or is it (at least a documentation) bug?
Also, might someone check whether this still does apply in Jaguar?
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.