summaryrefslogtreecommitdiffstats
path: root/meta-ivi/recipes-graphics/wayland/weston-1.6.0/0004-ivi-shell-add-the-shell-plugin-for-In-Vehicle-Infota.patch
blob: 9320abb3a9429bc30e33849db9f2a3fea1b62278 (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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
From 6b3f32ba6541b27062ab87aeb88665986c67e31d Mon Sep 17 00:00:00 2001
From: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
Date: Wed, 15 Oct 2014 11:26:29 +0900
Subject: [PATCH 04/15] ivi-shell: add the shell plugin for In-Vehicle
 Infotainment system

- ivi-shell.so
- introduces ivi-shell/ivi-shell.[ch]

In-Vehicle Infotainment system traditionally manages surfaces with
global identification. A protocol, ivi_application, supports such a
feature by implementing a request, ivi_application::surface_creation
defined in ivi_application.xml.

The ivi-shell explicitly loads ivi-layout.so and a module to add
business logic like how to layout surfaces by using ivi-layout APIs.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

ivi-shell: send ivi_surface configure event when ivi_layout_surface configured signal emitted.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: Release module when initialzing failed.

> f9839a9 ivi-shell: add the shell plugin for In-Vehicle Infotainment system
>
> New title: "ivi-shell: add ivi-shell.so shell module"
> Destructors and few minor things need fixing.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: Fix ivi_layout_surfaceSetPosition. Change int type from array type

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: Change quoted_printable_encode form camelcase

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: add comment why it doesn't use weston_load_module

The reason why the following code is written newly without using
weston_load_module is it doesn't open library with RTLD_GLOBAL option.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
 ivi-shell: Replace list_thing with thing_list.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell/ivi-shell.c: remove non-availalable header including

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: ivi-shell.[ch] clean-up code

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: Remove call wl_resource_set_implementation

> This call in not needed, AFAIK.
> [ntanibata] I will remove it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: Move surface_configure_notify() definition

> Move surface_configure_notify() definition above the line where it is
> needed, and remove the declaration from the beginning of the file.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: Add shell-surface destructor.

>> No destructor function? So what happens, if the client unexpectedly
>> disconnects, and libwayland-server destroys all wl_resources in a
>> random order? I think you'd be leaking everything you allocated in
>> this function.

> [ntanibata] I will check and fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

-------------------------------------------------------------------
ivi-shell: Fix wl_resource_create form application_surface_create

> 'res' is wrong, you need to use 'resource' which is the object whose
> method you are executing.
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Fix resource leak.

I think there is a bug.
surface_destroy() needs to call wl_resource_destroy(resource).
wl_resource_destroy() will internally as the last thing call the
destructor function you set with wl_resource_set_implementation(), which
means that shell_destroy_shell_surface() will get called when you call
wl_resource_destroy().

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Use error-code defined in ivi-application-protocol.
> > You also need to add the two error codes into ivi-application
> > interface and use those instead of WL_DISPLAY_ERROR_INVALID_OBJECT.
> [ntanibata] I will fix this according to two error codes.
> <enum name="error">
>       <entry name="role" value="0" summary="given wl_surface has
>       another role"/>
>       <entry name="ivi_id" value="1" summary="given ivi_id is assigned
>       to another wl_surface"/>
> </enum>

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Throw error-code when ivi-surface already created in application_surface_create

> [ntanibata] I will fix it.  [ntanibata] This is the first clarification.
> This is required for, - If application_surface_create is called as
> duplicate - id_surface is duplicate To avoid ivi_surface creation with the same id_surface.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Fix destinations of error when resource error occurred.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Remove an unnecessary call of weston_config_parse()

> Do not call weston_config_parse, but use weston_compositor::config instead.
> [ntanibata] I will fix it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Throw error-code when ivi-surface already created in application_surface_create

> [ntanibata] I will fix it.  [ntanibata] This is the first clarification.
> This is required for, - If application_surface_create is called as
> duplicate - id_surface is duplicate To avoid ivi_surface creation with the same id_surface.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Fix destinations of error when resource error occurred.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell, > wl_resource_post_error uses printf-format
arguments, and passing a
> non-constant string as the format string (here 'msg' argument) is
> considered
> a security hazard, which is why compilers warn about it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Register a ivi-surface destroy handler to weston-surface destroy signal.

> Even if you wanted that, you still need a destroy listener to reset the
> pointer to NULL. Otherwise you will have a dangling pointer to a freed
> struct weston_surface, if the weston_surface (wl_surface) gets
> destroyed.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: clean-up Makefile.am FR3.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Remove redundant cast

> if (weston_config_section_get_string( + section, "ivi-module", (char **)&dest->ivi_module, NULL ) != 0)
> Why the cast?

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c  +ivi_shell_setting_create(struct ivi_shell_setting *dest, struct > > +weston_compositor *compositor) > > Too long line.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, You could get rid of one level of indenting

            wl_resource_post_error(resource,
            IVI_APPLICATION_ERROR_ROLE,
            "wl_surface is invalid");
            return;
            }

    That's nice and clear: one can immediately read from each branch
