Design question: NSFIleHandle and NSFileHandleDataAvailableNotification
Design question: NSFIleHandle and NSFileHandleDataAvailableNotification
- Subject: Design question: NSFIleHandle and NSFileHandleDataAvailableNotification
- From: Jaime Magiera <email@hidden>
- Date: Mon, 1 Oct 2007 11:28:28 -0400
Hi,
This relates to the problem I had last week regarding NSFileHandle
("Re: filesystem copy error for movies"). It seems the best practice
in avoiding the copy-file-before-NSFileHande-has-finished problem is
to use the NSFileHandleDataAvailableNotification.
The outline below describes the current code, which on some machines
causes infinite writing because the handle isn't closed when the
method returns...
- new thread for export
- call export method
- export method calls addAtomToFile method
- addAtomToFile method returns to export method
- export method copies completed file to user space.
Right now, I'm trying to figure out the best way to use the
notification. Would something like this be a reasonable approach?
- new thread for export
- call export method
- new thread for atom tweaking
- export method calls addAtomToFile method in new thread
- export method does a while(), polling a BOOL in the class which
contains addAtomToFile
- addAtomToFile method sends NSFileHandleDataAvailableNotification
notification which is set to call "-(void)
acceptDataAvailableNotification:(NSNotification *)aNotification".
This method updates the BOOL value.
- addAtomToFile method returns to export method
- When the while() polls the child class's BOOL variable and sees
it is TRUE, the completed file is copied to user space.
I guess, in other words, I'm asking what is the best way to handle
NSNotifications when you want an app to stop doing other things until
the notification is received. While() loop seems the most simple, but
is there some methodology in Cocoa for working with notifications in
this way? I thought of sending the notification to the calling object
(export method). However, I'd prefer that the child keep all those
NSFileHandle writing details to itself. Is there a way to not have
the child return at all until it receives the notification? Then I
could avoid having the parent poll the child's BOOL.
Any help is greatly appreciated. this is new territory for me. Thanks!
Jaime Magiera
Sensory Research
http://www.sensoryresearch.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden