| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_C_PP_COMPLETION_CALLBACK_H_ | 5 #ifndef PPAPI_C_PP_COMPLETION_CALLBACK_H_ |
| 6 #define PPAPI_C_PP_COMPLETION_CALLBACK_H_ | 6 #define PPAPI_C_PP_COMPLETION_CALLBACK_H_ |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * @file | 9 * @file |
| 10 * Defines the API ... | 10 * Defines the API ... |
| 11 * | 11 * |
| 12 * @addtogroup PP | 12 * @addtogroup PP |
| 13 * @{ | 13 * @{ |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include <stdlib.h> | 16 #include <stdlib.h> |
| 17 | 17 |
| 18 #include "ppapi/c/pp_macros.h" |
| 18 #include "ppapi/c/pp_stdint.h" | 19 #include "ppapi/c/pp_stdint.h" |
| 19 | 20 |
| 20 typedef void (*PP_CompletionCallback_Func)(void* user_data, int32_t result); | 21 typedef void (*PP_CompletionCallback_Func)(void* user_data, int32_t result); |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * Any method that takes a PP_CompletionCallback has the option of completing | 24 * Any method that takes a PP_CompletionCallback has the option of completing |
| 24 * asynchronously if the operation would block. Such a method should return | 25 * asynchronously if the operation would block. Such a method should return |
| 25 * PP_Error_WouldBlock to indicate when the method will complete | 26 * PP_Error_WouldBlock to indicate when the method will complete |
| 26 * asynchronously. If the completion callback is NULL, then the operation will | 27 * asynchronously. If the completion callback is NULL, then the operation will |
| 27 * block if necessary to complete its work. PP_BlockUntilComplete() provides a | 28 * block if necessary to complete its work. PP_BlockUntilComplete() provides a |
| 28 * convenient way to specify blocking behavior. | 29 * convenient way to specify blocking behavior. |
| 29 * | 30 * |
| 30 * The result parameter passes an int32_t that if negative indicates an error | 31 * The result parameter passes an int32_t that if negative indicates an error |
| 31 * code. Otherwise the result value indicates success. If it is a positive | 32 * code. Otherwise the result value indicates success. If it is a positive |
| 32 * value then it may carry additional information. | 33 * value then it may carry additional information. |
| 33 */ | 34 */ |
| 34 struct PP_CompletionCallback { | 35 struct PP_CompletionCallback { |
| 35 PP_CompletionCallback_Func func; | 36 PP_CompletionCallback_Func func; |
| 36 void* user_data; | 37 void* user_data; |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 inline struct PP_CompletionCallback PP_MakeCompletionCallback( | 40 PP_INLINE struct PP_CompletionCallback PP_MakeCompletionCallback( |
| 40 PP_CompletionCallback_Func func, | 41 PP_CompletionCallback_Func func, |
| 41 void* user_data) { | 42 void* user_data) { |
| 42 struct PP_CompletionCallback cc = { func, user_data }; | 43 struct PP_CompletionCallback cc = { func, user_data }; |
| 43 return cc; | 44 return cc; |
| 44 } | 45 } |
| 45 | 46 |
| 46 inline void PP_RunCompletionCallback(struct PP_CompletionCallback* cc, | 47 PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc, |
| 47 int32_t res) { | 48 int32_t res) { |
| 48 cc->func(cc->user_data, res); | 49 cc->func(cc->user_data, res); |
| 49 } | 50 } |
| 50 | 51 |
| 51 /** | 52 /** |
| 52 * Use this in place of an actual completion callback to request blocking | 53 * Use this in place of an actual completion callback to request blocking |
| 53 * behavior. If specified, the calling thread will block until a method | 54 * behavior. If specified, the calling thread will block until a method |
| 54 * completes. This is only usable from background threads. | 55 * completes. This is only usable from background threads. |
| 55 */ | 56 */ |
| 56 inline struct PP_CompletionCallback PP_BlockUntilComplete() { | 57 PP_INLINE struct PP_CompletionCallback PP_BlockUntilComplete() { |
| 57 return PP_MakeCompletionCallback(NULL, NULL); | 58 return PP_MakeCompletionCallback(NULL, NULL); |
| 58 } | 59 } |
| 59 | 60 |
| 60 /** | 61 /** |
| 61 * @} | 62 * @} |
| 62 * End of addtogroup PP | 63 * End of addtogroup PP |
| 63 */ | 64 */ |
| 64 #endif // PPAPI_C_PP_COMPLETION_CALLBACK_H_ | 65 #endif // PPAPI_C_PP_COMPLETION_CALLBACK_H_ |
| OLD | NEW |