summaryrefslogtreecommitdiffstats
path: root/demo3/horizontal/waltham-server/include/wth-server-waltham-comm.h
blob: 1d58dde8de8e39904615676acab4827ac25550f9 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
/**
 * @licence app begin@
 *
 *
 *  TBD
 *
 *
 * @licence end@
 */
/*******************************************************************************
**                                                                            **
**  SRC-MODULE:                                                               **
**                                                                            **
**  TARGET    : linux                                                         **
**                                                                            **
**  PROJECT   : waltham-server                                                **
**                                                                            **
**  AUTHOR    :                                                               **
**                                                                            **
**                                                                            **
**                                                                            **
**  PURPOSE   : Header file declare macros, extern functions, data types etc, **
**  required to interface with waltham IPC library                            **
**                                                                            **
**  REMARKS   :                                                               **
**                                                                            **
**  PLATFORM DEPENDANT [yes/no]: yes                                          **
**                                                                            **
**  TO BE CHANGED BY USER [yes/no]: no                                        **
**                                                                            **
*******************************************************************************/

#ifndef WTH_SERVER_WALTHAM_COMM_H_
#define WTH_SERVER_WALTHAM_COMM_H_

#include <stdio.h>
#include <stdbool.h>
#include <sys/epoll.h>
#include <errno.h>
#include <netinet/in.h>
#include <string.h>
#include <assert.h>
#include <getopt.h>
#include <unistd.h>

#include <gst/gl/gl.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>

#include <wayland-egl.h>
#include <wayland-client.h>
#include <waltham-server.h>
#include <waltham-connection.h>

struct server;
struct client;
struct window;
struct pointer;
struct touch;
/*
pthread_mutex_t g_mutex;
pthread_cond_t g_cond;
int go_to_wait;
*/
extern const struct wth_display_interface display_implementation;

/**
* server_accept_client
*
* Accepts new waltham client connection and instantiates client structure
*
* @param names        struct server *srv
* @param value        socket connection info and client data
* @return             none
*/
void server_accept_client(struct server *srv);

/**
* server_flush_clients
*
* write all the pending requests from the clients to socket
*
* @param names        struct server *srv
* @param value        socket connection info and client data
* @return             none
*/
void server_flush_clients(struct server *srv);

/**
* client_destroy
*
* Destroy client connection
*
* @param names        struct client *c
* @param value        client data
* @return             none
*/
void client_destroy(struct client *c);

/**
* waltham_pointer_enter
*
* Send pointer enter event received from weston to waltham client
*
* @param names        struct window *window
*             uint32_t serial
*             wl_fixed_t sx
*             wl_fixed_t sy
* @param value        window - window information
*                     serial - serial number of the enter event
*             sx     - surface-local x coordinate
*             sy     - surface-local y coordinate
* @return             none
*/
void waltham_pointer_enter(struct window *window, uint32_t serial,
                      wl_fixed_t sx, wl_fixed_t sy);

/**
* waltham_pointer_leave
*
* Send pointer leave event received from weston to waltham client
*
* @param names        struct window *window
*             uint32_t serial
* @param value        window - window information
*                     serial - serial number of the leave event
* @return             none
*/
void waltham_pointer_leave(struct window *window, uint32_t serial);

/**
* waltham_pointer_motion
*
* Send pointer motion event received from weston to waltham client
*
* @param names        struct window *window
*             uint32_t time
*             wl_fixed_t sx
*             wl_fixed_t sy
* @param value        window - window information
*                     time   - timestamp with millisecond granularity
*             sx     - surface-local x coordinate
*             sy     - surface-local y coordinate
* @return             none
*/
void waltham_pointer_motion(struct window *window, uint32_t time,
                       wl_fixed_t sx, wl_fixed_t sy);

/**
* waltham_pointer_button
*
* Send pointer button event received from weston to waltham client
*
* @param names        struct window *window
*             uint32_t serial
*             uint32_t time
*                     uint32_t button
*             uint32_t state
* @param value        window - window information
*             serial - serial number of the button event
*                     time   - timestamp with millisecond granularity
*             button - button that produced the event
*             state  - physical state of the button
* @return             none
*/
void waltham_pointer_button(struct window *window, uint32_t serial,
               uint32_t time, uint32_t button,
               uint32_t state);

/**
* waltham_pointer_axis
*
* Send pointer axis event received from weston to waltham client
*
* @param names        struct window *window
*             uint32_t time
*             uint32_t axis
*             wl_fixed_t value
* @param value        window - window information
*             time   - timestamp with millisecond granularity
*             axis   - axis type
*                     value  - length of vector in surface-local coordinate space
* @return             none
*/
void waltham_pointer_axis(struct window *window, uint32_t time,
             uint32_t axis, wl_fixed_t value);

/**
* waltham_touch_down
*
* Send touch down event received from weston to waltham client
*
* @param names     struct window *window
*          uint32_t serial
*                  uint32_t time
*          int32_t id
*          wl_fixed_t x_w
*          wl_fixed_t y_w
* @param value     window - window information
*          serial - serial number of the touch down event
*          time   - timestamp with millisecond granularity
*          id     - the unique ID of this touch point
*          x_w    - surface-local x coordinate
*          y_w    - surface-local y coordinate
* @return          none
*/
void waltham_touch_down(struct window *window, uint32_t serial,
                   uint32_t time, int32_t id,
           wl_fixed_t x_w, wl_fixed_t y_w);

/**
* waltham_touch_up
*
* Send touch up event received from weston to waltham client
*
* @param names     struct window *window
*          uint32_t serial
*                  uint32_t time
*          int32_t id
* @param value     window - window information
*          serial - serial number of the touch up event
*          time   - timestamp with millisecond granularity
*          id     - the unique ID of this touch point
* @return          none
*/
void waltham_touch_up(struct window *window, uint32_t serial,
                 uint32_t time, int32_t id);

/**
* waltham_touch_motion
*
* Send touch motion event received from weston to waltham client
*
* @param names     struct window *window
*                  uint32_t time
*          int32_t id
*          wl_fixed_t x_w
*          wl_fixed_t y_w
* @param value     window - window information
*          time   - timestamp with millisecond granularity
*          id     - the unique ID of this touch point
*          x_w    - surface-local x coordinate
*          y_w    - surface-local y coordinate
* @return          none
*/
void waltham_touch_motion(struct window *window, uint32_t time,
             int32_t id, wl_fixed_t x_w, wl_fixed_t y_w);

/**
* waltham_touch_frame
*
* Send touch frame event received from weston to waltham client
*
* @param names        struct window *window
* @param value        window - window information
* @return             none
*/
void waltham_touch_frame(struct window *window);

/**
* waltham_touch_cancel
*
* Send touch cancel event received from weston to waltham client
*
* @param names        struct window *window
* @param value        window - window information
* @return             none
*/
void waltham_touch_cancel(struct window *window);


/***** macros *******/
#define MAX_EPOLL_WATCHES 2

#ifndef container_of
#define container_of(ptr, type, member) ({                              \
        const __typeof__( ((type *)0)->member ) *__mptr = (ptr);        \
        (type *)( (char *)__mptr - offsetof(type,member) );})
#endif

#define wl_list_last_until_empty(pos, head, member)                     \
        while (!wl_list_empty(head) &&                                  \
                (pos = wl_container_of((head)->prev, pos, member), 1))

#ifndef ARRAY_LENGTH
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#endif

#ifndef pr_fmt
#   define pr_fmt(fmt) fmt
#endif

#ifndef USE_STDOUT
#   define PRINT_OUT stderr
#else
#   define PRINT_OUT stdout
#endif

#define wth_error(fmt, ...) \
    ({ fprintf(PRINT_OUT, pr_fmt(fmt), ## __VA_ARGS__); fflush(PRINT_OUT); })
#define wth_verbose(fmt, ...) \
    ({ if (get_verbosity()) { fprintf(PRINT_OUT, pr_fmt(fmt), ## __VA_ARGS__); fflush(PRINT_OUT); } })

/****** incline functions *****/
static inline void *
zalloc(size_t size)
{
        return calloc(1, size);
}


/***** Data types *****/
/* wthp_region protocol object */
struct region {
    struct wthp_region *obj;
    /* pixman_region32_t region; */
    struct wl_list link; /* struct client::region_list */
};

/* wthp_compositor protocol object */
struct compositor {
    struct wthp_compositor *obj;
    struct client *client;
    struct wl_list link; /* struct client::compositor_list */
};

/* wthp_blob_factory protocol object */
struct blob_factory {
    struct wthp_blob_factory *obj;
    struct client *client;
    struct wl_list link; /* struct client::blob_factory_list */
};

/* wthp_buffer protocol object */
struct buffer {
    struct wthp_buffer *obj;
    uint32_t data_sz;
    void *data;
    int32_t width;
    int32_t height;
    int32_t stride;
    uint32_t format;
    struct wl_list link; /* struct client::buffer_list */
};

/* wthp_seat protocol object */
struct seat {
    struct wthp_seat *obj;
    struct client *client;
    struct pointer *pointer;
    struct keyboard *keyboard;
    struct touch *touch;
    struct wl_list link; /* struct client::seat_list */
};

/* wthp_pointer protocol object */
struct pointer {
    struct wthp_pointer *obj;
    struct seat *seat;
    struct wl_list link; /* struct client::pointer_list */
};

/* wthp_keyboard protocol object */
struct keyboard {
    struct wthp_keyboard *obj;
    struct seat *seat;
    struct wl_list link; /* struct client::keyboard_list */
};

/* wthp_touch protocol object */
struct touch {
    struct wthp_touch *obj;
    struct seat *seat;
    struct wl_list link; /* struct client::touch_list */
};

/* wthp_surface protocol object */
struct surface {
    struct wthp_surface *obj;
    uint32_t ivi_id;
    struct ivisurface3 *ivisurf;
    struct wthp_callback *cb;
    struct window *shm_window;
    struct wl_list link; /* struct client::surface_list */
};
/* wthp_ivi_surface protocol object */
struct ivisurface {
    struct wthp_ivi_surface *obj;
    struct wthp_callback *cb;
    struct wl_list link; /* struct client::surface_list */
    struct surface *surf;
};

/* wthp_ivi_application protocol object */
struct application {
        struct wthp_ivi_application *obj;
        struct client *client;
        struct wl_list link; /* struct client::surface_list */
};

/* wthp_registry protocol object */
struct registry {
    struct wthp_registry *obj;
    struct client *client;
    struct wl_list link; /* struct client::registry_list */
};

enum wthp_seat_capability {
    /**
     * the seat has pointer devices
     */
    WTHP_SEAT_CAPABILITY_POINTER = 1,
    /**
     * the seat has one or more keyboards
     */
    WTHP_SEAT_CAPABILITY_KEYBOARD = 2,
    /**
     * the seat has touch devices
     */
    WTHP_SEAT_CAPABILITY_TOUCH = 4,
};

/* epoll structure */
struct watch {
    struct server *server;
    int fd;
    void (*cb)(struct watch *w, uint32_t events);
};

struct client {
    struct wl_list link; /* struct server::client_list */
    struct server *server;

    struct wth_connection *connection;
    struct watch conn_watch;

    /* client object lists for clean-up on disconnection */
    struct wl_list registry_list;     /* struct registry::link */
    struct wl_list compositor_list;   /* struct compositor::link */
    struct wl_list region_list;       /* struct region::link */
    struct wl_list surface_list;      /* struct surface::link */
    struct wl_list buffer_list;       /* struct buffer::link */
    struct wl_list seat_list;         /* struct seat::link */
    struct wl_list pointer_list;      /* struct pointer::link */
    struct wl_list touch_list;        /* struct touch::link */
};

/* server structure */
struct server {
    int listen_fd;
    struct watch listen_watch;

    bool running;
    int epoll_fd;

    struct wl_list client_list; /* struct client::link */
};

struct shm_buffer {
    struct wl_buffer *buffer;
    void *shm_data;
    int busy;
};

struct display {
    struct wl_display *display;
    struct wl_registry *registry;
    struct wl_compositor *compositor;
    struct wl_shm *shm;
    bool has_xrgb;
    struct ivi_application *ivi_application;

    struct wl_seat *seat;
    struct wl_pointer *wl_pointer;
    struct wl_keyboard *wl_keyboard;
    struct wl_touch *wl_touch;
    struct window *window;
    struct {
	    EGLDisplay dpy;
	    EGLContext ctx;
	    EGLConfig conf;

	    PFNEGLCREATEIMAGEKHRPROC create_image;
	    PFNEGLDESTROYIMAGEKHRPROC destroy_image;
	    PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_texture_2d;
    } egl;
    struct {
	    GLuint vertex_shader;
	    GLuint fragment_shader;
	    GLuint program_object;
	    GLuint texture;
    } gl;
};

struct window {
    struct display *display;
    struct {
	GLuint rotation_uniform;
	GLuint pos;
	GLuint col;
    } gl;
    int width, height;
    struct wl_surface *surface;
    struct ivi_surface *ivi_surface;
    struct shm_buffer buffers[2];
    struct shm_buffer *prev_buffer;
    struct wl_callback *callback;
    uint32_t window_frames;
    uint32_t window_benchmark_time;
    int wait;
    struct surface *server_surf;
    struct wl_egl_window *native;
    EGLSurface egl_surface;
    EGLImageKHR egl_img;
    struct seat *server_seat;
    struct pointer *server_pointer;
    bool ready;
    uint32_t id_ivisurf;
};


#endif