1*10ce8018SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*10ce8018SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*10ce8018SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*10ce8018SAndrew Rist * distributed with this work for additional information 6*10ce8018SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*10ce8018SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*10ce8018SAndrew Rist * "License"); you may not use this file except in compliance 9*10ce8018SAndrew Rist * with the License. You may obtain a copy of the License at 10*10ce8018SAndrew Rist * 11*10ce8018SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*10ce8018SAndrew Rist * 13*10ce8018SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*10ce8018SAndrew Rist * software distributed under the License is distributed on an 15*10ce8018SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*10ce8018SAndrew Rist * KIND, either express or implied. See the License for the 17*10ce8018SAndrew Rist * specific language governing permissions and limitations 18*10ce8018SAndrew Rist * under the License. 19*10ce8018SAndrew Rist * 20*10ce8018SAndrew Rist *************************************************************/ 21*10ce8018SAndrew Rist 22*10ce8018SAndrew 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 44cdf0e10cSrcweir #error "Clash on using CSS as namespace define." 45cdf0e10cSrcweir #else 46cdf0e10cSrcweir #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 { 58cdf0e10cSrcweir //------------------------------------------------------------------------- 59cdf0e10cSrcweir public: 60cdf0e10cSrcweir 61cdf0e10cSrcweir static const ::sal_Int32 WAIT_INFINITE = 0; 62cdf0e10cSrcweir 63cdf0e10cSrcweir //------------------------------------------------------------------------- 64cdf0e10cSrcweir // interface 65cdf0e10cSrcweir //------------------------------------------------------------------------- 66cdf0e10cSrcweir 67cdf0e10cSrcweir public: 68cdf0e10cSrcweir 69cdf0e10cSrcweir //--------------------------------------------------------------------- Request()70cdf0e10cSrcweir explicit Request() 71cdf0e10cSrcweir : m_aJoiner ( ) 72cdf0e10cSrcweir , m_nRequest (-1) 73cdf0e10cSrcweir , m_lArguments( ) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir m_aJoiner.reset(); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir //--------------------------------------------------------------------- ~Request()79cdf0e10cSrcweir virtual ~Request() {}; 80cdf0e10cSrcweir 81cdf0e10cSrcweir //--------------------------------------------------------------------- setRequest(::sal_Int32 nRequest)82cdf0e10cSrcweir void setRequest(::sal_Int32 nRequest) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir m_nRequest = nRequest; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //--------------------------------------------------------------------- getRequest()88cdf0e10cSrcweir ::sal_Int32 getRequest() 89cdf0e10cSrcweir { 90cdf0e10cSrcweir return m_nRequest; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir //--------------------------------------------------------------------- clearArguments()94cdf0e10cSrcweir void clearArguments() 95cdf0e10cSrcweir { 96cdf0e10cSrcweir m_lArguments.clear(); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir //--------------------------------------------------------------------- 100cdf0e10cSrcweir template< class TArgumentType > setArgument(const::rtl::OUString & sName,const TArgumentType & aValue)101cdf0e10cSrcweir void setArgument(const ::rtl::OUString& sName , 102cdf0e10cSrcweir const TArgumentType& aValue) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir m_lArguments[sName] <<= aValue; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir //--------------------------------------------------------------------- 108cdf0e10cSrcweir template< class TArgumentType > getArgumentOrDefault(const::rtl::OUString & sName,const TArgumentType & aDefault)109cdf0e10cSrcweir TArgumentType getArgumentOrDefault(const ::rtl::OUString& sName , 110cdf0e10cSrcweir const TArgumentType& aDefault) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir return m_lArguments.getUnpackedValueOrDefault(sName, aDefault); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir //--------------------------------------------------------------------- 116cdf0e10cSrcweir void wait(::sal_Int32 nMilliSeconds = WAIT_INFINITE); 117cdf0e10cSrcweir 118cdf0e10cSrcweir void waitProcessMessages(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir //--------------------------------------------------------------------- 121cdf0e10cSrcweir void notify(); 122cdf0e10cSrcweir 123cdf0e10cSrcweir //------------------------------------------------------------------------- 124cdf0e10cSrcweir // member 125cdf0e10cSrcweir //------------------------------------------------------------------------- 126cdf0e10cSrcweir 127cdf0e10cSrcweir private: 128cdf0e10cSrcweir 129cdf0e10cSrcweir ::osl::Condition m_aJoiner; 130cdf0e10cSrcweir ::sal_Int32 m_nRequest; 131cdf0e10cSrcweir ::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 { 140cdf0e10cSrcweir public: 141cdf0e10cSrcweir virtual void before() = 0; 142cdf0e10cSrcweir virtual void doRequest(const RequestRef& rRequest) = 0; 143cdf0e10cSrcweir virtual void after() = 0; 144cdf0e10cSrcweir }; 145cdf0e10cSrcweir 146cdf0e10cSrcweir typedef ::boost::shared_ptr< RequestHandler > RequestHandlerRef; 147cdf0e10cSrcweir 148cdf0e10cSrcweir //----------------------------------------------------------------------------- 149cdf0e10cSrcweir /** @todo docuemnt me 150cdf0e10cSrcweir */ 151cdf0e10cSrcweir class AsyncRequests : private ::cppu::BaseMutex 152cdf0e10cSrcweir , public ::osl::Thread 153cdf0e10cSrcweir { 154cdf0e10cSrcweir public: 155cdf0e10cSrcweir static const ::sal_Int16 PROCESS_MESSAGES = 2; 156cdf0e10cSrcweir static const ::sal_Int16 BLOCKED = 1; 157cdf0e10cSrcweir static const ::sal_Int16 NON_BLOCKED = 0; 158cdf0e10cSrcweir 159cdf0e10cSrcweir //--------------------------------------------------------------------- 160cdf0e10cSrcweir /** creates the new asynchronous request executor. 161cdf0e10cSrcweir */ 162cdf0e10cSrcweir explicit AsyncRequests(const RequestHandlerRef& rHandler); 163cdf0e10cSrcweir setHandler(const RequestHandlerRef & rHandler)164cdf0e10cSrcweir void setHandler(const RequestHandlerRef& rHandler) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir m_rHandler = rHandler; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir //--------------------------------------------------------------------- 170cdf0e10cSrcweir /** does nothing special / excepting to make sure our class wont be inline .-) 171cdf0e10cSrcweir */ 172cdf0e10cSrcweir virtual ~AsyncRequests(); 173cdf0e10cSrcweir 174cdf0e10cSrcweir //--------------------------------------------------------------------- 175cdf0e10cSrcweir /** @todo document me 176cdf0e10cSrcweir */ 177cdf0e10cSrcweir void triggerRequestProcessMessages (const RequestRef& rRequest); 178cdf0e10cSrcweir 179cdf0e10cSrcweir //--------------------------------------------------------------------- 180cdf0e10cSrcweir /** @todo document me 181cdf0e10cSrcweir */ 182cdf0e10cSrcweir void triggerRequestBlocked(const RequestRef& rRequest); 183cdf0e10cSrcweir 184cdf0e10cSrcweir //--------------------------------------------------------------------- 185cdf0e10cSrcweir /** @todo document me 186cdf0e10cSrcweir */ 187cdf0e10cSrcweir void triggerRequestNonBlocked(const RequestRef& rRequest); 188cdf0e10cSrcweir 189cdf0e10cSrcweir //--------------------------------------------------------------------- 190cdf0e10cSrcweir /** @todo document me 191cdf0e10cSrcweir */ 192cdf0e10cSrcweir void triggerRequestDirectly(const RequestRef& rRequest); 193cdf0e10cSrcweir 194cdf0e10cSrcweir //--------------------------------------------------------------------- 195cdf0e10cSrcweir /** @todo document me 196cdf0e10cSrcweir */ 197cdf0e10cSrcweir void triggerRequestThreadAware(const RequestRef& rRequest, 198cdf0e10cSrcweir ::sal_Int16 nWait ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir private: 201cdf0e10cSrcweir 202cdf0e10cSrcweir //--------------------------------------------------------------------- 203cdf0e10cSrcweir /** our STA .-) 204cdf0e10cSrcweir * Will run between start() & finish(). Internaly it runs a loop ... 205cdf0e10cSrcweir * waiting for requests. Every request will be executed synchronously 206cdf0e10cSrcweir * in blocked mode. 207cdf0e10cSrcweir */ 208cdf0e10cSrcweir virtual void SAL_CALL run(); 209cdf0e10cSrcweir 210cdf0e10cSrcweir private: 211cdf0e10cSrcweir 212cdf0e10cSrcweir ::sal_Bool m_bFinish; 213cdf0e10cSrcweir RequestHandlerRef m_rHandler; 214cdf0e10cSrcweir 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