Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / fpicker / source / win32 / asyncrequests.hxx
blob5fbd7dde848f49899d2bc90fac3c86abcb31b06e
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_FPICKER_SOURCE_WIN32_FILEPICKER_ASYNCREQUESTS_HXX
21 #define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_ASYNCREQUESTS_HXX
23 #include <cppuhelper/basemutex.hxx>
24 #include <comphelper/sequenceashashmap.hxx>
25 #include <osl/conditn.hxx>
26 #include <osl/thread.hxx>
27 #include <osl/time.h>
28 #include <queue>
29 #include <memory>
31 namespace fpicker{
32 namespace win32{
33 namespace vista{
36 /** @todo document me
38 class Request
41 public:
43 static const ::sal_Int32 WAIT_INFINITE = 0;
46 // interface
49 public:
52 explicit Request()
53 : m_aJoiner ( )
54 , m_nRequest (-1)
55 , m_lArguments( )
57 m_aJoiner.reset();
61 virtual ~Request() {};
64 void setRequest(::sal_Int32 nRequest)
66 m_nRequest = nRequest;
70 ::sal_Int32 getRequest()
72 return m_nRequest;
76 void clearArguments()
78 m_lArguments.clear();
82 template< class TArgumentType >
83 void setArgument(const OUString& sName ,
84 const TArgumentType& aValue)
86 m_lArguments[sName] = css::uno::toAny(aValue);
90 template< class TArgumentType >
91 TArgumentType getArgumentOrDefault(const OUString& sName ,
92 const TArgumentType& aDefault)
94 return m_lArguments.getUnpackedValueOrDefault(sName, aDefault);
97 css::uno::Any getValue(OUString const & key) const
99 return m_lArguments.getValue(key);
102 void wait(::sal_Int32 nMilliSeconds = WAIT_INFINITE);
104 void waitProcessMessages();
107 void notify();
110 // member
113 private:
115 ::osl::Condition m_aJoiner;
116 ::sal_Int32 m_nRequest;
117 ::comphelper::SequenceAsHashMap m_lArguments;
120 typedef std::shared_ptr< Request > RequestRef;
121 typedef std::queue< RequestRef > RequestQueue;
124 class RequestHandler
126 public:
127 virtual ~RequestHandler() {}
128 virtual void before() = 0;
129 virtual void doRequest(const RequestRef& rRequest) = 0;
130 virtual void after() = 0;
133 typedef std::shared_ptr< RequestHandler > RequestHandlerRef;
136 /** @todo document me
138 class AsyncRequests final: private ::cppu::BaseMutex
139 , public ::osl::Thread
141 public:
142 static const ::sal_Int16 PROCESS_MESSAGES = 2;
143 static const ::sal_Int16 BLOCKED = 1;
144 static const ::sal_Int16 NON_BLOCKED = 0;
147 /** creates the new asynchronous request executor.
149 explicit AsyncRequests(const RequestHandlerRef& rHandler);
151 void setHandler(const RequestHandlerRef& rHandler)
153 m_rHandler = rHandler;
156 /// ensure the execution thread gets going.
157 void triggerJobExecution();
160 /** does nothing special / excepting to make sure our class won't be inline .-)
162 virtual ~AsyncRequests() override;
165 /** @todo document me
167 void triggerRequestProcessMessages (const RequestRef& rRequest);
170 /** @todo document me
172 void triggerRequestBlocked(const RequestRef& rRequest);
175 /** @todo document me
177 void triggerRequestNonBlocked(const RequestRef& rRequest);
180 /** @todo document me
182 void triggerRequestDirectly(const RequestRef& rRequest);
185 /** @todo document me
187 void triggerRequestThreadAware(const RequestRef& rRequest,
188 ::sal_Int16 nWait );
190 private:
193 /** our STA .-)
194 * Will run between start() & finish(). Internally it runs a loop ...
195 * waiting for requests. Every request will be executed synchronously
196 * in blocked mode.
198 virtual void SAL_CALL run() override;
200 private:
202 bool m_bFinish;
203 RequestHandlerRef m_rHandler;
204 RequestQueue m_lRequests;
205 osl::Condition maWait;
208 } // namespace vista
209 } // namespace win32
210 } // namespace fpicker
212 #endif // INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_ASYNCREQUESTS_HXX
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */