merge the formfield patch from ooo-build
[ooovba.git] / fpicker / source / win32 / filepicker / asyncrequests.hxx
blob0a7e5c2c15a30a3bdcb313d681d23f9df22c0012
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: asyncrequests.hxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
32 #define FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
34 //-----------------------------------------------------------------------------
35 // includes
36 //-----------------------------------------------------------------------------
38 #include <cppuhelper/basemutex.hxx>
39 #include <comphelper/sequenceashashmap.hxx>
40 #include <osl/conditn.hxx>
41 #include <osl/thread.hxx>
42 #include <osl/time.h>
43 #include <queue>
44 #include <boost/shared_ptr.hpp>
46 //-----------------------------------------------------------------------------
47 // namespace
48 //-----------------------------------------------------------------------------
50 #ifdef css
51 #error "Clash on using CSS as namespace define."
52 #else
53 #define css ::com::sun::star
54 #endif
56 namespace fpicker{
57 namespace win32{
58 namespace vista{
60 //-----------------------------------------------------------------------------
61 /** @todo document me
63 class Request
65 //-------------------------------------------------------------------------
66 public:
68 static const ::sal_Int32 WAIT_INFINITE = 0;
70 //-------------------------------------------------------------------------
71 // interface
72 //-------------------------------------------------------------------------
74 public:
76 //---------------------------------------------------------------------
77 explicit Request()
78 : m_aJoiner ( )
79 , m_nRequest (-1)
80 , m_lArguments( )
82 m_aJoiner.reset();
85 //---------------------------------------------------------------------
86 virtual ~Request() {};
88 //---------------------------------------------------------------------
89 void setRequest(::sal_Int32 nRequest)
91 m_nRequest = nRequest;
94 //---------------------------------------------------------------------
95 ::sal_Int32 getRequest()
97 return m_nRequest;
100 //---------------------------------------------------------------------
101 void clearArguments()
103 m_lArguments.clear();
106 //---------------------------------------------------------------------
107 template< class TArgumentType >
108 void setArgument(const ::rtl::OUString& sName ,
109 const TArgumentType& aValue)
111 m_lArguments[sName] <<= aValue;
114 //---------------------------------------------------------------------
115 template< class TArgumentType >
116 TArgumentType getArgumentOrDefault(const ::rtl::OUString& sName ,
117 const TArgumentType& aDefault)
119 return m_lArguments.getUnpackedValueOrDefault(sName, aDefault);
122 //---------------------------------------------------------------------
123 void wait(::sal_Int32 nMilliSeconds = WAIT_INFINITE);
125 void waitProcessMessages();
127 //---------------------------------------------------------------------
128 void notify();
130 //-------------------------------------------------------------------------
131 // member
132 //-------------------------------------------------------------------------
134 private:
136 ::osl::Condition m_aJoiner;
137 ::sal_Int32 m_nRequest;
138 ::comphelper::SequenceAsHashMap m_lArguments;
141 typedef ::boost::shared_ptr< Request > RequestRef;
142 typedef ::std::queue< RequestRef > RequestQueue;
144 //-----------------------------------------------------------------------------
145 class RequestHandler
147 public:
148 virtual void before() = 0;
149 virtual void doRequest(const RequestRef& rRequest) = 0;
150 virtual void after() = 0;
153 typedef ::boost::shared_ptr< RequestHandler > RequestHandlerRef;
155 //-----------------------------------------------------------------------------
156 /** @todo docuemnt me
158 class AsyncRequests : private ::cppu::BaseMutex
159 , public ::osl::Thread
161 public:
162 static const ::sal_Int16 PROCESS_MESSAGES = 2;
163 static const ::sal_Int16 BLOCKED = 1;
164 static const ::sal_Int16 NON_BLOCKED = 0;
166 //---------------------------------------------------------------------
167 /** creates the new asynchronous request executor.
169 explicit AsyncRequests(const RequestHandlerRef& rHandler);
171 void setHandler(const RequestHandlerRef& rHandler)
173 m_rHandler = rHandler;
176 //---------------------------------------------------------------------
177 /** does nothing special / excepting to make sure our class wont be inline .-)
179 virtual ~AsyncRequests();
181 //---------------------------------------------------------------------
182 /** @todo document me
184 void triggerRequestProcessMessages (const RequestRef& rRequest);
186 //---------------------------------------------------------------------
187 /** @todo document me
189 void triggerRequestBlocked(const RequestRef& rRequest);
191 //---------------------------------------------------------------------
192 /** @todo document me
194 void triggerRequestNonBlocked(const RequestRef& rRequest);
196 //---------------------------------------------------------------------
197 /** @todo document me
199 void triggerRequestDirectly(const RequestRef& rRequest);
201 //---------------------------------------------------------------------
202 /** @todo document me
204 void triggerRequestThreadAware(const RequestRef& rRequest,
205 ::sal_Int16 nWait );
207 private:
209 //---------------------------------------------------------------------
210 /** our STA .-)
211 * Will run between start() & finish(). Internaly it runs a loop ...
212 * waiting for requests. Every request will be executed synchronously
213 * in blocked mode.
215 virtual void SAL_CALL run();
217 private:
219 ::sal_Bool m_bFinish;
220 RequestHandlerRef m_rHandler;
221 RequestQueue m_lRequests;
224 } // namespace vista
225 } // namespace win32
226 } // namespace fpicker
228 #undef css
230 #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX