1*b1cdbd2cSJim Jagielski/**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski#ifndef __com_sun_star_util_XClosable_idl__
24*b1cdbd2cSJim Jagielski#define __com_sun_star_util_XClosable_idl__
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski#ifndef __com_sun_star_uno_XInterface_idl__
27*b1cdbd2cSJim Jagielski#include <com/sun/star/uno/XInterface.idl>
28*b1cdbd2cSJim Jagielski#endif
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski#ifndef __com_sun_star_util_XCloseBroadcaster_idl__
31*b1cdbd2cSJim Jagielski#include <com/sun/star/util/XCloseBroadcaster.idl>
32*b1cdbd2cSJim Jagielski#endif
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski//=============================================================================
35*b1cdbd2cSJim Jagielski
36*b1cdbd2cSJim Jagielskimodule com {  module sun {  module star {  module util {
37*b1cdbd2cSJim Jagielski
38*b1cdbd2cSJim Jagielski//=============================================================================
39*b1cdbd2cSJim Jagielski/** makes it possible to release any objects in a ordered manner by using
40*b1cdbd2cSJim Jagielski    a two-step mechanism
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski    <p>
43*b1cdbd2cSJim Jagielski    If an object should be terminated, it can be:<br>
44*b1cdbd2cSJim Jagielski    <ul>
45*b1cdbd2cSJim Jagielski        <li>disposed (if it supports <member scope="com::sun::star::lang">XComponent::dispose()</member>)</li>
46*b1cdbd2cSJim Jagielski        <li>closed   (if it supports <member>XCloseable::close()</member>)</li>
47*b1cdbd2cSJim Jagielski    </ul>
48*b1cdbd2cSJim Jagielski    First version gives the object no chance to disagree with that (e.g. if a
49*b1cdbd2cSJim Jagielski    process is still running and can't be cancelled realy). Last version
50*b1cdbd2cSJim Jagielski    provides this possibility, but can't guarantee real termination of called object.
51*b1cdbd2cSJim Jagielski    It depends from the environment of an object, if one or both mechanism are neccessary.
52*b1cdbd2cSJim Jagielski    </p>
53*b1cdbd2cSJim Jagielski
54*b1cdbd2cSJim Jagielski    <p>
55*b1cdbd2cSJim Jagielski    Base interface <type>XCloseBroadcaster</type> makes it possible that any listener
56*b1cdbd2cSJim Jagielski    which is interrested on life time of listened object ...
57*b1cdbd2cSJim Jagielski    <ul>
58*b1cdbd2cSJim Jagielski        <li>can get a notification about closing of it</li>
59*b1cdbd2cSJim Jagielski        <li>or can have a veto to break that.</li>
60*b1cdbd2cSJim Jagielski    </ul>
61*b1cdbd2cSJim Jagielski    </p>
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski    @see com::sun::star::lang::XComponent::dispose()
64*b1cdbd2cSJim Jagielski    @see XCloseBroadcaster
65*b1cdbd2cSJim Jagielski    @see XCloseListener
66*b1cdbd2cSJim Jagielski */
67*b1cdbd2cSJim Jagielskipublished interface XCloseable: XCloseBroadcaster
68*b1cdbd2cSJim Jagielski{
69*b1cdbd2cSJim Jagielski	//-------------------------------------------------------------------------
70*b1cdbd2cSJim Jagielski    /** try to close the object
71*b1cdbd2cSJim Jagielski
72*b1cdbd2cSJim Jagielski        <p>
73*b1cdbd2cSJim Jagielski        Must definitly be called before <member scope="com::sun::star::lang">XComponent::dispose()</member>.
74*b1cdbd2cSJim Jagielski        But nobody can guarentee real closing of called object - because it can disagree with that if any
75*b1cdbd2cSJim Jagielski        still running processes can't be cancelled yet. It's not allowed to block this call till internal
76*b1cdbd2cSJim Jagielski        operations will be finished here. They must be cancelled or call must return imediatly by throwing
77*b1cdbd2cSJim Jagielski        the <type>CloseVetoException</type>.  Otherwise (if nothing exist to disagree) it must return normaly.
78*b1cdbd2cSJim Jagielski        </p>
79*b1cdbd2cSJim Jagielski
80*b1cdbd2cSJim Jagielski        <p>
81*b1cdbd2cSJim Jagielski        Before any internal processes will be cancelled, all registered <type>XCloseListener</type>
82*b1cdbd2cSJim Jagielski        must be notified. Any of them can disagree with a <type>CloseVetoException</type> too.
83*b1cdbd2cSJim Jagielski        It's forbidden to catch this exception inside the called close() method because the caller must
84*b1cdbd2cSJim Jagielski        get this information!
85*b1cdbd2cSJim Jagielski        </p>
86*b1cdbd2cSJim Jagielski
87*b1cdbd2cSJim Jagielski        <p>
88*b1cdbd2cSJim Jagielski        If somewhere disagree with a CloseVetoException it will not clear who has to close the object again
89*b1cdbd2cSJim Jagielski        after still running processes was finished. The parameter <var>DeliverOwnership</var> regulate that.
90*b1cdbd2cSJim Jagielski        If it is set to <FALSE/> the caller of the method close() will be the owner of this object in every case.
91*b1cdbd2cSJim Jagielski        Then it's not allowed to call close() from any other place (may a registered XCloseListener).
92*b1cdbd2cSJim Jagielski        If it is set to <TRUE/> the caller gives up his ownership. If a XCloseListener throw the veto exception
93*b1cdbd2cSJim Jagielski        he will be the new owner of the closing object. This information is passed to the listener by a parameter of
94*b1cdbd2cSJim Jagielski        his notification method <member>XCloseListener::queryClosing()</member>. After his operations was finished
95*b1cdbd2cSJim Jagielski        he MUST try to close it again. If the closing object itselfs disagree by an exception and the parameter
96*b1cdbd2cSJim Jagielski        <var>DeliverOwnership</var> was set to <TRUE/> the object will be his own owner with all consequences of that.
97*b1cdbd2cSJim Jagielski        <br><strong>Note:</strong><br>
98*b1cdbd2cSJim Jagielski        There is no way to get the ownership back if it was delivered!
99*b1cdbd2cSJim Jagielski        </p>
100*b1cdbd2cSJim Jagielski
101*b1cdbd2cSJim Jagielski        <p>
102*b1cdbd2cSJim Jagielski        If this method was already called on an object it should return without any reaction. Normaly it's possible to throw
103*b1cdbd2cSJim Jagielski        a <type scope="com::sun::star::lang">DisposedException</type> for already disposed or closed objects
104*b1cdbd2cSJim Jagielski        (which represent a <type scope="com::sun::star::uno">RuntimeException</type> and can be thrown by every interface call),
105*b1cdbd2cSJim Jagielski        but it shouldn't be used here. The veto exception should be the only way to indicates the result.
106*b1cdbd2cSJim Jagielski        </p>
107*b1cdbd2cSJim Jagielski
108*b1cdbd2cSJim Jagielski        @param DeliverOwnership
109*b1cdbd2cSJim Jagielski                <TRUE/> delegates the ownership of ths closing object to any one which throw the CloseVetoException.
110*b1cdbd2cSJim Jagielski                This new owner has to close the closing object again if his still running processes will be finished.
111*b1cdbd2cSJim Jagielski                <br>
112*b1cdbd2cSJim Jagielski                <FALSE/> let the ownership at the original one which called the close() method. He must react for possible
113*b1cdbd2cSJim Jagielski                CloseVetoExceptions and try it again at a later time. This can be usefull for a generic UI handling.
114*b1cdbd2cSJim Jagielski
115*b1cdbd2cSJim Jagielski        @throws CloseVetoException
116*b1cdbd2cSJim Jagielski            indicates that the closing object himself or any of his currently registered listener disagree with this close() request.
117*b1cdbd2cSJim Jagielski
118*b1cdbd2cSJim Jagielski        @see XCloseListener
119*b1cdbd2cSJim Jagielski        @see CloseVetoException
120*b1cdbd2cSJim Jagielski        @see com::sun::star::lang::XComponent::dispose()
121*b1cdbd2cSJim Jagielski        @see com::sun::star::lang::DisposedException
122*b1cdbd2cSJim Jagielski	 */
123*b1cdbd2cSJim Jagielski    void close( [in] boolean DeliverOwnership )
124*b1cdbd2cSJim Jagielski            raises( CloseVetoException );
125*b1cdbd2cSJim Jagielski};
126*b1cdbd2cSJim Jagielski
127*b1cdbd2cSJim Jagielski//=============================================================================
128*b1cdbd2cSJim Jagielski
129*b1cdbd2cSJim Jagielski}; }; }; };
130*b1cdbd2cSJim Jagielski
131*b1cdbd2cSJim Jagielski#endif
132