[Libreoffice-commits] core.git: sw/source

Jan-Marek Glogowski glogow at fbihome.de
Fri Jan 13 13:02:12 UTC 2017


 sw/source/uibase/dbui/maildispatcher.cxx |  126 ++++++++++++++++---------------
 sw/source/uibase/inc/maildispatcher.hxx  |   37 ++++-----
 2 files changed, 84 insertions(+), 79 deletions(-)

New commits:
commit 66fd9738a5a17e382c3cd329a1ab48e57e354821
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Thu Jan 12 13:39:14 2017 +0100

    Rename mail dispatcher members
    
    Makes the members conform with most LO variable naming,
    
    This especially switches Active <=> Running in the member names.
    
    "Running" is normally referred to as the thread state, while it
    exists (also look into the osl::Thread API) and now active is the
    state, when messages are processed, controlled by the start() and
    stop() functions.
    
    Change-Id: I3b8437d4ff24731348272a84720ff81fdea90db7

diff --git a/sw/source/uibase/dbui/maildispatcher.cxx b/sw/source/uibase/dbui/maildispatcher.cxx
index ca68ba2..fcbdb94 100644
--- a/sw/source/uibase/dbui/maildispatcher.cxx
+++ b/sw/source/uibase/dbui/maildispatcher.cxx
@@ -94,12 +94,12 @@ namespace /* private */
 } // namespace private
 
 MailDispatcher::MailDispatcher(uno::Reference<mail::XSmtpService> const & mailserver) :
