1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: observablethread.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef _OBSERVABLETHREAD_HXX
31 #define _OBSERVABLETHREAD_HXX
33 #ifndef _OSL_THREAD_HXX_
34 #include <osl/thread.hxx>
36 #include <rtl/ref.hxx>
37 #include <osl/interlck.h>
39 #include <boost/weak_ptr.hpp>
40 #include <ithreadlistenerowner.hxx>
42 /** class for an observable thread
44 OD 2007-01-29 #i73788#
45 Note: A thread is ref-counted. Thus, an instance of a derived class has to
46 to be hold via a reference. The thread itself assures during its execution,
47 that the ref-count is increased. Its execution starts with its <run()> method
48 and ends with its <onTerminated()> method.
49 Note: A thread can be only observed by one or none thread observer in order
50 to notify, that the thread has finished its work.
54 class ObservableThread
: public osl::Thread
,
55 public rtl::IReference
59 virtual ~ObservableThread();
61 void SetListener( boost::weak_ptr
< IFinishedThreadListener
> pThreadListener
,
62 const oslInterlockedCount nThreadID
);
65 virtual oslInterlockedCount SAL_CALL
acquire();
66 virtual oslInterlockedCount SAL_CALL
release();
72 /** intrinsic function of the thread
75 Do not override this method again. Instead override <threadFunction()>.
76 Otherwise, it's not guaranteed, that its ref-count is increased
77 during the execution of the thread.
81 virtual void SAL_CALL
run();
83 virtual void threadFunction() = 0;
85 /** method called, when thread has finished its work
88 Do not override this method again. Instead override <threadFinished()>.
89 Otherwise, it's not guaranteed, that the ref-count is decreased at
90 the end of its execution and that the observer is notified, that
91 the thread has finished its work.
95 virtual void SAL_CALL
onTerminated();
97 virtual void threadFinished();
101 oslInterlockedCount mnRefCount
;
103 oslInterlockedCount mnThreadID
;
105 boost::weak_ptr
< IFinishedThreadListener
> mpThreadListener
;