config: add applications for special handling.
[profile/ivi/murphy.git] / packaging.in / murphy.lua
1 with_system_controller = false
2 with_amb = false
3 verbose = 0
4
5 m = murphy.get()
6
7 -- try loading the various logging plugins
8 m:try_load_plugin('systemd')
9 m:try_load_plugin('dlog')
10
11 -- load the console plugin
12 m:try_load_plugin('console')
13
14 m:try_load_plugin('console.disabled', 'webconsole', {
15                   address = 'wsck:127.0.0.1:3000/murphy',
16                   httpdir = '/usr/share/murphy/webconsole' });
17
18 -- load the dbus plugin
19 if m:plugin_exists('dbus') then
20     m:load_plugin('dbus')
21 end
22
23 -- load the native resource plugin
24 if m:plugin_exists('resource-native') then
25     m:load_plugin('resource-native')
26     m:info("native resource plugin loaded")
27 else
28     m:info("No native resource plugin found...")
29 end
30
31 -- load the dbus resource plugin
32 m:try_load_plugin('resource-dbus', {
33     dbus_bus = "system",
34     dbus_service = "org.Murphy",
35     dbus_track = true,
36     default_zone = "driver",
37     default_class = "implicit"
38 })
39
40 -- load the domain control plugin
41 if m:plugin_exists('domain-control') then
42     m:load_plugin('domain-control')
43 else
44     m:info("No domain-control plugin found...")
45 end
46
47 if m:plugin_exists('glib') then
48     m:load_plugin('glib')
49 else
50     m:info("No glib plugin found...")
51 end
52
53 -- load the AMB plugin
54 if m:plugin_exists('amb') then
55     m:try_load_plugin('amb')
56
57     if builtin.method.amb_initiate and
58        builtin.method.amb_update
59     then
60         with_amb = true
61     end
62 else
63     m:info("No amb plugin found...")
64 end
65
66 -- load the ASM resource plugin
67 if m:plugin_exists('resource-asm') then
68     m:try_load_plugin('resource-asm', {
69         zone = "driver",
70         share_mmplayer = "player:AVP,mandatory,exclusive,strict",
71         ignored_argv0 = "WebProcess"
72     })
73 else
74     m:info("No audio session manager plugin found...")
75 end
76
77 if m:plugin_exists('system-controller') then
78     with_system_controller = true
79 elseif m:plugin_exists('ivi-resource-manager') then
80     m:load_plugin('ivi-resource-manager')
81     with_system_controller = false
82 end
83
84 -- define application classes
85 application_class {
86     name     = "interrupt",
87     priority = 99,
88     modal    = true ,
89     share    = false,
90     order    = "fifo"
91 }
92
93 application_class {
94     name     = "emergency",
95     priority = 80,
96     modal    = false,
97     share    = false,
98     order    = "fifo"
99 }
100 application_class {
101     name     = "alert",
102     priority = 51,
103     modal    = false,
104     share    = false,
105     order    = "fifo"
106 }
107
108 application_class {
109     name     = "navigator",
110     priority = 50,
111     modal    = false,
112     share    = true,
113     order    = "fifo"
114 }
115
116 application_class {
117     name     = "phone",
118     priority = 6 ,
119     modal    = false,
120     share    = true ,
121     order    = "lifo"
122 }
123 application_class {
124     name     = "camera",
125     priority = 5,
126     modal    = false,
127     share    = false,
128     order    = "lifo"
129 }
130
131 application_class { name="event"    , priority=4 , modal=false, share=true , order="fifo" }
132 application_class { name="game"     , priority=3 , modal=false, share=false, order="lifo" }
133 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
134 --#application_class { name="basic"    , priority=2 , modal=false, share=false, order="lifo" }
135 application_class { name="player"   , priority=1 , modal=false, share=true , order="lifo" }
136 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
137
138 -- define zone attributes
139 zone.attributes {
140     type = {mdb.string, "common", "rw"},
141     location = {mdb.string, "anywhere", "rw"}
142 }
143
144 -- define zones
145 zone {
146      name = "driver",
147      attributes = {
148          type = "common",
149          location = "front-left"
150      }
151 }
152
153 zone {
154      name = "passanger1",
155      attributes = {
156          type = "private",
157          location = "front-right"
158      }
159 }
160
161 zone {
162      name = "passanger2",
163      attributes = {
164          type = "private",
165          location = "back-left"
166      }
167 }
168
169 zone {
170      name = "passanger3",
171      attributes = {
172          type = "private",
173          location = "back-right"
174      }
175 }
176
177 zone {
178      name = "passanger4",
179      attributes = {
180          type = "private",
181          location = "back-left"
182      }
183 }
184
185
186 -- define resource classes
187 if not m:plugin_exists('ivi-resource-manager') and
188    not with_system_controller
189 then
190    resource.class {
191         name = "audio_playback",
192         shareable = true,
193         attributes = {
194             role = { mdb.string, "music", "rw" },
195             pid = { mdb.string, "<unknown>", "rw" },
196             policy = { mdb.string, "relaxed", "rw" }
197         }
198    }
199 end
200
201 resource.class {
202      name = "audio_recording",
203      shareable = true,
204      attributes = {
205          role   = { mdb.string, "music"    , "rw" },
206          pid    = { mdb.string, "<unknown>", "rw" },
207          policy = { mdb.string, "relaxed"  , "rw" }
208      }
209 }
210
211 resource.class {
212      name = "video_playback",
213      shareable = false,
214 }
215
216 resource.class {
217      name = "video_recording",
218      shareable = false
219 }
220
221 if not m:plugin_exists('ivi-resource-manager') and
222    not with_system_controller
223 then
224     resource.method.veto = {
225         function(zone, rset, grant, owners, req_set)
226             return true
227          end
228     }
229 end
230
231 -- test for creating selections
232 mdb.select {
233            name = "audio_owner",
234            table = "audio_playback_owner",
235            columns = {"application_class"},
236            condition = "zone_name = 'driver'"
237 }
238
239 mdb.select {
240            name = "vehicle_speed",
241            table = "amb_vehicle_speed",
242            columns = {"value"},
243            condition = "key = 'VehicleSpeed'"
244 }
245
246 element.lua {
247    name    = "speed2volume",
248    inputs  = { speed = mdb.select.vehicle_speed, param = 9 },
249    outputs = {  mdb.table { name = "speedvol",
250                             index = {"zone", "device"},
251                             columns = {{"zone", mdb.string, 16},
252                                        {"device", mdb.string, 16},
253                                        {"value", mdb.floating}},
254                             create = true
255                            }
256              },
257    oldvolume = 0.0,
258    update  = function(self)
259                 speed = self.inputs.speed.single_value
260                 if (speed) then
261                     volume = (speed - 144.0) / 7.0
262                 else
263                     volume = 0.0
264                 end
265                 diff = volume - self.oldvolume
266                 if (diff*diff > self.inputs.param) then
267                     print("*** element "..self.name.." update "..volume)
268                     self.oldvolume = volume
269                     mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
270                 end
271              end
272 }
273
274 -- Night mode processing chain
275
276 mdb.select {
277     name = "exterior_brightness",
278     table = "amb_exterior_brightness",
279     columns = { "value" },
280     condition = "key = 'ExteriorBrightness'"
281 }
282
283 element.lua {
284     name    = "nightmode",
285     inputs  = { brightness = mdb.select.exterior_brightness },
286     oldmode = -1;
287     outputs = {
288         mdb.table {
289             name = "amb_nightmode",
290             index = { "id" },
291             create = true,
292             columns = {
293                 { "id", mdb.unsigned },
294                 { "night_mode", mdb.unsigned }
295             }
296         }
297     },
298     update = function(self)
299         -- This is a trivial function to calculate night mode. Later, we will
300         -- need a better threshold value and hysteresis to prevent oscillation.
301
302         brightness = self.inputs.brightness.single_value
303
304         if not brightness then
305             return
306         end
307
308         print("*** element "..self.name.." update brightness: "..brightness)
309
310         if brightness > 300 then
311             mode = 0
312         else
313             mode = 1
314         end
315
316         print("*** resulting mode: ".. mode)
317
318         if not (mode == self.oldmode) then
319             mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
320         end
321
322         self.oldmode = mode
323     end
324 }
325
326 mdb.select {
327     name = "select_night_mode",
328     table = "amb_nightmode",
329     columns = { "night_mode" },
330     condition = "id = 0"
331 }
332
333 if with_amb then
334     sink.lua {
335         name = "night_mode",
336         inputs = { owner = mdb.select.select_night_mode },
337         property = "NightMode",
338         type = "b",
339         initiate = builtin.method.amb_initiate,
340         update = builtin.method.amb_update
341     }
342 end
343
344 -- Night mode general handlers
345
346 sink.lua {
347     name = "nightmode_homescreen",
348     inputs = { owner = mdb.select.select_night_mode },
349     initiate = function(self)
350         -- data = mdb.select.select_night_mode.single_value
351         return true
352     end,
353     update = function(self)
354         data = mdb.select.select_night_mode.single_value
355
356         if verbose > 1 then
357             print("Night mode updated: " .. tostring(data))
358         end
359
360         if sc then
361             -- tell homescreen that night mode was updated
362             sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=2,state=data})}))
363         end
364         return true
365     end
366 }
367
368 -- Driving mode processing chain
369
370 element.lua {
371     name    = "drivingmode",
372     inputs  = { speed = mdb.select.vehicle_speed },
373     oldmode = -1;
374     outputs = {
375         mdb.table {
376             name = "amb_drivingmode",
377             index = { "id" },
378             create = true,
379             columns = {
380                 { "id", mdb.unsigned },
381                 { "driving_mode", mdb.unsigned }
382             }
383         }
384     },
385     update = function(self)
386
387         speed = self.inputs.speed.single_value
388
389         if not speed then
390             return
391         end
392
393         if speed == 0 then
394             mode = 0
395         else
396             mode = 1
397         end
398
399         if not (mode == self.oldmode) then
400             mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
401         end
402
403         self.oldmode = mode
404     end
405 }
406
407 mdb.select {
408     name = "select_driving_mode",
409     table = "amb_drivingmode",
410     columns = { "driving_mode" },
411     condition = "id = 0"
412 }
413
414 if with_amb then
415     sink.lua {
416         name = "driving_mode",
417         inputs = { owner = mdb.select.select_driving_mode },
418         property = "DrivingMode",
419         type = "u",
420         initiate = builtin.method.amb_initiate,
421         update = builtin.method.amb_update
422     }
423 end
424
425 -- turn signals (left, right)
426
427 mdb.select {
428     name = "winker",
429     table = "amb_turn_signal",
430     columns = { "value" },
431     condition = "key = 'TurnSignal'"
432 }
433
434 -- define three categories
435
436 mdb.select {
437     name = "undefined_applications",
438     table = "aul_applications",
439     columns = { "appid" },
440     condition = "category = '<undefined>'"
441 }
442
443 mdb.select {
444     name = "basic_applications",
445     table = "aul_applications",
446     columns = { "appid" },
447     condition = "category = 'basic'"
448 }
449
450 mdb.select {
451     name = "entertainment_applications",
452     table = "aul_applications",
453     columns = { "appid" },
454     condition = "category = 'entertainment'"
455 }
456
457 function ft(t)
458     -- filter the object garbage out of the tables
459     ret = {}
460
461     for k,v in pairs(t) do
462         if k ~= "userdata" and k ~= "new" then
463             ret[k] = v
464         end
465     end
466
467     return ret
468 end
469
470 function getApplication(appid)
471     local conf = nil
472
473     -- find the correct local application definition
474
475     for k,v in pairs(ft(application)) do
476         if appid == v.appid then
477             conf = v
478             break
479         end
480     end
481
482     return conf
483 end
484
485 function regulateApplications(t, regulation)
486     for k,v in pairs(ft(t)) do
487
488         -- iterate through the undefined and entertainment apps, see if
489         -- they have been overruled in local config
490
491         local conf = getApplication(v.appid)
492
493         if conf and conf.resource_class ~= "player" then
494             -- override, don't disable
495             resmgr:disable_screen_by_appid("*", "*", v.appid, false)
496         else
497             resmgr:disable_screen_by_appid("*", "*", v.appid, regulation == 1)
498         end
499     end
500 end
501
502 -- regulation (on), use "select_driving_mode"
503
504 sink.lua {
505     name = "driving_regulation",
506     inputs = { owner = mdb.select.select_driving_mode },
507     initiate = function(self)
508         -- local data = mdb.select.select_driving_mode.single_value
509         return true
510     end,
511     update = function(self)
512         local data = mdb.select.select_driving_mode.single_value
513
514         if verbose > 1 then
515             print("Driving mode updated: " .. tostring(data))
516         end
517
518         if not sc then
519             return true
520         end
521
522         -- tell homescreen that driving mode was updated
523         sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=1,state=data})}))
524
525         --[[
526         -- bulk handle the applications that need requisites
527         r = requisite { driving = true }
528         resmgr:disable_screen_by_requisite("*", "*", r, data == 1)
529         --]]
530
531         regulateApplications(ft(mdb.select.entertainment_applications), data)
532         regulateApplications(ft(mdb.select.undefined_applications), data)
533
534         return true
535     end
536 }
537
538 sink.lua {
539     name = "regulated_app_change",
540     inputs = { undef = mdb.select.undefined_applications,
541                entertainment = mdb.select.entertainment_applications },
542     initiate = function(self)
543         return true
544     end,
545     update = function(self)
546         local data = mdb.select.select_driving_mode.single_value
547
548         if not sc then
549             return
550         end
551
552         if verbose > 1 then
553             print("regulated application list was changed")
554         end
555
556         regulateApplications(ft(mdb.select.entertainment_applications), data)
557         regulateApplications(ft(mdb.select.undefined_applications), data)
558
559         return true
560     end
561 }
562
563 -- shift position (parking, reverse, other)
564
565 mdb.select {
566     name = "gear_position",
567     table = "amb_gear_position",
568     columns = { "value" },
569     condition = "key = 'GearPosition'"
570 }
571
572 -- cameras (back, front, left, right)
573
574 element.lua {
575     name    = "camera_state",
576     inputs  = { winker = mdb.select.winker, gear = mdb.select.gear_position },
577     oldmode = -1;
578     outputs = {
579         mdb.table {
580             name = "target_camera_state",
581             index = { "id" },
582             create = true,
583             columns = {
584                 { "id", mdb.unsigned },
585                 { "front_camera", mdb.unsigned },
586                 { "back_camera", mdb.unsigned },
587                 { "right_camera", mdb.unsigned },
588                 { "left_camera", mdb.unsigned }
589             }
590         }
591     },
592     update = function(self)
593
594         front_camera = 0
595         back_camera = 0
596         right_camera = 0
597         left_camera = 0
598
599         if self.inputs.gear == 128 then
600             back_camera = 1
601         elseif self.inputs.winker == 1 then
602             right_camera = 1
603         elseif self.inputs.winker == 2 then
604             left_camera = 1
605         end
606
607         mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
608
609     end
610 }
611
612 -- load the telephony plugin
613 m:try_load_plugin('telephony')
614
615
616 -- system controller test setup
617
618 if not with_system_controller then
619    return
620 end
621
622 m:load_plugin('system-controller')
623
624 window_manager_operation_names = {
625     [1] = "create",
626     [2] = "destroy"
627 }
628
629 function window_manager_operation_name(oper)
630     local name = window_manager_operation_names[oper]
631     if name then return name end
632     return "<unknown " .. tostring(oper) .. ">"
633 end
634
635 window_operation_names = {
636     [1] = "create",
637     [2] = "destroy",
638     [3] = "name_change",
639     [4] = "visible",
640     [5] = "configure",
641     [6] = "active"
642 }
643
644 function window_operation_name(oper)
645     local name = window_operation_names[oper]
646     if name then return name end
647     return "<unknown " .. tostring(oper) .. ">"
648 end
649
650 layer_operation_names = {
651     [1] = "create",
652     [2] = "destroy",
653     [3] = "visible"
654 }
655
656 function layer_operation_name(oper)
657     local name = layer_operation_names[oper]
658     if name then return name end
659     return "<unknown " .. tostring(oper) .. ">"
660 end
661
662 input_manager_operation_names = {
663     [1] = "create",
664     [2] = "destroy",
665     [3] = "ready"
666 }
667
668 function input_manager_operation_name(oper)
669     local name = input_manager_operation_names[oper]
670     if name then return name end
671     return "<unknown " .. tostring(oper) .. ">"
672 end
673
674 input_operation_names = {
675     [1] = "create",
676     [2] = "destroy",
677     [3] = "update"
678 }
679
680 function input_operation_name(oper)
681     local name = input_operation_names[oper]
682     if name then return name end
683     return "<unknown " .. tostring(oper) .. ">"
684 end
685
686 code_operation_names = {
687     [1] = "create",
688     [2] = "destroy",
689     [3] = "state_change"
690 }
691
692 function code_operation_name(oper)
693     local name = code_operation_names[oper]
694     if name then return name end
695     return "<unknown " .. tostring(oper) .. ">"
696 end
697
698 command_names = {
699     [0x00001] = "send_appid",
700     [0x10001] = "create",
701     [0x10002] = "destroy",
702     [0x10003] = "show",
703     [0x10004] = "hide",
704     [0x10005] = "move",
705     [0x10006] = "change_active",
706     [0x10007] = "change_layer",
707     [0x10008] = "change_attr",
708     [0x10009] = "name",
709     [0x10011] = "map_thumb",
710     [0x10012] = "unmap_thumb",
711     [0x10020] = "show layer",
712     [0x10021] = "hide_layer",
713     [0x10022] = "change_layer_attr",
714     [0x20001] = "add_input",
715     [0x20002] = "del_input",
716     [0x20003] = "send_input",
717     [0x40001] = "acquire_res",
718     [0x40002] = "release_res",
719     [0x40003] = "deprive_res",
720     [0x40004] = "waiting_res",
721     [0x40005] = "revert_res",
722     [0x40011] = "create_res",
723     [0x40012] = "destroy_res",
724     [0x50001] = "set_region",
725     [0x50002] = "unset_region",
726     [0x60001] = "change_state"
727 }
728
729 function command_name(command)
730     local name = command_names[command]
731     if name then return name end
732     return "<unknown " .. tostring(command) .. ">"
733 end
734
735 input_layer = {
736    [3] = true, -- input
737    [4] = true, -- touch
738    [5] = true  -- cursor
739 }
740
741 resmgr = resource_manager {
742   screen_event_handler = function(self, ev)
743                              local event = ev.event
744                              local surface = ev.surface
745
746                              if event == "grant" then
747                                  if verbose > 0 then
748                                     print("*** make visible surface "..surface)
749                                  end
750                                  local a = animation({})
751                                  local r = m:JSON({surface = surface,
752                                                    visible = 1,
753                                                    raise   = 1})
754                                  wmgr:window_request(r,a,0)
755                                  elseif event == "revoke" then
756                                  if verbose > 0 then
757                                     print("*** hide surface "..surface)
758                                  end
759                                  local a = animation({})
760                                  local r = m:JSON({surface = ev.surface,
761                                                    visible = 0})
762                                  wmgr:window_request(r,a,0)
763                              else
764                                  if verbose > 0 then
765                                     print("*** screen resource event: " ..
766                                           tostring(ev))
767                                  end
768                              end
769                          end,
770   audio_event_handler = function(self, ev)
771                              local event = ev.event
772                              local appid = ev.appid
773                              local audioid = ev.audioid
774
775                              if event == "grant" then
776                                  if verbose > 0 or true then
777                                     print("*** grant audio to "..appid..
778                                           " ("..audioid..") in '" ..
779                                           ev.zone .. "' zone")
780                                  end
781                              elseif event == "revoke" then
782                                  if verbose > 0 or true then
783                                     print("*** revoke audio from "..appid..
784                                           " ("..audioid..") in '" ..
785                                           ev.zone .. "' zone")
786                                  end
787                              else
788                                  if verbose > 0 or true then
789                                     print("*** audio resource event: " ..
790                                           tostring(ev))
791                                  end
792                              end
793                         end
794 }
795
796 resclnt = resource_client {}
797
798 wmgr = window_manager {
799   geometry = function(self, w,h, v)
800                   if type(v) == "function" then
801                       return v(w,h)
802                   end
803                   return v
804              end,
805
806   application = function(self, appid)
807                      if appid then
808                          local app = application_lookup(appid)
809                          if not app then
810                              app = application_lookup("default")
811                          end
812                          return app
813                      end
814                      return { privileges = {screen="none", audio="none"} }
815                 end,
816
817   outputs = { { name  = "Center",
818                 id    = 0,
819                 zone  = "driver",
820                 areas = { Status = {
821                               id     = 0,
822                               pos_x  = 0,
823                               pos_y  = 0,
824                               width  = function(w,h) return w end,
825                               height = 64
826                           },
827                           Full = {
828                               id     = 1,
829                               pos_x  = 0,
830                               pos_y  = 64,
831                               width  = function(w,h) return w end,
832                               height = function(w,h) return h-64-128 end
833                           },
834                           Upper = {
835                               id     = 2,
836                               pos_x  = 0,
837                               pos_y  = 64,
838                               width  = function(w,h) return w end,
839                               height = function(w,h) return (h-64-128)/2 end
840                           },
841                           Lower = {
842                               id     = 3,
843                               pos_x  = 0,
844                               pos_y  = function(w,h) return (h-64-128)/2+64 end,
845                               width  = function(w,h) return w end,
846                               height = function(w,h) return (h-64-128)/2 end
847                           },
848                           UpperLeft = {
849                               id     = 4,
850                               pos_x  = 0,
851                               pos_y  = 64,
852                               width  = function(w,h) return w/2 end,
853                               height = function(w,h) return (h-64-128)/2 end
854                           },
855                           UpperRight = {
856                               id     = 5,
857                               pos_x  = function(w,h) return w/2 end,
858                               pos_y  = 64,
859                               width  = function(w,h) return w/2 end,
860                               height = function(w,h) return (h-64-128)/2 end
861                           },
862                           LowerLeft = {
863                               id     = 6,
864                               pos_x  = 0,
865                               pos_y  = function(w,h) return (h-64-128/2)+64 end,
866                               width  = function(w,h) return w/2 end,
867                               height = function(w,h) return (h-64-128)/2 end
868                           },
869                           LowerRight = {
870                               id     = 7,
871                               pos_x  = function(w,h) return w/2 end,
872                               pos_y  = function(w,h) return (h-64-128/2)+64 end,
873                               width  = function(w,h) return w/2 end,
874                               height = function(w,h) return (h-64-128)/2 end
875                           },
876                           SysApp = {
877                               id     = 8,
878                               pos_x  = 0,
879                               pos_y  = 64,
880                               width  = function(w,h) return w end,
881                               height = function(w,h) return h-64-128 end
882                           },
883                           ["SysApp.Left"] = {
884                               id     = 9,
885                               pos_x  = 0,
886                               pos_y  = 64,
887                               width  = function(w,h) return w/2-181 end,
888                               height = function(w,h) return h-64-128 end
889                           },
890                           ["SysApp.Right"] = {
891                               id     = 10,
892                               pos_x  = function(w,h) return w/2+181 end,
893                               pos_y  = 64,
894                               width  = function(w,h) return w/2-181 end,
895                               height = function(w,h) return h-64-128 end
896                           },
897                         }
898                },
899                { name  = "Mid",
900                  zone  = "driver",
901                  id    = 1
902                }
903
904   },
905   layers = { {      0, "Background"   , 1 },
906              {      1, "Application"  , 2 },
907              {      2, "Softkeyboard" , 4 },
908              {      3, "HomeScreen"   , 2 },
909              {      4, "ControlBar"   , 2 },
910              {      5, "InterruptApp" , 2 },
911              {      6, "OnScreen"     , 2 },
912              {    101, "Input"        , 3 },
913              {    102, "Cursor"       , 5 },
914              {    103, "Startup"      , 6 },
915              { 0x1000, "Background"   , 1 },
916              { 0x2000, "Normal"       , 2 },
917              { 0x3000, "Fullscreen"   , 2 },
918              { 0x4000, "InputPanel"   , 3 },
919              { 0xA000, "Touch"        , 4 },
920              { 0xB000, "Cursor"       , 5 },
921              { 0xC000, "Startup"      , 6 }
922   },
923
924
925   manager_update = function(self, oper)
926                        if verbose > 0 then
927                            print("### <== WINDOW MANAGER UPDATE:" ..
928                                  window_manager_operation_name(oper))
929                        end
930                        if oper == 1 then
931                            local umask = window_mask { raise   = true,
932                                                        visible = true,
933                                                        active  = true }
934                            local rmask = window_mask { active  = true }
935                            local req = m:JSON({
936                                        passthrough_update  = umask:tointeger(),
937                                        passthrough_request = rmask:tointeger()
938                            })
939                            self:manager_request(req)
940                        end
941                    end,
942
943   window_update = function(self, oper, win, mask)
944                       if verbose > 0 then
945                           print("### <== WINDOW UPDATE oper:" ..
946                                 window_operation_name(oper) ..
947                                 " mask: " .. tostring(mask))
948                           if verbose > 1 then
949                               print(win)
950                           end
951                       end
952
953                       local arg = m:JSON({ surface = win.surface,
954                                            winname = win.name,
955                       })
956                       local command = 0
957
958                       if oper == 1 then -- create
959                            local layertype = win.layertype
960                            if layertype and input_layer[layertype] then
961                                if verbose > 0 then
962                                    print("ignoring input panel creation")
963                                end
964                                return
965                            end
966                            command     = 0x10001
967                       elseif oper == 2 then -- destroy
968                            command     = 0x10002
969                       elseif oper == 3 then  -- namechange
970                            command     = 0x10009
971                       elseif oper == 4 or oper == 5 then --visible or configure
972                            command     = 0x10008
973                            arg.zone    = win.area
974                            arg.node    = win.node
975                            arg.layer   = win.layer
976                            arg.pos_x   = win.pos_x
977                            arg.pos_y   = win.pos_y
978                            arg.width   = win.width
979                            arg.height  = win.height
980                            arg.raise   = win.raise
981                            arg.visible = win.visible
982                            arg.active  = win.active
983                       elseif oper == 6 then -- active
984                            command     = 0x10006
985                            arg.active  = win.active
986                       else
987                            if verbose > 0 then
988                                print("### nothing to do")
989                            end
990                            return
991                       end
992
993                       local msg = m:JSON({ command = command,
994                                            appid   = win.appid,
995                                            pid     = win.pid,
996                                            arg     = arg
997                       })
998                       if verbose > 0 then
999                           print("### <== sending " ..
1000                                 command_name(msg.command) ..
1001                                 " window message to '" .. win.name .. "'")
1002                           if verbose > 1 then
1003                               print(msg)
1004                           end
1005                       end
1006                       sc:send_message(homescreen, msg)
1007
1008                       if oper == 1 then -- create
1009                           local i = input_layer[win.layertype]
1010                           local p = self:application(win.appid)
1011                           local s = p.privileges.screen
1012
1013                           if s == "system" then
1014                               local a = animation({})
1015                               local r = m:JSON({surface = win.surface,
1016                                                 visible = 1,
1017                                                 raise   = 1})
1018                               self:window_request(r,a,0)
1019                           else
1020                               if i then
1021                                   if verbose > 0 then
1022                                       print("do not make resource for " ..
1023                                             "input window")
1024                                   end
1025                               else
1026                                   resclnt:resource_set_create("screen",
1027                                                                "driver",
1028                                                                win.appid,
1029                                                                win.surface)
1030                               end
1031                           end
1032                       elseif oper == 2 then -- destroy
1033                           resclnt:resource_set_destroy("screen", win.surface)
1034                       elseif oper == 6 then -- active
1035                           if win.active then
1036                               local i = input_layer[win.layertype]
1037                               local p = self:application(win.appid)
1038                               local s = p.privileges.screen
1039                               local surface = win.surface
1040                               if not i and s ~= "system" then
1041                                  resclnt:resource_set_acquire("screen",surface)
1042                                  resmgr:window_raise(win.appid, surface, 1)
1043                               end
1044                           end
1045                       end
1046                   end,
1047
1048   layer_update = function(self, oper, layer, mask)
1049                       if verbose > 0 then
1050                           print("### LAYER UPDATE:" ..
1051                                 layer_operation_name(oper) ..
1052                                 " mask: " .. tostring(mask))
1053                           if verbose > 1 then
1054                               print(layer)
1055                           end
1056                       end
1057                       if oper == 3 then -- visible
1058                          local command = 0x10022
1059                          local msg = m:JSON({
1060                                          command = command,
1061                                          appid = "",
1062                                          arg = m:JSON({layer = layer.id,
1063                                                        visible = layer.visible
1064                                          })
1065                                 })
1066                          if verbose > 0 then
1067                             print("### <== sending "..command_name(command)..
1068                                   " layer message")
1069                             if verbose > 1 then
1070                                 print(msg)
1071                             end
1072                          end
1073                          sc:send_message(homescreen, msg)
1074                       else
1075                            if verbose > 0 then
1076                                print("### nothing to do")
1077                            end
1078                       end
1079                  end,
1080
1081   output_update = function(self, oper, out, mask)
1082                       local idx = out.index
1083                       if verbose > 0 then
1084                           print("### OUTPUT UPDATE:" .. oper ..
1085                                 " mask: "..tostring(mask))
1086                       end
1087                       print(out)
1088                       local outdef = self.outputs[idx+1]
1089                       if (oper == 1) then -- create
1090                           if outdef then
1091                               self:output_request(m:JSON({index = idx,
1092                                                           id    = outdef.id,
1093                                                           name  = outdef.name
1094                                                           }))
1095                           end
1096                       elseif (oper == 5) then -- done
1097                           local ads = outdef.areas
1098                           local on = outdef.name
1099                           if ads then
1100                               for name,ad in pairs(ads) do
1101                                   local can = wmgr:canonical_name(on.."."..name)
1102                                   local a = m:JSON({name   = name,
1103                                                     output = out.index})
1104                                   for fld,val in pairs(ad) do
1105                                       a[fld] = self:geometry(out.width,
1106                                                              out.height,
1107                                                              val)
1108                                    end
1109                                    self:area_create(a)
1110                                    resmgr:area_create(area[can], outdef.zone)
1111                               end
1112                           end
1113                       end
1114                   end
1115 }
1116
1117
1118 imgr = input_manager {
1119   inputs = {{ name = "G27 Racing Wheel",
1120               id = 0,
1121               switch = { [2] = {appid="org.tizen.ico.app-soundsample"      },
1122                          [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1123                          [4] = {appid="org.tizen.ico.app-soundsample"      },
1124                          [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1125              }}
1126   },
1127
1128   manager_update = function(self, oper)
1129                        if verbose > 0 then
1130                            print("### <== INPUT MANAGER UPDATE:" ..
1131                                  input_manager_operation_name(oper))
1132                        end
1133                    end,
1134
1135   input_update = function(self, oper, inp, mask)
1136                      if verbose > 0 then
1137                          print("### INPUT UPDATE:" ..
1138                                 input_operation_name(oper) ..
1139                                 " mask: " .. tostring(mask))
1140                           if verbose > 1 then
1141                               print(inp)
1142                           end
1143                       end
1144                  end,
1145   code_update  = function(self, oper, code, mask)
1146                      if verbose > 0 then
1147                          print("### CODE UPDATE: mask: " .. tostring(mask))
1148                          if verbose > 1 then
1149                              print(code)
1150                          end
1151                      end
1152                      local msg = m:JSON({ command = 1,
1153                                           appid = "org.tizen.ico.homescreen",
1154                                           arg = m:JSON({ device = code.device,
1155                                                          time = code.time,
1156                                                          input = code.input,
1157                                                          code = code.id,
1158                                                          state = code.state
1159                                            })
1160                      })
1161                      if verbose > 0 then
1162                          print("### <== sending " ..
1163                                command_name(msg.command) ..
1164                                " input message")
1165                          if verbose > 1 then
1166                              print(msg)
1167                          end
1168                      end
1169                      sc:send_message(homescreen, msg)
1170                  end
1171 }
1172
1173 sc = m:get_system_controller()
1174
1175 -- resource sets
1176 sets = {}
1177
1178 -- user manager
1179 um = m:UserManager()
1180
1181 connected = false
1182 homescreen = ""
1183
1184 -- these shoud be before wmgr:connect() is called
1185 if verbose > 0 then
1186    print("====== creating applications ======")
1187 end
1188 application {
1189     appid          = "default",
1190     area           = "Center.Full",
1191     privileges     = { screen = "none", audio = "none" },
1192     resource_class = "player",
1193     screen_priority = 0
1194 }
1195
1196 application {
1197     appid           = "weston",
1198     area            = "Center.Full",
1199     privileges      = { screen = "system", audio = "none" },
1200     resource_class  = "implicit",
1201     screen_priority = 30
1202 }
1203
1204 application {
1205     appid           = "org.tizen.ico.homescreen",
1206     area            = "Center.Full",
1207     privileges      = { screen = "system", audio = "system" },
1208     resource_class  = "player",
1209     screen_priority = 20
1210 }
1211
1212 application {
1213     appid           = "org.tizen.ico.statusbar",
1214     area            = "Center.Status",
1215     privileges      = { screen = "system", audio = "none" },
1216     resource_class  = "player",
1217     screen_priority = 20
1218 }
1219
1220 application {
1221     appid           = "org.tizen.ico.login",
1222     area            = "Center.Full",
1223     privileges      = { screen = "system", audio = "system" },
1224     resource_class  = "player",
1225     screen_priority = 20
1226 }
1227
1228 application {
1229     appid           = "org.tizen.ico.camera_left",
1230     area            = "Center.SysApp.Left",
1231     privileges      = { screen = "system", audio = "none" },
1232     requisites      = { screen = "blinker_left", audio = "none" },
1233     resource_class  = "player",
1234     screen_priority = 30
1235 }
1236
1237 application {
1238     appid           = "org.tizen.ico.camera_right",
1239     area            = "Center.SysApp.Right",
1240     privileges      = { screen = "system", audio = "none" },
1241     requisites      = { screen = "blinker_right", audio = "none" },
1242     resource_class  = "player",
1243     screen_priority = 30
1244 }
1245
1246 application {
1247     appid           = "net.zmap.navi",
1248     area            = "Center.Full",
1249     privileges      = { screen = "none", audio = "none" },
1250     resource_class  = "navigator",
1251     screen_priority = 30
1252 }
1253
1254 if sc then
1255     sc.client_handler = function (self, cid, msg)
1256         local command = msg.command
1257         if verbose > 0 then
1258             print('### ==> client handler:')
1259             if verbose > 1 then
1260                 print(msg)
1261             end
1262         end
1263         if not connected then
1264             print('Setting homescreen='..msg.appid)
1265             homescreen = msg.appid
1266             print('Trying to connect to wayland...')
1267             connected = wmgr:connect()
1268         end
1269         if connected and command then
1270             if command == 1 then -- send_appid
1271                 local driving_mode = mdb.select.select_driving_mode.single_value
1272                 local night_mode = mdb.select.select_night_mode.single_value
1273
1274                 if not driving_mode then driving_mode = 0 end
1275                 if not night_mode then night_mode = 0 end
1276
1277                 local reply = m:JSON({ command = 0x60001,
1278                                        arg     = m:JSON({ stateid = 1,
1279                                                           state   = driving_mode})
1280                                      })
1281                  if verbose > 0 then
1282                      print("### <== sending " ..
1283                            command_name(command) .. " message")
1284                      if verbose > 1 then
1285                          print(reply)
1286                      end
1287                  end
1288                  sc:send_message(homescreen, reply)
1289
1290                  reply = m:JSON({ command = 0x60001,
1291                                   arg     = m:JSON({ stateid = 2,
1292                                                      state   = night_mode})
1293                                 })
1294                  if verbose > 0 then
1295                      print("### <== sending " ..
1296                            command_name(command) .. " message")
1297                      if verbose > 1 then
1298                          print(reply)
1299                      end
1300                  end
1301                  sc:send_message(homescreen, reply)
1302             end
1303         end
1304     end
1305
1306     sc.generic_handler = function (self, cid, msg)
1307         if verbose > 0 then
1308             print('### ==> generic handler:')
1309             if verbose > 1 then
1310                print(msg)
1311             end
1312         end
1313     end
1314
1315     sc.window_handler = function (self, cid, msg)
1316         if verbose > 0 then
1317             print('### ==> received ' ..
1318                    command_name(msg.command) .. ' message')
1319             if verbose > 1 then
1320                 print(tostring(msg))
1321             end
1322         end
1323
1324         local a = animation({})
1325         local nores = false
1326         if msg.command == 0x10003 then       -- ico SHOW command
1327             local raise_mask = 0x01000000
1328             local lower_mask = 0x02000000
1329             local nores_mask = 0x40000000
1330             local time_mask  = 0x00ffffff
1331             msg.arg.visible = 1
1332             if msg.arg then
1333                 local time = 200
1334                 if  msg.arg.anim_time then
1335                     local t = msg.arg.anim_time
1336                     time = m:AND(t, time_mask)
1337                     nores = m:AND(t, nores_mask)
1338                     if m:AND(t, raise_mask) then
1339                         msg.arg.raise = 1
1340                     elseif m:AND(t, lower_mask) then
1341                         msg.arg.raise = 0
1342                     end
1343                 end
1344                 if msg.arg.anim_name then
1345                     a.show = { msg.arg.anim_name, time }
1346                     print('time: ' .. tostring(a.show[2]))
1347                 end
1348             end
1349             if not nores then
1350                 local p = wmgr:application(msg.appid)
1351                 local s = p.privileges.screen
1352                 if s == "system" then
1353                     nores = true
1354                 end
1355             end
1356             if verbose > 2 then
1357                 print('### ==> SHOW')
1358                 print(tostring(msg.arg))
1359             end
1360             if nores then
1361                 wmgr:window_request(msg.arg, a, 0)
1362             else
1363                 local surface = msg.arg.surface
1364                 resclnt:resource_set_acquire("screen", surface)
1365                 resmgr:window_raise(msg.appid, surface, 1)
1366             end
1367         elseif msg.command == 0x10004 then   -- ico HIDE command
1368             local raise_mask = 0x01000000
1369             local lower_mask = 0x02000000
1370             local nores_mask = 0x40000000
1371             local time_mask  = 0x00ffffff
1372             msg.arg.visible = 0
1373             if msg.arg then
1374                 local time = 200
1375                 if msg.arg.anim_time then
1376                     local t = msg.arg.anim_time
1377                     time = m:AND(t, time_mask)
1378                     nores = m:AND(t, nores_mask)
1379                 end
1380                 if msg.arg.anim_name then
1381                     a.hide = { msg.arg.anim_name, time }
1382                     print('hide animation time: ' .. tostring(a.hide[2]))
1383                 end
1384             end
1385             if not nores then
1386                 local p = wmgr:application(msg.appid)
1387                 local s = p.privileges.screen
1388                 if s == "system" then
1389                     nores = true
1390                 end
1391             end
1392             if verbose > 2 then
1393                 print('### ==> HIDE REQUEST')
1394                 print(tostring(msg.arg))
1395             end
1396             if nores then
1397                 wmgr:window_request(msg.arg, a, 0)
1398             else
1399                 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1400             end
1401         elseif msg.command == 0x10005 then   -- ico MOVE
1402             if verbose > 2 then
1403                 print('### ==> MOVE REQUEST')
1404                 print(tostring(msg.arg))
1405             end
1406             wmgr:window_request(msg.arg, a, 0)
1407             -- TODO: handle if area changed
1408         elseif msg.command == 0x10006 then   -- ico ACTIVE
1409             if not msg.arg.active then
1410                 msg.arg.active = 3 -- pointer + keyboard
1411             end
1412             if verbose > 2 then
1413                 print('### ==> ACTIVE REQUEST')
1414                 print(tostring(msg.arg))
1415             end
1416             wmgr:window_request(msg.arg, a, 0)
1417         elseif msg.command == 0x10007 then   -- ico CHANGE_LAYER
1418             if verbose > 2 then
1419                 print('### ==> CHANGE_LAYER REQUEST')
1420                 print(tostring(msg.arg))
1421             end
1422             --[[
1423             if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1424                 print("do not change layer for other than cursor or touch")
1425                 return
1426             end
1427             --]]
1428             wmgr:window_request(msg.arg, a, 0)
1429         elseif msg.command == 0x10011 then   -- ico MAP_THUMB
1430             local framerate = msg.arg.framerate
1431             if not framerate or framerate < 0 then
1432                 framerate = 0
1433             end
1434             msg.arg.map = 1
1435             if verbose > 2 then
1436                 print('### ==> MAP_THUMB REQUEST')
1437                 print(msg.arg)
1438                 print('framerate: '..framerate)
1439             end
1440             wmgr:window_request(msg.arg, a, framerate)
1441         elseif msg.command == 0x10012 then   -- ico UNMAP_THUMB
1442             msg.arg.map = 0
1443             if verbose > 2 then
1444                 print('### ==> UNMAP_THUMB REQUEST')
1445                 print(msg.arg)
1446             end
1447             wmgr:window_request(msg.arg, a, 0)
1448         elseif msg.command == 0x10020 then   -- ico SHOW_LAYER command
1449             msg.arg.visible = 1
1450             if verbose > 2 then
1451                 print('### ==> SHOW_LAYER REQUEST')
1452                 print(msg.arg)
1453             end
1454             wmgr:layer_request(msg.arg)
1455         elseif msg.command == 0x10021 then   -- ico HIDE_LAYER command
1456             msg.arg.visible = 0
1457             if verbose > 2 then
1458                 print('### ==> HIDE_LAYER REQUEST')
1459                 print(msg.arg)
1460             end
1461             wmgr:layer_request(msg.arg)
1462         end
1463     end
1464
1465     sc.input_handler = function (self, cid, msg)
1466         if verbose > 0 then
1467             print('### ==> input handler: ' .. command_name(msg.command))
1468             if verbose > 1 then
1469                 print(msg)
1470             end
1471         end
1472         if msg.command == 0x20001 then -- add_input
1473             msg.arg.appid = msg.appid
1474             if verbose > 2 then
1475                 print('### ==> ADD_INPUT REQUEST')
1476                 print(tostring(msg.arg))
1477             end
1478             imgr:input_request(msg.arg)
1479         elseif msg.command == 0x20002 then -- del_input
1480             msg.arg.appid = ''
1481             if verbose > 2 then
1482                 print('### ==> DEL_INPUT REQUEST')
1483                 print(tostring(msg.arg))
1484             end
1485             imgr:input_request(msg.arg)
1486         elseif msg.command == 0x20003 then -- send_input
1487         end
1488     end
1489
1490     sc.user_handler = function (self, cid, msg)
1491         if verbose > 0 then
1492             print('### ==> user handler: ' .. command_name(msg.command))
1493             if verbose > 1 then
1494                 print(msg)
1495             end
1496         end
1497
1498         if not um then
1499             print("User Manager not initialized")
1500             return
1501         end
1502
1503         if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1504             print("command CHANGE_USER")
1505             if not msg.arg then
1506                 print("invalid message")
1507                 return
1508             end
1509
1510             username = msg.arg.user
1511             passwd = msg.arg.pass
1512
1513             if not username then
1514                 username = ""
1515             end
1516
1517             if not passwd then
1518                 passwd = ""
1519             end
1520
1521             success = um:changeUser(username, passwd)
1522
1523             if not success then
1524                 reply = m.JSON({
1525                     appid = msg.appid,
1526                     command = cmd
1527                 })
1528                 if sc:send_message(msg.appid, reply) then
1529                     print('*** sent authentication failed message')
1530                 else
1531                     print('*** failed to send authentication failed message')
1532                 end
1533             end
1534
1535         elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1536             print("command GET_USERLIST")
1537             if not msg.appid then
1538                 print("invalid message")
1539                 return
1540             end
1541
1542             users, currentUser = um:getUserList()
1543
1544             if not users then
1545                 print("failed to get user list")
1546                 return
1547             end
1548
1549             nUsers = 0
1550
1551             for i,v in pairs(users) do
1552                 nUsers = nUsers + 1
1553             end
1554
1555             if not currentUser then
1556                 currentUser = ""
1557             end
1558
1559             if verbose > 1 then
1560                 print("current user: " .. currentUser)
1561                 print("user list:")
1562                 for i,v in pairs(users) do
1563                     print(v)
1564                 end
1565             end
1566
1567             reply = m.JSON({
1568                 appid = msg.appid,
1569                 command = cmd,
1570                 arg = m.JSON({
1571                     user_num = nUsers,
1572                     user_list = users,
1573                     user_login = currentUser
1574                 })
1575             })
1576
1577             if verbose > 1 then
1578                 print("### <== GetUserList reply: " .. tostring(reply))
1579             end
1580
1581             if sc:send_message(msg.appid, reply) then
1582                 print('*** reply OK')
1583             else
1584                 print('*** reply FAILED')
1585             end
1586
1587         elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1588             print("command GET_LASTINFO")
1589             if not msg.appid then
1590                 print("invalid message")
1591                 return
1592             end
1593
1594             lastInfo = um:getLastInfo(msg.appid)
1595
1596             if not lastInfo then
1597                 print("failed to get last info for app" .. msg.appid)
1598                 return
1599             end
1600
1601             reply = m.JSON({
1602                 appid = msg.appid,
1603                 command = cmd,
1604                 arg = m.JSON({
1605                     lastinfo = lastinfo
1606                 })
1607             })
1608
1609             if sc:send_message(msg.appid, reply) then
1610                 print('*** reply OK')
1611             else
1612                 print('*** reply FAILED')
1613             end
1614
1615         elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1616             print("command SET_LASTINFO")
1617             if not msg.arg or not msg.appid then
1618                 print("invalid message")
1619                 return
1620             end
1621
1622             lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1623         end
1624     end
1625
1626     sc.resource_handler = function (self, cid, msg)
1627         if verbose > 0 then
1628             print('### ==> resource handler: ' .. command_name(msg.command))
1629             if verbose > 1 then
1630                 print(msg)
1631             end
1632         end
1633
1634         createResourceSet = function (ctl, client, msg)
1635             cb = function(rset, data)
1636                 print("> resource callback")
1637
1638                 -- type is either basic (0) or interrupt (1)
1639                 requestType = 0
1640                 if msg.res.type then
1641                     requestType = msg.res.type
1642                 end
1643
1644                 if rset.acquired then
1645                     cmd = 0x00040001 -- acquire
1646                 else
1647                     cmd = 0x00040002 -- release
1648                 end
1649
1650                 reply = m.JSON({
1651                         appid = data.client,
1652                         command = cmd,
1653                         res = {
1654                             type = requestType
1655                         }
1656                     })
1657
1658                 if rset.resources.audio_playback then
1659                     reply.res.sound = {
1660                         zone = "driver",
1661                         name = msg.appid,
1662                         adjust = 0,
1663                         -- id = "0"
1664                     }
1665                 end
1666
1667                 if rset.resources.display then
1668                     reply.res.window = {
1669                         zone = "driver",
1670                         name = msg.appid,
1671                         -- id = "0"
1672                     }
1673                 end
1674
1675                 if rset.resources.input then
1676                     reply.res.input = {
1677                         name = msg.appid,
1678                         event = 0
1679                     }
1680                 end
1681                 print("sending message to client: " .. data.client)
1682
1683                 if sc:send_message(data.client, reply) then
1684                     print('*** reply OK')
1685                 else
1686                     print('*** reply FAILED')
1687                 end
1688             end
1689
1690             rset = m:ResourceSet({
1691                     application_class = "player",
1692                     zone = "driver", -- msg.zone ("full")
1693                     callback = cb
1694                 })
1695
1696             rset.data = {
1697                 cid = cid,
1698                 ctl = ctl
1699             }
1700
1701             if msg.res.sound then
1702                 rset:addResource({
1703                         resource_name = "audio_playback"
1704                     })
1705                 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1706                 rset.resources.audio_playback.attributes.appid = msg.appid
1707                 print("sound name: " .. msg.res.sound.name)
1708                 print("sound zone:" .. msg.res.sound.zone)
1709                 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1710                 if msg.res.sound.id then
1711                     print("sound id: " .. msg.res.sound.id)
1712                 end
1713             end
1714
1715             if msg.res.input then
1716                 rset:addResource({
1717                         resource_name = "input"
1718                     })
1719                 rset.resources.input.attributes.pid = tostring(msg.pid)
1720                 rset.resources.input.attributes.appid = msg.appid
1721                 print("input name: " .. msg.res.sound.name)
1722                 print("input event:" .. tostring(msg.res.input.event))
1723             end
1724
1725             if msg.res.window then
1726                 rset:addResource({
1727                         resource_name = "display"
1728                     })
1729                 rset.resources.display.attributes.pid = tostring(msg.pid)
1730                 rset.resources.display.attributes.appid = msg.appid
1731                 print("display name: " .. msg.res.display.name)
1732                 print("display zone:" .. msg.res.display.zone)
1733                 if msg.res.display.id then
1734                     print("display id: " .. msg.res.display.id)
1735                 end
1736             end
1737
1738             return rset
1739         end
1740
1741         -- parse the message
1742
1743         -- fields common to all messages:
1744         --      msg.command
1745         --      msg.appid
1746         --      msg.pid
1747
1748         if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1749             print("command CREATE")
1750
1751             if not sets.cid then
1752                 sets.cid = createResourceSet(self, cid, msg)
1753             end
1754
1755         elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1756             print("command DESTROY")
1757
1758             if sets.cid then
1759                 sets.cid:release()
1760             end
1761
1762             sets.cid = nil -- garbage collecting
1763
1764         elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1765             print("command ACQUIRE")
1766
1767             if not sets.cid then
1768                 sets.cid = createResourceSet(self, cid, msg)
1769             end
1770
1771             sets.cid:acquire()
1772
1773         elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1774             print("command RELEASE")
1775
1776             if sets.cid then
1777                 sets.cid:release()
1778             end
1779
1780         elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1781             print("command DEPRIVE")
1782
1783         elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1784             print("command WAITING")
1785
1786         elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1787             print("command REVERT")
1788         end
1789     end
1790
1791     sc.inputdev_handler = function (self, cid, msg)
1792         if verbose > 0 then
1793             print('*** inputdev handler: ' .. command_name(msg.command))
1794             if verbose > 1 then
1795                 print(msg)
1796             end
1797         end
1798     end
1799 end