Design question: NSFIleHandle and NSFileHandleDataAvailableNotification

  • 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
previous month october 2007 next month
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today