DSWaylandServer: swap tizen_policy_ext files to tizen-policy-ext
[platform/core/uifw/libds.git] / src / DSWaylandServer / dswayland-server-tizen-policy-ext.cpp
1 /* Protocol XML file : wayland-extension/tizen-policy-ext.xml */
2
3 #include "dswayland-server-tizen-policy-ext.h"
4
5 #ifndef DS_UNLIKELY
6 #define DS_UNLIKELY(X) X
7 #endif
8 #ifndef DS_UNUSED
9 #define DS_UNUSED(X) (void)X
10 #endif
11 #ifndef DS_ASSERT
12 #define DS_ASSERT(COND) assert(COND)
13 #endif
14 #ifndef DS_ASSERT_X
15 #define DS_ASSERT_X(COND, ERR_TAG, ERR_MSG, X...) \
16     do {\
17          if (! (COND))\
18          {\
19              fprintf(stderr, "%s :: "#ERR_MSG, ERR_TAG, ##X);\
20              assert(COND);\
21          }\
22     } while(0)
23 #endif
24 #ifndef WRN
25 #define WRN(X...) fprintf(stderr,##X)
26 #endif
27
28 namespace DSWaylandServer {
29     tizen_policy_ext::tizen_policy_ext(struct ::wl_client *client, uint32_t id, int version)
30         : m_resource_map()
31         , m_resource(NULL)
32         , m_global(NULL)
33         , m_globalVersion(0)
34         , m_displayDestroyedListener()
35     {
36         init(client, id, version);
37     }
38
39     tizen_policy_ext::tizen_policy_ext(struct ::wl_display *display, int version)
40         : m_resource_map()
41         , m_resource(NULL)
42         , m_global(NULL)
43         , m_globalVersion(0)
44         , m_displayDestroyedListener()
45     {
46         init(display, version);
47     }
48
49     tizen_policy_ext::tizen_policy_ext(struct ::wl_resource *resource)
50         : m_resource_map()
51         , m_resource(NULL)
52         , m_global(NULL)
53         , m_globalVersion(0)
54         , m_displayDestroyedListener()
55     {
56         init(resource);
57     }
58
59     tizen_policy_ext::tizen_policy_ext()
60         : m_resource_map()
61         , m_resource(NULL)
62         , m_global(NULL)
63         , m_globalVersion(0)
64         , m_displayDestroyedListener()
65     {
66     }
67
68     tizen_policy_ext::~tizen_policy_ext()
69     {
70         std::multimap<struct ::wl_client*, tizen_policy_ext::Resource*>::iterator it;
71         for (it = m_resource_map.begin() ; it != m_resource_map.end() ; it++) {
72             tizen_policy_ext::Resource *resource = (*it).second;
73             wl_resource_set_implementation(resource->handle, NULL, NULL, NULL);
74         }
75
76         if (m_global) {
77             wl_global_destroy(m_global);
78             wl_list_remove(&m_displayDestroyedListener.link);
79         }
80     }
81
82     void tizen_policy_ext::init(struct ::wl_client *client, uint32_t id, int version)
83     {
84         m_resource = bind(client, id, version);
85     }
86
87     void tizen_policy_ext::init(struct ::wl_resource *resource)
88     {
89         m_resource = bind(resource);
90     }
91
92     tizen_policy_ext::Resource *tizen_policy_ext::add(struct ::wl_client *client, int version)
93     {
94         Resource *resource = bind(client, 0, version);
95         m_resource_map.insert(std::pair<struct ::wl_client*, Resource*>(client, resource));
96         return resource;
97     }
98
99     tizen_policy_ext::Resource *tizen_policy_ext::add(struct ::wl_client *client, uint32_t id, int version)
100     {
101         Resource *resource = bind(client, id, version);
102         m_resource_map.insert(std::pair<struct ::wl_client*, Resource*>(client, resource));
103         return resource;
104     }
105
106     void tizen_policy_ext::init(struct ::wl_display *display, int version)
107     {
108         m_global = wl_global_create(display, &::tizen_policy_ext_interface, version, this, bind_func);
109         m_globalVersion = version;
110         m_displayDestroyedListener.notify = tizen_policy_ext::display_destroy_func;
111         m_displayDestroyedListener.parent = this;
112         wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
113     }
114
115     const struct wl_interface *tizen_policy_ext::interface()
116     {
117         return &::tizen_policy_ext_interface;
118     }
119
120     tizen_policy_ext::Resource *tizen_policy_ext::tizen_policy_ext_allocate()
121     {
122         return new Resource;
123     }
124
125     void tizen_policy_ext::tizen_policy_ext_bind_resource(Resource *)
126     {
127     }
128
129     void tizen_policy_ext::tizen_policy_ext_destroy_resource(Resource *)
130     {
131     }
132
133     void tizen_policy_ext::bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id)
134     {
135         tizen_policy_ext *that = static_cast<tizen_policy_ext *>(data);
136         that->add(client, id, std::min(that->m_globalVersion, version));
137     }
138
139     void tizen_policy_ext::display_destroy_func(struct ::wl_listener *listener, void *data)
140     {
141         DS_UNUSED(data);
142         tizen_policy_ext *that = static_cast<tizen_policy_ext::DisplayDestroyedListener *>(listener)->parent;
143         that->m_global = NULL;
144     }
145
146     void tizen_policy_ext::destroy_func(struct ::wl_resource *client_resource)
147     {
148         Resource *resource = Resource::fromResource(client_resource);
149         DS_ASSERT(resource);
150         tizen_policy_ext *that = resource->tizen_policy_ext_object;
151         that->m_resource_map.erase(resource->client());
152         that->tizen_policy_ext_destroy_resource(resource);
153         delete resource;
154     }
155
156     tizen_policy_ext::Resource *tizen_policy_ext::bind(struct ::wl_client *client, uint32_t id, int version)
157     {
158         DS_ASSERT_X(!wl_client_get_object(client, id), "DSWaylandObject bind", "binding to object %u more than once", id);
159         struct ::wl_resource *handle = wl_resource_create(client, &::tizen_policy_ext_interface, version, id);
160         return bind(handle);
161     }
162
163     tizen_policy_ext::Resource *tizen_policy_ext::bind(struct ::wl_resource *handle)
164     {
165         Resource *resource = tizen_policy_ext_allocate();
166         resource->tizen_policy_ext_object = this;
167
168         wl_resource_set_implementation(handle, &m_tizen_policy_ext_interface, resource, destroy_func);
169         resource->handle = handle;
170         tizen_policy_ext_bind_resource(resource);
171         return resource;
172     }
173     tizen_policy_ext::Resource *tizen_policy_ext::Resource::fromResource(struct ::wl_resource *resource)
174     {
175         if (DS_UNLIKELY(!resource))
176             return NULL;
177         if (wl_resource_instance_of(resource, &::tizen_policy_ext_interface, &m_tizen_policy_ext_interface))
178             return static_cast<Resource *>(wl_resource_get_user_data(resource));
179         return NULL;
180     }
181
182     const struct ::tizen_policy_ext_interface tizen_policy_ext::m_tizen_policy_ext_interface = {
183         tizen_policy_ext::handle_get_rotation,
184         tizen_policy_ext::handle_get_active_angle
185     };
186
187     void tizen_policy_ext::tizen_policy_ext_get_rotation(Resource *, uint32_t, struct ::wl_resource *)
188     {
189     }
190
191     void tizen_policy_ext::tizen_policy_ext_get_active_angle(Resource *, struct ::wl_resource *)
192     {
193     }
194
195
196     void tizen_policy_ext::handle_get_rotation(
197         ::wl_client *client,
198         struct wl_resource *resource,
199         uint32_t id,
200         struct ::wl_resource *surface)
201     {
202         DS_UNUSED(client);
203         Resource *r = Resource::fromResource(resource);
204         static_cast<tizen_policy_ext *>(r->tizen_policy_ext_object)->tizen_policy_ext_get_rotation(
205             r,
206             id,
207             surface);
208     }
209
210     void tizen_policy_ext::handle_get_active_angle(
211         ::wl_client *client,
212         struct wl_resource *resource,
213         struct ::wl_resource *surface)
214     {
215         DS_UNUSED(client);
216         Resource *r = Resource::fromResource(resource);
217         static_cast<tizen_policy_ext *>(r->tizen_policy_ext_object)->tizen_policy_ext_get_active_angle(
218             r,
219             surface);
220     }
221
222     void tizen_policy_ext::send_active_angle(uint32_t angle)
223     {
224         DS_ASSERT_X(m_resource, "tizen_policy_ext::active_angle", "Uninitialised resource");
225         if (DS_UNLIKELY(!m_resource)) {
226             WRN("could not call tizen_policy_ext::active_angle as it's not initialised");
227             return;
228         }
229         send_active_angle(
230             m_resource->handle,
231             angle);
232     }
233
234     void tizen_policy_ext::send_active_angle(struct ::wl_resource *resource, uint32_t angle)
235     {
236         tizen_policy_ext_send_active_angle(
237             resource,
238             angle);
239     }
240
241
242     tizen_rotation::tizen_rotation(struct ::wl_client *client, uint32_t id, int version)
243         : m_resource_map()
244         , m_resource(NULL)
245         , m_global(NULL)
246         , m_globalVersion(0)
247         , m_displayDestroyedListener()
248     {
249         init(client, id, version);
250     }
251
252     tizen_rotation::tizen_rotation(struct ::wl_display *display, int version)
253         : m_resource_map()
254         , m_resource(NULL)
255         , m_global(NULL)
256         , m_globalVersion(0)
257         , m_displayDestroyedListener()
258     {
259         init(display, version);
260     }
261
262     tizen_rotation::tizen_rotation(struct ::wl_resource *resource)
263         : m_resource_map()
264         , m_resource(NULL)
265         , m_global(NULL)
266         , m_globalVersion(0)
267         , m_displayDestroyedListener()
268     {
269         init(resource);
270     }
271
272     tizen_rotation::tizen_rotation()
273         : m_resource_map()
274         , m_resource(NULL)
275         , m_global(NULL)
276         , m_globalVersion(0)
277         , m_displayDestroyedListener()
278     {
279     }
280
281     tizen_rotation::~tizen_rotation()
282     {
283         std::multimap<struct ::wl_client*, tizen_rotation::Resource*>::iterator it;
284         for (it = m_resource_map.begin() ; it != m_resource_map.end() ; it++) {
285             tizen_rotation::Resource *resource = (*it).second;
286             wl_resource_set_implementation(resource->handle, NULL, NULL, NULL);
287         }
288
289         if (m_global) {
290             wl_global_destroy(m_global);
291             wl_list_remove(&m_displayDestroyedListener.link);
292         }
293     }
294
295     void tizen_rotation::init(struct ::wl_client *client, uint32_t id, int version)
296     {
297         m_resource = bind(client, id, version);
298     }
299
300     void tizen_rotation::init(struct ::wl_resource *resource)
301     {
302         m_resource = bind(resource);
303     }
304
305     tizen_rotation::Resource *tizen_rotation::add(struct ::wl_client *client, int version)
306     {
307         Resource *resource = bind(client, 0, version);
308         m_resource_map.insert(std::pair<struct ::wl_client*, Resource*>(client, resource));
309         return resource;
310     }
311
312     tizen_rotation::Resource *tizen_rotation::add(struct ::wl_client *client, uint32_t id, int version)
313     {
314         Resource *resource = bind(client, id, version);
315         m_resource_map.insert(std::pair<struct ::wl_client*, Resource*>(client, resource));
316         return resource;
317     }
318
319     void tizen_rotation::init(struct ::wl_display *display, int version)
320     {
321         m_global = wl_global_create(display, &::tizen_rotation_interface, version, this, bind_func);
322         m_globalVersion = version;
323         m_displayDestroyedListener.notify = tizen_rotation::display_destroy_func;
324         m_displayDestroyedListener.parent = this;
325         wl_display_add_destroy_listener(display, &m_displayDestroyedListener);
326     }
327
328     const struct wl_interface *tizen_rotation::interface()
329     {
330         return &::tizen_rotation_interface;
331     }
332
333     tizen_rotation::Resource *tizen_rotation::tizen_rotation_allocate()
334     {
335         return new Resource;
336     }
337
338     void tizen_rotation::tizen_rotation_bind_resource(Resource *)
339     {
340     }
341
342     void tizen_rotation::tizen_rotation_destroy_resource(Resource *)
343     {
344     }
345
346     void tizen_rotation::bind_func(struct ::wl_client *client, void *data, uint32_t version, uint32_t id)
347     {
348         tizen_rotation *that = static_cast<tizen_rotation *>(data);
349         that->add(client, id, std::min(that->m_globalVersion, version));
350     }
351
352     void tizen_rotation::display_destroy_func(struct ::wl_listener *listener, void *data)
353     {
354         DS_UNUSED(data);
355         tizen_rotation *that = static_cast<tizen_rotation::DisplayDestroyedListener *>(listener)->parent;
356         that->m_global = NULL;
357     }
358
359     void tizen_rotation::destroy_func(struct ::wl_resource *client_resource)
360     {
361         Resource *resource = Resource::fromResource(client_resource);
362         DS_ASSERT(resource);
363         tizen_rotation *that = resource->tizen_rotation_object;
364         that->m_resource_map.erase(resource->client());
365         that->tizen_rotation_destroy_resource(resource);
366         delete resource;
367     }
368
369     tizen_rotation::Resource *tizen_rotation::bind(struct ::wl_client *client, uint32_t id, int version)
370     {
371         DS_ASSERT_X(!wl_client_get_object(client, id), "DSWaylandObject bind", "binding to object %u more than once", id);
372         struct ::wl_resource *handle = wl_resource_create(client, &::tizen_rotation_interface, version, id);
373         return bind(handle);
374     }
375
376     tizen_rotation::Resource *tizen_rotation::bind(struct ::wl_resource *handle)
377     {
378         Resource *resource = tizen_rotation_allocate();
379         resource->tizen_rotation_object = this;
380
381         wl_resource_set_implementation(handle, &m_tizen_rotation_interface, resource, destroy_func);
382         resource->handle = handle;
383         tizen_rotation_bind_resource(resource);
384         return resource;
385     }
386     tizen_rotation::Resource *tizen_rotation::Resource::fromResource(struct ::wl_resource *resource)
387     {
388         if (DS_UNLIKELY(!resource))
389             return NULL;
390         if (wl_resource_instance_of(resource, &::tizen_rotation_interface, &m_tizen_rotation_interface))
391             return static_cast<Resource *>(wl_resource_get_user_data(resource));
392         return NULL;
393     }
394
395     const struct ::tizen_rotation_interface tizen_rotation::m_tizen_rotation_interface = {
396         tizen_rotation::handle_destroy,
397         tizen_rotation::handle_set_available_angles,
398         tizen_rotation::handle_set_preferred_angle,
399         tizen_rotation::handle_ack_angle_change,
400         tizen_rotation::handle_set_geometry_hint
401     };
402
403     void tizen_rotation::tizen_rotation_destroy(Resource *)
404     {
405     }
406
407     void tizen_rotation::tizen_rotation_set_available_angles(Resource *, uint32_t )
408     {
409     }
410
411     void tizen_rotation::tizen_rotation_set_preferred_angle(Resource *, uint32_t )
412     {
413     }
414
415     void tizen_rotation::tizen_rotation_ack_angle_change(Resource *, uint32_t )
416     {
417     }
418
419     void tizen_rotation::tizen_rotation_set_geometry_hint(Resource *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t )
420     {
421     }
422
423
424     void tizen_rotation::handle_destroy(
425         ::wl_client *client,
426         struct wl_resource *resource)
427     {
428         DS_UNUSED(client);
429         Resource *r = Resource::fromResource(resource);
430         static_cast<tizen_rotation *>(r->tizen_rotation_object)->tizen_rotation_destroy(
431             r);
432     }
433
434     void tizen_rotation::handle_set_available_angles(
435         ::wl_client *client,
436         struct wl_resource *resource,
437         uint32_t angles)
438     {
439         DS_UNUSED(client);
440         Resource *r = Resource::fromResource(resource);
441         static_cast<tizen_rotation *>(r->tizen_rotation_object)->tizen_rotation_set_available_angles(
442             r,
443             angles);
444     }
445
446     void tizen_rotation::handle_set_preferred_angle(
447         ::wl_client *client,
448         struct wl_resource *resource,
449         uint32_t angle)
450     {
451         DS_UNUSED(client);
452         Resource *r = Resource::fromResource(resource);
453         static_cast<tizen_rotation *>(r->tizen_rotation_object)->tizen_rotation_set_preferred_angle(
454             r,
455             angle);
456     }
457
458     void tizen_rotation::handle_ack_angle_change(
459         ::wl_client *client,
460         struct wl_resource *resource,
461         uint32_t serial)
462     {
463         DS_UNUSED(client);
464         Resource *r = Resource::fromResource(resource);
465         static_cast<tizen_rotation *>(r->tizen_rotation_object)->tizen_rotation_ack_angle_change(
466             r,
467             serial);
468     }
469
470     void tizen_rotation::handle_set_geometry_hint(
471         ::wl_client *client,
472         struct wl_resource *resource,
473         uint32_t angle,
474         uint32_t x,
475         uint32_t y,
476         uint32_t w,
477         uint32_t h)
478     {
479         DS_UNUSED(client);
480         Resource *r = Resource::fromResource(resource);
481         static_cast<tizen_rotation *>(r->tizen_rotation_object)->tizen_rotation_set_geometry_hint(
482             r,
483             angle,
484             x,
485             y,
486             w,
487             h);
488     }
489
490     void tizen_rotation::send_available_angles_done(uint32_t angles)
491     {
492         DS_ASSERT_X(m_resource, "tizen_rotation::available_angles_done", "Uninitialised resource");
493         if (DS_UNLIKELY(!m_resource)) {
494             WRN("could not call tizen_rotation::available_angles_done as it's not initialised");
495             return;
496         }
497         send_available_angles_done(
498             m_resource->handle,
499             angles);
500     }
501
502     void tizen_rotation::send_available_angles_done(struct ::wl_resource *resource, uint32_t angles)
503     {
504         tizen_rotation_send_available_angles_done(
505             resource,
506             angles);
507     }
508
509
510     void tizen_rotation::send_preferred_angle_done(uint32_t angle)
511     {
512         DS_ASSERT_X(m_resource, "tizen_rotation::preferred_angle_done", "Uninitialised resource");
513         if (DS_UNLIKELY(!m_resource)) {
514             WRN("could not call tizen_rotation::preferred_angle_done as it's not initialised");
515             return;
516         }
517         send_preferred_angle_done(
518             m_resource->handle,
519             angle);
520     }
521
522     void tizen_rotation::send_preferred_angle_done(struct ::wl_resource *resource, uint32_t angle)
523     {
524         tizen_rotation_send_preferred_angle_done(
525             resource,
526             angle);
527     }
528
529
530     void tizen_rotation::send_angle_change(uint32_t angle, uint32_t serial)
531     {
532         DS_ASSERT_X(m_resource, "tizen_rotation::angle_change", "Uninitialised resource");
533         if (DS_UNLIKELY(!m_resource)) {
534             WRN("could not call tizen_rotation::angle_change as it's not initialised");
535             return;
536         }
537         send_angle_change(
538             m_resource->handle,
539             angle,
540             serial);
541     }
542
543     void tizen_rotation::send_angle_change(struct ::wl_resource *resource, uint32_t angle, uint32_t serial)
544     {
545         tizen_rotation_send_angle_change(
546             resource,
547             angle,
548             serial);
549     }
550
551
552     void tizen_rotation::send_angle_change_with_resize(uint32_t angle, uint32_t serial, uint32_t width, uint32_t height)
553     {
554         DS_ASSERT_X(m_resource, "tizen_rotation::angle_change_with_resize", "Uninitialised resource");
555         if (DS_UNLIKELY(!m_resource)) {
556             WRN("could not call tizen_rotation::angle_change_with_resize as it's not initialised");
557             return;
558         }
559         send_angle_change_with_resize(
560             m_resource->handle,
561             angle,
562             serial,
563             width,
564             height);
565     }
566
567     void tizen_rotation::send_angle_change_with_resize(struct ::wl_resource *resource, uint32_t angle, uint32_t serial, uint32_t width, uint32_t height)
568     {
569         tizen_rotation_send_angle_change_with_resize(
570             resource,
571             angle,
572             serial,
573             width,
574             height);
575     }
576
577 }
578