aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/imap/MCOIMAPFetchContentOperation.mm
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-03-26 00:58:03 -0700
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2013-03-26 00:58:03 -0700
commit1640f3525f830df5382edb96f6e6f6a71993787c (patch)
treee69912e9934bf1400d8d49f03cfa4b6f71749d48 /src/objc/imap/MCOIMAPFetchContentOperation.mm
parent1353cb0ee96d92192f05e1feb1518e1534ba8cbe (diff)
IMAP ObjC async operations implemented
Diffstat (limited to 'src/objc/imap/MCOIMAPFetchContentOperation.mm')
-rw-r--r--src/objc/imap/MCOIMAPFetchContentOperation.mm55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/objc/imap/MCOIMAPFetchContentOperation.mm b/src/objc/imap/MCOIMAPFetchContentOperation.mm
new file mode 100644
index 00000000..233eaff8
--- /dev/null
+++ b/src/objc/imap/MCOIMAPFetchContentOperation.mm
@@ -0,0 +1,55 @@
+//
+// MCOIMAPFetchContentOperation.m
+// mailcore2
+//
+// Created by DINH Viêt Hoà on 3/25/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPFetchContentOperation.h"
+
+#include "MCAsyncIMAP.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^completionType)(NSError *error, NSData * data);
+
+@implementation MCOIMAPFetchContentOperation {
+ completionType _completionBlock;
+}
+
+#define nativeType mailcore::IMAPFetchContentOperation
+
++ (void) load
+{
+ MCORegisterClass(self, &typeid(nativeType));
+}
+
++ (NSObject *) mco_objectWithMCObject:(mailcore::Object *)object
+{
+ nativeType * op = (nativeType *) object;
+ return [[[self alloc] initWithMCOperation:op] autorelease];
+}
+
+- (void) dealloc
+{
+ [_completionBlock release];
+ [super dealloc];
+}
+
+- (void)start:(void (^)(NSError *error, NSData * data))completionBlock {
+ _completionBlock = [completionBlock copy];
+ [self start];
+}
+
+- (void)operationCompleted {
+ nativeType *op = MCO_NATIVE_INSTANCE;
+ if (op->error() == mailcore::ErrorNone) {
+ _completionBlock(nil, MCO_TO_OBJC(op->data()));
+ } else {
+ _completionBlock([NSError mco_errorWithErrorCode:op->error()], nil);
+ }
+}
+
+@end