aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/utils
diff options
context:
space:
mode:
authorGravatar DINH Viet Hoa <dinh.viet.hoa@gmail.com>2013-03-22 18:25:43 -0700
committerGravatar DINH Viet Hoa <dinh.viet.hoa@gmail.com>2013-03-22 18:25:43 -0700
commitae907e6582b9d8faa49c85834dc8b4213af759ed (patch)
tree05a1f30f4e9d11f9632e6c1132e71ebd0e098c2b /src/objc/utils
parent490cc1aff6766defd64d52318389517f8b8b1c7f (diff)
moved MCOOperation to src/objc/utils
Diffstat (limited to 'src/objc/utils')
-rw-r--r--src/objc/utils/MCOOperation+Private.h23
-rw-r--r--src/objc/utils/MCOOperation.h15
-rw-r--r--src/objc/utils/MCOOperation.mm102
3 files changed, 140 insertions, 0 deletions
diff --git a/src/objc/utils/MCOOperation+Private.h b/src/objc/utils/MCOOperation+Private.h
new file mode 100644
index 00000000..620b0fe8
--- /dev/null
+++ b/src/objc/utils/MCOOperation+Private.h
@@ -0,0 +1,23 @@
+//
+// MCOOperation+Private.h
+// mailcore2
+//
+// Created by Matt Ronge on 01/31/13.
+// Copyright (c) 2013 MailCore. All rights reserved.
+//
+
+#ifdef __cplusplus
+namespace mailcore {
+ class Operation;
+}
+#endif
+
+// Shhh, secret stuff in here
+
+@interface MCOOperation (Private)
+#ifdef __cplusplus
+- (id)initWithMCOperation:(mailcore::Operation *)op;
+- (mailcore::Operation *)mcOperation;
+#endif
+- (void)start;
+@end \ No newline at end of file
diff --git a/src/objc/utils/MCOOperation.h b/src/objc/utils/MCOOperation.h
new file mode 100644
index 00000000..deafa165
--- /dev/null
+++ b/src/objc/utils/MCOOperation.h
@@ -0,0 +1,15 @@
+//
+// MCOOperation.h
+// mailcore2
+//
+// Created by Matt Ronge on 01/31/13.
+// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface MCOOperation : NSObject
+@property (readonly) BOOL isCancelled;
+
+- (void)cancel;
+@end
diff --git a/src/objc/utils/MCOOperation.mm b/src/objc/utils/MCOOperation.mm
new file mode 100644
index 00000000..b267dfc7
--- /dev/null
+++ b/src/objc/utils/MCOOperation.mm
@@ -0,0 +1,102 @@
+//
+// MCOOperation.m
+// mailcore2
+//
+// Created by Matt Ronge on 01/31/13.
+// Copyright (c) 2013 __MyCompanyName__. All rights reserved.
+//
+
+#import "MCOOperation.h"
+#import "MCOOperation+Private.h"
+
+#import "MCOperation.h"
+#import "MCOperationCallback.h"
+#import "MCOObjectWrapper.h"
+
+#import <Foundation/Foundation.h>
+
+using namespace mailcore;
+
+@interface MCOOperation ()
+- (void)_operationCompleted;
+@end
+
+class CompletionCallback : public Object, public OperationCallback {
+public:
+ CompletionCallback(MCOOperation *op) {
+ mOperation = op;
+ }
+
+ virtual void operationFinished(Operation * op)
+ {
+ [mOperation _operationCompleted];
+ }
+
+ private:
+ MCOOperation *mOperation;
+};
+
+@implementation MCOOperation {
+ Operation * _operation;
+ CompletionCallback * _callback;
+ BOOL _started;
+}
+
+- (id)initWithMCOperation:(Operation *)op
+{
+ self = [super init];
+
+ _operation = op;
+ _operation->retain();
+
+ _callback = new CompletionCallback(self);
+ _operation->setCallback(_callback);
+
+ return self;
+}
+
+- (void)dealloc
+{
+ _operation->release();
+ _callback->release();
+ [super dealloc];
+}
+
+- (BOOL)isCancelled
+{
+ return _operation->isCancelled();
+}
+
+- (void)cancel
+{
+ if (_started) {
+ _started = NO;
+ [self release];
+ }
+ _operation->cancel();
+}
+
+- (void)start
+{
+ _started = YES;
+ [self retain];
+ _operation->start();
+}
+
+- (mailcore::Operation *)mcOperation
+{
+ return _operation;
+}
+
+- (void)_operationCompleted
+{
+ _started = NO;
+ [self operationCompleted];
+ [self release];
+}
+
+- (void)operationCompleted
+{
+}
+
+@end