what went wrong if execution ends up there.

    You could get rid of one level of indenting but moving the if
(!weston_surface) check to the top, since it ends in return. No need for
an else block then.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, assert() would likely be enough here. Removes one level of indenting too.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Remove unnecessary check for application_surface_create()

> Didn't you already check for this condition above? Can it pass the
> earlier check and then fail here? How could this inconsistency happen?
> Or is this a paranoid check, that if we get here, there is an
> implementation bug somewhere server-side? If so, you should probably
> highlight it more, and at least make it distinguishable from the earlier check.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Fix memory leaks by shell_destroy_shell_surface()

> I believe you are missing free(ivisurf) here. The lifetime of ivisurf is
> tied to the lifetime of the ivi_surface protocol object (wl_resource).

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell:ivi-shell.c add null check of ivisurf->surface

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell:ivi-shell.c remove unused method, is_surf_in_surfaces

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, remove surface_set_native_content.

There are two use case to
- create ivi_surface without wl_surface to set property in advanced
- keep property per ID during deletion of ivi_surface.

This is supported later. For the time being, remove this function.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, Fix surface destructor.

> You cannot do this. The client is destroying the wl_surface, not the
> ivi_surface. Calling wl_resource_destroy() here creates a disagreement
> between the server and the client on what protocol objects exist. It
> inevitably leads to a protocol error if the client attempts to destroy
> the ivi_surface after the wl_surface.
> Instead, you need to detach all listeners etc. from the weston_surface
> here, and set ivisurf->surface = NULL.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: Fix invalid memory read/write. correct destruction methods

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

ivi-shell: ivi-shell, revert commit of

------------------------------------------------------------------
https://github.com/ntanibata/weston-ivi-shell/commit/f78b50f31f6ade37de2d00845ae70872707d9fd8
Distruction method shall be reorganized.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, revert of fix of destruction to be re-organized.

https://github.com/ntanibata/weston-ivi-shell/commit/0395a7ecc72ef4f4767c996473cccbbd121a34af

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, remove wl_resource_destroy

> vi_shell_surface,

