OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef PPAPI_CPP_DEV_MESSAGE_LOOP_DEV_H_ | 5 #ifndef PPAPI_CPP_MESSAGE_LOOP_H_ |
6 #define PPAPI_CPP_DEV_MESSAGE_LOOP_DEV_H_ | 6 #define PPAPI_CPP_MESSAGE_LOOP_H_ |
7 | 7 |
8 #include "ppapi/cpp/resource.h" | 8 #include "ppapi/cpp/resource.h" |
9 | 9 |
10 namespace pp { | 10 namespace pp { |
11 | 11 |
12 class CompletionCallback; | 12 class CompletionCallback; |
13 class InstanceHandle; | 13 class InstanceHandle; |
14 | 14 |
15 /// A message loop allows PPAPI calls to be issued on a thread. You may not | 15 /// A message loop allows PPAPI calls to be issued on a thread. You may not |
16 /// issue any API calls on a thread without creating a message loop. It also | 16 /// issue any API calls on a thread without creating a message loop. It also |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 /// CompletionCallbackFactory, use the following pattern: | 117 /// CompletionCallbackFactory, use the following pattern: |
118 /// | 118 /// |
119 /// pp::CompletionCallback callback = factory_.NewOptionalCallback(...); | 119 /// pp::CompletionCallback callback = factory_.NewOptionalCallback(...); |
120 /// int32_t result = message_loop.PostWork(callback); | 120 /// int32_t result = message_loop.PostWork(callback); |
121 /// if (result != PP_OK_COMPLETIONPENDING) | 121 /// if (result != PP_OK_COMPLETIONPENDING) |
122 /// callback.Run(result); | 122 /// callback.Run(result); |
123 /// | 123 /// |
124 /// This will run the callback with an error value, and assumes that the | 124 /// This will run the callback with an error value, and assumes that the |
125 /// implementation of your callback checks the "result" argument and returns | 125 /// implementation of your callback checks the "result" argument and returns |
126 /// immediately on error. | 126 /// immediately on error. |
127 class MessageLoop_Dev : public Resource { | 127 class MessageLoop : public Resource { |
128 public: | 128 public: |
129 /// Creates an is_null() MessageLoop resource. | 129 /// Creates an is_null() MessageLoop resource. |
130 MessageLoop_Dev(); | 130 MessageLoop(); |
131 | 131 |
132 /// Creates a message loop associated with the given instance. The resource | 132 /// Creates a message loop associated with the given instance. The resource |
133 /// will be is_null() on failure. | 133 /// will be is_null() on failure. |
134 /// | 134 /// |
135 /// This may be called from any thread. After your thread starts but before | 135 /// This may be called from any thread. After your thread starts but before |
136 /// issuing any other PPAPI calls on it, you must associate it with a message | 136 /// issuing any other PPAPI calls on it, you must associate it with a message |
137 /// loop by calling AttachToCurrentThread. | 137 /// loop by calling AttachToCurrentThread. |
138 explicit MessageLoop_Dev(const InstanceHandle& instance); | 138 explicit MessageLoop(const InstanceHandle& instance); |
139 | 139 |
140 MessageLoop_Dev(const MessageLoop_Dev& other); | 140 MessageLoop(const MessageLoop& other); |
141 | 141 |
142 /// Takes an additional ref to the resource. | 142 /// Takes an additional ref to the resource. |
143 explicit MessageLoop_Dev(PP_Resource pp_message_loop); | 143 explicit MessageLoop(PP_Resource pp_message_loop); |
144 | 144 |
145 static MessageLoop_Dev GetForMainThread(); | 145 static MessageLoop GetForMainThread(); |
146 static MessageLoop_Dev GetCurrent(); | 146 static MessageLoop GetCurrent(); |
147 | 147 |
148 /// Sets the given message loop resource as being the associated message loop | 148 /// Sets the given message loop resource as being the associated message loop |
149 /// for the currently running thread. | 149 /// for the currently running thread. |
150 /// | 150 /// |
151 /// You must call this function exactly once on a thread before making any | 151 /// You must call this function exactly once on a thread before making any |
152 /// PPAPI calls. A message loop can only be attached to one thread, and the | 152 /// PPAPI calls. A message loop can only be attached to one thread, and the |
153 /// message loop can not be changed later. The message loop will be attached | 153 /// message loop can not be changed later. The message loop will be attached |
154 /// as long as the thread is running or until you quit with should_destroy | 154 /// as long as the thread is running or until you quit with should_destroy |
155 /// set to PP_TRUE. | 155 /// set to PP_TRUE. |
156 /// | 156 /// |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 /// - PP_ERROR_BADARGUMENT: The function pointer for the completion callback | 231 /// - PP_ERROR_BADARGUMENT: The function pointer for the completion callback |
232 /// is null (this will be the case if you pass PP_BlockUntilComplete()). | 232 /// is null (this will be the case if you pass PP_BlockUntilComplete()). |
233 /// - PP_ERROR_FAILED: The message loop has been destroyed. | 233 /// - PP_ERROR_FAILED: The message loop has been destroyed. |
234 int32_t PostWork(const CompletionCallback& callback, | 234 int32_t PostWork(const CompletionCallback& callback, |
235 int64_t delay_ms = 0); | 235 int64_t delay_ms = 0); |
236 | 236 |
237 /// Posts a quit message to the given message loop's work queue. Work posted | 237 /// Posts a quit message to the given message loop's work queue. Work posted |
238 /// before that point will be processed before quitting. | 238 /// before that point will be processed before quitting. |
239 /// | 239 /// |
240 /// This may be called on the message loop registered for the current thread, | 240 /// This may be called on the message loop registered for the current thread, |
241 /// or it may be called on the message loop registered for another thread. | 241 /// or it may be called on the message loop registered for another thread. It |
| 242 /// is an error to attempt to quit the main thread loop. |
242 /// | 243 /// |
243 /// @param should_destroy Marks the message loop as being in a destroyed | 244 /// @param should_destroy Marks the message loop as being in a destroyed |
244 /// state and prevents further posting of messages. | 245 /// state and prevents further posting of messages. |
245 /// | 246 /// |
246 /// If you quit a message loop without setting should_destroy, it will still | 247 /// If you quit a message loop without setting should_destroy, it will still |
247 /// be attached to the thread and you can still run it again by calling Run() | 248 /// be attached to the thread and you can still run it again by calling Run() |
248 /// again. If you destroy it, it will be detached from the current thread. | 249 /// again. If you destroy it, it will be detached from the current thread. |
249 /// | 250 /// |
250 /// @return | 251 /// @return |
251 /// - PP_OK: The request to quit was successfully posted. | 252 /// - PP_OK: The request to quit was successfully posted. |
252 /// - PP_ERROR_BADRESOURCE: The message loop was invalid. | 253 /// - PP_ERROR_BADRESOURCE: The message loop was invalid. |
253 /// - PP_ERROR_WRONG_THREAD: You are attempting to quit the main thread. | 254 /// - PP_ERROR_WRONG_THREAD: You are attempting to quit the main thread. |
254 /// The main thread's message loop is managed by the system and can't be | 255 /// The main thread's message loop is managed by the system and can't be |
255 /// quit. | 256 /// quit. |
256 int32_t PostQuit(bool should_destroy); | 257 int32_t PostQuit(bool should_destroy); |
257 }; | 258 }; |
258 | 259 |
259 } // namespace pp | 260 } // namespace pp |
260 | 261 |
261 #endif // PPAPI_CPP_DEV_MESSAGE_LOOP_DEV_H_ | 262 #endif // PPAPI_CPP_MESSAGE_LOOP_H_ |
OLD | NEW |