OLD | NEW |
1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 /* Copyright 2013 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_SIMPLE_PS_EVENT_H_ | 5 #ifndef PPAPI_SIMPLE_PS_EVENT_H_ |
6 #define PPAPI_SIMPLE_PS_EVENT_H_ | 6 #define PPAPI_SIMPLE_PS_EVENT_H_ |
7 | 7 |
8 #include "ppapi/c/pp_bool.h" | 8 #include "ppapi/c/pp_bool.h" |
9 #include "ppapi/c/pp_resource.h" | 9 #include "ppapi/c/pp_resource.h" |
10 #include "ppapi/c/pp_var.h" | 10 #include "ppapi/c/pp_var.h" |
11 | 11 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 /* When the mouse lock is lost. */ | 54 /* When the mouse lock is lost. */ |
55 PSE_MOUSELOCK_MOUSELOCKLOST = 32, | 55 PSE_MOUSELOCK_MOUSELOCKLOST = 32, |
56 | 56 |
57 /* Enable all events. */ | 57 /* Enable all events. */ |
58 PSE_ALL = -1, | 58 PSE_ALL = -1, |
59 } PSEventType; | 59 } PSEventType; |
60 | 60 |
61 typedef uint32_t PSEventTypeMask; | 61 typedef uint32_t PSEventTypeMask; |
62 | 62 |
63 // Generic Event | 63 // Generic Event |
64 typedef struct { | 64 typedef struct PSEvent { |
65 PSEventType type; | 65 PSEventType type; |
66 union { | 66 union { |
67 PP_Bool as_bool; | 67 PP_Bool as_bool; |
68 PP_Resource as_resource; | 68 PP_Resource as_resource; |
69 struct PP_Var as_var; | 69 struct PP_Var as_var; |
70 }; | 70 }; |
| 71 |
| 72 /* Internal */ |
| 73 struct PSEvent* next; |
71 } PSEvent; | 74 } PSEvent; |
72 | 75 |
| 76 typedef void (*PSMessageHandler_t)(struct PP_Var key, |
| 77 struct PP_Var value, |
| 78 void* user_data); |
73 | 79 |
74 /** | 80 /** |
75 * Function for queuing, acquiring, and releasing events. | 81 * Function for queuing, acquiring, and releasing events. |
76 */ | 82 */ |
77 PSEvent* PSEventTryAcquire(); | 83 PSEvent* PSEventTryAcquire(); |
78 PSEvent* PSEventWaitAcquire(); | 84 PSEvent* PSEventWaitAcquire(); |
79 void PSEventRelease(PSEvent* event); | 85 void PSEventRelease(PSEvent* event); |
80 void PSEventSetFilter(PSEventTypeMask mask); | 86 void PSEventSetFilter(PSEventTypeMask mask); |
81 | 87 |
82 /** | 88 /** |
83 * Creates and adds an event of the specified type to the event queue if | 89 * Creates and adds an event of the specified type to the event queue if |
84 * that event type is not currently filtered. | 90 * that event type is not currently filtered. |
85 */ | 91 */ |
86 void PSEventPost(PSEventType type); | 92 void PSEventPost(PSEventType type); |
87 void PSEventPostBool(PSEventType type, PP_Bool state); | 93 void PSEventPostBool(PSEventType type, PP_Bool state); |
88 void PSEventPostVar(PSEventType type, struct PP_Var var); | 94 void PSEventPostVar(PSEventType type, struct PP_Var var); |
89 void PSEventPostResource(PSEventType type, PP_Resource resource); | 95 void PSEventPostResource(PSEventType type, PP_Resource resource); |
90 | 96 |
| 97 |
| 98 /* Register a message handler for messages that arrive from JavaScript with a |
| 99 * give names. |
| 100 * Messages are of the form: { message_name : <value> }. |
| 101 * |
| 102 * PSInstance will then not generate events but instead cause the handler to be |
| 103 * called upon message arrival. If handler is NULL then the current handler |
| 104 * will be removed. Example usage: |
| 105 * |
| 106 * JavaScript: |
| 107 * nacl_module.postMessage({'foo': 123}); |
| 108 * |
| 109 * C: |
| 110 * void MyMessageHandler(struct PP_Var key, |
| 111 * struct PP_Var value, |
| 112 * void* user_data) { |
| 113 * assert(key.type == PP_VARTYPE_STRING); |
| 114 * assert(value.type == PP_VARTYPE_INT32)); |
| 115 * assert(value.value.as_int == 123); |
| 116 * } |
| 117 * ... |
| 118 * PSInstanceRegisterMessageHandler("foo", &MyMessageHandler, NULL); */ |
| 119 void PSEventRegisterMessageHandler(const char* message_name, |
| 120 PSMessageHandler_t handler, |
| 121 void* user_data); |
| 122 |
91 EXTERN_C_END | 123 EXTERN_C_END |
92 | 124 |
93 #endif /* PPAPI_SIMPLE_PS_EVENT_H_ */ | 125 #endif /* PPAPI_SIMPLE_PS_EVENT_H_ */ |
OLD | NEW |