summaryrefslogtreecommitdiffstats
path: root/docs/reference/pygio-cancellable.xml
blob: c35388d8bbf6d99da150c600cc0c1b5242710544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?xml version="1.0" standalone="no"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">

<refentry id="class-giocancellable">
    <refnamediv>
        <refname>gio.Cancellable</refname>
        <refpurpose>Thread-safe Operation Cancellation Stack.</refpurpose>
    </refnamediv>

    <refsect1>
        <title>Synopsis</title>

    <classsynopsis language="python">
        <ooclass><classname>gio.Cancellable</classname></ooclass>
        <ooclass><classname><link linkend="class-gobject">gobject.GObject</link></classname></ooclass>
    
    <constructorsynopsis language="python">
	<methodname><link linkend="constructor-giocancellable">gio.Cancellable</link></methodname>
	<methodparam></methodparam>
    </constructorsynopsis>
    
    <methodsynopsis language="python">
        <methodname><link linkend="method-giocancellable--cancel">cancel</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-giocancellable--get-fd">get_fd</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-giocancellable--is-cancelled">is_cancelled</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-giocancellable--pop-current">pop_current</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-giocancellable--push-current">push_current</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-giocancellable--reset">reset</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    <methodsynopsis language="python">
        <methodname><link linkend="method-giocancellable--set-error-if-cancelled">set_error_if_cancelled</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    
    </classsynopsis>

<programlisting>
<emphasis role="bold">Functions</emphasis>
 
<methodsynopsis language="python">
    <methodname><link linkend="function-gio--cancellable-get-current">gio.cancellable_get_current</link></methodname>
    <methodparam></methodparam>
</methodsynopsis></programlisting>

    </refsect1>

    <refsect1>
        <title>Ancestry</title>

<synopsis>+-- <link linkend="class-gobject">gobject.GObject</link>
  +-- <link linkend="class-giocancellable">gio.Cancellable</link>
</synopsis>

    </refsect1>

    <refsect1>
        <title>Description</title>

        <para>
            The <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
            is a thread-safe operation cancellation stack used throughout GIO to allow for
            cancellation of synchronous and asynchronous operations.
        </para>
    </refsect1>

    <refsect1 id="constructor-giocancellable">
        <title>Constructor</title>
  
        <programlisting><constructorsynopsis language="python">
            <methodname>gio.Cancellable</methodname>
            <methodparam></methodparam>
        </constructorsynopsis></programlisting>
        <variablelist>
            <varlistentry>
                <term><emphasis>Returns</emphasis>&nbsp;:</term>
                <listitem><simpara>a new
                <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>.
                </simpara></listitem>
            </varlistentry>
        </variablelist>
    
        <para>
            Creates a new <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link> object.
        </para>
        <para>
            Applications that want to start one or more operations that should be cancellable should create a
            <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
            and pass it to the operations. 
        </para>
        <para>
            One <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
            can be used in multiple consecutive operations, but not in multiple concurrent operations.
        </para>
  
    </refsect1>

    <refsect1>
        <title>Methods</title>

        <refsect2 id="method-giocancellable--cancel">
            <title>gio.Cancellable.cancel</title>

            <programlisting><methodsynopsis language="python">
                <methodname>cancel</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
            </variablelist>
    
            <para>
                The <methodname>cancel</methodname>() method will set cancellable to cancelled,
                and will emit the "cancelled" signal. (However, see the warning about race conditions
                in the documentation for that signal if you are planning to connect to it.) 
            </para>
            <para>
                This function is thread-safe. In other words, you can safely call it from a thread
                other than the one running the operation that was passed the cancellable. 
            </para>
            <para>
                The convention within gio is that cancelling an asynchronous operation causes it
                to complete asynchronously. That is, if you cancel the operation from the same thread
                in which it is running, then the operation's GAsyncReadyCallback will not be invoked
                until the application returns to the main loop.
            </para>
        </refsect2>

        <refsect2 id="method-giocancellable--get-fd">
            <title>gio.Cancellable.get_fd</title>

            <programlisting><methodsynopsis language="python">
                <methodname>get_fd</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
            <varlistentry>
                <term><emphasis>Returns</emphasis>&nbsp;:</term>
                <listitem><simpara>A valid file descriptor. -1 if the file descriptor
                is not supported, or on errors.</simpara></listitem>
            </varlistentry>
            </variablelist>
    
            <para>
                The <methodname>get_fd</methodname>() method gets the file descriptor
                for a cancellable job. This can be used to implement cancellable operations
                on Unix systems. The returned fd will turn readable when cancellable is cancelled. 
            </para>
        </refsect2>

        <refsect2 id="method-giocancellable--is-cancelled">
            <title>gio.Cancellable.is_cancelled</title>

            <programlisting><methodsynopsis language="python">
                <methodname>is_cancelled</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
            <varlistentry>
                <term><emphasis>Returns</emphasis>&nbsp;:</term>
                <listitem><simpara><literal>True</literal> if cancellable is cancelled,
                <literal>False</literal> if called with <literal>None</literal> or if
                item is not cancelled. </simpara></listitem>
            </varlistentry>
            </variablelist>
    
            <para>
                The <methodname>get_fd</methodname>() method gets the file descriptor
                for a cancellable job. This can be used to implement cancellable operations
                on Unix systems. The returned fd will turn readable when cancellable is cancelled. 
            </para>
        </refsect2>

        <refsect2 id="method-giocancellable--pop-current">
            <title>gio.Cancellable.pop_current</title>

            <programlisting><methodsynopsis language="python">
                <methodname>pop_current</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
            </variablelist>
    
            <para>
                The <methodname>pop_current</methodname>() method pops cancellable off
                the cancellable stack (verifying that cancellable is on the top of the stack).
            </para>
        </refsect2>

        <refsect2 id="method-giocancellable--push-current">
            <title>gio.Cancellable.push_current</title>

            <programlisting><methodsynopsis language="python">
                <methodname>push_current</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
            </variablelist>
    
            <para>
                The <methodname>push_current</methodname>() method pushes cancellable onto
                the cancellable stack. The current cancllable can then be recieved using
                <methodname><link linkend="function-gio--cancellable-get-current">gio.cancellable_get_current</link></methodname>(). 
            </para>
        </refsect2>

        <refsect2 id="method-giocancellable--reset">
            <title>gio.Cancellable.reset</title>

            <programlisting><methodsynopsis language="python">
                <methodname>reset</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
            </variablelist>
    
            <para>
                The <methodname>reset</methodname>() method resets cancellable to its uncancelled state.
            </para>
        </refsect2>

        <refsect2 id="method-giocancellable--set-error-if-cancelled">
            <title>gio.Cancellable.set_error_if_cancelled</title>

            <programlisting><methodsynopsis language="python">
                <methodname>set_error_if_cancelled</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><emphasis>Returns</emphasis>&nbsp;:</term>
                    <listitem><simpara><literal>True</literal> if cancellable was cancelled,
                    <literal>False</literal> if it was not.</simpara></listitem>
                </varlistentry>
            </variablelist>
    
            <para>
                The <methodname>set_error_if_cancelled</methodname>() method, if the cancellable
                is cancelled, sets the error to notify that the operation was cancelled.
            </para>
        </refsect2>
    </refsect1>
    
    <refsect1>
        <title>Functions</title>

        <refsect2 id="function-gio--cancellable-get-current">
            <title>gio.cancellable_get_current</title>

            <programlisting><methodsynopsis language="python">
                <methodname>cancellable_get_current</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><emphasis>Returns</emphasis>&nbsp;:</term>
                    <listitem><simpara>A <link linkend="class-giocancellable"><classname>gio.Cancellable</classname></link>
                    from the top of the stack, or <literal>None</literal> if the stack is empty.</simpara></listitem>
                </varlistentry>
            </variablelist>

            <para>
                The <methodname>cancellable_get_current</methodname>() function gets the top cancellable from the stack.
            </para>
        </refsect2>
    </refsect1>
</refentry>