LCOV - code coverage report
Current view: top level - sw/source/ui/inc - maildispatcher.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 2 0.0 %
Date: 2012-08-25 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef INCLUDED_MAILDISPATCHER_HXX
      30                 :            : #define INCLUDED_MAILDISPATCHER_HXX
      31                 :            : 
      32                 :            : #include "com/sun/star/mail/XSmtpService.hpp"
      33                 :            : #include "com/sun/star/mail/XMailMessage.hpp"
      34                 :            : #include <osl/thread.hxx>
      35                 :            : #include <osl/conditn.hxx>
      36                 :            : #include <salhelper/refobj.hxx>
      37                 :            : 
      38                 :            : #include <list>
      39                 :            : 
      40                 :            : class IMailDispatcherListener;
      41                 :            : 
      42                 :            : /**
      43                 :            :     A MailDispatcher should be used for sending a bunch a mail messages
      44                 :            :     asynchronously. Usually a client enqueues a number of mail messages
      45                 :            :     and then calls start to begin sending them. An instance of this class
      46                 :            :     must not be shared among different client threads. Instead each client
      47                 :            :     thread should create an own instance of this class.
      48                 :            : */
      49                 :            : class MailDispatcher : public ::salhelper::ReferenceObject, private ::osl::Thread
      50                 :            : {
      51                 :            : public:
      52                 :            :     // bringing operator new/delete into scope
      53                 :            :     using osl::Thread::operator new;
      54                 :            :     using osl::Thread::operator delete;
      55                 :            :     using osl::Thread::join;
      56                 :            : 
      57                 :            : public:
      58                 :            : 
      59                 :            :     /**
      60                 :            :         @param xSmtpService
      61                 :            :         [in] a reference to a mail server. A user must be
      62                 :            :         connected to the mail server otherwise errors occur
      63                 :            :         during the delivery of mail messages.
      64                 :            : 
      65                 :            :         @throws ::com::sun::star::uno::RuntimeException
      66                 :            :         on errors during construction of an instance of this class.
      67                 :            :     */
      68                 :            :     MailDispatcher(::com::sun::star::uno::Reference< ::com::sun::star::mail::XSmtpService> xMailService);
      69                 :            : 
      70                 :            :     /**
      71                 :            :         Shutdown the mail dispatcher. Every mail messages
      72                 :            :         not yet sent will be discarded.
      73                 :            :     */
      74                 :            :     virtual ~MailDispatcher();
      75                 :            : 
      76                 :            :     /**
      77                 :            :         Enqueue a mail message for delivery. A client must
      78                 :            :         start the mail dispatcher in order to send the
      79                 :            :         enqueued mail messages.
      80                 :            : 
      81                 :            :         @param xMailMessage
      82                 :            :         [in] a mail message that should be send.
      83                 :            :     */
      84                 :            :     void enqueueMailMessage(::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> xMailMessage);
      85                 :            :     /**
      86                 :            :         Dequeues a mail message.
      87                 :            :         This enables the caller to remove attachments when sending mails is to be cancelled.
      88                 :            :     */
      89                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> dequeueMailMessage();
      90                 :            : 
      91                 :            :     /**
      92                 :            :         Start sending mail messages asynchronously. A client may register
      93                 :            :         a listener for mail dispatcher events. For every mail message sent
      94                 :            :         the notification will be sent. While handling such notification a
      95                 :            :         client may enqueue new mail messages. If there are no more mail
      96                 :            :         messages to send an respective notification is sent and the mail
      97                 :            :         dispatcher waits for more mail messages.
      98                 :            : 
      99                 :            :         @precond not isStarted()
     100                 :            :     */
     101                 :            :     void start();
     102                 :            : 
     103                 :            :     /**
     104                 :            :         Stop sending mail messages.
     105                 :            : 
     106                 :            :         @precond isStarted()
     107                 :            :     */
     108                 :            :     void stop();
     109                 :            : 
     110                 :            :     /**
     111                 :            :         Request shutdown of the mail dispatcher thread.
     112                 :            :         NOTE: You must call this method before you release
     113                 :            :         your last reference to this class otherwise the
     114                 :            :         mail dispatcher thread will never end.
     115                 :            :     */
     116                 :            :     void shutdown();
     117                 :            : 
     118                 :            :     /**
     119                 :            :         Check whether the mail dispatcher is started or not.
     120                 :            : 
     121                 :            :         @return
     122                 :            :         <TRUE/> if the sending thread is running.
     123                 :            :     */
     124                 :            :     bool isStarted() const;
     125                 :            : 
     126                 :            :     /** returns if the thread is still running
     127                 :            :     */
     128                 :            :     using osl::Thread::isRunning;
     129                 :            : 
     130                 :            :     /** returns if shutdown has already been called
     131                 :            :     */
     132                 :          0 :     bool isShutdownRequested() const
     133                 :          0 :         { return shutdown_requested_; }
     134                 :            :     /**
     135                 :            :         Register a listener for mail dispatcher events.
     136                 :            :     */
     137                 :            :     void addListener(::rtl::Reference<IMailDispatcherListener> listener);
     138                 :            : 
     139                 :            : protected:
     140                 :            :     virtual void SAL_CALL run();
     141                 :            :     virtual void SAL_CALL onTerminated();
     142                 :            : 
     143                 :            : private:
     144                 :            :     std::list< ::rtl::Reference<IMailDispatcherListener> > cloneListener();
     145                 :            :     void sendMailMessageNotifyListener(::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> message);
     146                 :            : 
     147                 :            : private:
     148                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::mail::XSmtpService> mailserver_;
     149                 :            :     ::std::list< ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage > > messages_;
     150                 :            :     ::std::list< ::rtl::Reference<IMailDispatcherListener> > listeners_;
     151                 :            :     ::osl::Mutex message_container_mutex_;
     152                 :            :     ::osl::Mutex listener_container_mutex_;
     153                 :            :     ::osl::Mutex thread_status_mutex_;
     154                 :            :     ::osl::Condition mail_dispatcher_active_;
     155                 :            :     ::osl::Condition wakening_call_;
     156                 :            :     ::rtl::Reference<MailDispatcher> m_xSelfReference;
     157                 :            :     bool run_;
     158                 :            :     bool shutdown_requested_;
     159                 :            : };
     160                 :            : 
     161                 :            : #endif // INCLUDED_MAILDISPATCHER_HXX
     162                 :            : 
     163                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10