1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
6 /* From extensions/dev/ppb_ext_events_dev.idl,
7 * modified Mon Mar 18 17:18:20 2013.
10 #ifndef PPAPI_C_EXTENSIONS_DEV_PPB_EXT_EVENTS_DEV_H_
11 #define PPAPI_C_EXTENSIONS_DEV_PPB_EXT_EVENTS_DEV_H_
13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_macros.h"
15 #include "ppapi/c/pp_stdint.h"
17 #define PPB_EXT_EVENTS_DEV_INTERFACE_0_1 "PPB_Ext_Events(Dev);0.1"
18 #define PPB_EXT_EVENTS_DEV_INTERFACE PPB_EXT_EVENTS_DEV_INTERFACE_0_1
26 * @addtogroup Typedefs
30 * Used to represent arbitrary C function pointers. Please note that usually
31 * the function that a <code>PP_Ext_GenericFuncType</code> pointer points to
32 * has a different signature than <code>void (*)()</code>.
34 typedef void (*PP_Ext_GenericFuncType
)(void);
44 * An event listener that can be registered with the browser and receive
45 * notifications via the callback function.
47 * A function is defined for each event type to return a properly-filled
48 * <code>PP_Ext_EventListener</code> struct, for example,
49 * <code>PP_Ext_Alarms_OnAlarm_Dev()</code>.
51 struct PP_Ext_EventListener
{
53 * The name of the event to register to.
55 const char* event_name
;
57 * A callback function whose signature is determined by
58 * <code>event_name</code>. All calls will happen on the same thread as the
59 * one on which <code>AddListener()</code> is called.
61 PP_Ext_GenericFuncType func
;
63 * An opaque pointer that will be passed to <code>func</code>.
72 * @addtogroup Interfaces
75 struct PPB_Ext_Events_Dev_0_1
{
77 * Registers a listener to an event.
79 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
81 * @param[in] listener A <code>PP_Ext_EventListener</code> struct.
83 * @return An listener ID, or 0 if failed.
85 uint32_t (*AddListener
)(PP_Instance instance
,
86 struct PP_Ext_EventListener listener
);
88 * Deregisters a listener.
90 * @param[in] instance A <code>PP_Instance</code> identifying one instance of
92 * @param[in] listener_id The ID returned by <code>AddListener()</code>.
94 void (*RemoveListener
)(PP_Instance instance
, uint32_t listener_id
);
97 typedef struct PPB_Ext_Events_Dev_0_1 PPB_Ext_Events_Dev
;
103 * Creates a <code>PP_Ext_EventListener</code> struct.
105 * Usually you should not call it directly. Instead you should call those
106 * functions that return a <code>PP_Ext_EventListener</code> struct for a
107 * specific event type, for example, <code>PP_Ext_Alarms_OnAlarm_Dev()</code>.
109 PP_INLINE
struct PP_Ext_EventListener
PP_Ext_MakeEventListener(
110 const char* event_name
,
111 PP_Ext_GenericFuncType func
,
113 struct PP_Ext_EventListener listener
;
114 listener
.event_name
= event_name
;
115 listener
.func
= func
;
116 listener
.user_data
= user_data
;
119 #endif /* PPAPI_C_EXTENSIONS_DEV_PPB_EXT_EVENTS_DEV_H_ */