diff options
author | CodaFi <devteam.codafi@gmail.com> | 2013-09-24 21:57:10 -0600 |
---|---|---|
committer | CodaFi <devteam.codafi@gmail.com> | 2013-09-24 21:57:10 -0600 |
commit | 63f2b3e29d92077a30f198ccfb6fe4cb7f262f87 (patch) | |
tree | be52bfb77f420798480748adb79a9373cd6fce0b /src/objc | |
parent | aae824111ba707346e1b90a0f9c778d9618d6c91 (diff) |
Implement Objective-C Interface
Diffstat (limited to 'src/objc')
-rw-r--r-- | src/objc/abstract/MCOConstants.h | 2 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPNoopOperation.h | 32 | ||||
-rw-r--r-- | src/objc/imap/MCOIMAPNoopOperation.mm | 69 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.h | 10 | ||||
-rwxr-xr-x | src/objc/imap/MCOIMAPSession.mm | 6 | ||||
-rw-r--r-- | src/objc/pop/MCOPOPNoopOperation.h | 34 | ||||
-rw-r--r-- | src/objc/pop/MCOPOPNoopOperation.mm | 70 | ||||
-rw-r--r-- | src/objc/pop/MCOPOPSession.h | 10 | ||||
-rw-r--r-- | src/objc/pop/MCOPOPSession.mm | 6 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPNoopOperation.h | 32 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPNoopOperation.mm | 66 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPSession.h | 10 | ||||
-rw-r--r-- | src/objc/smtp/MCOSMTPSession.mm | 9 | ||||
-rw-r--r-- | src/objc/utils/NSError+MCO.mm | 1 |
14 files changed, 357 insertions, 0 deletions
diff --git a/src/objc/abstract/MCOConstants.h b/src/objc/abstract/MCOConstants.h index b2516754..0c0f701b 100644 --- a/src/objc/abstract/MCOConstants.h +++ b/src/objc/abstract/MCOConstants.h @@ -334,6 +334,8 @@ typedef enum { MCOErrorNoSender, /** SMTP: Error when no recipient has been specified.*/ MCOErrorNoRecipient, + /** IMAP: Error when a noop operation fails.*/ + MCOErrorNoop, /** The count of all errors */ MCOErrorCodeCount, } MCOErrorCode; diff --git a/src/objc/imap/MCOIMAPNoopOperation.h b/src/objc/imap/MCOIMAPNoopOperation.h new file mode 100644 index 00000000..9e876748 --- /dev/null +++ b/src/objc/imap/MCOIMAPNoopOperation.h @@ -0,0 +1,32 @@ +// +// MCOIMAPNoopOperation.h +// mailcore2 +// +// Created by Robert Widmann on 9/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOIMAPNOOPOPERATION_H_ + +#define __MAILCORE_MCOIMAPNOOPOPERATION_H_ + +#import <MailCore/MCOIMAPBaseOperation.h> + +/* The class is used to perform a No-Op operation. */ +@interface MCOIMAPNoopOperation : MCOIMAPBaseOperation + +/** + Starts the asynchronous operation. + + @param completionBlock Called when the operation is finished. + + - On success `error` will be nil + + - On failure, `error` will be set + */ + +- (void) start:(void (^)(NSError * error))completionBlock; + +@end + +#endif diff --git a/src/objc/imap/MCOIMAPNoopOperation.mm b/src/objc/imap/MCOIMAPNoopOperation.mm new file mode 100644 index 00000000..a8878713 --- /dev/null +++ b/src/objc/imap/MCOIMAPNoopOperation.mm @@ -0,0 +1,69 @@ +// +// MCOIMAPNoopOperation.m +// mailcore2 +// +// Created by Robert Widmann on 9/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOIMAPNoopOperation.h" + +#include "MCAsyncIMAP.h" + +#import "MCOOperation+Private.h" +#import "MCOUtils.h" + +typedef void (^CompletionType)(NSError * error); + +@implementation MCOIMAPNoopOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::IMAPNoopOperation + ++ (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 { + _completionBlock([NSError mco_errorWithErrorCode:op->error()]); + } + [_completionBlock release]; + _completionBlock = nil; +} + +@end diff --git a/src/objc/imap/MCOIMAPSession.h b/src/objc/imap/MCOIMAPSession.h index 0759f714..82963f90 100755 --- a/src/objc/imap/MCOIMAPSession.h +++ b/src/objc/imap/MCOIMAPSession.h @@ -503,6 +503,16 @@ - (MCOIMAPOperation *)connectOperation; /** + Returns an operation that will perform a No-Op operation on the given IMAP server. + + MCOIMAPOperation * op = [session noopOperation]; + [op start:^(NSError * error) { + ... + }]; + */ +- (MCOIMAPOperation *) noopOperation; + +/** Returns an operation that will check whether the IMAP account is valid. MCOIMAPOperation * op = [session checkAccountOperation]; diff --git a/src/objc/imap/MCOIMAPSession.mm b/src/objc/imap/MCOIMAPSession.mm index e7732b16..38924c83 100755 --- a/src/objc/imap/MCOIMAPSession.mm +++ b/src/objc/imap/MCOIMAPSession.mm @@ -396,6 +396,12 @@ MCO_OBJC_SYNTHESIZE_SCALAR(unsigned int, unsigned int, setMaximumConnections, ma return OPAQUE_OPERATION(coreOp); } +- (MCOIMAPOperation *) noopOperation +{ + IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->noopOperation(); + return OPAQUE_OPERATION(coreOp); +} + - (MCOIMAPOperation *)checkAccountOperation { IMAPOperation *coreOp = MCO_NATIVE_INSTANCE->checkAccountOperation(); diff --git a/src/objc/pop/MCOPOPNoopOperation.h b/src/objc/pop/MCOPOPNoopOperation.h new file mode 100644 index 00000000..9fad4196 --- /dev/null +++ b/src/objc/pop/MCOPOPNoopOperation.h @@ -0,0 +1,34 @@ +// +// MCOPOPNoopOperation.h +// mailcore2 +// +// Created by Robert Widmann on 9/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOPOPNOOPOPERATION_H_ + +#define __MAILCORE_MCOPOPNOOPOPERATION_H_ + +#import <Foundation/Foundation.h> +#import <MailCore/MCOPOPOperation.h> + +/** This is an asynchronous operation that will perform a No-Op on the POP3 account. */ + +@interface MCOPOPNoopOperation : MCOPOPOperation + +/** + Starts the asynchronous noop operation. + + @param completionBlock Called when the operation is finished. + + - On success `error` will be nil + + - On failure, `error` will be set with `MCOErrorDomain` as domain and an + error code available in MCOConstants.h + */ +- (void) start:(void (^)(NSError * error))completionBlock; + +@end + +#endif diff --git a/src/objc/pop/MCOPOPNoopOperation.mm b/src/objc/pop/MCOPOPNoopOperation.mm new file mode 100644 index 00000000..b8faf30f --- /dev/null +++ b/src/objc/pop/MCOPOPNoopOperation.mm @@ -0,0 +1,70 @@ +// +// MCOPOPNoopOperation.m +// mailcore2 +// +// Created by Robert Widmann on 9/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOPOPNoopOperation.h" + +#include "MCAsyncPOP.h" + +#import "MCOOperation+Private.h" +#import "MCOUtils.h" + +typedef void (^CompletionType)(NSError *error); + +@implementation MCOPOPNoopOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::POPNoopOperation + ++ (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 { + _completionBlock([NSError mco_errorWithErrorCode:op->error()]); + } + [_completionBlock release]; + _completionBlock = nil; +} + + +@end diff --git a/src/objc/pop/MCOPOPSession.h b/src/objc/pop/MCOPOPSession.h index 4f98421c..aa381a62 100644 --- a/src/objc/pop/MCOPOPSession.h +++ b/src/objc/pop/MCOPOPSession.h @@ -130,6 +130,16 @@ See MCOConnectionType for more information.*/ */ - (MCOPOPOperation *) checkAccountOperation; +/** + Returns an operation that will perform a No-Op operation. + + MCOPOPOperation * op = [session noopOperation]; + [op start:^(NSError * error) { + ... + }]; + */ +- (MCOPOPOperation *) noopOperation; + @end #endif diff --git a/src/objc/pop/MCOPOPSession.mm b/src/objc/pop/MCOPOPSession.mm index fb48cb1e..1037f951 100644 --- a/src/objc/pop/MCOPOPSession.mm +++ b/src/objc/pop/MCOPOPSession.mm @@ -158,6 +158,12 @@ MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled) return OPAQUE_OPERATION(coreOp); } +- (MCOPOPOperation *) noopOperation +{ + mailcore::POPOperation * coreOp = MCO_NATIVE_INSTANCE->noopOperation(); + return OPAQUE_OPERATION(coreOp); +} + - (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data { _connectionLogger(sender, logType, data); diff --git a/src/objc/smtp/MCOSMTPNoopOperation.h b/src/objc/smtp/MCOSMTPNoopOperation.h new file mode 100644 index 00000000..38ab386e --- /dev/null +++ b/src/objc/smtp/MCOSMTPNoopOperation.h @@ -0,0 +1,32 @@ +// +// MCOSMTPNoopOperation.h +// mailcore2 +// +// Created by Robert Widmann on 9/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCOSMTPNOOPOPERATION_H_ + +#define __MAILCORE_MCOSMTPNOOPOPERATION_H_ + +#import <MailCore/MCOSMTPOperation.h> + +/** This is an asynchronous operation that will perform a noop operation through SMTP. */ +@interface MCOSMTPNoopOperation : MCOSMTPOperation + +/* + Starts the asynchronous operation. + + @param completionBlock Called when the operation is finished. + + - On success `error` will be nil + + - On failure, `error` will be set with `MCOErrorDomain` as domain and an + error code available in MCOConstants.h, + */ +- (void) start:(void (^)(NSError * error))completionBlock; + +@end + +#endif diff --git a/src/objc/smtp/MCOSMTPNoopOperation.mm b/src/objc/smtp/MCOSMTPNoopOperation.mm new file mode 100644 index 00000000..3a1fced0 --- /dev/null +++ b/src/objc/smtp/MCOSMTPNoopOperation.mm @@ -0,0 +1,66 @@ +// +// MCOSMTPNoopOperation.m +// mailcore2 +// +// Created by Robert Widmann on 9/24/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#import "MCOSMTPNoopOperation.h" + +#include "MCAsyncSMTP.h" + +#import "MCOUtils.h" +#import "MCOOperation+Private.h" + +typedef void (^CompletionType)(NSError *error); + +@implementation MCOSMTPNoopOperation { + CompletionType _completionBlock; +} + +#define nativeType mailcore::SMTPNoopOperation + ++ (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; + + NSError * error = [NSError mco_errorWithErrorCode:MCO_NATIVE_INSTANCE->error()]; + _completionBlock(error); + [_completionBlock release]; + _completionBlock = NULL; +} + + +@end diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h index 6716ee30..90351551 100644 --- a/src/objc/smtp/MCOSMTPSession.h +++ b/src/objc/smtp/MCOSMTPSession.h @@ -120,6 +120,16 @@ */ - (MCOSMTPOperation *) checkAccountOperationWithFrom:(MCOAddress *)from; +/** + Returns an operation that will perform a No-Op. + + MCOPOPOperation * op = [session noopOperation]; + [op start:^(NSError * error) { + ... + }]; + */ +- (MCOSMTPOperation *) noopOperation; + @end #endif diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm index 0c24f66c..29211118 100644 --- a/src/objc/smtp/MCOSMTPSession.mm +++ b/src/objc/smtp/MCOSMTPSession.mm @@ -12,6 +12,7 @@ #import "MCOUtils.h" #import "MCOSMTPSendOperation.h" +#import "MCOSMTPNoopOperation.h" #import "MCOSMTPOperation.h" #import "MCOOperation+Private.h" #import "MCOAddress.h" @@ -130,6 +131,14 @@ MCO_OBJC_SYNTHESIZE_BOOL(setUseHeloIPEnabled, useHeloIPEnabled) return result; } +- (MCOSMTPOperation *) noopOperation +{ + mailcore::SMTPOperation * coreOp = MCO_NATIVE_INSTANCE->noopOperation(); + MCOSMTPNoopOperation * result = [[[MCOSMTPNoopOperation alloc] initWithMCOperation:coreOp] autorelease]; + [result setSession:self]; + return result; +} + - (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data { _connectionLogger(sender, logType, data); diff --git a/src/objc/utils/NSError+MCO.mm b/src/objc/utils/NSError+MCO.mm index 8b903043..6d49e4bb 100644 --- a/src/objc/utils/NSError+MCO.mm +++ b/src/objc/utils/NSError+MCO.mm @@ -47,6 +47,7 @@ static NSString * MCOLocalizedDescriptionTable[] = { @"Compression is not available", /** MCOErrorCompression */ @"A sender is required to send message", /** MCOErrorNoSender */ @"A recipient is required to send message", /** MCOErrorNoRecipient */ + @"An error occured while performing a No-Op operation.", /** MCOErrorNoop */ }; @implementation NSError (MCO) |