1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
29 #define FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 #include <cppuhelper/basemutex.hxx>
36 #include <comphelper/sequenceashashmap.hxx>
37 #include <osl/conditn.hxx>
38 #include <osl/thread.hxx>
41 #include <boost/shared_ptr.hpp>
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
48 #error "Clash on using CSS as namespace define."
50 #define css ::com::sun::star
57 //-----------------------------------------------------------------------------
62 //-------------------------------------------------------------------------
65 static const ::sal_Int32 WAIT_INFINITE
= 0;
67 //-------------------------------------------------------------------------
69 //-------------------------------------------------------------------------
73 //---------------------------------------------------------------------
82 //---------------------------------------------------------------------
83 virtual ~Request() {};
85 //---------------------------------------------------------------------
86 void setRequest(::sal_Int32 nRequest
)
88 m_nRequest
= nRequest
;
91 //---------------------------------------------------------------------
92 ::sal_Int32
getRequest()
97 //---------------------------------------------------------------------
100 m_lArguments
.clear();
103 //---------------------------------------------------------------------
104 template< class TArgumentType
>
105 void setArgument(const ::rtl::OUString
& sName
,
106 const TArgumentType
& aValue
)
108 m_lArguments
[sName
] <<= aValue
;
111 //---------------------------------------------------------------------
112 template< class TArgumentType
>
113 TArgumentType
getArgumentOrDefault(const ::rtl::OUString
& sName
,
114 const TArgumentType
& aDefault
)
116 return m_lArguments
.getUnpackedValueOrDefault(sName
, aDefault
);
119 //---------------------------------------------------------------------
120 void wait(::sal_Int32 nMilliSeconds
= WAIT_INFINITE
);
122 void waitProcessMessages();
124 //---------------------------------------------------------------------
127 //-------------------------------------------------------------------------
129 //-------------------------------------------------------------------------
133 ::osl::Condition m_aJoiner
;
134 ::sal_Int32 m_nRequest
;
135 ::comphelper::SequenceAsHashMap m_lArguments
;
138 typedef ::boost::shared_ptr
< Request
> RequestRef
;
139 typedef ::std::queue
< RequestRef
> RequestQueue
;
141 //-----------------------------------------------------------------------------
145 virtual void before() = 0;
146 virtual void doRequest(const RequestRef
& rRequest
) = 0;
147 virtual void after() = 0;
150 typedef ::boost::shared_ptr
< RequestHandler
> RequestHandlerRef
;
152 //-----------------------------------------------------------------------------
153 /** @todo docuemnt me
155 class AsyncRequests
: private ::cppu::BaseMutex
156 , public ::osl::Thread
159 static const ::sal_Int16 PROCESS_MESSAGES
= 2;
160 static const ::sal_Int16 BLOCKED
= 1;
161 static const ::sal_Int16 NON_BLOCKED
= 0;
163 //---------------------------------------------------------------------
164 /** creates the new asynchronous request executor.
166 explicit AsyncRequests(const RequestHandlerRef
& rHandler
);
168 void setHandler(const RequestHandlerRef
& rHandler
)
170 m_rHandler
= rHandler
;
173 //---------------------------------------------------------------------
174 /** does nothing special / excepting to make sure our class wont be inline .-)
176 virtual ~AsyncRequests();
178 //---------------------------------------------------------------------
179 /** @todo document me
181 void triggerRequestProcessMessages (const RequestRef
& rRequest
);
183 //---------------------------------------------------------------------
184 /** @todo document me
186 void triggerRequestBlocked(const RequestRef
& rRequest
);
188 //---------------------------------------------------------------------
189 /** @todo document me
191 void triggerRequestNonBlocked(const RequestRef
& rRequest
);
193 //---------------------------------------------------------------------
194 /** @todo document me
196 void triggerRequestDirectly(const RequestRef
& rRequest
);
198 //---------------------------------------------------------------------
199 /** @todo document me
201 void triggerRequestThreadAware(const RequestRef
& rRequest
,
206 //---------------------------------------------------------------------
208 * Will run between start() & finish(). Internaly it runs a loop ...
209 * waiting for requests. Every request will be executed synchronously
212 virtual void SAL_CALL
run();
216 ::sal_Bool m_bFinish
;
217 RequestHandlerRef m_rHandler
;
218 RequestQueue m_lRequests
;
223 } // namespace fpicker
227 #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX