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 FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
21 #define FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
23 #include <cppuhelper/basemutex.hxx>
24 #include <comphelper/sequenceashashmap.hxx>
25 #include <osl/conditn.hxx>
26 #include <osl/thread.hxx>
29 #include <boost/shared_ptr.hpp>
35 //-----------------------------------------------------------------------------
40 //-------------------------------------------------------------------------
43 static const ::sal_Int32 WAIT_INFINITE
= 0;
45 //-------------------------------------------------------------------------
47 //-------------------------------------------------------------------------
51 //---------------------------------------------------------------------
60 //---------------------------------------------------------------------
61 virtual ~Request() {};
63 //---------------------------------------------------------------------
64 void setRequest(::sal_Int32 nRequest
)
66 m_nRequest
= nRequest
;
69 //---------------------------------------------------------------------
70 ::sal_Int32
getRequest()
75 //---------------------------------------------------------------------
81 //---------------------------------------------------------------------
82 template< class TArgumentType
>
83 void setArgument(const OUString
& sName
,
84 const TArgumentType
& aValue
)
86 m_lArguments
[sName
] <<= aValue
;
89 //---------------------------------------------------------------------
90 template< class TArgumentType
>
91 TArgumentType
getArgumentOrDefault(const OUString
& sName
,
92 const TArgumentType
& aDefault
)
94 return m_lArguments
.getUnpackedValueOrDefault(sName
, aDefault
);
97 //---------------------------------------------------------------------
98 void wait(::sal_Int32 nMilliSeconds
= WAIT_INFINITE
);
100 void waitProcessMessages();
102 //---------------------------------------------------------------------
105 //-------------------------------------------------------------------------
107 //-------------------------------------------------------------------------
111 ::osl::Condition m_aJoiner
;
112 ::sal_Int32 m_nRequest
;
113 ::comphelper::SequenceAsHashMap m_lArguments
;
116 typedef ::boost::shared_ptr
< Request
> RequestRef
;
117 typedef ::std::queue
< RequestRef
> RequestQueue
;
119 //-----------------------------------------------------------------------------
123 virtual void before() = 0;
124 virtual void doRequest(const RequestRef
& rRequest
) = 0;
125 virtual void after() = 0;
128 typedef ::boost::shared_ptr
< RequestHandler
> RequestHandlerRef
;
130 //-----------------------------------------------------------------------------
131 /** @todo document me
133 class AsyncRequests
: private ::cppu::BaseMutex
134 , public ::osl::Thread
137 static const ::sal_Int16 PROCESS_MESSAGES
= 2;
138 static const ::sal_Int16 BLOCKED
= 1;
139 static const ::sal_Int16 NON_BLOCKED
= 0;
141 //---------------------------------------------------------------------
142 /** creates the new asynchronous request executor.
144 explicit AsyncRequests(const RequestHandlerRef
& rHandler
);
146 void setHandler(const RequestHandlerRef
& rHandler
)
148 m_rHandler
= rHandler
;
151 /// ensure the execution thread gets going.
152 void triggerJobExecution();
154 //---------------------------------------------------------------------
155 /** does nothing special / excepting to make sure our class wont be inline .-)
157 virtual ~AsyncRequests();
159 //---------------------------------------------------------------------
160 /** @todo document me
162 void triggerRequestProcessMessages (const RequestRef
& rRequest
);
164 //---------------------------------------------------------------------
165 /** @todo document me
167 void triggerRequestBlocked(const RequestRef
& rRequest
);
169 //---------------------------------------------------------------------
170 /** @todo document me
172 void triggerRequestNonBlocked(const RequestRef
& rRequest
);
174 //---------------------------------------------------------------------
175 /** @todo document me
177 void triggerRequestDirectly(const RequestRef
& rRequest
);
179 //---------------------------------------------------------------------
180 /** @todo document me
182 void triggerRequestThreadAware(const RequestRef
& rRequest
,
187 //---------------------------------------------------------------------
189 * Will run between start() & finish(). Internaly it runs a loop ...
190 * waiting for requests. Every request will be executed synchronously
193 virtual void SAL_CALL
run();
197 ::sal_Bool m_bFinish
;
198 RequestHandlerRef m_rHandler
;
199 RequestQueue m_lRequests
;
200 osl::Condition maWait
;
205 } // namespace fpicker
207 #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */