LCOV - code coverage report
Current view: top level - sw/source/uibase/inc - maildispatcher.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 3 0.0 %
Date: 2014-11-03 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX
      21             : #define INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX
      22             : 
      23             : #include <com/sun/star/mail/XSmtpService.hpp>
      24             : #include <com/sun/star/mail/XMailMessage.hpp>
      25             : #include <osl/thread.hxx>
      26             : #include <osl/conditn.hxx>
      27             : #include <salhelper/refobj.hxx>
      28             : 
      29             : #include <list>
      30             : 
      31             : #include <swdllapi.h>
      32             : 
      33             : class IMailDispatcherListener;
      34             : 
      35             : /**
      36             :     A MailDispatcher should be used for sending a bunch a mail messages
      37             :     asynchronously. Usually a client enqueues a number of mail messages
      38             :     and then calls start to begin sending them. An instance of this class
      39             :     must not be shared among different client threads. Instead each client
      40             :     thread should create an own instance of this class.
      41             : */
      42             : class SW_DLLPUBLIC MailDispatcher
      43             :     : public ::salhelper::ReferenceObject
      44             :     , private ::osl::Thread
      45             : {
      46             : public:
      47             :     // bringing operator new/delete into scope
      48             :     using osl::Thread::operator new;
      49             :     using osl::Thread::operator delete;
      50             :     using osl::Thread::join;
      51             : 
      52             : public:
      53             : 
      54             :     /**
      55             :         @param xSmtpService
      56             :         [in] a reference to a mail server. A user must be
      57             :         connected to the mail server otherwise errors occur
      58             :         during the delivery of mail messages.
      59             : 
      60             :         @throws ::com::sun::star::uno::RuntimeException
      61             :         on errors during construction of an instance of this class.
      62             :     */
      63             :     MailDispatcher(::com::sun::star::uno::Reference< ::com::sun::star::mail::XSmtpService> xMailService);
      64             : 
      65             :     /**
      66             :         Shutdown the mail dispatcher. Every mail messages
      67             :         not yet sent will be discarded.
      68             :     */
      69             :     virtual ~MailDispatcher();
      70             : 
      71             :     /**
      72             :         Enqueue a mail message for delivery. A client must
      73             :         start the mail dispatcher in order to send the
      74             :         enqueued mail messages.
      75             : 
      76             :         @param xMailMessage
      77             :         [in] a mail message that should be send.
      78             :     */
      79             :     void enqueueMailMessage(::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> xMailMessage);
      80             :     /**
      81             :         Dequeues a mail message.
      82             :         This enables the caller to remove attachments when sending mails is to be cancelled.
      83             :     */
      84             :     ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> dequeueMailMessage();
      85             : 
      86             :     /**
      87             :         Start sending mail messages asynchronously. A client may register
      88             :         a listener for mail dispatcher events. For every mail message sent
      89             :         the notification will be sent. While handling such notification a
      90             :         client may enqueue new mail messages. If there are no more mail
      91             :         messages to send an respective notification is sent and the mail
      92             :         dispatcher waits for more mail messages.
      93             : 
      94             :         @precond not isStarted()
      95             :     */
      96             :     void start();
      97             : 
      98             :     /**
      99             :         Stop sending mail messages.
     100             : 
     101             :         @precond isStarted()
     102             :     */
     103             :     void stop();
     104             : 
     105             :     /**
     106             :         Request shutdown of the mail dispatcher thread.
     107             :         NOTE: You must call this method before you release
     108             :         your last reference to this class otherwise the
     109             :         mail dispatcher thread will never end.
     110             :     */
     111             :     void shutdown();
     112             : 
     113             :     /**
     114             :         Check whether the mail dispatcher is started or not.
     115             : 
     116             :         @return
     117             :         <TRUE/> if the sending thread is running.
     118             :     */
     119           0 :     bool isStarted() const { return run_;}
     120             : 
     121             :     /** returns if the thread is still running
     122             :     */
     123             :     using osl::Thread::isRunning;
     124             : 
     125             :     /** returns if shutdown has already been called
     126             :     */
     127           0 :     bool isShutdownRequested() const
     128           0 :         { return shutdown_requested_; }
     129             :     /**
     130             :         Register a listener for mail dispatcher events.
     131             :     */
     132             :     void addListener(::rtl::Reference<IMailDispatcherListener> listener);
     133             : 
     134             : protected:
     135             :     virtual void SAL_CALL run() SAL_OVERRIDE;
     136             :     virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
     137             : 
     138             : private:
     139             :     std::list< ::rtl::Reference<IMailDispatcherListener> > cloneListener();
     140             :     void sendMailMessageNotifyListener(::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> message);
     141             : 
     142             : private:
     143             :     ::com::sun::star::uno::Reference< ::com::sun::star::mail::XSmtpService> mailserver_;
     144             :     ::std::list< ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage > > messages_;
     145             :     ::std::list< ::rtl::Reference<IMailDispatcherListener> > listeners_;
     146             :     ::osl::Mutex message_container_mutex_;
     147             :     ::osl::Mutex listener_container_mutex_;
     148             :     ::osl::Mutex thread_status_mutex_;
     149             :     ::osl::Condition mail_dispatcher_active_;
     150             :     ::osl::Condition wakening_call_;
     151             :     ::rtl::Reference<MailDispatcher> m_xSelfReference;
     152             :     bool run_;
     153             :     bool shutdown_requested_;
     154             : };
     155             : 
     156             : #endif // INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10