-    mailserver_ (mailserver),
-    run_(false),
-    shutdown_requested_(false)
+    m_xMailserver( mailserver ),
+    m_bActive( false ),
+    m_bShutdownRequested( false )
 {
-    wakening_call_.reset();
-    mail_dispatcher_active_.reset();
+    m_aWakeupCondition.reset();
+    m_aRunCondition.reset();
 
     if (!create())
         throw uno::RuntimeException();
@@ -107,7 +107,7 @@ MailDispatcher::MailDispatcher(uno::Reference<mail::XSmtpService> const & mailse
     // wait until the mail dispatcher thread is really alive
     // and has acquired a reference to this instance of the
     // class
-    mail_dispatcher_active_.wait();
+    m_aRunCondition.wait();
 }
 
 MailDispatcher::~MailDispatcher()
@@ -116,24 +116,24 @@ MailDispatcher::~MailDispatcher()
 
 void MailDispatcher::enqueueMailMessage(uno::Reference<mail::XMailMessage> const & message)
 {
-    ::osl::MutexGuard thread_status_guard(thread_status_mutex_);
-    ::osl::MutexGuard message_container_guard(message_container_mutex_);
+    ::osl::MutexGuard thread_status_guard( m_aThreadStatusMutex );
+    ::osl::MutexGuard message_container_guard( m_aMessageContainerMutex );
 
-    OSL_PRECOND(!shutdown_requested_, "MailDispatcher thread is shuting down already");
+    OSL_PRECOND( !m_bShutdownRequested, "MailDispatcher thread is shuting down already" );
 
-    messages_.push_back(message);
-    if (run_)
-        wakening_call_.set();
+    m_aXMessageList.push_back( message );
+    if ( m_bActive )
+        m_aWakeupCondition.set();
 }
 
 uno::Reference<mail::XMailMessage> MailDispatcher::dequeueMailMessage()
 {
-    ::osl::MutexGuard guard(message_container_mutex_);
+    ::osl::MutexGuard guard( m_aMessageContainerMutex );
     uno::Reference<mail::XMailMessage> message;
-    if(!messages_.empty())
+    if ( !m_aXMessageList.empty() )
     {
-        message = messages_.front();
-        messages_.pop_front();
+        message = m_aXMessageList.front();
+        m_aXMessageList.pop_front();
     }
     return message;
 }
@@ -142,18 +142,19 @@ void MailDispatcher::start()
 {
     OSL_PRECOND(!isStarted(), "MailDispatcher is already started!");
 
-    ::osl::ClearableMutexGuard thread_status_guard(thread_status_mutex_);
+    ::osl::ClearableMutexGuard thread_status_guard( m_aThreadStatusMutex );
 
-    OSL_PRECOND(!shutdown_requested_, "MailDispatcher thread is shuting down already");
+    OSL_PRECOND(!m_bShutdownRequested, "MailDispatcher thread is shuting down already");
 
-    if (!shutdown_requested_)
+    if ( !m_bShutdownRequested )
     {
-        run_ = true;
-        wakening_call_.set();
+        m_bActive = true;
+        m_aWakeupCondition.set();
         thread_status_guard.clear();
 
-        MailDispatcherListenerContainer_t listeners_cloned(cloneListener());
-        std::for_each(listeners_cloned.begin(), listeners_cloned.end(), GenericEventNotifier(&IMailDispatcherListener::started, this));
+        MailDispatcherListenerContainer_t aClonedListenerList(cloneListener());
+        std::for_each( aClonedListenerList.begin(), aClonedListenerList.end(),
+                       GenericEventNotifier(&IMailDispatcherListener::started, this) );
     }
 }
 
@@ -161,63 +162,67 @@ void MailDispatcher::stop()
 {
     OSL_PRECOND(isStarted(), "MailDispatcher not started!");
 
-    ::osl::ClearableMutexGuard thread_status_guard(thread_status_mutex_);
+    ::osl::ClearableMutexGuard thread_status_guard( m_aThreadStatusMutex );
 
-    OSL_PRECOND(!shutdown_requested_, "MailDispatcher thread is shuting down already");
+    OSL_PRECOND(!m_bShutdownRequested, "MailDispatcher thread is shuting down already");
 
-    if (!shutdown_requested_)
+    if (!m_bShutdownRequested)
     {
-        run_ = false;
-        wakening_call_.reset();
+        m_bActive = false;
+        m_aWakeupCondition.reset();
         thread_status_guard.clear();
 
-        MailDispatcherListenerContainer_t listeners_cloned(cloneListener());
-        std::for_each(listeners_cloned.begin(), listeners_cloned.end(), GenericEventNotifier(&IMailDispatcherListener::stopped, this));
+        MailDispatcherListenerContainer_t aClonedListenerList(cloneListener());
+        std::for_each( aClonedListenerList.begin(), aClonedListenerList.end(),
+                       GenericEventNotifier(&IMailDispatcherListener::stopped, this) );
     }
 }
 
 void MailDispatcher::shutdown()
 {
-    ::osl::MutexGuard thread_status_guard(thread_status_mutex_);
+    ::osl::MutexGuard thread_status_guard( m_aThreadStatusMutex );
 
-    OSL_PRECOND(!shutdown_requested_, "MailDispatcher thread is shuting down already");
+    OSL_PRECOND(!m_bShutdownRequested, "MailDispatcher thread is shuting down already");
 
-    shutdown_requested_ = true;
-    wakening_call_.set();
+    m_bShutdownRequested = true;
+    m_aWakeupCondition.set();
 }
 
 
 void MailDispatcher::addListener(::rtl::Reference<IMailDispatcherListener> const & listener)
 {
-    OSL_PRECOND(!shutdown_requested_, "MailDispatcher thread is shuting down already");
+    OSL_PRECOND(!m_bShutdownRequested, "MailDispatcher thread is shuting down already");
 
-    ::osl::MutexGuard guard(listener_container_mutex_);
-    listeners_.push_back(listener);
+    ::osl::MutexGuard guard( m_aListenerContainerMutex );
+    m_aListenerList.push_back( listener );
 }
 
 std::list< ::rtl::Reference<IMailDispatcherListener> > MailDispatcher::cloneListener()
 {
-    ::osl::MutexGuard guard(listener_container_mutex_);
-    return listeners_;
+    ::osl::MutexGuard guard( m_aListenerContainerMutex );
+    return m_aListenerList;
 }
 
 void MailDispatcher::sendMailMessageNotifyListener(uno::Reference<mail::XMailMessage> const & message)
 {
     try
     {
-        mailserver_->sendMailMessage(message);
-        MailDispatcherListenerContainer_t listeners_cloned(cloneListener());
-        std::for_each(listeners_cloned.begin(), listeners_cloned.end(), MailDeliveryNotifier(this, message));
+        m_xMailserver->sendMailMessage( message );
+        MailDispatcherListenerContainer_t aClonedListenerList(cloneListener());
+        std::for_each( aClonedListenerList.begin(), aClonedListenerList.end(),
+                       MailDeliveryNotifier(this, message) );
     }
     catch (const mail::MailException& ex)
     {
-        MailDispatcherListenerContainer_t listeners_cloned(cloneListener());
-        std::for_each(listeners_cloned.begin(), listeners_cloned.end(), MailDeliveryErrorNotifier(this, message, ex.Message));
+        MailDispatcherListenerContainer_t aClonedListenerList(cloneListener());
+        std::for_each( aClonedListenerList.begin(), aClonedListenerList.end(),
+                       MailDeliveryErrorNotifier(this, message, ex.Message) );
     }
     catch (const uno::RuntimeException& ex)
     {
-        MailDispatcherListenerContainer_t listeners_cloned(cloneListener());
-        std::for_each(listeners_cloned.begin(), listeners_cloned.end(), MailDeliveryErrorNotifier(this, message, ex.Message));
+        MailDispatcherListenerContainer_t aClonedListenerList(cloneListener());
+        std::for_each( aClonedListenerList.begin(), aClonedListenerList.end(),
+                       MailDeliveryErrorNotifier(this, message, ex.Message) );
     }
 }
 
@@ -234,35 +239,36 @@ void MailDispatcher::run()
     m_xSelfReference = this;
 
     // signal that the mail dispatcher thread is now alive
-    mail_dispatcher_active_.set();
+    m_aRunCondition.set();
 
     for(;;)
     {
-        wakening_call_.wait();
+        m_aWakeupCondition.wait();
 
-        ::osl::ClearableMutexGuard thread_status_guard(thread_status_mutex_);
-        if (shutdown_requested_)
-           break;
+        ::osl::ClearableMutexGuard thread_status_guard( m_aThreadStatusMutex );
+        if ( m_bShutdownRequested )
+            break;
 
-        ::osl::ClearableMutexGuard message_container_guard(message_container_mutex_);
+        ::osl::ClearableMutexGuard message_container_guard( m_aMessageContainerMutex );
 
-        if (messages_.size())
+        if ( m_aXMessageList.size() )
         {
             thread_status_guard.clear();
-            uno::Reference<mail::XMailMessage> message = messages_.front();
-            messages_.pop_front();
+            uno::Reference<mail::XMailMessage> message = m_aXMessageList.front();
+            m_aXMessageList.pop_front();
             message_container_guard.clear();
-            sendMailMessageNotifyListener(message);
+            sendMailMessageNotifyListener( message );
         }
         else // idle - put ourself to sleep
         {
-            wakening_call_.reset();
+            m_aWakeupCondition.reset();
             message_container_guard.clear();
             thread_status_guard.clear();
-            MailDispatcherListenerContainer_t listeners_cloned(cloneListener());
-            std::for_each(listeners_cloned.begin(), listeners_cloned.end(), GenericEventNotifier(&IMailDispatcherListener::idle, this));
+            MailDispatcherListenerContainer_t aListenerListcloned( cloneListener() );
+            std::for_each( aListenerListcloned.begin(), aListenerListcloned.end(),
+                           GenericEventNotifier(&IMailDispatcherListener::idle, this) );
         }
-    } // end for        SSH ALI
+    }
 }
 
 void MailDispatcher::onTerminated()
