LibreOffice Module sw (master)  1
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
MailDispatcher Class Reference

A MailDispatcher should be used for sending a bunch a mail messages asynchronously. More...

#include <maildispatcher.hxx>

Inheritance diagram for MailDispatcher:
[legend]
Collaboration diagram for MailDispatcher:
[legend]

Public Member Functions

 MailDispatcher (css::uno::Reference< css::mail::XSmtpService > const &xMailService)
 
virtual ~MailDispatcher () override
 Shutdown the mail dispatcher. More...
 
void enqueueMailMessage (css::uno::Reference< css::mail::XMailMessage > const &xMailMessage)
 Enqueue a mail message for delivery. More...
 
css::uno::Reference< css::mail::XMailMessage > dequeueMailMessage ()
 Dequeues a mail message. More...
 
void start ()
 Start sending mail messages asynchronously. More...
 
void stop ()
 Stop sending mail messages. More...
 
void shutdown ()
 Request shutdown of the mail dispatcher thread. More...
 
bool isStarted () const
 Check whether the mail dispatcher is started or not. More...
 
bool isShutdownRequested () const
 returns if shutdown has already been called More...
 
void addListener (::rtl::Reference< IMailDispatcherListener > const &listener)
 Register a listener for mail dispatcher events. More...
 
- Public Member Functions inherited from salhelper::SimpleReferenceObject
 SimpleReferenceObject ()
 
void acquire ()
 
void release ()
 

Protected Member Functions

virtual void SAL_CALL run () override
 
virtual void SAL_CALL onTerminated () override
 
- Protected Member Functions inherited from salhelper::SimpleReferenceObject
virtual ~SimpleReferenceObject () COVERITY_NOEXCEPT_FALSE
 

Private Member Functions

std::vector< ::rtl::Reference< IMailDispatcherListener > > cloneListener ()
 
void sendMailMessageNotifyListener (css::uno::Reference< css::mail::XMailMessage > const &message)
 

Private Attributes

css::uno::Reference< css::mail::XSmtpService > m_xMailserver
 
std::list< css::uno::Reference< css::mail::XMailMessage > > m_aXMessageList
 
std::vector< ::rtl::Reference< IMailDispatcherListener > > m_aListenerVector
 
::osl::Mutex m_aMessageContainerMutex
 
::osl::Mutex m_aListenerContainerMutex
 
::osl::Mutex m_aThreadStatusMutex
 
::osl::Condition m_aRunCondition
 
::osl::Condition m_aWakeupCondition
 
::rtl::Reference< MailDispatcherm_xSelfReference
 
bool m_bActive
 
bool m_bShutdownRequested
 

Additional Inherited Members

- Static Public Member Functions inherited from salhelper::SimpleReferenceObject
static voidoperator new (std::size_t nSize)
 
static voidoperator new (std::size_t nSize, std::nothrow_t const &rNothrow)
 
static void operator delete (void *pPtr)
 
static void operator delete (void *pPtr, std::nothrow_t const &rNothrow)
 
- Protected Attributes inherited from salhelper::SimpleReferenceObject
oslInterlockedCount m_nCount
 

Detailed Description

A MailDispatcher should be used for sending a bunch a mail messages asynchronously.

Usually a client enqueues a number of mail messages and then calls start to begin sending them. An instance of this class must not be shared among different client threads. Instead each client thread should create an own instance of this class.

Definition at line 44 of file maildispatcher.hxx.

Constructor & Destructor Documentation

MailDispatcher::MailDispatcher ( css::uno::Reference< css::mail::XSmtpService > const &  xMailService)
Parameters
xSmtpService[in] a reference to a mail server. A user must be connected to the mail server otherwise errors occur during the delivery of mail messages.
Exceptions
css::uno::RuntimeExceptionon errors during construction of an instance of this class.

Definition at line 97 of file maildispatcher.cxx.

References create(), m_aRunCondition, and m_aWakeupCondition.

MailDispatcher::~MailDispatcher ( )
overridevirtual

Shutdown the mail dispatcher.

Every mail messages not yet sent will be discarded.

Definition at line 114 of file maildispatcher.cxx.

Member Function Documentation

void MailDispatcher::addListener ( ::rtl::Reference< IMailDispatcherListener > const &  listener)

Register a listener for mail dispatcher events.

Definition at line 193 of file maildispatcher.cxx.

References m_aListenerContainerMutex, m_aListenerVector, and m_bShutdownRequested.

std::vector<::rtl::Reference< IMailDispatcherListener > > MailDispatcher::cloneListener ( )
private

Definition at line 201 of file maildispatcher.cxx.

References m_aListenerContainerMutex, and m_aListenerVector.

Referenced by run(), sendMailMessageNotifyListener(), start(), and stop().

uno::Reference< mail::XMailMessage > MailDispatcher::dequeueMailMessage ( )

