update dev300-m58
[ooovba.git] / sw / source / ui / inc / maildispatcher.hxx
blob898e715470f3851495cbc5d37efd8439c9e00a59
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: maildispatcher.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_MAILDISPATCHER_HXX
32 #define INCLUDED_MAILDISPATCHER_HXX
34 //#ifndef _COM_SUN_STAR_MAIL_XMAILSERVER_HPP_
35 //#include "com/sun/star/mail/XMailServer.hpp"
36 //#endif
37 #include "com/sun/star/mail/XSmtpService.hpp"
38 #include "com/sun/star/mail/XMailMessage.hpp"
39 #include <osl/thread.hxx>
40 #include <osl/conditn.hxx>
41 #include <salhelper/refobj.hxx>
43 #include <list>
45 class IMailDispatcherListener;
47 /**
48 A MailDispatcher should be used for sending a bunch a mail messages
49 asynchronously. Usually a client enqueues a number of mail messages
50 and then calls start to begin sending them. An instance of this class
51 must not be shared among different client threads. Instead each client
52 thread should create an own instance of this class.
53 */
54 class MailDispatcher : public ::salhelper::ReferenceObject, private ::osl::Thread
56 public:
57 // bringing operator new/delete into scope
58 using osl::Thread::operator new;
59 using osl::Thread::operator delete;
60 using osl::Thread::join;
62 public:
64 /**
65 @param xSmtpService
66 [in] a reference to a mail server. A user must be
67 connected to the mail server otherwise errors occur
68 during the delivery of mail messages.
70 @throws ::com::sun::star::uno::RuntimeException
71 on errors during construction of an instance of this class.
73 MailDispatcher(::com::sun::star::uno::Reference< ::com::sun::star::mail::XSmtpService> xMailService);
75 /**
76 Shutdown the mail dispatcher. Every mail messages
77 not yet sent will be discarded.
78 */
79 virtual ~MailDispatcher();
81 /**
82 Enqueue a mail message for delivery. A client must
83 start the mail dispatcher in order to send the
84 enqueued mail messages.
86 @param xMailMessage
87 [in] a mail message that should be send.
89 void enqueueMailMessage(::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> xMailMessage);
90 /**
91 Dequeues a mail message.
92 This enables the caller to remove attachments when sending mails is to be cancelled.
94 ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> dequeueMailMessage();
96 /**
97 Start sending mail messages asynchronously. A client may register
98 a listener for mail dispatcher events. For every mail message sent
99 the notification will be sent. While handling such notification a
100 client may enqueue new mail messages. If there are no more mail
101 messages to send an respective notification is sent and the mail
102 dispatcher waits for more mail messages.
104 @precond not isStarted()
106 void start();
109 Stop sending mail messages.
111 @precond isStarted()
113 void stop();
116 Request shutdown of the mail dispatcher thread.
117 NOTE: You must call this method before you release
118 your last reference to this class otherwise the
119 mail dispatcher thread will never end.
121 void shutdown();
124 Check whether the mail dispatcher is started or not.
126 @return
127 <TRUE/> if the sending thread is running.
129 bool isStarted() const;
131 /** returns if the thread is still running
133 using osl::Thread::isRunning;
134 bool isRunning() const;
136 /** returns if shutdown has already been called
138 bool isShutdownRequested() const
139 { return shutdown_requested_; }
141 Register a listener for mail dispatcher events.
143 void addListener(::rtl::Reference<IMailDispatcherListener> listener);
146 Unregister a listener for mail dispatcher events
148 void removeListener(::rtl::Reference<IMailDispatcherListener> listener);
150 protected:
151 virtual void SAL_CALL run();
152 virtual void SAL_CALL onTerminated();
154 private:
155 std::list< ::rtl::Reference<IMailDispatcherListener> > cloneListener();
156 void sendMailMessageNotifyListener(::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage> message);
158 private:
159 ::com::sun::star::uno::Reference< ::com::sun::star::mail::XSmtpService> mailserver_;
160 ::std::list< ::com::sun::star::uno::Reference< ::com::sun::star::mail::XMailMessage > > messages_;
161 ::std::list< ::rtl::Reference<IMailDispatcherListener> > listeners_;
162 ::osl::Mutex message_container_mutex_;
163 ::osl::Mutex listener_container_mutex_;
164 ::osl::Mutex thread_status_mutex_;
165 ::osl::Condition mail_dispatcher_active_;
166 ::osl::Condition wakening_call_;
167 ::rtl::Reference<MailDispatcher> m_xSelfReference;
168 bool run_;
169 bool shutdown_requested_;
170 bool bIsInRun;
173 #endif // INCLUDED_MAILDISPATCHER_HXX