diff --git a/sw/source/uibase/inc/maildispatcher.hxx b/sw/source/uibase/inc/maildispatcher.hxx
index 3410cae..ddcb48e 100644
--- a/sw/source/uibase/inc/maildispatcher.hxx
+++ b/sw/source/uibase/inc/maildispatcher.hxx
@@ -50,8 +50,6 @@ public:
     using osl::Thread::operator delete;
     using osl::Thread::join;
 
-public:
-
     /**
         @param xSmtpService
         [in] a reference to a mail server. A user must be
@@ -117,19 +115,20 @@ public:
         @return
         <TRUE/> if the sending thread is running.
     */
-    bool isStarted() const { return run_;}
+    bool isStarted() const { return m_bActive; }
 
     /** returns if the thread is still running
     */
     using osl::Thread::isRunning;
 
-    /** returns if shutdown has already been called
-    */
-    bool isShutdownRequested() const
-        { return shutdown_requested_; }
     /**
-        Register a listener for mail dispatcher events.
-    */
+     * returns if shutdown has already been called
+     */
+    bool isShutdownRequested() const { return m_bShutdownRequested; }
+
+    /**
+     * Register a listener for mail dispatcher events
+     */
     void addListener(::rtl::Reference<IMailDispatcherListener> const & listener);
 
 protected:
@@ -141,17 +140,17 @@ private:
     void sendMailMessageNotifyListener(css::uno::Reference< css::mail::XMailMessage> const & message);
 
 private:
-    css::uno::Reference< css::mail::XSmtpService> mailserver_;
-    std::list< css::uno::Reference< css::mail::XMailMessage > > messages_;
-    std::list< ::rtl::Reference<IMailDispatcherListener> > listeners_;
-    ::osl::Mutex message_container_mutex_;
-    ::osl::Mutex listener_container_mutex_;
-    ::osl::Mutex thread_status_mutex_;
-    ::osl::Condition mail_dispatcher_active_;
-    ::osl::Condition wakening_call_;
+    css::uno::Reference< css::mail::XSmtpService> m_xMailserver;
+    std::list< css::uno::Reference< css::mail::XMailMessage > > m_aXMessageList;
+    std::list< ::rtl::Reference<IMailDispatcherListener> > m_aListenerList;
+    ::osl::Mutex m_aMessageContainerMutex;
+    ::osl::Mutex m_aListenerContainerMutex;
+    ::osl::Mutex m_aThreadStatusMutex;
+    ::osl::Condition m_aRunCondition;
+    ::osl::Condition m_aWakeupCondition;
     ::rtl::Reference<MailDispatcher> m_xSelfReference;
-    bool run_;
-    bool shutdown_requested_;
+    bool m_bActive;
+    bool m_bShutdownRequested;
 };
 
 #endif // INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX


More information about the Libreoffice-commits mailing list