1 /*
2 * Copyright (C) 2013 DENSO CORPORATION
3 * Copyright (c) 2013 BMW Car IT GmbH
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24 #ifndef IVI_APPLICATION_CLIENT_PROTOCOL_H
25 #define IVI_APPLICATION_CLIENT_PROTOCOL_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <stdint.h>
32 #include <stddef.h>
33 #include "wayland-client.h"
34
35 struct wl_client;
36 struct wl_resource;
37
38 struct ivi_surface;
39 struct ivi_application;
40
41 extern const struct wl_interface ivi_surface_interface;
42 extern const struct wl_interface ivi_application_interface;
43
44 #ifndef IVI_SURFACE_WARNING_CODE_ENUM
45 #define IVI_SURFACE_WARNING_CODE_ENUM
46 /**
47 * @brief Possible warning codes returned by ivi compositor
48 *
49 * These define all possible warning codes returned by ivi compositor on
50 * server-side warnings.
51 */
52 enum ivi_surface_warning_code {
53 IVI_SURFACE_WARNING_CODE_INVALID_WL_SURFACE = 1, /**< Surface is invalid. */
54 IVI_SURFACE_WARNING_CODE_IVI_ID_IN_USE = 2, /**< ivi_id is in use and cannot be shared. */
55 };
56 #endif /* IVI_SURFACE_WARNING_CODE_ENUM */
57
58 /**
59 * @brief Application interface to surface in ivi compositor
60 */
61 struct ivi_surface_listener {
62 /**
63 * @brief Visibility of surface in ivi compositor has
64 * changed
65 *
66 * The new visibility state is provided in argument @p visibility.
67 * If @p visibility is 0, the surface has become invisible. If
68 * @p visibility is not 0, the surface has become visible.
69 */
70 void (*visibility)(void *data,
71 struct ivi_surface *ivi_surface,
72 int32_t visibility);
73 /**
74 * @brief Server-side warning detected
75 *
76 * The ivi compositor encountered warning while processing a
77 * request by this application. The warning is defined by argument
78 * @p warning_code and optional @p warning_text. If the warning is
79 * detected, client shall destroy the @p ivi_surface object.
80 *
81 * When a warning event is sent, the compositor turns the
82 * @p ivi_surface object inert. The @p ivi_surface will not deliver
83 * further events, all requests on it are ignored except 'destroy',
84 * and the association to the ivi_id is removed. The client should
85 * destroy the @p ivi_surface object. If an inert @p ivi_surface object
86 * is used as an argument to any other object's request, that
87 * request will [produce a fatal error / produce a warning / be
88 * ignored].
89 */
90 void (*warning)(void *data,
91 struct ivi_surface *ivi_surface,
92 int32_t warning_code,
93 const char *warning_text);
94 };
95
96 static inline int
ivi_surface_add_listener(struct ivi_surface * ivi_surface,const struct ivi_surface_listener * listener,void * data)97 ivi_surface_add_listener(struct ivi_surface *ivi_surface,
98 const struct ivi_surface_listener *listener, void *data)
99 {
100 return wl_proxy_add_listener((struct wl_proxy *) ivi_surface,
101 (void (**)(void)) listener, data);
102 }
103
104 #define IVI_SURFACE_DESTROY 0
105
106 static inline void
ivi_surface_set_user_data(struct ivi_surface * ivi_surface,void * user_data)107 ivi_surface_set_user_data(struct ivi_surface *ivi_surface, void *user_data)
108 {
109 wl_proxy_set_user_data((struct wl_proxy *) ivi_surface, user_data);
110 }
111
112 static inline void *
ivi_surface_get_user_data(struct ivi_surface * ivi_surface)113 ivi_surface_get_user_data(struct ivi_surface *ivi_surface)
114 {
115 return wl_proxy_get_user_data((struct wl_proxy *) ivi_surface);
116 }
117
118 static inline void
ivi_surface_destroy(struct ivi_surface * ivi_surface)119 ivi_surface_destroy(struct ivi_surface *ivi_surface)
120 {
121 wl_proxy_marshal((struct wl_proxy *) ivi_surface,
122 IVI_SURFACE_DESTROY);
123
124 wl_proxy_destroy((struct wl_proxy *) ivi_surface);
125 }
126
127 #define IVI_APPLICATION_SURFACE_CREATE 0
128
129 static inline void
ivi_application_set_user_data(struct ivi_application * ivi_application,void * user_data)130 ivi_application_set_user_data(struct ivi_application *ivi_application, void *user_data)
131 {
132 wl_proxy_set_user_data((struct wl_proxy *) ivi_application, user_data);
133 }
134
135 static inline void *
ivi_application_get_user_data(struct ivi_application * ivi_application)136 ivi_application_get_user_data(struct ivi_application *ivi_application)
137 {
138 return wl_proxy_get_user_data((struct wl_proxy *) ivi_application);
139 }
140
141 static inline void
ivi_application_destroy(struct ivi_application * ivi_application)142 ivi_application_destroy(struct ivi_application *ivi_application)
143 {
144 wl_proxy_destroy((struct wl_proxy *) ivi_application);
145 }
146
147 static inline struct ivi_surface *
ivi_application_surface_create(struct ivi_application * ivi_application,uint32_t ivi_id,struct wl_surface * surface)148 ivi_application_surface_create(struct ivi_application *ivi_application, uint32_t ivi_id, struct wl_surface *surface)
149 {
150 struct wl_proxy *id;
151
152 id = wl_proxy_marshal_constructor((struct wl_proxy *) ivi_application,
153 IVI_APPLICATION_SURFACE_CREATE, &ivi_surface_interface, ivi_id, surface, NULL);
154
155 return (struct ivi_surface *) id;
156 }
157
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif
163