1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX 29 #define FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX 30 31 //----------------------------------------------------------------------------- 32 // includes 33 //----------------------------------------------------------------------------- 34 35 #include <cppuhelper/basemutex.hxx> 36 #include <comphelper/sequenceashashmap.hxx> 37 #include <osl/conditn.hxx> 38 #include <osl/thread.hxx> 39 #include <osl/time.h> 40 #include <queue> 41 #include <boost/shared_ptr.hpp> 42 43 //----------------------------------------------------------------------------- 44 // namespace 45 //----------------------------------------------------------------------------- 46 47 #ifdef css 48 #error "Clash on using CSS as namespace define." 49 #else 50 #define css ::com::sun::star 51 #endif 52 53 namespace fpicker{ 54 namespace win32{ 55 namespace vista{ 56 57 //----------------------------------------------------------------------------- 58 /** @todo document me 59 */ 60 class Request 61 { 62 //------------------------------------------------------------------------- 63 public: 64 65 static const ::sal_Int32 WAIT_INFINITE = 0; 66 67 //------------------------------------------------------------------------- 68 // interface 69 //------------------------------------------------------------------------- 70 71 public: 72 73 //--------------------------------------------------------------------- 74 explicit Request() 75 : m_aJoiner ( ) 76 , m_nRequest (-1) 77 , m_lArguments( ) 78 { 79 m_aJoiner.reset(); 80 } 81 82 //--------------------------------------------------------------------- 83 virtual ~Request() {}; 84 85 //--------------------------------------------------------------------- 86 void setRequest(::sal_Int32 nRequest) 87 { 88 m_nRequest = nRequest; 89 } 90 91 //--------------------------------------------------------------------- 92 ::sal_Int32 getRequest() 93 { 94 return m_nRequest; 95 } 96 97 //--------------------------------------------------------------------- 98 void clearArguments() 99 { 100 m_lArguments.clear(); 101 } 102 103 //--------------------------------------------------------------------- 104 template< class TArgumentType > 105 void setArgument(const ::rtl::OUString& sName , 106 const TArgumentType& aValue) 107 { 108 m_lArguments[sName] <<= aValue; 109 } 110 111 //--------------------------------------------------------------------- 112 template< class TArgumentType > 113 TArgumentType getArgumentOrDefault(const ::rtl::OUString& sName , 114 const TArgumentType& aDefault) 115 { 116 return m_lArguments.getUnpackedValueOrDefault(sName, aDefault); 117 } 118 119 //--------------------------------------------------------------------- 120 void wait(::sal_Int32 nMilliSeconds = WAIT_INFINITE); 121 122 void waitProcessMessages(); 123 124 //--------------------------------------------------------------------- 125 void notify(); 126 127 //------------------------------------------------------------------------- 128 // member 129 //------------------------------------------------------------------------- 130 131 private: 132 133 ::osl::Condition m_aJoiner; 134 ::sal_Int32 m_nRequest; 135 ::comphelper::SequenceAsHashMap m_lArguments; 136 }; 137 138 typedef ::boost::shared_ptr< Request > RequestRef; 139 typedef ::std::queue< RequestRef > RequestQueue; 140 141 //----------------------------------------------------------------------------- 142 class RequestHandler 143 { 144 public: 145 virtual void before() = 0; 146 virtual void doRequest(const RequestRef& rRequest) = 0; 147 virtual void after() = 0; 148 }; 149 150 typedef ::boost::shared_ptr< RequestHandler > RequestHandlerRef; 151 152 //----------------------------------------------------------------------------- 153 /** @todo docuemnt me 154 */ 155 class AsyncRequests : private ::cppu::BaseMutex 156 , public ::osl::Thread 157 { 158 public: 159 static const ::sal_Int16 PROCESS_MESSAGES = 2; 160 static const ::sal_Int16 BLOCKED = 1; 161 static const ::sal_Int16 NON_BLOCKED = 0; 162 163 //--------------------------------------------------------------------- 164 /** creates the new asynchronous request executor. 165 */ 166 explicit AsyncRequests(const RequestHandlerRef& rHandler); 167 168 void setHandler(const RequestHandlerRef& rHandler) 169 { 170 m_rHandler = rHandler; 171 } 172 173 //--------------------------------------------------------------------- 174 /** does nothing special / excepting to make sure our class wont be inline .-) 175 */ 176 virtual ~AsyncRequests(); 177 178 //--------------------------------------------------------------------- 179 /** @todo document me 180 */ 181 void triggerRequestProcessMessages (const RequestRef& rRequest); 182 183 //--------------------------------------------------------------------- 184 /** @todo document me 185 */ 186 void triggerRequestBlocked(const RequestRef& rRequest); 187 188 //--------------------------------------------------------------------- 189 /** @todo document me 190 */ 191 void triggerRequestNonBlocked(const RequestRef& rRequest); 192 193 //--------------------------------------------------------------------- 194 /** @todo document me 195 */ 196 void triggerRequestDirectly(const RequestRef& rRequest); 197 198 //--------------------------------------------------------------------- 199 /** @todo document me 200 */ 201 void triggerRequestThreadAware(const RequestRef& rRequest, 202 ::sal_Int16 nWait ); 203 204 private: 205 206 //--------------------------------------------------------------------- 207 /** our STA .-) 208 * Will run between start() & finish(). Internaly it runs a loop ... 209 * waiting for requests. Every request will be executed synchronously 210 * in blocked mode. 211 */ 212 virtual void SAL_CALL run(); 213 214 private: 215 216 ::sal_Bool m_bFinish; 217 RequestHandlerRef m_rHandler; 218 RequestQueue m_lRequests; 219 }; 220 221 } // namespace vista 222 } // namespace win32 223 } // namespace fpicker 224 225 #undef css 226 227 #endif // FPICKER_WIN32_VISTA_ASYNCREQUESTS_HXX 228