>   + surface_destroy_listener); + + if (ivisurf->resource) { +
> wl_resource_destroy(ivisurf->resource);

You cannot do this. The client is destroying the wl_surface, not the
ivi_surface. Calling wl_resource_destroy() here creates a disagreement
between the server and the client on what protocol objects exist. It
inevitably leads to a protocol error if the client attempts to destroy
the ivi_surface after the wl_surface.

Instead, you need to detach all listeners etc. from the weston_surface
here, and set ivisurf->surface = NULL.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, add comment FIXMEs to improve creation and
destruction process.

When I compare this code with desktop-shell/shell.c, there are several
differences in process.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, move destruction process from
shell_destroy_shell_surface to shell_handle_surface_destroy.

This follows the same way in desktop-shell.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, fix simple bug of assert

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell, remove unnecessary code.

This removeing code for listener of ivi_layout_surface is already called
in ivi_layout.c. Additonally, ivisurf.ivi_layout_surface is already
cleaned up before this distroy destruction.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shekk, Remove a link from surface-list of shell.

Forget to remove it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell.c: add comments about the destruction sequence

Also move surface_destroy_listener together with the weston_surface
pointer it watches.

------------------------------------------------------------------
ivi-shell: ivi-shell.c, Set NULL to resource of ivisurface when shell_destroy_shell_surface called

> /* FIXME: Need to set ivisurf->resource = NULL. */

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, Remove unnecessary check for weston_surface of application_surface_create()

> FIXME: This is not checked in desktop_shell, required to check?
> - Not required to check this, because libwayland-server will raise
> a protocol error automatically, if the passed in object is null
> but the protocol XML does not specify allow-null="true" for the argument.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, Add NULL check of ivisurf->resource

> FIXME: shell_surf->resource might be NULL,
> if controller decides to reconfigure a surface after a client
> has destroyed it.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c, Move down function call for wl_resource creation

> FIXME: this shall be done below:TAG_1, if I use the same order of
> calling in  create_common_surface
> FIXME: not required if move res to below:TAG_1
> FIXME: Move below:TAG_1

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>

------------------------------------------------------------------
ivi-shell: ivi-shell.c,Move ivi_layout_interface into struct ivi_shell

> FIXME: move this static variable into struct ivi_shell.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp>
---
 Makefile.am           |   17 +-
 ivi-shell/ivi-shell.c |  529 +++++++++++++++++++++++++++++++++++++++++++++++++
 ivi-shell/ivi-shell.h |   37 ++++
 3 files changed, 582 insertions(+), 1 deletion(-)
 create mode 100644 ivi-shell/ivi-shell.c
 create mode 100644 ivi-shell/ivi-shell.h

diff --git a/Makefile.am b/Makefile.am
index 812b4bd..b16cfaa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -723,7 +723,8 @@ endif
 if ENABLE_IVI_SHELL
 
 module_LTLIBRARIES +=				\
-	$(ivi_layout)
+	$(ivi_layout)				\
+	$(ivi_shell)
 
 ivi_layout = ivi-layout.la
 ivi_layout_la_LDFLAGS = -module -avoid-version
@@ -737,6 +738,20 @@ ivi_layout_la_SOURCES =				\
 
 BUILT_SOURCES += $(nodist_ivi_layout_la_SOURCES)
 
+ivi_shell = ivi-shell.la
+ivi_shell_la_LDFLAGS = -module -avoid-version
+ivi_shell_la_LIBADD = $(COMPOSITOR_LIBS) libshared.la
+ivi_shell_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
+ivi_shell_la_SOURCES =				\
+	ivi-shell/ivi-shell.h			\
+	ivi-shell/ivi-shell.c			\
+	ivi-shell/ivi-layout-private.h
+nodist_ivi_shell_la_SOURCES =			\
+	protocol/ivi-application-protocol.c		\
+	protocol/ivi-application-server-protocol.h
+
+BUILT_SOURCES += $(nodist_ivi_shell_la_SOURCES)
+
 endif
 
 
diff --git a/ivi-shell/ivi-shell.c b/ivi-shell/ivi-shell.c
new file mode 100644
index 0000000..3904402
--- /dev/null
+++ b/ivi-shell/ivi-shell.c
@@ -0,0 +1,529 @@
+/*
+ * Copyright (C) 2013 DENSO CORPORATION
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * ivi-shell supports a type of shell for In-Vehicle Infotainment system.
+ * In-Vehicle Infotainment system traditionally manages surfaces with global
+ * identification. A protocol, ivi_application, supports such a feature
+ * by implementing a request, ivi_application::surface_creation defined in
+ * ivi_application.xml.
+ *
+ *  The ivi-shell explicitly loads a module to add business logic like how to
+ *  layout surfaces by using internal ivi-layout APIs.
+ */
+#include "config.h"
+
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <linux/input.h>
+#include <dlfcn.h>
+#include <limits.h>
+#include <assert.h>
+
+#include "ivi-shell.h"
+#include "ivi-application-server-protocol.h"
+#include "ivi-layout-private.h"
+
+#include "../shared/os-compatibility.h"
+
+/* Representation of ivi_surface protocol object. */
+struct ivi_shell_surface
+{
+	struct wl_resource* resource;
+	struct ivi_shell *shell;
+	struct ivi_layout_surface *layout_surface;
+
+	struct weston_surface *surface;
+	struct wl_listener surface_destroy_listener;
+
+	uint32_t id_surface;
+
+	int32_t width;
+	int32_t height;
+
+	struct wl_list link;
+
+	struct wl_listener configured_listener;
+};
+
+struct ivi_shell_setting
+{
+	char *ivi_module;
+};
+
+/* FIXME: move this static variable into struct ivi_shell.
+ * FIXED: Moved
+ */
+
+/*
+ * Implementation of ivi_surface
+ */
+
+static void
+surface_configure_notify(struct wl_listener *listener, void *data)
+{
+	struct ivi_layout_surface *layout_surf =
+		(struct ivi_layout_surface *)data;
+
+	struct ivi_shell_surface *shell_surf =
+		container_of(listener,
+			     struct ivi_shell_surface,
+			     configured_listener);
+
+	int32_t dest_width = 0;
+	int32_t dest_height = 0;
+	shell_surf->shell->ivi_layout->get_surface_dimension(layout_surf,
+					  &dest_width, &dest_height);
+
+	/* FIXME: shell_surf->resource might be NULL,
+	 * if controller decides to reconfigure a surface after a client
+	 * has destroyed it.
+	 * FIXED: Add NULL Check
+	 */
+	if (shell_surf->resource)
+		ivi_surface_send_configure(shell_surf->resource,
+					   dest_width, dest_height);
+}
+
+static void
+ivi_shell_surface_configure(struct weston_surface *, int32_t, int32_t);
+
+static struct ivi_shell_surface *
+get_ivi_shell_surface(struct weston_surface *surface)
+{
+	if (surface->configure == ivi_shell_surface_configure)
+		return surface->configure_private;
+
+	return NULL;
+}
+
+static void
+ivi_shell_surface_configure(struct weston_surface *surface,
+			    int32_t sx, int32_t sy)
+{
+	struct ivi_shell_surface *ivisurf = get_ivi_shell_surface(surface);
+	struct weston_view *view;
+	float from_x;
+	float from_y;
+	float to_x;
+	float to_y;
+
+	if (surface->width == 0 || surface->height == 0 || ivisurf == NULL)
+		return;
+
+	view = ivisurf->shell->ivi_layout->get_weston_view(ivisurf->layout_surface);
+	if (view == NULL)
+		return;
+
+	if (ivisurf->width != surface->width ||
+	    ivisurf->height != surface->height) {
+		ivisurf->width  = surface->width;
+		ivisurf->height = surface->height;
+
+		weston_view_to_global_float(view, 0, 0, &from_x, &from_y);
+		weston_view_to_global_float(view, sx, sy, &to_x, &to_y);
+
+		weston_view_set_position(view,
+					 view->geometry.x + to_x - from_x,
+					 view->geometry.y + to_y - from_y);
+		weston_view_update_transform(view);
+
+		ivisurf->shell->ivi_layout->surface_configure(ivisurf->layout_surface,
+					      surface->width, surface->height);
+	}
+}
+
+/*
+ * The ivi_surface wl_resource destructor.
+ *
+ * Gets called via ivi_surface.destroy request or automatic wl_client clean-up.
+ */
+static void
+shell_destroy_shell_surface(struct wl_resource *resource)
+{
+/* FIXME: When I compare destruction logic of desktop-shell,
+	  this part shall be done in shell_handle_surface_destroy, not here?
+FIXED: moved.
+*/
+	/* FIXME: Need to set ivisurf->resource = NULL.
+	 * FIXED: ivisurf->resource = NULL
+	 */
+	struct ivi_shell_surface *ivisurf = wl_resource_get_user_data(resource);
+	ivisurf->resource = NULL;
+}
+
+/* Gets called through the weston_surface destroy signal. */
+static void
+shell_handle_surface_destroy(struct wl_listener *listener, void *data)
+{
+	struct ivi_shell_surface *ivisurf =
+			container_of(listener, struct ivi_shell_surface,
+				     surface_destroy_listener);
+
+	assert(ivisurf != NULL);
+
+	/* FIXME: When I see desktop-shell, the following part is divided as
+		  subfuction, destroy_shell_surface.
+	 * - Looking at shell.c, looks like destroy_shell_surface() would
+	 * not need to be a separate function. It could be done in
+	 * shell_handle_surface_destroy() too.
+	*/
+	if (ivisurf->surface!=NULL) {
+		ivisurf->surface->configure = NULL;
+		ivisurf->surface->configure_private = NULL;
+		ivisurf->surface = NULL;
+	}
+
+	wl_list_remove(&ivisurf->surface_destroy_listener.link);
+	wl_list_remove(&ivisurf->link);
+	ivisurf->resource = NULL;
+	free(ivisurf);
+
+}
+
+/* Gets called, when a client sends ivi_surface.destroy request. */
+static void
+surface_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+	/*
+	 * Fires the wl_resource destroy signal, and then calls
+	 * ivi_surface wl_resource destructor: shell_destroy_shell_surface()
+	 */
+	wl_resource_destroy(resource);
+}
+
+static const struct ivi_surface_interface surface_implementation = {
+	surface_destroy,
+};
+
+/**
+ * Request handler for ivi_application.surface_create.
+ *
+ * Creates an ivi_surface protocol object associated with the given wl_surface.
+ * ivi_surface protocol object is represented by struct ivi_shell_surface.
+ *
+ * \param client The client.
+ * \param resource The ivi_application protocol object.
+ * \param id_surface The IVI surface ID.
+ * \param surface_resource The wl_surface protocol object.
+ * \param id The protocol object id for the new ivi_surface protocol object.
+ *
+ * The wl_surface is given the ivi_surface role and associated with a unique
+ * IVI ID which is used to identify the surface in a controller
+ * (window manager).
+ */
+static void
+application_surface_create(struct wl_client *client,
+			   struct wl_resource *resource,
+			   uint32_t id_surface,
+			   struct wl_resource *surface_resource,
+			   uint32_t id)
+{
+	struct ivi_shell *shell = wl_resource_get_user_data(resource);
+	struct ivi_shell_surface *ivisurf;
+	struct ivi_layout_surface *layout_surface;
+	struct weston_surface *weston_surface =
+		wl_resource_get_user_data(surface_resource);
+	struct wl_resource *res;
+
+
+	/* FIXME: This is not checked in desktop_shell, required to check?
+	 * - Not required to check this, because libwayland-server will raise
+	 * a protocol error automatically, if the passed in object is null
+	 * but the protocol XML does not specify allow-null="true" for the
+	 * argument.
+	 * FIXED: Delete NULL check
+	 */
+
+	/* FIXME: This is the similar check with
+		  desktop-shell::get_shell_surface
+	 * - Yes. To be changed into a weston_surface_set_role() call,
+	 * rebasing on top of upstream master branch.
+	 */
+	/* check if a wl_surface already has another role*/
+	if (weston_surface->configure) {
+		wl_resource_post_error(resource,
+				       IVI_APPLICATION_ERROR_ROLE,
+				       "surface->configure already "
+				       "set");
+		return;
+	}
+
+
+	/* FIXME: from here, it is the similar functionality
+		  with desktop-shell::create_common_surface */
+	layout_surface = shell->ivi_layout->surface_create(weston_surface,
+						    id_surface);
+
+	/* check if id_ivi is already used for wl_surface*/
+	if (layout_surface == NULL){
+		wl_resource_post_error(resource,
+				       IVI_APPLICATION_ERROR_IVI_ID,
+				       "surface_id is already assigned "
+				       "by another app");
+		return;
+	}
+
+	/* FIXME: this shall be done below:TAG_1, if I use the same order of calling in
+		  create_common_surface
+	 * FIXED: Moved
+	 */
+
+	ivisurf = zalloc(sizeof *ivisurf);
+	if (ivisurf == NULL) {
+		wl_resource_post_no_memory(resource);
+		/*FIXME: not required if move res to below:TAG_1
+		 *FIXED: Delete
+		 */
+		return;
+	}
+
+	wl_list_init(&ivisurf->link);
+	wl_list_insert(&shell->ivi_surface_list, &ivisurf->link);
+
+	ivisurf->shell = shell;
+	ivisurf->id_surface = id_surface;
+
+	/*FIXME: Move below:TAG_1
+	 *FIXED: Moved
+	 */
+	ivisurf->width = 0;
+	ivisurf->height = 0;
+	ivisurf->layout_surface = layout_surface;
+	ivisurf->configured_listener.notify = surface_configure_notify;
+	ivisurf->shell->ivi_layout->add_surface_configured_listener(layout_surface,
+						&ivisurf->configured_listener);
+
+	/*FIXME: when I compare this logic with desktop shell: create_common_surface
+
+shsurf->resource_destroy_listener.notify = handle_resource_destroy;
+wl_resource_add_destroy_listener(surface->resource,
+&shsurf->resource_destroy_listener);
+
+		to be add the above lisnter??
+	 * - That is linking to the wl_resource destroy signal, this below
+	 * here is linking to the weston_surface destroy signal. They have
+	 * a different purpose, and you need to choose which suits the
+	 * semantics you want, or if might need both. So, figure out what
+	 * semantics you want first.
+	 */
+
+	ivisurf->surface_destroy_listener.notify = shell_handle_surface_destroy;
+	wl_signal_add(&weston_surface->destroy_signal,
+		      &ivisurf->surface_destroy_listener);
+
+	ivisurf->surface = weston_surface;
+
+	weston_surface->configure = ivi_shell_surface_configure;
+	weston_surface->configure_private = ivisurf;
+
+	/* FIXME: End of desktop-shell::create_common_surface */
+	/* FIXME: TAG_1 */
+	res = wl_resource_create(client, &ivi_surface_interface, 1, id);
+	if (res == NULL) {
+		wl_client_post_no_memory(client);
+		return;
+	}
+
+	ivisurf->resource = res;
+
+	wl_resource_set_implementation(res, &surface_implementation,
+				       ivisurf, shell_destroy_shell_surface);
+}
+
+static const struct ivi_application_interface application_implementation = {
+	application_surface_create
+};
+
+/*
+ * Handle wl_registry.bind of ivi_application global singleton.
+ */
+static void
+bind_ivi_application(struct wl_client *client,
+		     void *data, uint32_t version, uint32_t id)
+{
+	struct ivi_shell *shell = data;
+	struct wl_resource *resource;
+
+	resource = wl_resource_create(client, &ivi_application_interface,
+				      1, id);
+
+	wl_resource_set_implementation(resource,
+				       &application_implementation,
+				       shell, NULL);
+}
+
+/*
+ * Called through the compositor's destroy signal.
+ */
+static void
+shell_destroy(struct wl_listener *listener, void *data)
+{
+	struct ivi_shell *shell =
+		container_of(listener, struct ivi_shell, destroy_listener);
+	struct ivi_shell_surface *ivisurf, *next;
+
+	wl_list_for_each_safe(ivisurf, next, &shell->ivi_surface_list, link) {
+		wl_list_remove(&ivisurf->link);
+		free(ivisurf);
+	}
+
+	free(shell);
+}
+
+static void
+init_ivi_shell(struct weston_compositor *compositor, struct ivi_shell *shell)
+{
+	shell->compositor = compositor;
+
+	wl_list_init(&shell->ivi_surface_list);
+
+}
+
+static int
+ivi_shell_setting_create(struct ivi_shell_setting *dest,
+			 struct weston_compositor *compositor)
+{
+	int result = 0;
+	struct weston_config *config = compositor->config;
+	struct weston_config_section *section;
+
+	if (NULL == dest)
+		return -1;
+
+	section = weston_config_get_section(config, "ivi-shell", NULL, NULL);
+
+	if (weston_config_section_get_string(
+		section, "ivi-module", &dest->ivi_module, NULL) != 0)
+	{
+		result = -1;
+	}
+
+	return result;
+}
+
+/*
+ * Initialization of ivi-shell.
+ */
+static int
+ivi_load_modules(struct weston_compositor *compositor, const char *modules,
+		 int *argc, char *argv[])
+{
+	const char *p, *end;
+	char buffer[256];
+	int (*module_init)(struct weston_compositor *compositor,
+			   int *argc, char *argv[]);
+
+	if (modules == NULL)
+		return 0;
+
+	p = modules;
+	while (*p) {
+		end = strchrnul(p, ',');
+		snprintf(buffer, sizeof buffer, "%.*s", (int)(end - p), p);
+
+		module_init = weston_load_module(buffer, "module_init");
+		if (module_init)
+			module_init(compositor, argc, argv);
+
+		p = end;
+		while (*p == ',')
+			p++;
+	}
+
+	return 0;
+}
+
+WL_EXPORT int
+module_init(struct weston_compositor *compositor,
+	    int *argc, char *argv[])
+{
+	struct ivi_shell *shell;
+	char ivi_layout_path[PATH_MAX];
+	void *module;
+	struct ivi_shell_setting setting = { };
+
+	shell = zalloc(sizeof *shell);
+	if (shell == NULL)
+		return -1;
+
+	init_ivi_shell(compositor, shell);
+
+	shell->destroy_listener.notify = shell_destroy;
+	wl_signal_add(&compositor->destroy_signal, &shell->destroy_listener);
+
+
+	if (wl_global_create(compositor->wl_display,
+			     &ivi_application_interface, 1,
+			     shell, bind_ivi_application) == NULL)
+		return -1;
+
+	if (ivi_shell_setting_create(&setting, compositor) != 0)
+		return -1;
+
+	/*
+	 * load module:ivi-layout
+	 * ivi_layout_interface is referred by ivi-shell to use ivi-layout.
+	 * The reason why the following code is written newly without
+	 * using weston_load_module is it doesn't open library with
+	 * RTLD_GLOBAL option.
+	 */
+	snprintf(ivi_layout_path, sizeof ivi_layout_path,
+		 "%s/%s", MODULEDIR, "ivi-layout.so");
+	module = dlopen(ivi_layout_path, RTLD_NOW | RTLD_NOLOAD);
+	if (module) {
+		weston_log("ivi-shell: Module '%s' already loaded\n",
+			   ivi_layout_path);
+		dlclose(module);
+		return -1;
+	}
+
+	weston_log("ivi-shell: Loading module '%s'\n", ivi_layout_path);
+	module = dlopen(ivi_layout_path, RTLD_NOW | RTLD_GLOBAL);
+	if (!module) {
+		weston_log("ivi-shell: Failed to load module: %s\n", dlerror());
+		return -1;
+	}
+
+	shell->ivi_layout = dlsym(module,"ivi_layout_interface");
+	if (!shell->ivi_layout){
+		weston_log("ivi-shell: couldn't find ivi_layout_interface in '%s'\n", ivi_layout_path);
+		free(setting.ivi_module);
+		dlclose(module);
+		return -1;
+	}
+
+	shell->ivi_layout->init_with_compositor(compositor);
+
+	/* Call module_init of ivi-modules which are defined in weston.ini */
+	if (ivi_load_modules(compositor, setting.ivi_module, argc, argv) < 0) {
+		free(setting.ivi_module);
+		dlclose(module);
+		return -1;
+	}
+
+	free(setting.ivi_module);
+	return 0;
+}
diff --git a/ivi-shell/ivi-shell.h b/ivi-shell/ivi-shell.h
new file mode 100644
index 0000000..1283a00
--- /dev/null
+++ b/ivi-shell/ivi-shell.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013 DENSO CORPORATION
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.  The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <stdbool.h>
+
+#include "compositor.h"
+
+struct ivi_shell
+{
+	struct wl_resource *resource;
+	struct wl_listener destroy_listener;
+
+	struct weston_compositor *compositor;
+
+	struct wl_list ivi_surface_list; /* struct ivi_shell_surface::link */
+
+	struct ivi_layout_interface *ivi_layout;
+};
-- 
1.7.9.5