xref: /AOO41X/main/desktop/source/deployment/gui/dp_gui_thread.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_THREAD_HXX
29 #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_THREAD_HXX
30 
31 #include "sal/config.h"
32 
33 #include <cstddef>
34 #include <new>
35 #include "osl/thread.hxx"
36 #include "sal/types.h"
37 #include "salhelper/simplereferenceobject.hxx"
38 
39 /// @HTML
40 
41 namespace dp_gui {
42 
43 /**
44    A safe encapsulation of <code>osl::Thread</code>.
45 */
46 class Thread: public salhelper::SimpleReferenceObject, private osl::Thread {
47 public:
48     Thread();
49 
50     /**
51        Launch the thread.
52 
53        <p>This function must be called at most once.</p>
54     */
55     void launch();
56 
57     using osl::Thread::join;
58 
59     static void * operator new(std::size_t size) throw (std::bad_alloc);
60 
61     static void operator delete(void * p) throw ();
62 
63 protected:
64     virtual ~Thread();
65 
66     /**
67        The main function executed by the thread.
68 
69        <p>Any exceptions terminate the thread and are effectively ignored.</p>
70     */
71     virtual void execute() = 0;
72 
73 private:
74     Thread(Thread &); // not defined
75     void operator =(Thread &); // not defined
76 
77     virtual void SAL_CALL run();
78 
79     virtual void SAL_CALL onTerminated();
80 };
81 
82 }
83 
84 #endif
85