aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/nntp
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/nntp
parentc1607b6787a8430d32058c6ab430bcc75285a577 (diff)
Fixed #1002: implemented operationqueue callback for smtp/nntp/pop
Diffstat (limited to 'src/objc/nntp')
-rw-r--r--src/objc/nntp/MCONNTPSession.h28
-rw-r--r--src/objc/nntp/MCONNTPSession.mm63
2 files changed, 84 insertions, 7 deletions
diff --git a/src/objc/nntp/MCONNTPSession.h b/src/objc/nntp/MCONNTPSession.h
index 413de507..083d973b 100644
--- a/src/objc/nntp/MCONNTPSession.h
+++ b/src/objc/nntp/MCONNTPSession.h
@@ -64,7 +64,35 @@
It will make MCONNTPSession safe. It will also set all the callbacks of operations to run on this given queue.
Defaults to the main queue.
This property should be used only if there's performance issue using MCONNTPSession in the main thread. */
+#if OS_OBJECT_USE_OBJC
+@property (nonatomic, retain) dispatch_queue_t dispatchQueue;
+#else
@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/nntp/MCONNTPSession.mm b/src/objc/nntp/MCONNTPSession.mm
index 95c87364..374e6018 100644
--- a/src/objc/nntp/MCONNTPSession.mm
+++ b/src/objc/nntp/MCONNTPSession.mm
@@ -15,18 +15,20 @@
#import "MCOOperation+Private.h"
#import "MCONNTPFetchAllArticlesOperation.h"
#import "MCONNTPOperation+Private.h"
+#include "MCOperationQueueCallback.h"
using namespace mailcore;
@interface MCONNTPSession ()
- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data;
+- (void) _queueRunningChanged;
@end
-class MCONNTPConnectionLoggerBridge : public Object, public ConnectionLogger {
+class MCONNTPCallbackBridge : public Object, public ConnectionLogger, public OperationQueueCallback {
public:
- MCONNTPConnectionLoggerBridge(MCONNTPSession * session)
+ MCONNTPCallbackBridge(MCONNTPSession * session)
{
mSession = session;
}
@@ -35,7 +37,17 @@ public:
{
[mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
}
-
+
+ virtual void queueStartRunning()
+ {
+ [mSession _queueRunningChanged];
+ }
+
+ virtual void queueStoppedRunning()
+ {
+ [mSession _queueRunningChanged];
+ }
+
private:
MCONNTPSession * mSession;
};
@@ -43,7 +55,8 @@ private:
@implementation MCONNTPSession {
mailcore::NNTPAsyncSession * _session;
MCOConnectionLogger _connectionLogger;
- MCONNTPConnectionLoggerBridge * _loggerBridge;
+ MCONNTPCallbackBridge * _callbackBridge;
+ MCOOperationQueueRunningChangeBlock _operationQueueRunningChangeBlock;
}
#define nativeType mailcore::NNTPAsyncSession
@@ -62,13 +75,13 @@ private:
self = [super init];
_session = new mailcore::NNTPAsyncSession();
- _loggerBridge = new MCONNTPConnectionLoggerBridge(self);
+ _callbackBridge = new MCONNTPCallbackBridge(self);
return self;
}
- (void)dealloc {
- MC_SAFE_RELEASE(_loggerBridge);
+ MC_SAFE_RELEASE(_callbackBridge);
[_connectionLogger release];
_session->setConnectionLogger(NULL);
_session->release();
@@ -90,7 +103,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);
@@ -102,6 +115,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
@@ -182,4 +218,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