aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc
diff options
context:
space:
mode:
authorGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2016-03-07 22:14:47 -0800
committerGravatar Hoa V. DINH <dinh.viet.hoa@gmail.com>2016-03-07 22:14:47 -0800
commitf3be74e24f4b460bf309e4b6289973c34b137382 (patch)
treeda08b5c577685b6fc395d87a287b8d8717cbb149 /src/objc
parenta55c8f370bd663ea1d31fed230987711aa1cf176 (diff)
Improved error management
Diffstat (limited to 'src/objc')
-rw-r--r--src/objc/imap/MCOIMAPCheckAccountOperation.h22
-rw-r--r--src/objc/imap/MCOIMAPCheckAccountOperation.mm74
-rwxr-xr-xsrc/objc/imap/MCOIMAPSession.mm2
3 files changed, 97 insertions, 1 deletions
diff --git a/src/objc/imap/MCOIMAPCheckAccountOperation.h b/src/objc/imap/MCOIMAPCheckAccountOperation.h
new file mode 100644
index 00000000..f2ad3340
--- /dev/null
+++ b/src/objc/imap/MCOIMAPCheckAccountOperation.h
@@ -0,0 +1,22 @@
+//
+// MCOIMAPCheckAccountOperation.h
+// mailcore2
+//
+// Created by Hoa V. DINH on 3/7/16.
+// Copyright © 2016 MailCore. All rights reserved.
+//
+
+#ifndef MAILCORE_MCOIMAPCHECKACCOUNTOPERATION_H
+
+#define MAILCORE_MCOIMAPCHECKACCOUNTOPERATION_H
+
+#import <MailCore/MCOIMAPOperation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+/* The class is used to perform a No-Op operation. */
+@interface MCOIMAPCheckAccountOperation : MCOIMAPOperation
+
+@end
+NS_ASSUME_NONNULL_END
+
+#endif
diff --git a/src/objc/imap/MCOIMAPCheckAccountOperation.mm b/src/objc/imap/MCOIMAPCheckAccountOperation.mm
new file mode 100644
index 00000000..f1aa59b4
--- /dev/null
+++ b/src/objc/imap/MCOIMAPCheckAccountOperation.mm
@@ -0,0 +1,74 @@
+//
+// MCOIMAPCheckAccountOperation.m
+// mailcore2
+//
+// Created by Hoa V. DINH on 3/7/16.
+// Copyright © 2016 MailCore. All rights reserved.
+//
+
+#import "MCOIMAPCheckAccountOperation.h"
+
+#include "MCIMAPCheckAccountOperation.h"
+
+#import "MCOOperation+Private.h"
+#import "MCOUtils.h"
+
+typedef void (^CompletionType)(NSError *error);
+
+@implementation MCOIMAPCheckAccountOperation {
+ CompletionType _completionBlock;
+}
+
+#define nativeType mailcore::IMAPCheckAccountOperation
+
++ (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))completionBlock
+{
+ _completionBlock = [completionBlock copy];
+ [self start];
+}
+
+- (void) cancel
+{
+ [_completionBlock release];
+ _completionBlock = nil;
+ [super cancel];
+}
+
+- (void) operationCompleted
+{
+ if (_completionBlock == NULL)
+ return;
+
+ nativeType *op = MCO_NATIVE_INSTANCE;
+ if (op->error() == mailcore::ErrorNone) {
+ _completionBlock(nil);
+ } else {
+ NSError * error = [NSError mco_errorWithErrorCode:op->error()];
+ if (op->loginResponse() != NULL) {
+ NSDictionary * userInfo = @{@"IMAPServerError": MCO_TO_OBJC(op->loginResponse())};
+ error = [NSError errorWithDomain:[error domain] code:[error code] userInfo:userInfo];
+ }
+ _completionBlock(error);
+ }
+ [_completionBlock release];
+ _completionBlock = nil;
+}
+
+@end
diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm
index fdd57886..bec998c8 100755
--- a/src/objc/imap/MCOIMAPSession.mm
+++ b/src/objc/imap/MCOIMAPSession.mm
@@ -616,7 +616,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
- (MCOIMAPOperation *)checkAccountOperation
{
IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation();
- return OPAQUE_OPERATION(coreOp);
+ return MCO_TO_OBJC_OP(coreOp);
}
- (MCOIMAPCapabilityOperation *) capabilityOperation