diff options
Diffstat (limited to 'src/async/smtp')
-rw-r--r-- | src/async/smtp/MCSMTPAsyncSession.cc | 67 | ||||
-rw-r--r-- | src/async/smtp/MCSMTPAsyncSession.h | 12 | ||||
-rw-r--r-- | src/async/smtp/MCSMTPDisconnectOperation.cc | 28 | ||||
-rw-r--r-- | src/async/smtp/MCSMTPDisconnectOperation.h | 32 | ||||
-rw-r--r-- | src/async/smtp/MCSMTPOperation.cc | 1 |
5 files changed, 112 insertions, 28 deletions
diff --git a/src/async/smtp/MCSMTPAsyncSession.cc b/src/async/smtp/MCSMTPAsyncSession.cc index 95101a50..73bc2a54 100644 --- a/src/async/smtp/MCSMTPAsyncSession.cc +++ b/src/async/smtp/MCSMTPAsyncSession.cc @@ -1,22 +1,50 @@ #include "MCSMTPAsyncSession.h" #include "MCSMTPSession.h" -//#include "MCSMTPSendWithRecipientOperation.h" #include "MCSMTPSendWithDataOperation.h" -//#include "MCSMTPSendWithBuilderOperation.h" #include "MCSMTPCheckAccountOperation.h" +#include "MCSMTPDisconnectOperation.h" #include "MCSMTPOperation.h" +#include "MCOperationQueueCallback.h" using namespace mailcore; +namespace mailcore { + class SMTPOperationQueueCallback : public Object, public OperationQueueCallback { + public: + SMTPOperationQueueCallback(SMTPAsyncSession * session) { + mSession = session; + } + + virtual ~SMTPOperationQueueCallback() { + } + + virtual void queueStartRunning() { + mSession->retain(); + } + + virtual void queueStoppedRunning() { + mSession->tryAutomaticDisconnect(); + mSession->release(); + } + + private: + SMTPAsyncSession * mSession; + }; +} + SMTPAsyncSession::SMTPAsyncSession() { mSession = new SMTPSession(); mQueue = new OperationQueue(); + mQueueCallback = new SMTPOperationQueueCallback(this); + mQueue->setCallback(mQueueCallback); } SMTPAsyncSession::~SMTPAsyncSession() { + cancelDelayedPerformMethod((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL); + MC_SAFE_RELEASE(mQueueCallback); MC_SAFE_RELEASE(mQueue); MC_SAFE_RELEASE(mSession); } @@ -113,7 +141,7 @@ bool SMTPAsyncSession::useHeloIPEnabled() void SMTPAsyncSession::runOperation(SMTPOperation * operation) { -#warning disconnect after delay + cancelDelayedPerformMethod((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL); mQueue->addOperation(operation); } @@ -122,35 +150,31 @@ SMTPSession * SMTPAsyncSession::session() return mSession; } -#if 0 -SMTPOperation * SMTPAsyncSession::sendMessageOperationWithFromAndRecipient(Address * from, Array * recipients, Data * messageData) +void SMTPAsyncSession::tryAutomaticDisconnect() { - SMTPSendWithRecipientOperation * op = new SMTPSendWithRecipientOperation(); - op->setSession(this); - op->setFrom(from); - op->setRecipients(recipients); - op->setMessageData(messageData); - return (SMTPOperation *) op->autorelease(); + // It's safe since no thread is running when this function is called. + if (mSession->isDisconnected()) { + return; + } + + performMethodAfterDelay((Object::Method) &SMTPAsyncSession::tryAutomaticDisconnectAfterDelay, NULL, 30); } -#endif -SMTPOperation * SMTPAsyncSession::sendMessageOperation(Data * messageData) +void SMTPAsyncSession::tryAutomaticDisconnectAfterDelay(void * context) { - SMTPSendWithDataOperation * op = new SMTPSendWithDataOperation(); + SMTPDisconnectOperation * op = new SMTPDisconnectOperation(); op->setSession(this); - op->setMessageData(messageData); - return (SMTPOperation *) op->autorelease(); + op->autorelease(); + op->start(); } -#if 0 -SMTPOperation * SMTPAsyncSession::sendMessageOperation(MessageBuilder * msg) +SMTPOperation * SMTPAsyncSession::sendMessageOperation(Data * messageData) { - SMTPSendWithBuilderOperation * op = new SMTPSendWithBuilderOperation(); + SMTPSendWithDataOperation * op = new SMTPSendWithDataOperation(); op->setSession(this); - op->setBuilder(msg); + op->setMessageData(messageData); return (SMTPOperation *) op->autorelease(); } -#endif SMTPOperation * SMTPAsyncSession::checkAccountOperation(Address * from) { @@ -159,4 +183,3 @@ SMTPOperation * SMTPAsyncSession::checkAccountOperation(Address * from) op->setSession(this); return (SMTPOperation *) op->autorelease(); } - diff --git a/src/async/smtp/MCSMTPAsyncSession.h b/src/async/smtp/MCSMTPAsyncSession.h index 0be287af..9cd7a8f0 100644 --- a/src/async/smtp/MCSMTPAsyncSession.h +++ b/src/async/smtp/MCSMTPAsyncSession.h @@ -13,6 +13,7 @@ namespace mailcore { class SMTPOperation; class SMTPSession; class Address; + class SMTPOperationQueueCallback; class SMTPAsyncSession : public Object { public: @@ -52,13 +53,14 @@ namespace mailcore { public: // private virtual void runOperation(SMTPOperation * operation); virtual SMTPSession * session(); + virtual void tryAutomaticDisconnect(); private: - SMTPSession * mSession; - OperationQueue * mQueue; - - void queue(SMTPOperation * op); - + SMTPSession * mSession; + OperationQueue * mQueue; + SMTPOperationQueueCallback * mQueueCallback; + + virtual void tryAutomaticDisconnectAfterDelay(void * context); }; } diff --git a/src/async/smtp/MCSMTPDisconnectOperation.cc b/src/async/smtp/MCSMTPDisconnectOperation.cc new file mode 100644 index 00000000..592ceb48 --- /dev/null +++ b/src/async/smtp/MCSMTPDisconnectOperation.cc @@ -0,0 +1,28 @@ +// +// SMTPDisconnectOperation.cpp +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#include "MCSMTPDisconnectOperation.h" + +#include "MCSMTPAsyncSession.h" +#include "MCSMTPSession.h" + +using namespace mailcore; + +SMTPDisconnectOperation::SMTPDisconnectOperation() +{ +} + +SMTPDisconnectOperation::~SMTPDisconnectOperation() +{ +} + +void SMTPDisconnectOperation::main() +{ + session()->session()->disconnect(); + setError(ErrorCode::ErrorNone); +} diff --git a/src/async/smtp/MCSMTPDisconnectOperation.h b/src/async/smtp/MCSMTPDisconnectOperation.h new file mode 100644 index 00000000..dacf72a6 --- /dev/null +++ b/src/async/smtp/MCSMTPDisconnectOperation.h @@ -0,0 +1,32 @@ +// +// SMTPDisconnectOperation.h +// mailcore2 +// +// Created by DINH Viêt Hoà on 6/22/13. +// Copyright (c) 2013 MailCore. All rights reserved. +// + +#ifndef __MAILCORE_MCSMTPDISCONNECTOPERATION_H_ +#define __MAILCORE_MCSMTPDISCONNECTOPERATION_H_ + +#include <MailCore/MCBaseTypes.h> +#include <MailCore/MCAbstract.h> +#include <MailCore/MCSMTPOperation.h> + +#ifdef __cplusplus + +namespace mailcore { + + class SMTPDisconnectOperation : public SMTPOperation { + public: + SMTPDisconnectOperation(); + virtual ~SMTPDisconnectOperation(); + + public: // subclass behavior + virtual void main(); + }; +} + +#endif + +#endif
\ No newline at end of file diff --git a/src/async/smtp/MCSMTPOperation.cc b/src/async/smtp/MCSMTPOperation.cc index 532c6ab4..e8211a24 100644 --- a/src/async/smtp/MCSMTPOperation.cc +++ b/src/async/smtp/MCSMTPOperation.cc @@ -82,4 +82,3 @@ void SMTPOperation::bodyProgressOnMainThread(void * ctx) } free(context); } - |