1*0a1e2f0eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*0a1e2f0eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*0a1e2f0eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*0a1e2f0eSAndrew Rist * distributed with this work for additional information 6*0a1e2f0eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*0a1e2f0eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*0a1e2f0eSAndrew Rist * "License"); you may not use this file except in compliance 9*0a1e2f0eSAndrew Rist * with the License. You may obtain a copy of the License at 10*0a1e2f0eSAndrew Rist * 11*0a1e2f0eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*0a1e2f0eSAndrew Rist * 13*0a1e2f0eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*0a1e2f0eSAndrew Rist * software distributed under the License is distributed on an 15*0a1e2f0eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*0a1e2f0eSAndrew Rist * KIND, either express or implied. See the License for the 17*0a1e2f0eSAndrew Rist * specific language governing permissions and limitations 18*0a1e2f0eSAndrew Rist * under the License. 19*0a1e2f0eSAndrew Rist * 20*0a1e2f0eSAndrew Rist *************************************************************/ 21*0a1e2f0eSAndrew Rist 22*0a1e2f0eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_THREAD_HXX 25cdf0e10cSrcweir #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_THREAD_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "sal/config.h" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <cstddef> 30cdf0e10cSrcweir #include <new> 31cdf0e10cSrcweir #include "osl/thread.hxx" 32cdf0e10cSrcweir #include "sal/types.h" 33cdf0e10cSrcweir #include "salhelper/simplereferenceobject.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir /// @HTML 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace dp_gui { 38cdf0e10cSrcweir 39cdf0e10cSrcweir /** 40cdf0e10cSrcweir A safe encapsulation of <code>osl::Thread</code>. 41cdf0e10cSrcweir */ 42cdf0e10cSrcweir class Thread: public salhelper::SimpleReferenceObject, private osl::Thread { 43cdf0e10cSrcweir public: 44cdf0e10cSrcweir Thread(); 45cdf0e10cSrcweir 46cdf0e10cSrcweir /** 47cdf0e10cSrcweir Launch the thread. 48cdf0e10cSrcweir 49cdf0e10cSrcweir <p>This function must be called at most once.</p> 50cdf0e10cSrcweir */ 51cdf0e10cSrcweir void launch(); 52cdf0e10cSrcweir 53cdf0e10cSrcweir using osl::Thread::join; 54cdf0e10cSrcweir 55cdf0e10cSrcweir static void * operator new(std::size_t size) throw (std::bad_alloc); 56cdf0e10cSrcweir 57cdf0e10cSrcweir static void operator delete(void * p) throw (); 58cdf0e10cSrcweir 59cdf0e10cSrcweir protected: 60cdf0e10cSrcweir virtual ~Thread(); 61cdf0e10cSrcweir 62cdf0e10cSrcweir /** 63cdf0e10cSrcweir The main function executed by the thread. 64cdf0e10cSrcweir 65cdf0e10cSrcweir <p>Any exceptions terminate the thread and are effectively ignored.</p> 66cdf0e10cSrcweir */ 67cdf0e10cSrcweir virtual void execute() = 0; 68cdf0e10cSrcweir 69cdf0e10cSrcweir private: 70cdf0e10cSrcweir Thread(Thread &); // not defined 71cdf0e10cSrcweir void operator =(Thread &); // not defined 72cdf0e10cSrcweir 73cdf0e10cSrcweir virtual void SAL_CALL run(); 74cdf0e10cSrcweir 75cdf0e10cSrcweir virtual void SAL_CALL onTerminated(); 76cdf0e10cSrcweir }; 77cdf0e10cSrcweir 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir #endif 81