FROM : Mike Abdullah
DATE : Tue Aug 01 19:50:47 2006
Thanks Shawn. I tried to get the callback system to work, but I
couldn't persuade it :( Does anyone have any sample code for this?
I shall also have a look at the docs like you suggest as well.
Mike.
On 1 Aug 2006, at 16:51, Shawn Erickson wrote:
>
> On Aug 1, 2006, at 8:38 AM, Mike Abdullah wrote:
>
>>
>> 10.4 only is fine for me. I've had a look at FSCopyObjectAsync,
>> and after a search around, found Apple's nice FSFileOperation
>> sample code:
>>
>> http://developer.apple.com/samplecode/FSFileOperation/
>>
>> I've got a quick simple project up and running using this,
>> however, I wonder if someone could help clarify something for me.
>> My code is:
>>
>> - (IBAction)doCopy:(id)sender
>> {
>> OSStatus err;
>> FSRef sourceFileRef, destinationDirectoryRef;
>>
>> // Build the parameters
>> FSFileOperationRef fileOp = FSFileOperationCreate
>> (kCFAllocatorDefault);
>>
>> FSPathMakeRef((UInt8 *)[@"/Users/dev/Desktop/test.dmg"
>> fileSystemRepresentation], &sourceFileRef, NULL);
>>
>> FSPathMakeRef((UInt8 *)[@"/Users/dev/Desktop/Copy/"
>> fileSystemRepresentation], &destinationDirectoryRef, NULL);
>>
>> OptionBits options = kFSFileOperationDefaultOptions;
>>
>>
>> // Do the copy
>> err = FSCopyObjectAsync(fileOp, &sourceFileRef,
>> &destinationDirectoryRef, NULL, options, NULL, 0.01, NULL);
>>
>> while (YES)
>> {
>> CFRunLoopRunInMode(kCFRunLoopDefaultMode, 5.0, true);
>>
>> CFDictionaryRef infoDict2;
>> (void) FSFileOperationCopyStatus(fileOp, NULL, NULL, &err,
>> &infoDict2, NULL);
>>
>> NSLog(@"%@", (NSDictionary *)infoDict2);
>> }
>> }
>>
>> Now obviously, I need to do this in a separate thread which isn't
>> a problem. However, what I don't really understand is what
>> exactly goes on with the CFRunLoopRunInMode call. It seems that
>> during the duration of this method, that's when a chunk of file
>> copying is actually done, but once I stick the code in a thread,
>> should I really use this, or is there something better?
>
> You don't actually have to do this in a separate thread. You can
> register a callback and execute this operation on your main thread
> (the main thread in a Cocoa application has an active runloop). You
> will get callbacks from your main runloop as the copy progresses
> and when it finishes.
>
> The example above is written to be run from a secondary thread and
> doesn't leverage the callback capability (why it is running its own
> runloop periodically).
>
> Review the docs on runloops (CFRunLoop and NSRunLoop) if you don't
> understand what those are.
>
> -Shawn
DATE : Tue Aug 01 19:50:47 2006
Thanks Shawn. I tried to get the callback system to work, but I
couldn't persuade it :( Does anyone have any sample code for this?
I shall also have a look at the docs like you suggest as well.
Mike.
On 1 Aug 2006, at 16:51, Shawn Erickson wrote:
>
> On Aug 1, 2006, at 8:38 AM, Mike Abdullah wrote:
>
>>
>> 10.4 only is fine for me. I've had a look at FSCopyObjectAsync,
>> and after a search around, found Apple's nice FSFileOperation
>> sample code:
>>
>> http://developer.apple.com/samplecode/FSFileOperation/
>>
>> I've got a quick simple project up and running using this,
>> however, I wonder if someone could help clarify something for me.
>> My code is:
>>
>> - (IBAction)doCopy:(id)sender
>> {
>> OSStatus err;
>> FSRef sourceFileRef, destinationDirectoryRef;
>>
>> // Build the parameters
>> FSFileOperationRef fileOp = FSFileOperationCreate
>> (kCFAllocatorDefault);
>>
>> FSPathMakeRef((UInt8 *)[@"/Users/dev/Desktop/test.dmg"
>> fileSystemRepresentation], &sourceFileRef, NULL);
>>
>> FSPathMakeRef((UInt8 *)[@"/Users/dev/Desktop/Copy/"
>> fileSystemRepresentation], &destinationDirectoryRef, NULL);
>>
>> OptionBits options = kFSFileOperationDefaultOptions;
>>
>>
>> // Do the copy
>> err = FSCopyObjectAsync(fileOp, &sourceFileRef,
>> &destinationDirectoryRef, NULL, options, NULL, 0.01, NULL);
>>
>> while (YES)
>> {
>> CFRunLoopRunInMode(kCFRunLoopDefaultMode, 5.0, true);
>>
>> CFDictionaryRef infoDict2;
>> (void) FSFileOperationCopyStatus(fileOp, NULL, NULL, &err,
>> &infoDict2, NULL);
>>
>> NSLog(@"%@", (NSDictionary *)infoDict2);
>> }
>> }
>>
>> Now obviously, I need to do this in a separate thread which isn't
>> a problem. However, what I don't really understand is what
>> exactly goes on with the CFRunLoopRunInMode call. It seems that
>> during the duration of this method, that's when a chunk of file
>> copying is actually done, but once I stick the code in a thread,
>> should I really use this, or is there something better?
>
> You don't actually have to do this in a separate thread. You can
> register a callback and execute this operation on your main thread
> (the main thread in a Cocoa application has an active runloop). You
> will get callbacks from your main runloop as the copy progresses
> and when it finishes.
>
> The example above is written to be run from a secondary thread and
> doesn't leverage the callback capability (why it is running its own
> runloop periodically).
>
> Review the docs on runloops (CFRunLoop and NSRunLoop) if you don't
> understand what those are.
>
> -Shawn
| Related mails | Author | Date |
|---|---|---|
| Mike Abdullah | Jul 31, 18:04 | |
| Scott Ribe | Jul 31, 19:32 | |
| Mike Abdullah | Aug 1, 02:06 | |
| Adam R. Maxwell | Aug 1, 03:33 | |
| Mike Abdullah | Aug 1, 17:38 | |
| Shawn Erickson | Aug 1, 17:51 | |
| Mike Abdullah | Aug 1, 19:50 |






Cocoa mail archive

