Source

kinect-viewer / KVDepthRecorder.m

Full commit
/*
 * Copyright 2010 Cliff L. Biffle.  All Rights Reserved.
 * Use of this source code is governed by the Apache License 2.0,
 * which can be found in the LICENSE file.
 */

#import "KVDepthRecorder.h"

@interface KVDepthRecorder ()

@property dispatch_queue_t dispatchQueue;
@property NSFileHandle *fileHandle;

@end


@implementation KVDepthRecorder
@synthesize fileHandle;
@synthesize dispatchQueue;

- init {
  if (!(self = [super init])) return nil;
  
  dispatchQueue = dispatch_queue_create("org.mg8.kinect.depth-recorder", 0);

  return self;
}

- (void)finalize {
  dispatch_release(dispatchQueue);
  [super finalize];
}

- (void) open: (NSString *) path {
  @synchronized (self) {
    [[NSFileManager defaultManager] createFileAtPath: path contents: nil attributes: nil];
    fileHandle = [NSFileHandle fileHandleForWritingAtPath: path];
  }
}

- (void) close {
  @synchronized (self) {
    NSFileHandle *h = fileHandle;
    fileHandle = nil;
    [h closeFile];
  }
}

- (void) setLatestDepthSamples: (NSData *) data {
  NSData *copy = [NSData dataWithBytes: [data bytes] length: [data length]];
  dispatch_async(dispatchQueue, ^{
    [fileHandle writeData: copy];
  });
}

- (NSData *) latestDepthSamples {
  return nil;
}

@end