• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: What part of DO don't I understand?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What part of DO don't I understand?


  • Subject: Re: What part of DO don't I understand?
  • From: Byron Wright <email@hidden>
  • Date: Thu, 24 Feb 2005 12:43:57 -0800

thanks Charles,

that certainly got me closer to a solutions. However, I am now running into a problem where the properties of my object is not getting copy, so an NSDistantObject is getting created for all my objects properties. I turned DO debugging on in my environment variables and am seeing the following :

005-02-24 12:29:15.702 CFC[3361] CFCComponentVO.m:183 -[CFCComponentVO encodeWithCoder:] -
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 3c14b0 (CFCOIDVO) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] new isLocal NSDistantObject 3c9400 for 3c14b0 on conn 369780
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 3c5b10 (CFCOIDVO) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] new isLocal NSDistantObject 3c8e70 for 3c5b10 on conn 369780
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 3ca910 (NSCFString) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 3c5d70 (CFCType) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] new isLocal NSDistantObject 3c9840 for 3c5d70 on conn 369780
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 3c9c60 (NSCFString) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 3ca8b0 (NSCFString) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] encodeObject: a01901a4 (NSNull) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 3c9ca0 (NSCFString) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.702 CFC[3361] encodeObject: 0 (<nil>) isBycopy:(0) isByref:(0)
2005-02-24 12:29:15.703 CFC[3361] encodeObject: 3c39d0 (NSCFArray) isBycopy:(0) isByref:(0)


for my custom class CFCOIDVO and CFCType I am doing the exact same to support DO however as the debug statement says, it's isBycopy(0) and not isBycopy(1). My -[CFCOIDVO replacementObjectForPortCoder:] and [CFCType replacementObjectForPortCoder:] are not getting called.


Any ideas?


On Feb 22, 2005, at 6:39 PM, Charles Crowley wrote:

Byron,

I ran into this same problem. You figured out the first part, that is, to call replacementObjectForPortCoder. After this gets called then Cocoa calls your "encodeWithCoder: (NSCoder *) encoder" method with an encoder. But this encoder is not a keyed archiving encoder but the older kind that encodes by order. You are probably calling "encodeObject:forKey:" in that method and this is the error you are seeing. Change your method to something like this:

- (void) encodeWithCoder: (NSCoder *) encoder {
    if( [encoder allowsKeyedCoding] ) {
	[encoder encodeObject: [self firstName] forKey: firstNameKey];
	[encoder encodeObject: [self lastName] forKey: lastNameKey];
    } else {
	[encoder encodeObject: [self firstName]];
	[encoder encodeObject: [self lastName]];
    }
}

Of course, instead of firstName and lastName you need all the variables in the class that you need to archive. You probably already have all the "encodeObject:forKey:" lines that you need. Just copy them and remove the "forKey:" part.

You need to do a similar thing for your "initWithCoder: (NSCoder *) decoder" method on the receiving side of the DO.

Hope this helps.

--Charlie Crowley


On Feb 22, 2005, at 12:35 PM, Byron Wright wrote:

ok after digging around I found I need to implement the following method in my class to so that bycopy does not return a NSProxy / NSDistributedObject :

- (id)replacementObjectForPortCoder:(NSPortCoder *)encoder
{
	if ([encoder isBycopy]) return self;
	return [super replacementObjectForPortCoder:encoder];
}

I need that but now I get the following exception :

Exception raised during posting of notification. Ignored. exception: *** -encodeObject:forKey: only defined for abstract class. Define -[NSConcretePortCoder encodeObject:forKey:]!

This only happens when my custom class initWithCoder:(NSCoder *) coder gets called.

Any ideas?

- Byron



On Feb 21, 2005, at 6:45 PM, Byron Wright wrote:

So I am attempting to create a server in another thread that is responsible for fetching data on a remote server. I want to collect the data and then send it back to the main thread asynch. I am using Distributed Objects to send the newly created data from the server thread to the main thread. The issue I am having is that the newly created objects (in the server thread) are always sent back to the main thread as a proxy and not copied even though I have the bycopy hint in the method sig. Here is the code I am using as a prototype to understand DO, assume the connects have already been setup (which they have).

//MyServer.h

@class Testobject;

@protocol MyServerMethods

- (oneway void) doSomework;


@end

@protocol MyClientMethods

- (oneway void) workDone : (in bycopy Testobject *) obj;
- (void) setServer: (id) server;

@end

@interface MyServer : NSObject <MyServerMethods>
{
	id clientProxy;
}

- (id) initWithClient: (id) client;
- (oneway void) doSomework;
+ (void)connectWithPorts:(NSArray *)portArray;
@end
/ /-------------------------------------------------------------------- ----


//myClient.h

@interface MyClient : NSObject <MyClientMethods> {

	id<MyServerMethods> myServer ;
	NSConnection* kitConnection;

}
- (IBAction) doWork: (id) sender;
- (void) setServer: (id) server;
- (oneway void) workDone : (in bycopy Testobject *) obj;
- (void) createServer;


@end
/ /-------------------------------------------------------------------- ----


so my server does some work then sends a new object to the main thread (MyClient)

so my client called doSomework from the main thread.

- (oneway void) doSomework
{
	int total = 1000;
	int it = 0;
	for(it ; it < total; ++it)
	{
		NSLog(@"doSomework %i",it);
	}
	Testobject * obj = [[Testobject alloc] init];
	//done send back to main thread
	[clientProxy workDone:obj ];
	//[obj release];
}

MyClient then accepts the new data :

- (oneway void) workDone : (in bycopy Testobject *) obj;
{
	NSLog(@"myClient:workDone");
	if([obj isProxy])
	{
		NSLog(@"I am baffled");
	}
	NSLog(@"obj = %@",[obj description]);
}

problem is obj isProxy is always true. Also, something else I found out the hard way, NSLog(@"obj = %@",obj) always crashes if it's an NSProxy, I am guessing because NSProxy does not know how to dispatch this call?

here is the simple data object I am using for testing:

@interface Testobject : NSObject  <NSCoding>{
	NSString * val;
}
- (NSString *)val;
- (void)setVal:(NSString *)aVal;

@end


Any help is always appreciated.

Cheers,
Byron


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden





Byron Wright
Software Developer
Siemens Business Services Media
(formerly BBC Technology)
Mobile: 206-227-4645
Email: email@hidden
www.bbctechnology.com
www.siemens.co.uk/sbs

This e-mail (and any attachments) contains confidential information and is for the exclusive use of the addressee/s. Any views contained in this e-mail are not the views of Siemens Business Services Media Holdings Ltd unless specifically stated. If you are not the addressee, then any distribution, copying or use of this e-mail is prohibited. If received in error, please advise the sender and delete/destroy it immediately. We accept no liability for any loss or damage suffered by any person arising from use of this e-mail/fax. Please note that Siemens Business Services Media Holdings Ltd monitors e-mails sent or received. Further communication will signify your consent to this.

Siemens Business Services Media Holdings Ltd
Registered No: 04128934 England
Registered Office: Siemens House, Oldbury, Bracknell, Berkshire, RG12 8FZ


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >What part of DO don't I understand? (From: Byron Wright <email@hidden>)
 >Re: What part of DO don't I understand? (From: Byron Wright <email@hidden>)
 >Re: What part of DO don't I understand? (From: Charles Crowley <email@hidden>)

  • Prev by Date: NSURLDownload Example with Progress Indicator
  • Next by Date: Re: affine transformation of bitmap images
  • Previous by thread: Re: What part of DO don't I understand?
  • Next by thread: commandline tool should start Cocoa GUI
  • Index(es):
    • Date
    • Thread