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

Side by Side Diff: ppapi/api/dev/ppb_message_loop_dev.idl

Issue 8965082: Add API definition and error values for running message loops. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 12 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
« no previous file with comments | « no previous file | ppapi/api/pp_errors.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 * found in the LICENSE file.
4 */
5
6 /**
7 * Defines the PPB_MessageLoop_Dev interface.
8 */
9 label Chrome {
10 M18 = 0.1
11 },
12
13 /**
14 * A message loop allows PPAPI calls to be issued on a thread. You may not
15 * issue any API calls on a thread without creating a message loop. It also
16 * allows you to post work to threads that will be issued on the message loop.
17 *
18 * To process work posted to the message loop, as well as completion callbacks
19 * for asynchronous operations, you must run the message loop via Run().
20 *
21 * Note the system manages the lifetime of the instance (and all associated
22 * resources). If the instance is deleted from the page, background threads may
23 * suddenly see their PP_Resource handles become invalid. In this case, calls
24 * will fail with PP_ERROR_BADRESOURCE. If you need to access data associated
25 * with your instance, you will probably want to create some kind of threadsafe
26 * proxy object that can handle asynchonous destruction of the instance object.
27 *
28 * Typical usage:
29 * On the main thread:
30 * - Create the thread yourself (using pthreads).
31 * - Create the message loop resource.
32 * - Pass the message loop resource to your thread's main function.
33 * - Call PostWork() on the message loop to run functions on the thread.
34 *
35 * From the background thread's main function:
36 * - Call AttachToCurrentThread() with the message loop resource.
37 * - Call Run() with the message loop resource.
38 *
39 * (You can also create the message loop resource on the background thread,
40 * but then the main thread will have no reference to it should you want to
41 * call PostWork()).
42 *
43 *
44 * The main thread has an implicitly created message loop. The main thread is
45 * the thread where PPP_InitializeModule and PPP_Instance functions are called.
46 * You can retrieve a reference to this message loop by calling
47 * GetForMainThread() or, if your code is on the main thread,
48 * GetForCurrentThread() will also work.
49 *
50 * Some special threads created by the system can not have message loops. In
51 * particular, the background thread created for audio processing has this
52 * requirement because it's intended to be highly responsive to keep up with
53 * the realtime requirements of audio processing. You can not make PPAPI calls
54 * from these threads.
55 *
56 * Once you associate a message loop for a thread, you don't have to keep a
57 * reference to it. The system will hold a reference to the message loop for as
58 * long as the thread is running. The current message loop can be retrieved
59 * using the GetCurrent() function.
60 *
61 * It is legal to create threads in your plugin without message loops, but
62 * PPAPI calls will fail.
63 *
64 * You can create a message loop object on a thread and never actually run the
65 * message loop. This will allow you to call blocking PPAPI calls (via
66 * PP_BlockUntilComplete()). If you make any asynchronous calls, the callbacks
67 * from those calls will be queued in the message loop and never run. The same
68 * thing will happen if work is scheduled after the message loop exits and
69 * the message loop is not run again.
70 */
71 interface PPB_MessageLoop_Dev {
72 /**
73 * Creates a message loop resource.
74 *
75 * This may be called from any thread. After your thread starts but before
76 * issuing any other PPAPI calls on it, you must associate it with a message
77 * loop by calling AttachToCurrentThread.
78 */
79 PP_Resource Create(PP_Module module);
80
81 /**
82 * Returns a resource identifying the message loop for the main thread. The
83 * main thread always has a message loop created by the system.
84 */
85 PP_Resource GetForMainThread();
86
87 /**
88 * Returns a reference to the PPB_MessageLoop object attached to the current
89 * thread. If there is no attached message loop, the return value will be 0.
90 */
91 PP_Resource GetCurrent();
dmichael (off chromium) 2011/12/29 19:41:21 Does it have to be on the stack? I.e., if I've don
brettw 2011/12/29 20:07:39 "Once you associate a message loop for a thread, y
92
93 /**
94 * Sets the given message loop resource as being the associated message loop
95 * for the currently running thread.
96 *
97 * You must call this function exactly once on a thread before making any
98 * PPAPI calls. A message loop can only be attached to one thread, and the
99 * message loop can not be changed later. The message loop will be attached
100 * as long as the thread is running.
101 *
102 * If this function fails, attempting to run the message loop will fail.
103 * Note that you can still post work to the message loop: it will get queued
104 * up should the message loop eventually be successfully attached and run.
105 *
106 * @return
107 * - PP_OK: The message loop was successfully attached to the thread and is
108 * ready to use.
109 * - PP_ERROR_BADRESOURCE: The given message loop resource is invalid.
110 * - PP_ERROR_INPROGRESS: The current thread already has a message loop
111 * attached. This will always be the case for the main thread, which has
112 * an implicit system-created message loop attached.
113 * - PP_ERROR_WRONG_THREAD: The current thread type can not have a message
114 * loop attached to it. See the interface level discussion about these
115 * special threads, which include realtime audio threads.
116 */
117 int32_t AttachToCurrentThread([in] PP_Resource message_loop);
118
119 /**
120 * Runs the thread message loop. Running the message loop is required for you
121 * to get issued completion callbacks on the thread.
122 *
123 * The message loop identified by the argument must have been previously
124 * successfully attached to the current thread.
125 *
126 * You may call Run() nested inside another message loop. This nested loop
127 * will run until it's requested to quit, and control will then return to the
128 * next outermost message loop on the stack. Nested message loops can be
129 * tricky, so use with caution.
130 *
131 * You may not call Run() on the main thread's message loop. The system
132 * implicitly runs a message loop on the main thread where it issues PPP_
133 * calls, and nested message loops are not permitted on the main thread to
134 * avoid reentrancy issues with PPAPI calls.
135 *
136 * @return
137 * - PP_OK: The message loop was successfully run. Note that on
138 * success, the message loop will only exit when you call QuitNow() or
139 * PostQuit().
140 * - PP_ERROR_BADRESOURCE: The given message loop resource is invalid.
141 * - PP_ERROR_WRONG_THREAD: You are attempting to run a message loop that
142 * has not been successfully attached to the current thread. Call
143 * AttachToCurrentThread().
144 * - PP_ERROR_BLOCKS_MAIN_THREAD: You are attempting to call this function
145 * on the main thread. This is not supported as described above.
146 */
147 int32_t Run([in] PP_Resource message_loop);
dmichael (off chromium) 2011/12/29 19:41:21 I think we probably want to allow a timeout and/or
brettw 2011/12/29 20:07:39 If you want to run the message loop for some time,
dmichael (off chromium) 2012/01/04 04:30:26 In Chromium, we own the message loop and can add t
148
149 /**
150 * Quits the message loop identified by the given resource without running
151 * pending work. This function may only be called from within the current
152 * message loop for the current thread.
153 *
154 * See also PostQuit(), which is usually more appropriate for most uses.
155 *
156 * If there are nested message loops, this will only quit the outermost one.
yzshen1 2011/12/30 21:08:24 Do you mean that I can create nested message loops
brettw 2011/12/31 23:01:47 Yes.
157 *
158 * @return
159 * - PP_OK if the message loop will be exited.
160 * - PP_ERROR_BADRESOURCE: The given message loop resource is invalid.
161 * - PP_ERROR_WRONG_THREAD: The message loop does not identify the message
162 * loop registered for the current thread, or the current thread is the
163 * main thread (which you can not exit).
164 */
165 int32_t QuitNow([in] PP_Resource message_loop);
166
167 /**
168 * Schedules work to run on the given message loop. This may be called from
169 * any thread. Posted work will be executed in the order it was posted when
170 * the message loop is Run().
171 *
172 * @arg message_loop The message loop resource.
173 *
174 * @arg callback A pointer to the completion callback to execute from the
175 * message loop.
176 *
177 * @arg callback_result_arg This value will be passed as the first parameter
178 * ("result") to the completion callback. It can be anything you want, it is
179 * not used internally.
180 *
181 * You can call this function before the message loop has started and the
182 * work will get queued until the message loop is run. If the message loop
183 * is never run, the completion callback will never be executed.
184 *
185 * You can also post work after the message loop has exited. Because the
186 * system does not know whether you plan to run the message loop on the
187 * thread again in the future, it will queue the work. If you don't run the
188 * message loop again, the requests will be lost. If your application
189 * depends on guaranteed execution, you may want to add additional signaling
190 * to avoid this race condition.
191 *
192 * @return
193 * - PP_OK: The work was posted to the message loop's queue. As described
194 * above, this does not mean that the work has been or will be executed
195 * (if you never run the message loop after posting).
196 * - PP_ERROR_BADRESOURCE: The given message loop resource is invalid.
197 * - PP_ERROR_BADARGUMENT: The function pointer for the completion callback
198 * is null (this will be the case if you pass PP_BlockUntilComplete()).
199 */
200 int32_t PostWork([in] PP_Resource message_loop,
201 [in] PP_CompletionCallback callback,
202 [in] int32_t callback_result_arg);
203
204 /**
205 * Schedules work to run on the given message loop. This is identical to
206 * PostWork() except that it allows additional control.
207 *
208 * @arg delay_ms The number of millseconds to delay execution of the given
209 * completion callback. Passing 0 means it will get queued normally and
210 * executed in order, as with PostWork().
211 *
212 * @arg prevent_nested Controls whether the callback can be executed in a
213 * nested message loop. Normal tasks posted via PostWork() will execute in
214 * nested message loops (prevent_nested = PP_FALSE). If you pass PP_TRUE,
215 * only the outermost invocation of the message loop's Run() function on the
yzshen1 2011/12/30 21:08:24 I think 'outermost' on this line has different mea
216 * stack will execute the given completion callback. This can be useful if
217 * you need to do some cleanup (like deleting a pointer) that must be done
218 * after all code currently on the stack executes.
219 */
220 int32_t PostWorkEx([in] PP_Resource message_loop,
viettrungluu 2011/12/30 16:52:20 Ugh. For the C API, I think this should be folded
221 [in] PP_CompletionCallback callback,
222 [in] int32_t callback_result,
223 [in] int64 delay_ms,
224 [in] PP_Bool prevent_nested);
225
226 /**
227 * Posts a quit message to the given message loop's work queue. Work posted
228 * before that point will be processed before quitting.
229 *
230 * This may be called on the message loop registered for the current thread,
231 * or it may be called on the message loop registered for another thread.
232 *
233 * If you are running nested message loops, this will only quit the outermost
234 * one. This may not be what your calling code expects, so you will need to
235 * be extra cautious if you run nested message loops.
236 *
237 * @return
238 * - PP_OK: The request to quit was successfully posted.
239 * - PP_ERROR_BADRESOURCE: The message loop was invalid.
240 * - PP_ERROR_WRONG_THREAD: You are attempting to quit the main thread.
241 * The main thread's message loop is managed by the system and can't be
242 * quit.
243 */
244 int32_t PostQuit([in] PP_Resource message_loop);
245 };
viettrungluu 2011/12/30 16:58:35 I think there should be a distinction between leav
OLDNEW
« no previous file with comments | « no previous file | ppapi/api/pp_errors.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698