aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objc/pop/MCOPOPSession.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/objc/pop/MCOPOPSession.mm')
-rw-r--r--src/objc/pop/MCOPOPSession.mm58
1 files changed, 55 insertions, 3 deletions
diff --git a/src/objc/pop/MCOPOPSession.mm b/src/objc/pop/MCOPOPSession.mm
index 11f7cad6..42c76646 100644
--- a/src/objc/pop/MCOPOPSession.mm
+++ b/src/objc/pop/MCOPOPSession.mm
@@ -16,8 +16,34 @@
#import "MCOPOPFetchMessagesOperation.h"
#import "MCOPOPOperation+Private.h"
+using namespace mailcore;
+
+@interface MCOPOPSession ()
+
+- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data;
+
+@end
+
+class MCOPOPConnectionLoggerBridge : public Object, public ConnectionLogger {
+public:
+ MCOPOPConnectionLoggerBridge(MCOPOPSession * session)
+ {
+ mSession = session;
+ }
+
+ virtual void log(void * context, void * sender, ConnectionLogType logType, Data * data)
+ {
+ [mSession _logWithSender:sender connectionType:(MCOConnectionLogType)logType data:MCO_TO_OBJC(data)];
+ }
+
+private:
+ MCOPOPSession * mSession;
+};
+
@implementation MCOPOPSession {
mailcore::POPAsyncSession * _session;
+ MCOConnectionLogger _connectionLogger;
+ MCOPOPConnectionLoggerBridge * _loggerBridge;
}
#define nativeType mailcore::POPAsyncSession
@@ -34,13 +60,16 @@
- (id)init {
self = [super init];
- if (self) {
- _session = new mailcore::POPAsyncSession();
- }
+
+ _session = new mailcore::POPAsyncSession();
+ _loggerBridge = new MCOPOPConnectionLoggerBridge(self);
+
return self;
}
- (void)dealloc {
+ MC_SAFE_RELEASE(_loggerBridge);
+ [_connectionLogger release];
_session->release();
[super dealloc];
}
@@ -54,6 +83,24 @@ MCO_OBJC_SYNTHESIZE_SCALAR(MCOConnectionType, mailcore::ConnectionType, setConne
MCO_OBJC_SYNTHESIZE_SCALAR(NSTimeInterval, time_t, setTimeout, timeout)
MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled)
+- (void) setConnectionLogger:(MCOConnectionLogger)connectionLogger
+{
+ [_connectionLogger release];
+ _connectionLogger = [connectionLogger copy];
+
+ if (_connectionLogger != nil) {
+ _session->setConnectionLogger(_loggerBridge);
+ }
+ else {
+ _session->setConnectionLogger(NULL);
+ }
+}
+
+- (MCOConnectionLogger) connectionLogger
+{
+ return _connectionLogger;
+}
+
#pragma mark - Operations
@@ -111,4 +158,9 @@ MCO_OBJC_SYNTHESIZE_BOOL(setCheckCertificateEnabled, isCheckCertificateEnabled)
return OPAQUE_OPERATION(coreOp);
}
+- (void) _logWithSender:(void *)sender connectionType:(MCOConnectionLogType)logType data:(NSData *)data
+{
+ _connectionLogger(sender, logType, data);
+}
+
@end