LibreOffice Module sw (master)  1
maildispatcher.hxx
Go to the documentation of this file.
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 <rtl/ref.hxx>
29 
30 #include <list>
31 #include <vector>
32 
33 #include <swdllapi.h>
34 
36 
44 class SW_DLLPUBLIC MailDispatcher : public salhelper::SimpleReferenceObject, 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 
61  MailDispatcher(css::uno::Reference<css::mail::XSmtpService> const& xMailService);
62 
67  virtual ~MailDispatcher() override;
68 
77  void enqueueMailMessage(css::uno::Reference<css::mail::XMailMessage> const& xMailMessage);
82  css::uno::Reference<css::mail::XMailMessage> dequeueMailMessage();
83 
94  void start();
95 
101  void stop();
102 
109  void shutdown();
110 
117  bool isStarted() const { return m_bActive; }
118 
121  using osl::Thread::isRunning;
122 
126  bool isShutdownRequested() const { return m_bShutdownRequested; }
127 
132 
133 protected:
134  virtual void SAL_CALL run() override;
135  virtual void SAL_CALL onTerminated() override;
136 
137 private:
138  std::vector<::rtl::Reference<IMailDispatcherListener>> cloneListener();
139  void sendMailMessageNotifyListener(css::uno::Reference<css::mail::XMailMessage> const& message);
140 
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;
147  ::osl::Mutex m_aThreadStatusMutex;
148  ::osl::Condition m_aRunCondition;
149  ::osl::Condition m_aWakeupCondition;
151  bool m_bActive;
153 };
154 
155 #endif // INCLUDED_SW_SOURCE_UIBASE_INC_MAILDISPATCHER_HXX
156 
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::osl::Mutex m_aListenerContainerMutex
css::uno::Reference< css::mail::XSmtpService > m_xMailserver
bool isShutdownRequested() const
returns if shutdown has already been called
MailDispatcher listener interface.
std::list< css::uno::Reference< css::mail::XMailMessage > > m_aXMessageList
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::lang::XEventListener > &xListener)
::osl::Condition m_aWakeupCondition
def run
std::vector<::rtl::Reference< IMailDispatcherListener > > m_aListenerVector
::osl::Mutex m_aThreadStatusMutex
def stop
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
::osl::Condition m_aRunCondition
::osl::Mutex m_aMessageContainerMutex
bool isStarted() const
Check whether the mail dispatcher is started or not.
::rtl::Reference< MailDispatcher > m_xSelfReference
A MailDispatcher should be used for sending a bunch a mail messages asynchronously.