| 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 * | |
| 12 * @addtogroup PP | |
| 13 * @{ | |
| 14 */ | 11 */ |
| 15 | 12 |
| 16 #include <stdlib.h> | 13 #include <stdlib.h> |
| 17 | 14 |
| 18 #include "ppapi/c/pp_macros.h" | 15 #include "ppapi/c/pp_macros.h" |
| 19 #include "ppapi/c/pp_stdint.h" | 16 #include "ppapi/c/pp_stdint.h" |
| 20 | 17 |
| 18 /** |
| 19 * @addtogroup Typedefs |
| 20 * @{ |
| 21 */ |
| 21 typedef void (*PP_CompletionCallback_Func)(void* user_data, int32_t result); | 22 typedef void (*PP_CompletionCallback_Func)(void* user_data, int32_t result); |
| 23 /** |
| 24 * @} |
| 25 */ |
| 26 |
| 27 /** |
| 28 * @addtogroup Structs |
| 29 * @{ |
| 30 */ |
| 22 | 31 |
| 23 /** | 32 /** |
| 24 * Any method that takes a PP_CompletionCallback has the option of completing | 33 * Any method that takes a PP_CompletionCallback has the option of completing |
| 25 * asynchronously if the operation would block. Such a method should return | 34 * asynchronously if the operation would block. Such a method should return |
| 26 * PP_Error_WouldBlock to indicate when the method will complete | 35 * PP_Error_WouldBlock to indicate when the method will complete |
| 27 * asynchronously. If the completion callback is NULL, then the operation will | 36 * asynchronously. If the completion callback is NULL, then the operation will |
| 28 * block if necessary to complete its work. PP_BlockUntilComplete() provides a | 37 * block if necessary to complete its work. PP_BlockUntilComplete() provides a |
| 29 * convenient way to specify blocking behavior. | 38 * convenient way to specify blocking behavior. |
| 30 * | 39 * |
| 31 * The result parameter passes an int32_t that if negative indicates an error | 40 * The result parameter passes an int32_t that if negative indicates an error |
| 32 * code. Otherwise the result value indicates success. If it is a positive | 41 * code. Otherwise the result value indicates success. If it is a positive |
| 33 * value then it may carry additional information. | 42 * value then it may carry additional information. |
| 34 */ | 43 */ |
| 35 struct PP_CompletionCallback { | 44 struct PP_CompletionCallback { |
| 36 PP_CompletionCallback_Func func; | 45 PP_CompletionCallback_Func func; |
| 37 void* user_data; | 46 void* user_data; |
| 38 }; | 47 }; |
| 48 /** |
| 49 * @} |
| 50 */ |
| 39 | 51 |
| 52 /** |
| 53 * @addtogroup Functions |
| 54 * @{ |
| 55 */ |
| 40 PP_INLINE struct PP_CompletionCallback PP_MakeCompletionCallback( | 56 PP_INLINE struct PP_CompletionCallback PP_MakeCompletionCallback( |
| 41 PP_CompletionCallback_Func func, | 57 PP_CompletionCallback_Func func, |
| 42 void* user_data) { | 58 void* user_data) { |
| 43 struct PP_CompletionCallback cc; | 59 struct PP_CompletionCallback cc; |
| 44 cc.func = func; | 60 cc.func = func; |
| 45 cc.user_data = user_data; | 61 cc.user_data = user_data; |
| 46 return cc; | 62 return cc; |
| 47 } | 63 } |
| 64 /** |
| 65 * @} |
| 66 */ |
| 48 | 67 |
| 68 /** |
| 69 * @addtogroup Functions |
| 70 * @{ |
| 71 */ |
| 49 PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc, | 72 PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc, |
| 50 int32_t res) { | 73 int32_t res) { |
| 51 cc->func(cc->user_data, res); | 74 cc->func(cc->user_data, res); |
| 52 } | 75 } |
| 76 /** |
| 77 * @} |
| 78 */ |
| 79 |
| 80 /** |
| 81 * @addtogroup Functions |
| 82 * @{ |
| 83 */ |
| 53 | 84 |
| 54 /** | 85 /** |
| 55 * Use this in place of an actual completion callback to request blocking | 86 * Use this in place of an actual completion callback to request blocking |
| 56 * behavior. If specified, the calling thread will block until a method | 87 * behavior. If specified, the calling thread will block until a method |
| 57 * completes. This is only usable from background threads. | 88 * completes. This is only usable from background threads. |
| 58 */ | 89 */ |
| 59 PP_INLINE struct PP_CompletionCallback PP_BlockUntilComplete() { | 90 PP_INLINE struct PP_CompletionCallback PP_BlockUntilComplete() { |
| 60 return PP_MakeCompletionCallback(NULL, NULL); | 91 return PP_MakeCompletionCallback(NULL, NULL); |
| 61 } | 92 } |
| 62 | |
| 63 /** | 93 /** |
| 64 * @} | 94 * @} |
| 65 * End of addtogroup PP | |
| 66 */ | 95 */ |
| 96 |
| 67 #endif /* PPAPI_C_PP_COMPLETION_CALLBACK_H_ */ | 97 #endif /* PPAPI_C_PP_COMPLETION_CALLBACK_H_ */ |
| 68 | 98 |
| OLD | NEW |