1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
43 static const ::sal_Int32 WAIT_INFINITE
= 0;
61 virtual ~Request() {};
64 void setRequest(::sal_Int32 nRequest
)
66 m_nRequest
= nRequest
;
70 ::sal_Int32
getRequest()
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();
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
;
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
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
,
194 * Will run between start() & finish(). Internally it runs a loop ...
195 * waiting for requests. Every request will be executed synchronously
198 virtual void SAL_CALL
run() override
;
203 RequestHandlerRef m_rHandler
;
204 RequestQueue m_lRequests
;
205 osl::Condition maWait
;
210 } // namespace fpicker
212 #endif // INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_ASYNCREQUESTS_HXX
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */