bump product version to 4.1.6.2
[LibreOffice.git] / fpicker / source / win32 / filepicker / asyncrequests.hxx
blob6653a6c7cb9cea61995f819d95b4424eb1e48650
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <osl/time.h>
28 #include <queue>
29 #include <boost/shared_ptr.hpp>
31 namespace fpicker{
32 namespace win32{
33 namespace vista{
35 //-----------------------------------------------------------------------------
36 /** @todo document me
38 class Request
40 //-------------------------------------------------------------------------
41 public:
43 static const ::sal_Int32 WAIT_INFINITE = 0;
45 //-------------------------------------------------------------------------
46 // interface
47 //-------------------------------------------------------------------------
49 public:
51 //---------------------------------------------------------------------
52 explicit Request()
53 : m_aJoiner ( )
54 , m_nRequest (-1)
55 , m_lArguments( )
57 m_aJoiner.reset();
60 //---------------------------------------------------------------------
61 virtual ~Request() {};
63 //---------------------------------------------------------------------
64 void setRequest(::sal_Int32 nRequest)
66 m_nRequest = nRequest;
69 //---------------------------------------------------------------------
70 ::sal_Int32 getRequest()
72 return m_nRequest;
75 //---------------------------------------------------------------------
76 void clearArguments()
78 m_lArguments.clear();
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 //---------------------------------------------------------------------
103 void notify();
105 //-------------------------------------------------------------------------
106 // member
107 //-------------------------------------------------------------------------
109 private:
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 //-----------------------------------------------------------------------------
120 class RequestHandler
122 public:
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
136 public:
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,
183 ::sal_Int16 nWait );
185 private:
187 //---------------------------------------------------------------------
188 /** our STA .-)
189 * Will run between start() & finish(). Internaly it runs a loop ...
190 * waiting for requests. Every request will be executed synchronously
191 * in blocked mode.
193 virtual void SAL_CALL run();
195 private:
197 ::sal_Bool m_bFinish;
198 RequestHandlerRef m_rHandler;
199 RequestQueue m_lRequests;
200 osl::Condition maWait;
203 } // namespace vista
204 } // namespace win32
205 } // namespace fpicker
207 #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */