merged tag ooo/DEV300_m102
[LibreOffice.git] / fpicker / source / win32 / filepicker / asyncrequests.hxx
blob752d919c2199e82ed2f88ce49609bcefdfd9d07e
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 //-----------------------------------------------------------------------------
32 // includes
33 //-----------------------------------------------------------------------------
35 #include <cppuhelper/basemutex.hxx>
36 #include <comphelper/sequenceashashmap.hxx>
37 #include <osl/conditn.hxx>
38 #include <osl/thread.hxx>
39 #include <osl/time.h>
40 #include <queue>
41 #include <boost/shared_ptr.hpp>
43 //-----------------------------------------------------------------------------
44 // namespace
45 //-----------------------------------------------------------------------------
47 #ifdef css
48 #error "Clash on using CSS as namespace define."
49 #else
50 #define css ::com::sun::star
51 #endif
53 namespace fpicker{
54 namespace win32{
55 namespace vista{
57 //-----------------------------------------------------------------------------
58 /** @todo document me
60 class Request
62 //-------------------------------------------------------------------------
63 public:
65 static const ::sal_Int32 WAIT_INFINITE = 0;
67 //-------------------------------------------------------------------------
68 // interface
69 //-------------------------------------------------------------------------
71 public:
73 //---------------------------------------------------------------------
74 explicit Request()
75 : m_aJoiner ( )
76 , m_nRequest (-1)
77 , m_lArguments( )
79 m_aJoiner.reset();
82 //---------------------------------------------------------------------
83 virtual ~Request() {};
85 //---------------------------------------------------------------------
86 void setRequest(::sal_Int32 nRequest)
88 m_nRequest = nRequest;
91 //---------------------------------------------------------------------
92 ::sal_Int32 getRequest()
94 return m_nRequest;
97 //---------------------------------------------------------------------
98 void clearArguments()
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 //---------------------------------------------------------------------
125 void notify();
127 //-------------------------------------------------------------------------
128 // member
129 //-------------------------------------------------------------------------
131 private:
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 //-----------------------------------------------------------------------------
142 class RequestHandler
144 public:
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
158 public:
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,
202 ::sal_Int16 nWait );
204 private:
206 //---------------------------------------------------------------------
207 /** our STA .-)
208 * Will run between start() & finish(). Internaly it runs a loop ...
209 * waiting for requests. Every request will be executed synchronously
210 * in blocked mode.
212 virtual void SAL_CALL run();
214 private:
216 ::sal_Bool m_bFinish;
217 RequestHandlerRef m_rHandler;
218 RequestQueue m_lRequests;
221 } // namespace vista
222 } // namespace win32
223 } // namespace fpicker
225 #undef css
227 #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX