Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: ppapi/api/pp_completion_callback.idl

Issue 7308010: Formatting changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 5
6 /** 6 /**
7 * This file defines the API to create and run a callback. 7 * This file defines the API to create and run a callback.
8 */ 8 */
9 9
10 /** 10 /**
11 * PP_CompletionCallback_Func defines the function signature that you implement 11 * This typedef defines the signature that you implement to receive callbacks
12 * to receive callbacks on asynchronous completion of an operation. 12 * on asynchronous completion of an operation.
13 * 13 *
14 * |user_data| is a pointer to user-specified data associated with this 14 * @param[in] user_data A pointer to user data passed to a callback function.
15 * function at callback creation. See PP_MakeCompletionCallback() for details. 15 * @param[in] result If result is 0 (PP_OK), the operation succeeded. Negative
16 * 16 * values (other than -1 or PP_OK_COMPLETE) indicate error and are specified
17 * |result| is the result of the operation. Non-positive values correspond to 17 * in pp_errors.h. Positive values for result usually indicate success and have
18 * the error codes from pp_errors.h (excluding PP_OK_COMPLETIONPENDING). 18 * some operation-dependent meaning (such as bytes read).
19 * Positive values indicate additional information such as bytes read.
20 */ 19 */
21 typedef void PP_CompletionCallback_Func([inout] mem_t user_data, 20 typedef void PP_CompletionCallback_Func([inout] mem_t user_data,
22 [in] int32_t result); 21 [in] int32_t result);
23 22
24 /** 23 /**
25 * This enumeration contains flags used to control how non-NULL callbacks are 24 * This enumeration contains flags used to control how non-NULL callbacks are
26 * scheduled by asynchronous methods. 25 * scheduled by asynchronous methods.
27 */ 26 */
28 [assert_size(4)] 27 [assert_size(4)]
29 enum PP_CompletionCallback_Flag { 28 enum PP_CompletionCallback_Flag {
(...skipping 15 matching lines...) Expand all
45 * On synchronous method completion, the completion result will be returned 44 * On synchronous method completion, the completion result will be returned
46 * by the method itself. Otherwise, the method will return 45 * by the method itself. Otherwise, the method will return
47 * PP_OK_COMPLETIONPENDING, and the callback will be invoked asynchronously on 46 * PP_OK_COMPLETIONPENDING, and the callback will be invoked asynchronously on
48 * the main thread of PPAPI execution. 47 * the main thread of PPAPI execution.
49 */ 48 */
50 PP_COMPLETIONCALLBACK_FLAG_OPTIONAL = 1 << 0 49 PP_COMPLETIONCALLBACK_FLAG_OPTIONAL = 1 << 0
51 }; 50 };
52 51
53 52
54 /** 53 /**
55 * Any method that takes a PP_CompletionCallback can complete asynchronously. 54 * Any method that takes a <code>PP_CompletionCallback</code> has the option of
56 * Refer to PP_CompletionCallback_Flag for more information. 55 * completing asynchronously if the operation would block. Such a method
56 * should return <code>PP_OK_COMPLETIONPENDING</code> to indicate that the
57 * method will complete asynchronously and notify the caller and will always be
58 * invoked from the main thread of PPAPI execution. If the completion callback
59 * is NULL, then the operation will block if necessary to complete its work.
60 * <code>PP_BlockUntilComplete()</code> provides a convenient way to specify
61 * blocking behavior. Refer to <code>PP_BlockUntilComplete</code> for more
62 * information.
57 * 63 *
58 * If PP_CompletionCallback_Func is NULL, the operation might block if necessary 64 * The result parameter passed to <code>func</code> is an int32_t that, if
59 * to complete the work. Refer to PP_BlockUntilComplete for more information. 65 * negative or equal to 0, indicate if the call will complete asynchronously
der Springer 2011/08/10 21:35:43 indicates ? Also, I think |func| is called only *
jond 2011/08/11 19:12:27 Done.
60 * 66 * (the callback will be called with a status code). A value greater than zero
61 * See PP_MakeCompletionCallback() for the description of each field. 67 * indicates an error code.
62 */ 68 */
63 [passByValue] struct PP_CompletionCallback { 69 [passByValue] struct PP_CompletionCallback {
70 /**
71 * This value is a callback function that will be called.
72 */
64 PP_CompletionCallback_Func func; 73 PP_CompletionCallback_Func func;
74 /**
75 * This value is a pointer to user data passed to a callback function.
76 */
65 mem_t user_data; 77 mem_t user_data;
78
79 /**
80 * Flags used to control how non-NULL callbacks are scheduled by
81 * asynchronous methods.
82 */
66 int32_t flags; 83 int32_t flags;
67 }; 84 };
68 85
69 #inline c 86 #inline c
70 #include <stdlib.h> 87 #include <stdlib.h>
71 88
72 /** 89 /**
73 * @addtogroup Functions 90 * @addtogroup Functions
74 * @{ 91 * @{
75 */ 92 */
76 /** 93 /**
77 * PP_MakeCompletionCallback() is used to create a PP_CompletionCallback 94 * PP_MakeCompletionCallback() is used to create a
78 * without flags. If you want to alter the default callback behavior, set the 95 * <code>PP_CompletionCallback</code>.
79 * flags to a bit field combination of PP_CompletionCallback_Flag's.
80 * 96 *
81 * Example: 97 * <strong>Example:</strong>
82 * struct PP_CompletionCallback cc = PP_MakeCompletionCallback(Foo, NULL);
83 * cc.flags = cc.flags | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL;
84 * 98 *
85 * @param[in] func A PP_CompletionCallback_Func to be called on completion. 99 * <code>
86 * @param[in] user_data A pointer to user data passed to be passed to the 100 * struct PP_CompletionCallback cc = PP_MakeCompletionCallback(Foo, NULL);
87 * callback function. This is optional and is typically used to help track state 101 * cc.flags = cc.flags | PP_COMPLETIONCALLBACK_FLAG_OPTIONAL;
88 * in case of multiple pending callbacks. 102 * </code>
89 * 103 *
90 * @return A PP_CompletionCallback structure. 104 * @param[in] func A <code>PP_CompletionCallback_Func</code> that will be
105 * called.
106 * @param[in] user_data A pointer to user data passed to your callback
107 * function. This is optional and is typically used to help track state
108 * when you may have multiple callbacks pending.
109 *
110 * @return A <code>PP_CompletionCallback</code> structure.
91 */ 111 */
92 PP_INLINE struct PP_CompletionCallback PP_MakeCompletionCallback( 112 PP_INLINE struct PP_CompletionCallback PP_MakeCompletionCallback(
93 PP_CompletionCallback_Func func, 113 PP_CompletionCallback_Func func,
94 void* user_data) { 114 void* user_data) {
95 struct PP_CompletionCallback cc; 115 struct PP_CompletionCallback cc;
96 cc.func = func; 116 cc.func = func;
97 cc.user_data = user_data; 117 cc.user_data = user_data;
98 cc.flags = PP_COMPLETIONCALLBACK_FLAG_NONE; 118 cc.flags = PP_COMPLETIONCALLBACK_FLAG_NONE;
99 return cc; 119 return cc;
100 } 120 }
(...skipping 23 matching lines...) Expand all
124 /** 144 /**
125 * @addtogroup Functions 145 * @addtogroup Functions
126 * @{ 146 * @{
127 */ 147 */
128 148
129 /** 149 /**
130 * PP_RunCompletionCallback() is used to run a callback. It invokes 150 * PP_RunCompletionCallback() is used to run a callback. It invokes
131 * the callback function passing it user data specified on creation and 151 * the callback function passing it user data specified on creation and
132 * completion |result|. 152 * completion |result|.
133 * 153 *
134 * @param[in] cc A pointer to a PP_CompletionCallback that will be run. 154 * @param[in] cc A pointer to a <code>PP_CompletionCallback</code> that will be
155 * run.
135 * @param[in] result The result of the operation. Non-positive values correspond 156 * @param[in] result The result of the operation. Non-positive values correspond
136 * to the error codes from pp_errors.h (excluding PP_OK_COMPLETIONPENDING). 157 * to the error codes from pp_errors.h (excluding PP_OK_COMPLETIONPENDING).
137 * Positive values indicate additional information such as bytes read. 158 * Positive values indicate additional information such as bytes read.
138 */ 159 */
139 PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc, 160 PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc,
140 int32_t result) { 161 int32_t result) {
141 cc->func(cc->user_data, result); 162 cc->func(cc->user_data, result);
142 } 163 }
143 164
144 /** 165 /**
145 * @} 166 * @}
146 */ 167 */
147 168
148 /** 169 /**
149 * @addtogroup Functions 170 * @addtogroup Functions
150 * @{ 171 * @{
151 */ 172 */
152 173
153 /** 174 /**
154 * PP_BlockUntilComplete() is used in place of an actual completion callback 175 * PP_BlockUntilComplete() is used in place of an actual completion callback
155 * to request blocking behavior. If specified, the calling thread will block 176 * to request blocking behavior. If specified, the calling thread will block
156 * until the function completes. Blocking completion callbacks are only allowed 177 * until the function completes. Blocking completion callbacks are only allowed
157 * from background threads. 178 * from background threads.
158 * 179 *
159 * @return A PP_CompletionCallback structure corresponding to a NULL callback. 180 * @return A <code>PP_CompletionCallback</code> structure.
160 */ 181 */
161 PP_INLINE struct PP_CompletionCallback PP_BlockUntilComplete() { 182 PP_INLINE struct PP_CompletionCallback PP_BlockUntilComplete() {
162 return PP_MakeCompletionCallback(NULL, NULL); 183 return PP_MakeCompletionCallback(NULL, NULL);
163 } 184 }
164 185
165 /** 186 /**
166 * Runs a callback and clears the reference to it. 187 * PP_RunAndClearCompletionCallback() runs a callback and clears the reference
188 * to that callback.
167 * 189 *
168 * This is used when the null-ness of a completion callback is used as a signal 190 * This function is used when the null-ness of a completion callback is used as
169 * for whether a completion callback has been registered. In this case, after 191 * a signal for whether a completion callback has been registered. In this
170 * the execution of the callback, it should be cleared. 192 * case, after the execution of the callback, it should be cleared. However,
171 * 193 * this introduces a conflict if the completion callback wants to schedule more
172 * However, this introduces a conflict if the completion callback wants to 194 * work that involves the same completion callback again (for example, when
173 * schedule more work that involves the same completion callback again (for 195 * reading data from an URLLoader, one would typically queue up another read
174 * example, when reading data from an URLLoader, one would typically queue up 196 * callback). As a result, this function clears the pointer
175 * another read callback). As a result, this function clears the pointer 197 * before the provided callback is executed.
176 * *before* the given callback is executed.
177 */ 198 */
178 PP_INLINE void PP_RunAndClearCompletionCallback( 199 PP_INLINE void PP_RunAndClearCompletionCallback(
179 struct PP_CompletionCallback* cc, 200 struct PP_CompletionCallback* cc,
180 int32_t res) { 201 int32_t res) {
181 struct PP_CompletionCallback temp = *cc; 202 struct PP_CompletionCallback temp = *cc;
182 *cc = PP_BlockUntilComplete(); 203 *cc = PP_BlockUntilComplete();
183 PP_RunCompletionCallback(&temp, res); 204 PP_RunCompletionCallback(&temp, res);
184 } 205 }
185 /** 206 /**
186 * @} 207 * @}
187 */ 208 */
188 209
189 #endinl 210 #endinl
190 211
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698