1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: asyncrequests.hxx,v $
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 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 #include <cppuhelper/basemutex.hxx>
39 #include <comphelper/sequenceashashmap.hxx>
40 #include <osl/conditn.hxx>
41 #include <osl/thread.hxx>
44 #include <boost/shared_ptr.hpp>
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
51 #error "Clash on using CSS as namespace define."
53 #define css ::com::sun::star
60 //-----------------------------------------------------------------------------
65 //-------------------------------------------------------------------------
68 static const ::sal_Int32 WAIT_INFINITE
= 0;
70 //-------------------------------------------------------------------------
72 //-------------------------------------------------------------------------
76 //---------------------------------------------------------------------
85 //---------------------------------------------------------------------
86 virtual ~Request() {};
88 //---------------------------------------------------------------------
89 void setRequest(::sal_Int32 nRequest
)
91 m_nRequest
= nRequest
;
94 //---------------------------------------------------------------------
95 ::sal_Int32
getRequest()
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 //---------------------------------------------------------------------
130 //-------------------------------------------------------------------------
132 //-------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
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
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
,
209 //---------------------------------------------------------------------
211 * Will run between start() & finish(). Internaly it runs a loop ...
212 * waiting for requests. Every request will be executed synchronously
215 virtual void SAL_CALL
run();
219 ::sal_Bool m_bFinish
;
220 RequestHandlerRef m_rHandler
;
221 RequestQueue m_lRequests
;
226 } // namespace fpicker
230 #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX