Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Unified Diff: native_client_sdk/src/libraries/ppapi_simple/ps_event.h

Issue 914983003: [NaCl SDK] Switch ppapi_simple to C library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tty output bug Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/ppapi_simple/ps_event.h
diff --git a/native_client_sdk/src/libraries/ppapi_simple/ps_event.h b/native_client_sdk/src/libraries/ppapi_simple/ps_event.h
index 731f053b130b4eebf9c9e91849b082007d09d9b2..7c2f0d4db0c48990b9fada820c467600c1f017fb 100644
--- a/native_client_sdk/src/libraries/ppapi_simple/ps_event.h
+++ b/native_client_sdk/src/libraries/ppapi_simple/ps_event.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013 The Chromium Authors. All rights reserved.
+/* Copyright 2013 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. */
@@ -61,15 +61,21 @@ typedef enum {
typedef uint32_t PSEventTypeMask;
// Generic Event
-typedef struct {
+typedef struct PSEvent {
PSEventType type;
union {
PP_Bool as_bool;
PP_Resource as_resource;
struct PP_Var as_var;
};
+
+ /* Internal */
+ struct PSEvent* next;
} PSEvent;
+typedef void (*PSMessageHandler_t)(struct PP_Var key,
+ struct PP_Var value,
+ void* user_data);
/**
* Function for queuing, acquiring, and releasing events.
@@ -88,6 +94,32 @@ void PSEventPostBool(PSEventType type, PP_Bool state);
void PSEventPostVar(PSEventType type, struct PP_Var var);
void PSEventPostResource(PSEventType type, PP_Resource resource);
+
+/* Register a message handler for messages that arrive from JavaScript with a
+ * give names.
+ * Messages are of the form: { message_name : <value> }.
+ *
+ * PSInstance will then not generate events but instead cause the handler to be
+ * called upon message arrival. If handler is NULL then the current handler
+ * will be removed. Example usage:
+ *
+ * JavaScript:
+ * nacl_module.postMessage({'foo': 123});
+ *
+ * C:
+ * void MyMessageHandler(struct PP_Var key,
+ * struct PP_Var value,
+ * void* user_data) {
+ * assert(key.type == PP_VARTYPE_STRING);
+ * assert(value.type == PP_VARTYPE_INT32));
+ * assert(value.value.as_int == 123);
+ * }
+ * ...
+ * PSInstanceRegisterMessageHandler("foo", &MyMessageHandler, NULL); */
+void PSEventRegisterMessageHandler(const char* message_name,
+ PSMessageHandler_t handler,
+ void* user_data);
+
EXTERN_C_END
#endif /* PPAPI_SIMPLE_PS_EVENT_H_ */

Powered by Google App Engine
This is Rietveld 408576698