110ce8018SAndrew Rist /************************************************************** 2*f6675432Smseidel * 310ce8018SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 410ce8018SAndrew Rist * or more contributor license agreements. See the NOTICE file 510ce8018SAndrew Rist * distributed with this work for additional information 610ce8018SAndrew Rist * regarding copyright ownership. The ASF licenses this file 710ce8018SAndrew Rist * to you under the Apache License, Version 2.0 (the 810ce8018SAndrew Rist * "License"); you may not use this file except in compliance 910ce8018SAndrew Rist * with the License. You may obtain a copy of the License at 10*f6675432Smseidel * 1110ce8018SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f6675432Smseidel * 1310ce8018SAndrew Rist * Unless required by applicable law or agreed to in writing, 1410ce8018SAndrew Rist * software distributed under the License is distributed on an 1510ce8018SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1610ce8018SAndrew Rist * KIND, either express or implied. See the License for the 1710ce8018SAndrew Rist * specific language governing permissions and limitations 1810ce8018SAndrew Rist * under the License. 19*f6675432Smseidel * 2010ce8018SAndrew Rist *************************************************************/ 2110ce8018SAndrew Rist 2210ce8018SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX 25cdf0e10cSrcweir #define FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir //----------------------------------------------------------------------------- 28cdf0e10cSrcweir // includes 29cdf0e10cSrcweir //----------------------------------------------------------------------------- 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 32cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx> 33cdf0e10cSrcweir #include <osl/conditn.hxx> 34cdf0e10cSrcweir #include <osl/thread.hxx> 35cdf0e10cSrcweir #include <osl/time.h> 36cdf0e10cSrcweir #include <queue> 37cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 38cdf0e10cSrcweir 39cdf0e10cSrcweir //----------------------------------------------------------------------------- 40cdf0e10cSrcweir // namespace 41cdf0e10cSrcweir //----------------------------------------------------------------------------- 42cdf0e10cSrcweir 43cdf0e10cSrcweir #ifdef css 44*f6675432Smseidel #error "Clash on using CSS as namespace define." 45cdf0e10cSrcweir #else 46*f6675432Smseidel #define css ::com::sun::star 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace fpicker{ 50cdf0e10cSrcweir namespace win32{ 51cdf0e10cSrcweir namespace vista{ 52cdf0e10cSrcweir 53cdf0e10cSrcweir //----------------------------------------------------------------------------- 54cdf0e10cSrcweir /** @todo document me 55cdf0e10cSrcweir */ 56cdf0e10cSrcweir class Request 57cdf0e10cSrcweir { 58*f6675432Smseidel //------------------------------------------------------------------------- 59*f6675432Smseidel public: 60*f6675432Smseidel 61*f6675432Smseidel static const ::sal_Int32 WAIT_INFINITE = 0; 62*f6675432Smseidel 63*f6675432Smseidel //------------------------------------------------------------------------- 64*f6675432Smseidel // interface 65*f6675432Smseidel //------------------------------------------------------------------------- 66*f6675432Smseidel 67*f6675432Smseidel public: 68*f6675432Smseidel 69*f6675432Smseidel //--------------------------------------------------------------------- Request()70*f6675432Smseidel explicit Request() 71*f6675432Smseidel : m_aJoiner ( ) 72*f6675432Smseidel , m_nRequest (-1) 73*f6675432Smseidel , m_lArguments( ) 74*f6675432Smseidel { 75*f6675432Smseidel m_aJoiner.reset(); 76*f6675432Smseidel } 77*f6675432Smseidel 78*f6675432Smseidel //--------------------------------------------------------------------- ~Request()79*f6675432Smseidel virtual ~Request() {}; 80*f6675432Smseidel 81*f6675432Smseidel //--------------------------------------------------------------------- setRequest(::sal_Int32 nRequest)82*f6675432Smseidel void setRequest(::sal_Int32 nRequest) 83*f6675432Smseidel { 84*f6675432Smseidel m_nRequest = nRequest; 85*f6675432Smseidel } 86*f6675432Smseidel 87*f6675432Smseidel //--------------------------------------------------------------------- getRequest()88*f6675432Smseidel ::sal_Int32 getRequest() 89*f6675432Smseidel { 90*f6675432Smseidel return m_nRequest; 91*f6675432Smseidel } 92*f6675432Smseidel 93*f6675432Smseidel //--------------------------------------------------------------------- clearArguments()94*f6675432Smseidel void clearArguments() 95*f6675432Smseidel { 96*f6675432Smseidel m_lArguments.clear(); 97*f6675432Smseidel } 98*f6675432Smseidel 99*f6675432Smseidel //--------------------------------------------------------------------- 100*f6675432Smseidel template< class TArgumentType > setArgument(const::rtl::OUString & sName,const TArgumentType & aValue)101*f6675432Smseidel void setArgument(const ::rtl::OUString& sName , 102*f6675432Smseidel const TArgumentType& aValue) 103*f6675432Smseidel { 104*f6675432Smseidel m_lArguments[sName] <<= aValue; 105*f6675432Smseidel } 106*f6675432Smseidel 107*f6675432Smseidel //--------------------------------------------------------------------- 108*f6675432Smseidel template< class TArgumentType > getArgumentOrDefault(const::rtl::OUString & sName,const TArgumentType & aDefault)109*f6675432Smseidel TArgumentType getArgumentOrDefault(const ::rtl::OUString& sName , 110*f6675432Smseidel const TArgumentType& aDefault) 111*f6675432Smseidel { 112*f6675432Smseidel return m_lArguments.getUnpackedValueOrDefault(sName, aDefault); 113*f6675432Smseidel } 114*f6675432Smseidel 115*f6675432Smseidel //--------------------------------------------------------------------- 116*f6675432Smseidel void wait(::sal_Int32 nMilliSeconds = WAIT_INFINITE); 117*f6675432Smseidel 118cdf0e10cSrcweir void waitProcessMessages(); 119*f6675432Smseidel 120*f6675432Smseidel //--------------------------------------------------------------------- 121*f6675432Smseidel void notify(); 122*f6675432Smseidel 123*f6675432Smseidel //------------------------------------------------------------------------- 124*f6675432Smseidel // member 125*f6675432Smseidel //------------------------------------------------------------------------- 126*f6675432Smseidel 127*f6675432Smseidel private: 128*f6675432Smseidel 129*f6675432Smseidel ::osl::Condition m_aJoiner; 130*f6675432Smseidel ::sal_Int32 m_nRequest; 131*f6675432Smseidel ::comphelper::SequenceAsHashMap m_lArguments; 132cdf0e10cSrcweir }; 133cdf0e10cSrcweir 134cdf0e10cSrcweir typedef ::boost::shared_ptr< Request > RequestRef; 135cdf0e10cSrcweir typedef ::std::queue< RequestRef > RequestQueue; 136cdf0e10cSrcweir 137cdf0e10cSrcweir //----------------------------------------------------------------------------- 138cdf0e10cSrcweir class RequestHandler 139cdf0e10cSrcweir { 140*f6675432Smseidel public: 141*f6675432Smseidel virtual void before() = 0; 142*f6675432Smseidel virtual void doRequest(const RequestRef& rRequest) = 0; 143*f6675432Smseidel virtual void after() = 0; 144cdf0e10cSrcweir }; 145cdf0e10cSrcweir 146cdf0e10cSrcweir typedef ::boost::shared_ptr< RequestHandler > RequestHandlerRef; 147cdf0e10cSrcweir 148cdf0e10cSrcweir //----------------------------------------------------------------------------- 149*f6675432Smseidel /** @todo document me 150cdf0e10cSrcweir */ 151cdf0e10cSrcweir class AsyncRequests : private ::cppu::BaseMutex 152*f6675432Smseidel , public ::osl::Thread 153cdf0e10cSrcweir { 154*f6675432Smseidel public: 155*f6675432Smseidel static const ::sal_Int16 PROCESS_MESSAGES = 2; 156*f6675432Smseidel static const ::sal_Int16 BLOCKED = 1; 157*f6675432Smseidel static const ::sal_Int16 NON_BLOCKED = 0; 158*f6675432Smseidel 159*f6675432Smseidel //--------------------------------------------------------------------- 160*f6675432Smseidel /** creates the new asynchronous request executor. 161*f6675432Smseidel */ 162*f6675432Smseidel explicit AsyncRequests(const RequestHandlerRef& rHandler); 163*f6675432Smseidel setHandler(const RequestHandlerRef & rHandler)164*f6675432Smseidel void setHandler(const RequestHandlerRef& rHandler) 165*f6675432Smseidel { 166*f6675432Smseidel m_rHandler = rHandler; 167*f6675432Smseidel } 168*f6675432Smseidel 169*f6675432Smseidel //--------------------------------------------------------------------- 170*f6675432Smseidel /** does nothing special / except to make sure our class won't be inline .-) 171*f6675432Smseidel */ 172*f6675432Smseidel virtual ~AsyncRequests(); 173*f6675432Smseidel 174*f6675432Smseidel //--------------------------------------------------------------------- 175*f6675432Smseidel /** @todo document me 176*f6675432Smseidel */ 177cdf0e10cSrcweir void triggerRequestProcessMessages (const RequestRef& rRequest); 178*f6675432Smseidel 179*f6675432Smseidel //--------------------------------------------------------------------- 180*f6675432Smseidel /** @todo document me 181*f6675432Smseidel */ 182*f6675432Smseidel void triggerRequestBlocked(const RequestRef& rRequest); 183*f6675432Smseidel 184*f6675432Smseidel //--------------------------------------------------------------------- 185*f6675432Smseidel /** @todo document me 186*f6675432Smseidel */ 187*f6675432Smseidel void triggerRequestNonBlocked(const RequestRef& rRequest); 188*f6675432Smseidel 189*f6675432Smseidel //--------------------------------------------------------------------- 190*f6675432Smseidel /** @todo document me 191*f6675432Smseidel */ 192*f6675432Smseidel void triggerRequestDirectly(const RequestRef& rRequest); 193*f6675432Smseidel 194*f6675432Smseidel //--------------------------------------------------------------------- 195*f6675432Smseidel /** @todo document me 196*f6675432Smseidel */ 197*f6675432Smseidel void triggerRequestThreadAware(const RequestRef& rRequest, 198*f6675432Smseidel ::sal_Int16 nWait ); 199*f6675432Smseidel 200*f6675432Smseidel private: 201*f6675432Smseidel 202*f6675432Smseidel //--------------------------------------------------------------------- 203*f6675432Smseidel /** our STA .-) 204*f6675432Smseidel * Will run between start() & finish(). Internally it runs a loop... 205*f6675432Smseidel * waiting for requests. Every request will be executed synchronously 206*f6675432Smseidel * in blocked mode. 207*f6675432Smseidel */ 208*f6675432Smseidel virtual void SAL_CALL run(); 209*f6675432Smseidel 210*f6675432Smseidel private: 211*f6675432Smseidel 212*f6675432Smseidel ::sal_Bool m_bFinish; 213*f6675432Smseidel RequestHandlerRef m_rHandler; 214*f6675432Smseidel RequestQueue m_lRequests; 215cdf0e10cSrcweir }; 216cdf0e10cSrcweir 217cdf0e10cSrcweir } // namespace vista 218cdf0e10cSrcweir } // namespace win32 219cdf0e10cSrcweir } // namespace fpicker 220cdf0e10cSrcweir 221cdf0e10cSrcweir #undef css 222cdf0e10cSrcweir 223cdf0e10cSrcweir #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX 224*f6675432Smseidel 225*f6675432Smseidel /* vim: set noet sw=4 ts=4: */ 226