1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef __FRAMEWORK_HELPER_WAKEUPTHREAD_HXX_ 25 #define __FRAMEWORK_HELPER_WAKEUPTHREAD_HXX_ 26 27 //_______________________________________________ 28 // include files of own module 29 30 #include <threadhelp/threadhelpbase.hxx> 31 #include <macros/debug.hxx> 32 #include <macros/generic.hxx> 33 34 #ifndef __FRAMEWORK_GENERAL_HXX_ 35 #include <general.h> 36 #endif 37 38 //_______________________________________________ 39 // include UNO interfaces 40 41 #ifndef _COM_SUN_STAR_URTIL_XUPDATABLE_HPP_ 42 #include <com/sun/star/util/XUpdatable.hpp> 43 #endif 44 45 //_______________________________________________ 46 // include all others 47 #include <cppuhelper/weakref.hxx> 48 #include <osl/thread.hxx> 49 50 //_______________________________________________ 51 // namespace 52 53 namespace framework{ 54 55 //_______________________________________________ 56 // definitions 57 58 //=============================================== 59 /** @short implements a "sleeping" thread, which try to sleep 60 without a using cpu consumption :-) */ 61 class WakeUpThread : public ThreadHelpBase 62 , public ::osl::Thread 63 { 64 //------------------------------------------- 65 // member 66 private: 67 68 /** @short this listener will be notified if this thread 69 waked up. */ 70 css::uno::WeakReference< css::util::XUpdatable > m_xListener; 71 72 //------------------------------------------- 73 // interface 74 public: 75 76 /** @short Register a new listener on this thread. 77 78 @descr The listener is holded as a weak reference. 79 If the thread detects, that no listener exists ... 80 he will terminate itself. 81 */ 82 WakeUpThread(const css::uno::Reference< css::util::XUpdatable >& xListener); 83 84 /** @descr The thread waits on a condition using a fix timeout value. 85 If the thread wakes up he notify the internal set listener. 86 The listener can use this "timeout" info for it's own purpose. 87 The thread itself will wait on the condition again. 88 */ 89 virtual void SAL_CALL run(); 90 91 virtual void SAL_CALL onTerminated(); 92 }; 93 94 } // namespace framework 95 96 #endif // __FRAMEWORK_HELPER_WAKEUPTHREAD_HXX_ 97