diff options
author | 2013-06-26 02:35:34 -0700 | |
---|---|---|
committer | 2013-06-26 02:35:34 -0700 | |
commit | e8649c3ecfc093e379439aa4e88910b3dc27422e (patch) | |
tree | 296c456f51d43b8f4fc2184045aea3de16502f0f /src/async/pop | |
parent | 74558e034a096331841a0327a48fdfc5ab095ec6 (diff) |
Logger API for SMTP, POP
Diffstat (limited to 'src/async/pop')
-rw-r--r-- | src/async/pop/MCPOPAsyncSession.cc | 58 | ||||
-rw-r--r-- | src/async/pop/MCPOPAsyncSession.h | 9 |
2 files changed, 66 insertions, 1 deletions
diff --git a/src/async/pop/MCPOPAsyncSession.cc b/src/async/pop/MCPOPAsyncSession.cc index 1269a34b..d72da0b3 100644 --- a/src/async/pop/MCPOPAsyncSession.cc +++ b/src/async/pop/MCPOPAsyncSession.cc @@ -15,6 +15,7 @@ #include "MCPOPFetchMessagesOperation.h" #include "MCPOPCheckAccountOperation.h" #include "MCOperationQueueCallback.h" +#include "MCConnectionLogger.h" using namespace mailcore; @@ -39,6 +40,24 @@ namespace mailcore { private: POPAsyncSession * mSession; }; + + class POPConnectionLogger : public Object, public ConnectionLogger { + public: + POPConnectionLogger(POPAsyncSession * session) { + mSession = session; + } + + virtual ~POPConnectionLogger() { + } + + virtual void log(void * context, void * sender, ConnectionLogType logType, Data * buffer) + { + mSession->logConnection(logType, buffer); + } + + private: + POPAsyncSession * mSession; + }; } POPAsyncSession::POPAsyncSession() @@ -47,10 +66,16 @@ POPAsyncSession::POPAsyncSession() mQueue = new OperationQueue(); mQueueCallback = new POPOperationQueueCallback(this); mQueue->setCallback(mQueueCallback); + mConnectionLogger = NULL; + pthread_mutex_init(&mConnectionLoggerLock, NULL); + mInternalLogger = new POPConnectionLogger(this); + mSession->setConnectionLogger(mInternalLogger); } POPAsyncSession::~POPAsyncSession() { + MC_SAFE_RELEASE(mInternalLogger); + pthread_mutex_destroy(&mConnectionLoggerLock); MC_SAFE_RELEASE(mQueueCallback); MC_SAFE_RELEASE(mSession); MC_SAFE_RELEASE(mQueue); @@ -193,3 +218,36 @@ void POPAsyncSession::runOperation(POPOperation * operation) { mQueue->addOperation(operation); } + +void POPAsyncSession::setConnectionLogger(ConnectionLogger * logger) +{ + pthread_mutex_lock(&mConnectionLoggerLock); + mConnectionLogger = logger; + if (mConnectionLogger != NULL) { + mSession->setConnectionLogger(mInternalLogger); + } + else { + mSession->setConnectionLogger(NULL); + } + pthread_mutex_unlock(&mConnectionLoggerLock); +} + +ConnectionLogger * POPAsyncSession::connectionLogger() +{ + ConnectionLogger * result; + + pthread_mutex_lock(&mConnectionLoggerLock); + result = mConnectionLogger; + pthread_mutex_unlock(&mConnectionLoggerLock); + + return result; +} + +void POPAsyncSession::logConnection(ConnectionLogType logType, Data * buffer) +{ + pthread_mutex_lock(&mConnectionLoggerLock); + if (mConnectionLogger != NULL) { + mConnectionLogger->log(mConnectionLogger->context(), this, logType, buffer); + } + pthread_mutex_unlock(&mConnectionLoggerLock); +} diff --git a/src/async/pop/MCPOPAsyncSession.h b/src/async/pop/MCPOPAsyncSession.h index 452d4d75..0345ecd6 100644 --- a/src/async/pop/MCPOPAsyncSession.h +++ b/src/async/pop/MCPOPAsyncSession.h @@ -23,6 +23,7 @@ namespace mailcore { class POPDeleteMessagesOperation; class POPFetchMessagesOperation; class POPOperationQueueCallback; + class POPConnectionLogger; class POPAsyncSession : public Object { public: @@ -53,6 +54,9 @@ namespace mailcore { virtual void setCheckCertificateEnabled(bool enabled); virtual bool isCheckCertificateEnabled(); + virtual void setConnectionLogger(ConnectionLogger * logger); + virtual ConnectionLogger * connectionLogger(); + virtual POPFetchMessagesOperation * fetchMessagesOperation(); virtual POPFetchHeaderOperation * fetchHeaderOperation(unsigned int index); @@ -70,11 +74,14 @@ namespace mailcore { POPSession * mSession; OperationQueue * mQueue; POPOperationQueueCallback * mQueueCallback; + ConnectionLogger * mConnectionLogger; + pthread_mutex_t mConnectionLoggerLock; + POPConnectionLogger * mInternalLogger; public: // private virtual void runOperation(POPOperation * operation); virtual POPSession * session(); - + virtual void logConnection(ConnectionLogType logType, Data * buffer); }; } |