Add empty implementation for tizen_policy by adding new interface
[platform/core/uifw/pepper-dali.git] / pepper-dali / internal / extensions / tizen-policy.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "tizen-policy.h"
19
20 #include <dali/integration-api/debug.h>
21 #include <tizen-extension-server-protocol.h>
22
23 namespace Dali
24 {
25
26 namespace Pepper
27 {
28
29 namespace Internal
30 {
31
32 namespace Extension
33 {
34
35 namespace
36 {
37
38 #if defined(DEBUG_ENABLED)
39 Integration::Log::Filter* gPepperTizenPolicyLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_PEPPER_TIZEN_POLICY" );
40 #endif
41
42 } // unnamed namespace
43
44 /* tizen policy data for pepper_surface_t */
45 typedef struct
46 {
47    pepper_surface_t *psurf;
48    pepper_event_listener_t *psurf_destroy_listener;
49    struct wl_list resource_list;
50    VisibilityState visibility;
51    int references;
52 } tzpol_surface_t;
53
54 const static char       *tsurf_data_key = "tzpol-surf";
55 static struct wl_global *_tzpol_global = NULL;
56 static struct wl_list    _tzpol_res_list;
57
58 static void
59 _tzpol_surface_del(tzpol_surface_t *tsurf)
60 {
61    free(tsurf);
62 }
63
64 static void
65 _tzpol_surface_unref(tzpol_surface_t *tsurf, struct wl_resource *unref)
66 {
67    int res;
68
69    res = wl_list_empty(&tsurf->resource_list);
70    if (res)
71      {
72         DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "Couldn't unreference, list is empty" );
73         return;
74      }
75
76    wl_list_remove(wl_resource_get_link(unref));
77    wl_resource_set_user_data(unref, NULL);
78
79    res = wl_list_empty(&tsurf->resource_list);
80    if (res)
81      {
82         pepper_event_listener_remove(tsurf->psurf_destroy_listener);
83         pepper_object_set_user_data((pepper_object_t *)tsurf->psurf,
84                                     (const void *)tsurf_data_key, NULL, NULL);
85         _tzpol_surface_del(tsurf);
86      }
87 }
88
89 static void
90 _tzpol_surface_ref(tzpol_surface_t *tsurf, struct wl_resource *ref)
91 {
92    wl_list_insert(&tsurf->resource_list, wl_resource_get_link(ref));
93    wl_resource_set_user_data(ref, tsurf);
94 }
95
96 static void
97 _tzpol_surface_pepper_surf_cb_destroy(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
98 {
99    tzpol_surface_t *tsurf;
100    struct wl_resource *res, *tmp;
101
102    tsurf = (tzpol_surface_t*)data;
103
104    wl_resource_for_each_safe(res, tmp, &tsurf->resource_list)
105         _tzpol_surface_unref(tsurf, res);
106 }
107
108 static tzpol_surface_t *
109 _tzpol_surface_get(pepper_surface_t *psurf)
110 {
111    tzpol_surface_t *tsurf;
112
113    tsurf = (tzpol_surface_t*)pepper_object_get_user_data((pepper_object_t *)psurf,
114                                        (const void *)tsurf_data_key);
115    if (!tsurf)
116      {
117         tsurf = (tzpol_surface_t*)calloc(1, sizeof(*tsurf));
118         if (!tsurf)
119           return NULL;
120
121         tsurf->psurf = psurf;
122
123         wl_list_init(&tsurf->resource_list);
124
125         tsurf->psurf_destroy_listener =
126            pepper_object_add_event_listener((pepper_object_t *)psurf,
127                                             PEPPER_EVENT_OBJECT_DESTROY, 0,
128                                             _tzpol_surface_pepper_surf_cb_destroy, tsurf);
129         pepper_object_set_user_data((pepper_object_t *)psurf,
130                                     (const void *)tsurf_data_key, tsurf, NULL);
131      }
132
133    tsurf->references++;
134
135    return tsurf;
136 }
137
138 // --------------------------------------------------------
139 // visibility
140 // --------------------------------------------------------
141 static void
142 _tzvis_iface_cb_destroy(struct wl_client *client, struct wl_resource *res_tzvis)
143 {
144    wl_resource_destroy(res_tzvis);
145 }
146
147 static const struct tizen_visibility_interface _tzvis_iface =
148 {
149    _tzvis_iface_cb_destroy
150 };
151
152 static void
153 _tzvis_res_cb_destroy(struct wl_resource *res_tzvis)
154 {
155    tzpol_surface_t *tsurf;
156
157    tsurf = (tzpol_surface_t*)wl_resource_get_user_data(res_tzvis);
158    if (!tsurf)
159      return;
160
161    _tzpol_surface_unref(tsurf, res_tzvis);
162 }
163
164 static void
165 _tzpol_iface_cb_vis_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surf)
166 {
167    tzpol_surface_t *tsurf;
168    pepper_surface_t *psurf;
169    struct wl_resource *new_res;
170    int ver;
171
172    if (!surf)
173      {
174         wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
175                                "tizen_policy::visibility_get requires surface");
176         return;
177      }
178
179    psurf = (pepper_surface_t*)wl_resource_get_user_data(surf);
180    if (!psurf)
181      {
182         DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to get pepper_surface from wl_resource" );
183         wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
184                                "tizen_policy::visibility_get invalid surface resource");
185         return;
186      }
187
188    DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::visibility_get" );
189    tsurf = _tzpol_surface_get(psurf);
190    if (!tsurf)
191      {
192         wl_resource_post_no_memory(res_tzpol);
193         return;
194      }
195
196    ver = wl_resource_get_version(res_tzpol);
197    new_res = wl_resource_create(client, &tizen_visibility_interface, ver, id);
198    if (!new_res)
199      {
200         wl_resource_post_no_memory(res_tzpol);
201         return;
202      }
203
204    wl_resource_set_implementation(new_res, &_tzvis_iface, tsurf, _tzvis_res_cb_destroy);
205    _tzpol_surface_ref(tsurf, new_res);
206 }
207
208 // --------------------------------------------------------
209 // position
210 // --------------------------------------------------------
211 static void
212 _tzpos_iface_cb_destroy(struct wl_client *client, struct wl_resource *res_tzpos)
213 {
214    wl_resource_destroy(res_tzpos);
215 }
216
217 static void
218 _tzpos_iface_cb_set(struct wl_client *client, struct wl_resource *res_tzpos, int32_t x, int32_t y)
219 {
220    (void)client;
221    (void)res_tzpos;
222    (void)x;
223    (void)y;
224 }
225
226 static const struct tizen_position_interface _tzpos_iface =
227 {
228    _tzpos_iface_cb_destroy,
229    _tzpos_iface_cb_set,
230 };
231
232 static void
233 _tzpos_res_cb_destroy(struct wl_resource *res_tzpos)
234 {
235    tzpol_surface_t *tsurf;
236
237    tsurf = (tzpol_surface_t*)wl_resource_get_user_data(res_tzpos);
238    if (!tsurf)
239      return;
240
241    _tzpol_surface_unref(tsurf, res_tzpos);
242 }
243
244 static void
245 _tzpol_iface_cb_pos_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surf)
246 {
247    tzpol_surface_t *tsurf;
248    pepper_surface_t *psurf;
249    struct wl_resource *new_res;
250    int ver;
251
252    if (!surf)
253      {
254         wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
255                                "tizen_policy::visibility_get requires surface");
256         return;
257      }
258
259    psurf = (pepper_surface_t*)wl_resource_get_user_data(surf);
260    if (!psurf)
261      {
262         DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to get pepper_surface from wl_resource" );
263         wl_resource_post_error(res_tzpol, WL_DISPLAY_ERROR_INVALID_OBJECT,
264                                "tizen_policy::visibility_get invalid surface resource");
265         return;
266      }
267
268    DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::visibility_get" );
269    tsurf = _tzpol_surface_get(psurf);
270    if (!tsurf)
271      {
272         wl_resource_post_no_memory(res_tzpol);
273         return;
274      }
275
276    ver = wl_resource_get_version(res_tzpol);
277    new_res = wl_resource_create(client, &tizen_position_interface, ver, id);
278    if (!new_res)
279      {
280         wl_resource_post_no_memory(res_tzpol);
281         return;
282      }
283
284    wl_resource_set_implementation(new_res, &_tzpos_iface, tsurf, _tzpos_res_cb_destroy);
285    _tzpol_surface_ref(tsurf, new_res);
286 }
287
288 // --------------------------------------------------------
289 // stack: activate, raise, lower
290 // --------------------------------------------------------
291 static void
292 _tzpol_iface_cb_activate(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
293 {
294    (void)client;
295    (void)res_tzpol;
296    (void)surf;
297 }
298
299 static void
300 _tzpol_iface_cb_activate_below_by_res_id(struct wl_client *client, struct wl_resource *res_tzpol,  uint32_t res_id, uint32_t below_res_id)
301 {
302    (void)client;
303    (void)res_tzpol;
304    (void)res_id;
305    (void)below_res_id;
306 }
307
308 static void
309 _tzpol_iface_cb_raise(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
310 {
311    (void)client;
312    (void)res_tzpol;
313    (void)surf;
314 }
315
316 static void
317 _tzpol_iface_cb_lower(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
318 {
319    (void)client;
320    (void)res_tzpol;
321    (void)surf;
322 }
323
324 static void
325 _tzpol_iface_cb_lower_by_res_id(struct wl_client *client, struct wl_resource *res_tzpol,  uint32_t res_id)
326 {
327    (void)client;
328    (void)res_tzpol;
329    (void)res_id;
330 }
331
332 // --------------------------------------------------------
333 // focus
334 // --------------------------------------------------------
335 static void
336 _tzpol_iface_cb_focus_skip_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
337 {
338    (void)client;
339    (void)res_tzpol;
340    (void)surf;
341 }
342
343 static void
344 _tzpol_iface_cb_focus_skip_unset(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
345 {
346    (void)client;
347    (void)res_tzpol;
348    (void)surf;
349 }
350
351 // --------------------------------------------------------
352 // role
353 // --------------------------------------------------------
354 static void
355 _tzpol_iface_cb_role_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, const char *role)
356 {
357    (void)client;
358    (void)res_tzpol;
359    (void)surf;
360    (void)role;
361 }
362
363 static void
364 _tzpol_iface_cb_type_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t type)
365 {
366    (void)client;
367    (void)res_tzpol;
368    (void)surf;
369    (void)type;
370 }
371
372 // --------------------------------------------------------
373 // conformant
374 // --------------------------------------------------------
375 static void
376 _tzpol_iface_cb_conformant_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
377 {
378    (void)client;
379    (void)res_tzpol;
380    (void)surf;
381 }
382
383 static void
384 _tzpol_iface_cb_conformant_unset(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
385 {
386    (void)client;
387    (void)res_tzpol;
388    (void)surf;
389 }
390
391 static void
392 _tzpol_iface_cb_conformant_get(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
393 {
394    (void)client;
395    (void)res_tzpol;
396    (void)surf;
397 }
398
399 // --------------------------------------------------------
400 // notification level
401 // --------------------------------------------------------
402 static void
403 _tzpol_iface_cb_notilv_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t lv)
404 {
405    (void)client;
406    (void)res_tzpol;
407    (void)surf;
408    (void)lv;
409 }
410
411 // --------------------------------------------------------
412 // transient for
413 // --------------------------------------------------------
414 static void
415 _tzpol_iface_cb_transient_for_set(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t child_id, uint32_t parent_id)
416 {
417    (void)client;
418    (void)res_tzpol;
419    (void)child_id;
420    (void)parent_id;
421 }
422
423 static void
424 _tzpol_iface_cb_transient_for_unset(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t child_id)
425 {
426    (void)client;
427    (void)res_tzpol;
428    (void)child_id;
429 }
430
431 // --------------------------------------------------------
432 // window screen mode
433 // --------------------------------------------------------
434 static void
435 _tzpol_iface_cb_win_scrmode_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t mode)
436 {
437    (void)client;
438    (void)res_tzpol;
439    (void)surf;
440    (void)mode;
441 }
442
443 // --------------------------------------------------------
444 // subsurface
445 // --------------------------------------------------------
446 static void
447 _tzpol_iface_cb_subsurf_place_below_parent(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *subsurf)
448 {
449    (void)client;
450    (void)res_tzpol;
451    (void)subsurf;
452 }
453
454 static void
455 _tzpol_iface_cb_subsurf_stand_alone_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *subsurf)
456 {
457    (void)client;
458    (void)res_tzpol;
459    (void)subsurf;
460 }
461
462 static void
463 _tzpol_iface_cb_subsurface_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surface, uint32_t parent_id)
464 {
465    (void)client;
466    (void)res_tzpol;
467    (void)id;
468    (void)surface;
469    (void)parent_id;
470 }
471
472 static void
473 _tzpol_iface_cb_opaque_state_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surface, int32_t state)
474 {
475    (void)client;
476    (void)res_tzpol;
477    (void)surface;
478    (void)state;
479 }
480
481 // --------------------------------------------------------
482 // iconify
483 // --------------------------------------------------------
484 static void
485 _tzpol_iface_cb_iconify(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
486 {
487    (void)client;
488    (void)res_tzpol;
489    (void)surf;
490 }
491
492 static void
493 _tzpol_iface_cb_uniconify(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
494 {
495    (void)client;
496    (void)res_tzpol;
497    (void)surf;
498 }
499
500 static void
501 _tzpol_iface_cb_aux_hint_add(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id, const char *name, const char *value)
502 {
503    (void)client;
504    (void)res_tzpol;
505    (void)surf;
506    (void)id;
507    (void)name;
508    (void)value;
509 }
510
511 static void
512 _tzpol_iface_cb_aux_hint_change(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id, const char *value)
513 {
514    (void)client;
515    (void)res_tzpol;
516    (void)surf;
517    (void)id;
518    (void)value;
519 }
520
521 static void
522 _tzpol_iface_cb_aux_hint_del(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, int32_t id)
523 {
524    (void)client;
525    (void)res_tzpol;
526    (void)surf;
527    (void)id;
528 }
529
530 static void
531 _tzpol_iface_cb_supported_aux_hints_get(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
532 {
533    (void)client;
534    (void)res_tzpol;
535    (void)surf;
536 }
537
538 static void
539 _tzpol_iface_cb_background_state_set(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t pid)
540 {
541    (void)client;
542    (void)res_tzpol;
543    (void)pid;
544 }
545
546 static void
547 _tzpol_iface_cb_background_state_unset(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t pid)
548 {
549    (void)client;
550    (void)res_tzpol;
551    (void)pid;
552 }
553
554 static void
555 _tzpol_iface_cb_floating_mode_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
556 {
557    (void)client;
558    (void)res_tzpol;
559    (void)surf;
560 }
561
562 static void
563 _tzpol_iface_cb_floating_mode_unset(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf)
564 {
565    (void)client;
566    (void)res_tzpol;
567    (void)surf;
568 }
569
570 static void
571 _tzpol_iface_cb_stack_mode_set(struct wl_client *client, struct wl_resource *res_tzpol, struct wl_resource *surf, uint32_t mode)
572 {
573    (void)client;
574    (void)res_tzpol;
575    (void)surf;
576    (void)mode;
577 }
578
579 static const struct tizen_policy_interface _tzpol_iface =
580 {
581    _tzpol_iface_cb_vis_get,
582    _tzpol_iface_cb_pos_get,
583    _tzpol_iface_cb_activate,
584    _tzpol_iface_cb_activate_below_by_res_id,
585    _tzpol_iface_cb_raise,
586    _tzpol_iface_cb_lower,
587    _tzpol_iface_cb_lower_by_res_id,
588    _tzpol_iface_cb_focus_skip_set,
589    _tzpol_iface_cb_focus_skip_unset,
590    _tzpol_iface_cb_role_set,
591    _tzpol_iface_cb_type_set,
592    _tzpol_iface_cb_conformant_set,
593    _tzpol_iface_cb_conformant_unset,
594    _tzpol_iface_cb_conformant_get,
595    _tzpol_iface_cb_notilv_set,
596    _tzpol_iface_cb_transient_for_set,
597    _tzpol_iface_cb_transient_for_unset,
598    _tzpol_iface_cb_win_scrmode_set,
599    _tzpol_iface_cb_subsurf_place_below_parent,
600    _tzpol_iface_cb_subsurf_stand_alone_set,
601    _tzpol_iface_cb_subsurface_get,
602    _tzpol_iface_cb_opaque_state_set,
603    _tzpol_iface_cb_iconify,
604    _tzpol_iface_cb_uniconify,
605    _tzpol_iface_cb_aux_hint_add,
606    _tzpol_iface_cb_aux_hint_change,
607    _tzpol_iface_cb_aux_hint_del,
608    _tzpol_iface_cb_supported_aux_hints_get,
609    _tzpol_iface_cb_background_state_set,
610    _tzpol_iface_cb_background_state_unset,
611    _tzpol_iface_cb_floating_mode_set,
612    _tzpol_iface_cb_floating_mode_unset,
613    _tzpol_iface_cb_stack_mode_set,
614 };
615
616 static void
617 _tzpol_cb_bind(struct wl_client *client, void *data, uint32_t ver, uint32_t id)
618 {
619    struct wl_resource *resource;
620
621    DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::bind" );
622
623    resource = wl_resource_create(client, &tizen_policy_interface, ver, id);
624    if (!resource)
625      {
626         DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to create resource for tizen_policy" );
627         wl_client_post_no_memory(client);
628         return;
629      }
630
631    wl_resource_set_implementation(resource, &_tzpol_iface, NULL, NULL);
632
633    wl_list_insert(&_tzpol_res_list, wl_resource_get_link(resource));
634 }
635
636 bool
637 TizenPolicyInit(pepper_compositor_t *comp)
638 {
639    struct wl_display *wl_disp;
640
641    DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::init" );
642
643    if (_tzpol_global)
644      goto end;
645
646    wl_list_init(&_tzpol_res_list);
647
648    wl_disp = pepper_compositor_get_display(comp);
649    _tzpol_global = wl_global_create(wl_disp, &tizen_policy_interface, 1, NULL, _tzpol_cb_bind);
650    if (!_tzpol_global)
651      {
652         DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "failed to create global for tizen policy" );
653         return false;
654      }
655 end:
656    return true;
657 }
658
659 void
660 TizenPolicyShutdown(void)
661 {
662    struct wl_resource *res, *tmp;
663
664    DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "tizen_policy::shutdown" );
665
666    wl_resource_for_each_safe(res, tmp, &_tzpol_res_list)
667      {
668         wl_list_remove(wl_resource_get_link(res));
669         wl_resource_destroy(res);
670      }
671
672    wl_global_destroy(_tzpol_global);
673    _tzpol_global = NULL;
674 }
675
676 bool
677 TizenPolicySetVisibility( pepper_surface_t* psurf, VisibilityState state )
678 {
679    tzpol_surface_t *tsurf;
680    struct wl_resource *resource;
681    int res;
682
683    tsurf = (tzpol_surface_t*)pepper_object_get_user_data((pepper_object_t *)psurf, (const void *)tsurf_data_key);
684    if (!tsurf)
685      {
686         DALI_LOG_INFO( gPepperTizenPolicyLogging, Debug::General, "there is no data for 'tzpol_surface_t' in 'pepper_surface_t'" );
687         return false;
688      }
689
690    if (tsurf->visibility == state)
691      return true;
692
693    tsurf->visibility = state;
694    wl_resource_for_each(resource, &tsurf->resource_list)
695      {
696         res = wl_resource_instance_of(resource, &tizen_visibility_interface, &_tzvis_iface);
697         if (!res)
698           continue;
699         tizen_visibility_send_notify(resource, state);
700      }
701
702    return true;
703 }
704
705 } // namespace Extension
706
707 } // namespace Internal
708
709 } // namespace Pepper
710
711 } // namespace Dali