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

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 > 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 ()
 

Private Member Functions

virtual void SAL_CALL run () override
 
virtual void SAL_CALL onTerminated () override
 
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 void * operator new (std::size_t nSize)
 
static void * operator 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 Member Functions inherited from salhelper::SimpleReferenceObject
virtual ~SimpleReferenceObject () COVERITY_NOEXCEPT_FALSE
 
- 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::MailDispatcher ( css::uno::Reference< css::mail::XSmtpService >  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 72 of file maildispatcher.cxx.

References create(), m_aRunCondition, and m_aWakeupCondition.

◆ ~MailDispatcher()

MailDispatcher::~MailDispatcher ( )
overridevirtual

Shutdown the mail dispatcher.

Every mail messages not yet sent will be discarded.

Definition at line 89 of file maildispatcher.cxx.

Member Function Documentation

◆ addListener()

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

Register a listener for mail dispatcher events.

Definition at line 160 of file maildispatcher.cxx.

References m_aListenerContainerMutex, m_aListenerVector, and m_bShutdownRequested.

◆ cloneListener()

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

Definition at line 168 of file maildispatcher.cxx.

References m_aListenerContainerMutex, and m_aListenerVector.

Referenced by run(), and sendMailMessageNotifyListener().

◆ dequeueMailMessage()

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 105 of file maildispatcher.cxx.

References m_aMessageContainerMutex, and m_aXMessageList.

◆ enqueueMailMessage()

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 93 of file maildispatcher.cxx.

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

◆ isShutdownRequested()

bool MailDispatcher::isShutdownRequested ( ) const
inline

returns if shutdown has already been called

Definition at line 127 of file maildispatcher.hxx.

◆ isStarted()

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 118 of file maildispatcher.hxx.

Referenced by start(), and stop().

◆ onTerminated()

void MailDispatcher::onTerminated ( )
overrideprivatevirtual

Definition at line 242 of file maildispatcher.cxx.

References m_xSelfReference.

◆ run()

void MailDispatcher::run ( )
overrideprivatevirtual

◆ sendMailMessageNotifyListener()

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

Definition at line 174 of file maildispatcher.cxx.

References cloneListener(), ex, and m_xMailserver.

Referenced by run().

◆ shutdown()

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 149 of file maildispatcher.cxx.

References m_aThreadStatusMutex, m_aWakeupCondition, and m_bShutdownRequested.

◆ start()

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.

@precond not isStarted()

Definition at line 117 of file maildispatcher.cxx.

References isStarted(), m_aThreadStatusMutex, m_aWakeupCondition, m_bActive, and m_bShutdownRequested.

◆ stop()

void MailDispatcher::stop ( )

Stop sending mail messages.

@precond isStarted()

Definition at line 133 of file maildispatcher.cxx.

References isStarted(), m_aThreadStatusMutex, m_aWakeupCondition, m_bActive, and m_bShutdownRequested.

Member Data Documentation

◆ m_aListenerContainerMutex

::osl::Mutex MailDispatcher::m_aListenerContainerMutex
private

Definition at line 145 of file maildispatcher.hxx.

Referenced by addListener(), and cloneListener().

◆ m_aListenerVector

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

Definition at line 143 of file maildispatcher.hxx.

Referenced by addListener(), and cloneListener().

◆ m_aMessageContainerMutex

::osl::Mutex MailDispatcher::m_aMessageContainerMutex
private

Definition at line 144 of file maildispatcher.hxx.

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

◆ m_aRunCondition

::osl::Condition MailDispatcher::m_aRunCondition
private

Definition at line 147 of file maildispatcher.hxx.

Referenced by MailDispatcher(), and run().

◆ m_aThreadStatusMutex

::osl::Mutex MailDispatcher::m_aThreadStatusMutex
private

Definition at line 146 of file maildispatcher.hxx.

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

◆ m_aWakeupCondition

::osl::Condition MailDispatcher::m_aWakeupCondition
private

Definition at line 148 of file maildispatcher.hxx.

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

◆ m_aXMessageList

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

Definition at line 142 of file maildispatcher.hxx.

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

◆ m_bActive

bool MailDispatcher::m_bActive
private

Definition at line 150 of file maildispatcher.hxx.

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

◆ m_bShutdownRequested

bool MailDispatcher::m_bShutdownRequested
private

Definition at line 151 of file maildispatcher.hxx.

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

◆ m_xMailserver

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

Definition at line 141 of file maildispatcher.hxx.

Referenced by sendMailMessageNotifyListener().

◆ m_xSelfReference

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

Definition at line 149 of file maildispatcher.hxx.

Referenced by onTerminated(), and run().


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