aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/smtp
diff options
context:
space:
mode:
authorGravatar Hoa V. Dinh <dinh.viet.hoa@gmail.com>2014-12-18 12:38:10 -0800
committerGravatar Hoa V. Dinh <dinh.viet.hoa@gmail.com>2014-12-18 12:38:10 -0800
commit3dfb8a6907c66698700cfaf279d4f94e7cd0f21e (patch)
treefca8bf99786e56ddb3f2e3354a6ff13554c57b4b /src/objc/smtp
parentc1607b6787a8430d32058c6ab430bcc75285a577 (diff)
Fixed #1002: implemented operationqueue callback for smtp/nntp/pop
Diffstat (limited to 'src/objc/smtp')
-rw-r--r--src/objc/smtp/MCOSMTPSession.h24
-rw-r--r--src/objc/smtp/MCOSMTPSession.mm63
2 files changed, 80 insertions, 7 deletions
diff --git a/src/objc/smtp/MCOSMTPSession.h b/src/objc/smtp/MCOSMTPSession.h
index db9056b8..64389c14 100644
--- a/src/objc/smtp/MCOSMTPSession.h
+++ b/src/objc/smtp/MCOSMTPSession.h
@@ -86,6 +86,30 @@
@property (nonatomic, assign) dispatch_queue_t dispatchQueue;
#endif
+/**
+ The value will be YES when asynchronous operations are running, else it will return NO.
+ */
+@property (nonatomic, assign, readonly, getter=isOperationQueueRunning) BOOL operationQueueRunning;
+
+/**
+ Sets operation running callback. It will be called when operations start or stop running.
+
+ [session setOperationQueueRunningChangeBlock:^{
+ if ([session isOperationQueueRunning]) {
+ ...
+ }
+ else {
+ ...
+ }
+ }];
+ */
+@property (nonatomic, copy) MCOOperationQueueRunningChangeBlock operationQueueRunningChangeBlock;
+
+/**
+ Cancel all operations
+ */
+- (void) cancelAllOperations;
+
/** @name Operations */
/**
diff --git a/src/objc/smtp/MCOSMTPSession.mm b/src/objc/smtp/MCOSMTPSession.mm
index 6b40c709..eb48f3fb 100644
--- a/src/objc/smtp/MCOSMTPSession.mm
+++ b/src/objc/smtp/MCOSMTPSession.mm
@@ -18,18 +18,20 @@
#import "MCOOperation+Private.h"
#import "MCOAddress.h"
#import "MCOSMTPOperation+Private.h"
+#include "MCOperationQueueCallback.h"
using namespace mailcore;
@interface MCOSMTPSession ()
- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data;
+- (void) _queueRunningChanged;
@end
-class MCOSMTPConnectionLoggerBridge : public Object, public ConnectionLogger {
+class MCOSMTPCallbackBridge : public Object, public ConnectionLogger, public OperationQueueCallback {
public:
- MCOSMTPConnectionLoggerBridge(MCOSMTPSession * session)
+ MCOSMTPCallbackBridge(MCOSMTPSession * session)
{
mSession = session;
}
@@ -38,7 +40,17 @@ public:
{
[mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
}
-
+
+ virtual void queueStartRunning()
+ {
+ [mSession _queueRunningChanged];
+ }
+
+ virtual void queueStoppedRunning()
+ {
+ [mSession _queueRunningChanged];
+ }
+
private:
MCOSMTPSession * mSession;
};
@@ -46,7 +58,8 @@ private:
@implementation MCOSMTPSession {
mailcore::SMTPAsyncSession * _session;
MCOConnectionLogger _connectionLogger;
- MCOSMTPConnectionLoggerBridge * _loggerBridge;
+ MCOSMTPCallbackBridge * _callbackBridge;
+ MCOOperationQueueRunningChangeBlock _operationQueueRunningChangeBlock;
}
#define nativeType mailcore::SMTPAsyncSession
@@ -60,13 +73,13 @@ private:
self = [super init];
_session = new mailcore::SMTPAsyncSession();
- _loggerBridge = new MCOSMTPConnectionLoggerBridge(self);
+ _callbackBridge = new MCOSMTPCallbackBridge(self);
return self;
}
- (void)dealloc {
- MC_SAFE_RELEASE(_loggerBridge);
+ MC_SAFE_RELEASE(_callbackBridge);
[_connectionLogger release];
_session->setConnectionLogger(NULL);
_session->release();
@@ -91,7 +104,7 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
_connectionLogger = [connectionLogger copy];
if (_connectionLogger != nil) {
- _session->setConnectionLogger(_loggerBridge);
+ _session->setConnectionLogger(_callbackBridge);
}
else {
_session->setConnectionLogger(NULL);
@@ -103,6 +116,29 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
return _connectionLogger;
}
+- (void) setOperationQueueRunningChangeBlock:(MCOOperationQueueRunningChangeBlock)operationQueueRunningChangeBlock
+{
+ [_operationQueueRunningChangeBlock release];
+ _operationQueueRunningChangeBlock = [operationQueueRunningChangeBlock copy];
+
+ if (_operationQueueRunningChangeBlock != nil) {
+ _session->setOperationQueueCallback(_callbackBridge);
+ }
+ else {
+ _session->setOperationQueueCallback(NULL);
+ }
+}
+
+- (MCOOperationQueueRunningChangeBlock) operationQueueRunningChangeBlock
+{
+ return _operationQueueRunningChangeBlock;
+}
+
+- (void) cancelAllOperations
+{
+ MCO_NATIVE_INSTANCE->cancelAllOperations();
+}
+
#pragma mark - Operations
- (MCOSMTPOperation *) loginOperation
@@ -155,4 +191,17 @@ MCO_OBJC_SYNTHESIZE_SCALAR(dispatch_queue_t, dispatch_queue_t, setDispatchQueue,
_connectionLogger(sender, logType, data);
}
+- (void) _queueRunningChanged
+{
+ if (_operationQueueRunningChangeBlock == NULL)
+ return;
+
+ _operationQueueRunningChangeBlock();
+}
+
+- (BOOL) isOperationQueueRunning
+{
+ return _session->isOperationQueueRunning();
+}
+
@end