blob: 9fbe71b7b14079a503f4b330c5568ef219443575 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/* Copyright (c) 2010 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef PPAPI_C_PP_COMPLETION_CALLBACK_H_
#define PPAPI_C_PP_COMPLETION_CALLBACK_H_
/**
* @file
* Defines the API ...
*/
#include <stdlib.h>
#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_stdint.h"
/**
* @addtogroup Typedefs
* @{
*/
typedef void (*PP_CompletionCallback_Func)(void* user_data, int32_t result);
/**
* @}
*/
/**
* @addtogroup Structs
* @{
*/
/**
* Any method that takes a PP_CompletionCallback has the option of completing
* asynchronously if the operation would block. Such a method should return
* PP_ERROR_WOULDBLOCK to indicate that the method will complete
* asynchronously. In this case it will signal completion by invoking the
* supplied completion callback, which will always be invoked from the main
* PPAPI thread of execution. If the method returns any other value,
* including PP_OK, the completion callback will not be invoked. If the
* completion callback is NULL, then the method will block if necessary to
* complete its work. PP_BlockUntilComplete() provides a convenient way to
* specify blocking behavior.
*
* The result parameter passes an int32_t that if negative indicates an error
* code. Otherwise the result value indicates success. If it is a positive
* value then it may carry additional information.
*/
struct PP_CompletionCallback {
PP_CompletionCallback_Func func;
void* user_data;
};
/**
* @}
*/
/**
* @addtogroup Functions
* @{
*/
PP_INLINE struct PP_CompletionCallback PP_MakeCompletionCallback(
PP_CompletionCallback_Func func,
void* user_data) {
struct PP_CompletionCallback cc;
cc.func = func;
cc.user_data = user_data;
return cc;
}
/**
* @}
*/
/**
* @addtogroup Functions
* @{
*/
PP_INLINE void PP_RunCompletionCallback(struct PP_CompletionCallback* cc,
int32_t res) {
cc->func(cc->user_data, res);
}
/**
* @}
*/
/**
* @addtogroup Functions
* @{
*/
/**
* Use this in place of an actual completion callback to request blocking
* behavior. If specified, the calling thread will block until a method
* completes. This is only usable from background threads.
*/
PP_INLINE struct PP_CompletionCallback PP_BlockUntilComplete() {
return PP_MakeCompletionCallback(NULL, NULL);
}
/**
* @}
*/
#endif /* PPAPI_C_PP_COMPLETION_CALLBACK_H_ */
|