Dequeues a mail message.

This enables the caller to remove attachments when sending mails is to be cancelled.

Definition at line 130 of file maildispatcher.cxx.

References m_aMessageContainerMutex, and m_aXMessageList.

void MailDispatcher::enqueueMailMessage ( css::uno::Reference< css::mail::XMailMessage > const &  xMailMessage)

Enqueue a mail message for delivery.

A client must start the mail dispatcher in order to send the enqueued mail messages.

Parameters
xMailMessage[in] a mail message that should be send.

Definition at line 118 of file maildispatcher.cxx.

References m_aMessageContainerMutex, m_aThreadStatusMutex, m_aWakeupCondition, m_aXMessageList, m_bActive, and m_bShutdownRequested.

bool MailDispatcher::isShutdownRequested ( ) const
inline

returns if shutdown has already been called

Definition at line 128 of file maildispatcher.hxx.

bool MailDispatcher::isStarted ( ) const
inline

Check whether the mail dispatcher is started or not.

Returns
<TRUE> if the sending thread is running.

Definition at line 119 of file maildispatcher.hxx.

Referenced by start(), and stop().

void MailDispatcher::onTerminated ( )
overrideprotectedvirtual

Definition at line 275 of file maildispatcher.cxx.

References m_xSelfReference.

void MailDispatcher::run ( )
overrideprotectedvirtual
void MailDispatcher::sendMailMessageNotifyListener ( css::uno::Reference< css::mail::XMailMessage > const &  message)
private

Definition at line 207 of file maildispatcher.cxx.

References cloneListener(), and m_xMailserver.

Referenced by run().

void MailDispatcher::shutdown ( )

Request shutdown of the mail dispatcher thread.

NOTE: You must call this method before you release your last reference to this class otherwise the mail dispatcher thread will never end.

Definition at line 182 of file maildispatcher.cxx.

References m_aThreadStatusMutex, m_aWakeupCondition, and m_bShutdownRequested.

void MailDispatcher::start ( )

Start sending mail messages asynchronously.

A client may register a listener for mail dispatcher events. For every mail message sent the notification will be sent. While handling such notification a client may enqueue new mail messages. If there are no more mail messages to send a respective notification is sent and the mail dispatcher waits for more mail messages.

not isStarted()

Definition at line 142 of file maildispatcher.cxx.

References cloneListener(), isStarted(), m_aThreadStatusMutex, m_aWakeupCondition, m_bActive, m_bShutdownRequested, and IMailDispatcherListener::started().

void MailDispatcher::stop ( )

Member Data Documentation

::osl::Mutex MailDispatcher::m_aListenerContainerMutex
private

Definition at line 148 of file maildispatcher.hxx.

Referenced by addListener(), and cloneListener().

std::vector< ::rtl::Reference<IMailDispatcherListener> > MailDispatcher::m_aListenerVector
private

Definition at line 146 of file maildispatcher.hxx.

Referenced by addListener(), and cloneListener().

::osl::Mutex MailDispatcher::m_aMessageContainerMutex
private

Definition at line 147 of file maildispatcher.hxx.

Referenced by dequeueMailMessage(), enqueueMailMessage(), and run().

::osl::Condition MailDispatcher::m_aRunCondition
private

Definition at line 150 of file maildispatcher.hxx.

Referenced by MailDispatcher(), and run().

::osl::Mutex MailDispatcher::m_aThreadStatusMutex
private

Definition at line 149 of file maildispatcher.hxx.

Referenced by enqueueMailMessage(), run(), shutdown(), start(), and stop().

::osl::Condition MailDispatcher::m_aWakeupCondition
private

Definition at line 151 of file maildispatcher.hxx.

Referenced by enqueueMailMessage(), MailDispatcher(), run(), shutdown(), start(), and stop().

std::list< css::uno::Reference< css::mail::XMailMessage > > MailDispatcher::m_aXMessageList
private

Definition at line 145 of file maildispatcher.hxx.

Referenced by dequeueMailMessage(), enqueueMailMessage(), and run().

bool MailDispatcher::m_bActive
private

Definition at line 153 of file maildispatcher.hxx.

Referenced by enqueueMailMessage(), start(), and stop().

bool MailDispatcher::m_bShutdownRequested
private

Definition at line 154 of file maildispatcher.hxx.

Referenced by addListener(), enqueueMailMessage(), run(), shutdown(), start(), and stop().

css::uno::Reference< css::mail::XSmtpService> MailDispatcher::m_xMailserver
private

Definition at line 144 of file maildispatcher.hxx.

Referenced by sendMailMessageNotifyListener().

::rtl::Reference<MailDispatcher> MailDispatcher::m_xSelfReference
private

Definition at line 152 of file maildispatcher.hxx.

Referenced by onTerminated(), and run().


The documentation for this class was generated from the following files: