nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / uibase / inc / maildispatcher.hxx
blobe6f9f0cc788871aa1d68666949e8a1fba1138685
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX
21 #define INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX
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 <rtl/ref.hxx>
28 #include <salhelper/simplereferenceobject.hxx>
30 #include <list>
31 #include <vector>
33 #include <swdllapi.h>
35 class IMailDispatcherListener;
37 /**
38 A MailDispatcher should be used for sending a bunch a mail messages
39 asynchronously. Usually a client enqueues a number of mail messages
40 and then calls start to begin sending them. An instance of this class
41 must not be shared among different client threads. Instead each client
42 thread should create an own instance of this class.
44 class SW_DLLPUBLIC MailDispatcher : public salhelper::SimpleReferenceObject, private ::osl::Thread
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;
52 /**
53 @param xSmtpService
54 [in] a reference to a mail server. A user must be
55 connected to the mail server otherwise errors occur
56 during the delivery of mail messages.
58 @throws css::uno::RuntimeException
59 on errors during construction of an instance of this class.
61 MailDispatcher(css::uno::Reference<css::mail::XSmtpService> const& xMailService);
63 /**
64 Shutdown the mail dispatcher. Every mail messages
65 not yet sent will be discarded.
67 virtual ~MailDispatcher() override;
69 /**
70 Enqueue a mail message for delivery. A client must
71 start the mail dispatcher in order to send the
72 enqueued mail messages.
74 @param xMailMessage
75 [in] a mail message that should be send.
77 void enqueueMailMessage(css::uno::Reference<css::mail::XMailMessage> const& xMailMessage);
78 /**
79 Dequeues a mail message.
80 This enables the caller to remove attachments when sending mails is to be cancelled.
82 css::uno::Reference<css::mail::XMailMessage> dequeueMailMessage();
84 /**
85 Start sending mail messages asynchronously. A client may register
86 a listener for mail dispatcher events. For every mail message sent
87 the notification will be sent. While handling such notification a
88 client may enqueue new mail messages. If there are no more mail
89 messages to send a respective notification is sent and the mail
90 dispatcher waits for more mail messages.
92 @precond not isStarted()
94 void start();
96 /**
97 Stop sending mail messages.
99 @precond isStarted()
101 void stop();
104 Request shutdown of the mail dispatcher thread.
105 NOTE: You must call this method before you release
106 your last reference to this class otherwise the
107 mail dispatcher thread will never end.
109 void shutdown();
112 Check whether the mail dispatcher is started or not.
114 @return
115 <TRUE/> if the sending thread is running.
117 bool isStarted() const { return m_bActive; }
119 /** returns if the thread is still running
121 using osl::Thread::isRunning;
124 * returns if shutdown has already been called
126 bool isShutdownRequested() const { return m_bShutdownRequested; }
129 * Register a listener for mail dispatcher events
131 void addListener(::rtl::Reference<IMailDispatcherListener> const& listener);
133 protected:
134 virtual void SAL_CALL run() override;
135 virtual void SAL_CALL onTerminated() override;
137 private:
138 std::vector<::rtl::Reference<IMailDispatcherListener>> cloneListener();
139 void sendMailMessageNotifyListener(css::uno::Reference<css::mail::XMailMessage> const& message);
141 private:
142 css::uno::Reference<css::mail::XSmtpService> m_xMailserver;
143 std::list<css::uno::Reference<css::mail::XMailMessage>> m_aXMessageList;
144 std::vector<::rtl::Reference<IMailDispatcherListener>> m_aListenerVector;
145 ::osl::Mutex m_aMessageContainerMutex;
146 ::osl::Mutex m_aListenerContainerMutex;
147 ::osl::Mutex m_aThreadStatusMutex;
148 ::osl::Condition m_aRunCondition;
149 ::osl::Condition m_aWakeupCondition;
150 ::rtl::Reference<MailDispatcher> m_xSelfReference;
151 bool m_bActive;
152 bool m_bShutdownRequested;
155 #endif // INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */