1 with_system_controller = false
7 -- try loading the various logging plugins
8 m:try_load_plugin('systemd')
9 m:try_load_plugin('dlog')
11 -- load the console plugin
12 m:try_load_plugin('console')
14 m:try_load_plugin('console.disabled', 'webconsole', {
15 address = 'wsck:127.0.0.1:3000/murphy',
16 httpdir = '/usr/share/murphy/webconsole' });
18 -- load the dbus plugin
19 if m:plugin_exists('dbus') then
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")
28 m:info("No native resource plugin found...")
31 -- load the dbus resource plugin
32 m:try_load_plugin('resource-dbus', {
34 dbus_service = "org.Murphy",
36 default_zone = "driver",
37 default_class = "implicit"
40 -- load the domain control plugin
41 if m:plugin_exists('domain-control') then
42 m:load_plugin('domain-control')
44 m:info("No domain-control plugin found...")
47 if m:plugin_exists('glib') then
50 m:info("No glib plugin found...")
53 -- load the AMB plugin
54 if m:plugin_exists('amb') then
55 m:try_load_plugin('amb')
57 if builtin.method.amb_initiate and
58 builtin.method.amb_update
63 m:info("No amb plugin found...")
66 -- load the ASM resource plugin
67 if m:plugin_exists('resource-asm') then
68 m:try_load_plugin('resource-asm', {
70 share_mmplayer = "player:AVP,mandatory,exclusive,strict",
71 ignored_argv0 = "WebProcess"
74 m:info("No audio session manager plugin found...")
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
84 -- define application classes
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" }
138 -- define zone attributes
140 type = {mdb.string, "common", "rw"},
141 location = {mdb.string, "anywhere", "rw"}
149 location = "front-left"
157 location = "front-right"
165 location = "back-left"
173 location = "back-right"
181 location = "back-left"
186 -- define resource classes
187 if not m:plugin_exists('ivi-resource-manager') and
188 not with_system_controller
191 name = "audio_playback",
194 role = { mdb.string, "music", "rw" },
195 pid = { mdb.string, "<unknown>", "rw" },
196 policy = { mdb.string, "relaxed", "rw" }
202 name = "audio_recording",
205 role = { mdb.string, "music" , "rw" },
206 pid = { mdb.string, "<unknown>", "rw" },
207 policy = { mdb.string, "relaxed" , "rw" }
212 name = "video_playback",
217 name = "video_recording",
221 if not m:plugin_exists('ivi-resource-manager') and
222 not with_system_controller
224 resource.method.veto = {
225 function(zone, rset, grant, owners, req_set)
231 -- test for creating selections
233 name = "audio_owner",
234 table = "audio_playback_owner",
235 columns = {"application_class"},
236 condition = "zone_name = 'driver'"
240 name = "vehicle_speed",
241 table = "amb_vehicle_speed",
243 condition = "key = 'VehicleSpeed'"
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}},
258 update = function(self)
259 speed = self.inputs.speed.single_value
261 volume = (speed - 144.0) / 7.0
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})
274 -- Night mode processing chain
277 name = "exterior_brightness",
278 table = "amb_exterior_brightness",
279 columns = { "value" },
280 condition = "key = 'ExteriorBrightness'"
285 inputs = { brightness = mdb.select.exterior_brightness },
289 name = "amb_nightmode",
293 { "id", mdb.unsigned },
294 { "night_mode", mdb.unsigned }
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.
302 brightness = self.inputs.brightness.single_value
304 if not brightness then
308 print("*** element "..self.name.." update brightness: "..brightness)
310 if brightness > 300 then
316 print("*** resulting mode: ".. mode)
318 if not (mode == self.oldmode) then
319 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
327 name = "select_night_mode",
328 table = "amb_nightmode",
329 columns = { "night_mode" },
336 inputs = { owner = mdb.select.select_night_mode },
337 property = "NightMode",
339 initiate = builtin.method.amb_initiate,
340 update = builtin.method.amb_update
344 -- Night mode general handlers
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 print("Night mode initiated: " .. tostring(data))
354 update = function(self)
355 data = mdb.select.select_night_mode.single_value
356 print("Night mode updated: " .. tostring(data))
359 -- tell homescreen that night mode was updated
360 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=2,state=data})}))
366 -- Driving mode processing chain
369 name = "drivingmode",
370 inputs = { speed = mdb.select.vehicle_speed },
374 name = "amb_drivingmode",
378 { "id", mdb.unsigned },
379 { "driving_mode", mdb.unsigned }
383 update = function(self)
385 speed = self.inputs.speed.single_value
397 if not (mode == self.oldmode) then
398 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
406 name = "select_driving_mode",
407 table = "amb_drivingmode",
408 columns = { "driving_mode" },
414 name = "driving_mode",
415 inputs = { owner = mdb.select.select_driving_mode },
416 property = "DrivingMode",
418 initiate = builtin.method.amb_initiate,
419 update = builtin.method.amb_update
423 -- turn signals (left, right)
427 table = "amb_turn_signal",
428 columns = { "value" },
429 condition = "key = 'TurnSignal'"
432 -- regulation (on), use "select_driving_mode"
435 name = "driving_regulation",
436 inputs = { owner = mdb.select.select_driving_mode },
437 initiate = function(self)
438 data = mdb.select.select_driving_mode.single_value
439 print("Driving mode initiated: " .. tostring(data))
442 update = function(self)
443 data = mdb.select.select_driving_mode.single_value
444 print("Driving mode updated: " .. tostring(data))
447 -- tell homescreen that driving mode was updated
448 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=1,state=data})}))
454 -- shift position (parking, reverse, other)
457 name = "gear_position",
458 table = "amb_gear_position",
459 columns = { "value" },
460 condition = "key = 'GearPosition'"
463 -- cameras (back, front, left, right)
466 name = "camera_state",
467 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
471 name = "target_camera_state",
475 { "id", mdb.unsigned },
476 { "front_camera", mdb.unsigned },
477 { "back_camera", mdb.unsigned },
478 { "right_camera", mdb.unsigned },
479 { "left_camera", mdb.unsigned }
483 update = function(self)
490 if self.inputs.gear == 128 then
492 elseif self.inputs.winker == 1 then
494 elseif self.inputs.winker == 2 then
498 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
503 -- load the telephony plugin
504 m:try_load_plugin('telephony')
507 -- system controller test setup
509 if not with_system_controller then
513 m:load_plugin('system-controller')
515 window_manager_operation_names = {
520 function window_manager_operation_name(oper)
521 local name = window_manager_operation_names[oper]
522 if name then return name end
523 return "<unknown " .. tostring(oper) .. ">"
526 window_operation_names = {
535 function window_operation_name(oper)
536 local name = window_operation_names[oper]
537 if name then return name end
538 return "<unknown " .. tostring(oper) .. ">"
541 layer_operation_names = {
547 function layer_operation_name(oper)
548 local name = layer_operation_names[oper]
549 if name then return name end
550 return "<unknown " .. tostring(oper) .. ">"
553 input_manager_operation_names = {
559 function input_manager_operation_name(oper)
560 local name = input_manager_operation_names[oper]
561 if name then return name end
562 return "<unknown " .. tostring(oper) .. ">"
565 input_operation_names = {
571 function input_operation_name(oper)
572 local name = input_operation_names[oper]
573 if name then return name end
574 return "<unknown " .. tostring(oper) .. ">"
577 code_operation_names = {
583 function code_operation_name(oper)
584 local name = code_operation_names[oper]
585 if name then return name end
586 return "<unknown " .. tostring(oper) .. ">"
590 [0x00001] = "send_appid",
591 [0x10001] = "create",
592 [0x10002] = "destroy",
596 [0x10006] = "change_active",
597 [0x10007] = "change_layer",
598 [0x10008] = "change_attr",
600 [0x10011] = "map_thumb",
601 [0x10012] = "unmap_thumb",
602 [0x10020] = "show layer",
603 [0x10021] = "hide_layer",
604 [0x10022] = "change_layer_attr",
605 [0x20001] = "add_input",
606 [0x20002] = "del_input",
607 [0x20003] = "send_input",
608 [0x40001] = "acquire_res",
609 [0x40002] = "release_res",
610 [0x40003] = "deprive_res",
611 [0x40004] = "waiting_res",
612 [0x40005] = "revert_res",
613 [0x40011] = "create_res",
614 [0x40012] = "destroy_res",
615 [0x50001] = "set_region",
616 [0x50002] = "unset_region",
617 [0x60001] = "change_state"
620 function command_name(command)
621 local name = command_names[command]
622 if name then return name end
623 return "<unknown " .. tostring(command) .. ">"
632 resmgr = resource_manager {
633 screen_event_handler = function(self, ev)
634 local event = ev.event
635 local surface = ev.surface
637 if event == "grant" then
639 print("*** make visible surface "..surface)
641 local a = animation({})
642 local r = m:JSON({surface = surface,
645 wmgr:window_request(r,a,0)
646 elseif event == "revoke" then
648 print("*** hide surface "..surface)
650 local a = animation({})
651 local r = m:JSON({surface = ev.surface,
653 wmgr:window_request(r,a,0)
656 print("*** screen resource event: " ..
661 audio_event_handler = function(self, ev)
662 local event = ev.event
663 local appid = ev.appid
664 local audioid = ev.audioid
666 if event == "grant" then
667 if verbose > 0 or true then
668 print("*** grant audio to "..appid..
669 " ("..audioid..") in '" ..
672 elseif event == "revoke" then
673 if verbose > 0 or true then
674 print("*** revoke audio from "..appid..
675 " ("..audioid..") in '" ..
679 if verbose > 0 or true then
680 print("*** audio resource event: " ..
687 resclnt = resource_client {}
689 wmgr = window_manager {
690 geometry = function(self, w,h, v)
691 if type(v) == "function" then
697 application = function(self, appid)
699 local app = application_lookup(appid)
701 app = application_lookup("default")
705 return { privileges = {screen="none", audio="none"} }
708 outputs = { { name = "Center",
715 width = function(w,h) return w end,
722 width = function(w,h) return w end,
723 height = function(w,h) return h-64-128 end
729 width = function(w,h) return w end,
730 height = function(w,h) return (h-64-128)/2 end
735 pos_y = function(w,h) return (h-64-128)/2+64 end,
736 width = function(w,h) return w end,
737 height = function(w,h) return (h-64-128)/2 end
743 width = function(w,h) return w/2 end,
744 height = function(w,h) return (h-64-128)/2 end
748 pos_x = function(w,h) return w/2 end,
750 width = function(w,h) return w/2 end,
751 height = function(w,h) return (h-64-128)/2 end
756 pos_y = function(w,h) return (h-64-128/2)+64 end,
757 width = function(w,h) return w/2 end,
758 height = function(w,h) return (h-64-128)/2 end
762 pos_x = function(w,h) return w/2 end,
763 pos_y = function(w,h) return (h-64-128/2)+64 end,
764 width = function(w,h) return w/2 end,
765 height = function(w,h) return (h-64-128)/2 end
771 width = function(w,h) return w end,
772 height = function(w,h) return h-64-128 end
778 width = function(w,h) return w/2-181 end,
779 height = function(w,h) return h-64-128 end
783 pos_x = function(w,h) return w/2+181 end,
785 width = function(w,h) return w/2-181 end,
786 height = function(w,h) return h-64-128 end
796 layers = { { 0, "Background" , 1 },
797 { 1, "Application" , 2 },
798 { 2, "Softkeyboard" , 4 },
799 { 3, "HomeScreen" , 2 },
800 { 4, "ControlBar" , 2 },
801 { 5, "InterruptApp" , 2 },
802 { 6, "OnScreen" , 2 },
803 { 101, "Input" , 3 },
804 { 102, "Cursor" , 5 },
805 { 103, "Startup" , 6 },
806 { 0x1000, "Background" , 1 },
807 { 0x2000, "Normal" , 2 },
808 { 0x3000, "Fullscreen" , 2 },
809 { 0x4000, "InputPanel" , 3 },
810 { 0xA000, "Touch" , 4 },
811 { 0xB000, "Cursor" , 5 },
812 { 0xC000, "Startup" , 6 }
816 manager_update = function(self, oper)
818 print("### <== WINDOW MANAGER UPDATE:" ..
819 window_manager_operation_name(oper))
822 local umask = window_mask { raise = true,
825 local rmask = window_mask { active = true }
827 passthrough_update = umask:tointeger(),
828 passthrough_request = rmask:tointeger()
830 self:manager_request(req)
834 window_update = function(self, oper, win, mask)
836 print("### <== WINDOW UPDATE oper:" ..
837 window_operation_name(oper) ..
838 " mask: " .. tostring(mask))
844 local arg = m:JSON({ surface = win.surface,
849 if oper == 1 then -- create
850 local layertype = win.layertype
851 if layertype and input_layer[layertype] then
853 print("ignoring input panel creation")
858 elseif oper == 2 then -- destroy
860 elseif oper == 3 then -- namechange
862 elseif oper == 4 or oper == 5 then --visible or configure
866 arg.layer = win.layer
867 arg.pos_x = win.pos_x
868 arg.pos_y = win.pos_y
869 arg.width = win.width
870 arg.height = win.height
871 arg.raise = win.raise
872 arg.visible = win.visible
873 arg.active = win.active
874 elseif oper == 6 then -- active
876 arg.active = win.active
879 print("### nothing to do")
884 local msg = m:JSON({ command = command,
890 print("### <== sending " ..
891 command_name(msg.command) ..
892 " window message to '" .. win.name .. "'")
897 sc:send_message(homescreen, msg)
899 if oper == 1 then -- create
900 local i = input_layer[win.layertype]
901 local p = self:application(win.appid)
902 local s = p.privileges.screen
904 if s == "system" then
905 local a = animation({})
906 local r = m:JSON({surface = win.surface,
909 self:window_request(r,a,0)
913 print("do not make resource for " ..
917 resclnt:resource_set_create("screen",
923 elseif oper == 2 then -- destroy
924 resclnt:resource_set_destroy("screen", win.surface)
925 elseif oper == 6 then -- active
927 local i = input_layer[win.layertype]
928 local p = self:application(win.appid)
929 local s = p.privileges.screen
930 local surface = win.surface
931 if not i and s ~= "system" then
932 resclnt:resource_set_acquire("screen",surface)
933 resmgr:window_raise(win.appid, surface, 1)
939 layer_update = function(self, oper, layer, mask)
941 print("### LAYER UPDATE:" ..
942 layer_operation_name(oper) ..
943 " mask: " .. tostring(mask))
948 if oper == 3 then -- visible
949 local command = 0x10022
953 arg = m:JSON({layer = layer.id,
954 visible = layer.visible
958 print("### <== sending "..command_name(command)..
964 sc:send_message(homescreen, msg)
967 print("### nothing to do")
972 output_update = function(self, oper, out, mask)
973 local idx = out.index
975 print("### OUTPUT UPDATE:" .. oper ..
976 " mask: "..tostring(mask))
979 local outdef = self.outputs[idx+1]
980 if (oper == 1) then -- create
982 self:output_request(m:JSON({index = idx,
987 elseif (oper == 5) then -- done
988 local ads = outdef.areas
989 local on = outdef.name
991 for name,ad in pairs(ads) do
992 local can = wmgr:canonical_name(on.."."..name)
993 local a = m:JSON({name = name,
995 for fld,val in pairs(ad) do
996 a[fld] = self:geometry(out.width,
1001 resmgr:area_create(area[can], outdef.zone)
1009 imgr = input_manager {
1010 inputs = {{ name = "G27 Racing Wheel",
1012 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1013 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1014 [4] = {appid="org.tizen.ico.app-soundsample" },
1015 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1019 manager_update = function(self, oper)
1021 print("### <== INPUT MANAGER UPDATE:" ..
1022 input_manager_operation_name(oper))
1026 input_update = function(self, oper, inp, mask)
1028 print("### INPUT UPDATE:" ..
1029 input_operation_name(oper) ..
1030 " mask: " .. tostring(mask))
1036 code_update = function(self, oper, code, mask)
1038 print("### CODE UPDATE: mask: " .. tostring(mask))
1043 local msg = m:JSON({ command = 1,
1044 appid = "org.tizen.ico.homescreen",
1045 arg = m:JSON({ device = code.device,
1053 print("### <== sending " ..
1054 command_name(msg.command) ..
1060 sc:send_message(homescreen, msg)
1064 sc = m:get_system_controller()
1070 um = m:UserManager()
1075 -- these shoud be before wmgr:connect() is called
1077 print("====== creating applications ======")
1081 area = "Center.Full",
1082 privileges = { screen = "none", audio = "none" },
1083 resource_class = "player",
1089 area = "Center.Full",
1090 privileges = { screen = "system", audio = "none" },
1091 resource_class = "implicit",
1092 screen_priority = 30
1096 appid = "org.tizen.ico.homescreen",
1097 area = "Center.Full",
1098 privileges = { screen = "system", audio = "system" },
1099 resource_class = "player",
1100 screen_priority = 20
1104 appid = "org.tizen.ico.statusbar",
1105 area = "Center.Status",
1106 privileges = { screen = "system", audio = "none" },
1107 resource_class = "player",
1108 screen_priority = 20
1112 appid = "org.tizen.ico.login",
1113 area = "Center.Full",
1114 privileges = { screen = "system", audio = "system" },
1115 resource_class = "player",
1116 screen_priority = 20
1120 appid = "org.tizen.ico.camera_left",
1121 area = "Center.SysApp.Left",
1122 privileges = { screen = "system", audio = "none" },
1123 requisites = { screen = "blinker_left", audio = "none" },
1124 resource_class = "player",
1125 screen_priority = 30
1130 appid = "org.tizen.ico.camera_right",
1131 area = "Center.SysApp.Right",
1132 privileges = { screen = "system", audio = "none" },
1133 requisites = { screen = "blinker_right", audio = "none" },
1134 resource_class = "player",
1135 screen_priority = 30
1140 sc.client_handler = function (self, cid, msg)
1141 local command = msg.command
1143 print('### ==> client handler:')
1148 if not connected then
1149 print('Setting homescreen='..msg.appid)
1150 homescreen = msg.appid
1151 print('Trying to connect to wayland...')
1152 connected = wmgr:connect()
1154 if connected and command then
1155 if command == 1 then -- send_appid
1156 local driving_mode = mdb.select.select_driving_mode.single_value
1157 local night_mode = mdb.select.select_night_mode.single_value
1159 if not driving_mode then driving_mode = 0 end
1160 if not night_mode then night_mode = 0 end
1162 local reply = m:JSON({ command = 0x60001,
1163 arg = m:JSON({ stateid = 1,
1164 state = driving_mode})
1167 print("### <== sending " ..
1168 command_name(command) .. " message")
1173 sc:send_message(homescreen, reply)
1175 reply = m:JSON({ command = 0x60001,
1176 arg = m:JSON({ stateid = 2,
1177 state = night_mode})
1180 print("### <== sending " ..
1181 command_name(command) .. " message")
1186 sc:send_message(homescreen, reply)
1191 sc.generic_handler = function (self, cid, msg)
1193 print('### ==> generic handler:')
1200 sc.window_handler = function (self, cid, msg)
1202 print('### ==> received ' ..
1203 command_name(msg.command) .. ' message')
1205 print(tostring(msg))
1209 local a = animation({})
1211 if msg.command == 0x10003 then -- ico SHOW command
1212 local raise_mask = 0x01000000
1213 local lower_mask = 0x02000000
1214 local nores_mask = 0x40000000
1215 local time_mask = 0x00ffffff
1219 if msg.arg.anim_time then
1220 local t = msg.arg.anim_time
1221 time = m:AND(t, time_mask)
1222 nores = m:AND(t, nores_mask)
1223 if m:AND(t, raise_mask) then
1225 elseif m:AND(t, lower_mask) then
1229 if msg.arg.anim_name then
1230 a.show = { msg.arg.anim_name, time }
1231 print('time: ' .. tostring(a.show[2]))
1235 local p = wmgr:application(msg.appid)
1236 local s = p.privileges.screen
1237 if s == "system" then
1242 print('### ==> SHOW')
1243 print(tostring(msg.arg))
1246 wmgr:window_request(msg.arg, a, 0)
1248 local surface = msg.arg.surface
1249 resclnt:resource_set_acquire("screen", surface)
1250 resmgr:window_raise(msg.appid, surface, 1)
1252 elseif msg.command == 0x10004 then -- ico HIDE command
1253 local raise_mask = 0x01000000
1254 local lower_mask = 0x02000000
1255 local nores_mask = 0x40000000
1256 local time_mask = 0x00ffffff
1260 if msg.arg.anim_time then
1261 local t = msg.arg.anim_time
1262 time = m:AND(t, time_mask)
1263 nores = m:AND(t, nores_mask)
1265 if msg.arg.anim_name then
1266 a.hide = { msg.arg.anim_name, time }
1267 print('hide animation time: ' .. tostring(a.hide[2]))
1271 local p = wmgr:application(msg.appid)
1272 local s = p.privileges.screen
1273 if s == "system" then
1278 print('### ==> HIDE REQUEST')
1279 print(tostring(msg.arg))
1282 wmgr:window_request(msg.arg, a, 0)
1284 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1286 elseif msg.command == 0x10005 then -- ico MOVE
1288 print('### ==> MOVE REQUEST')
1289 print(tostring(msg.arg))
1291 wmgr:window_request(msg.arg, a, 0)
1292 -- TODO: handle if area changed
1293 elseif msg.command == 0x10006 then -- ico ACTIVE
1294 if not msg.arg.active then
1295 msg.arg.active = 3 -- pointer + keyboard
1298 print('### ==> ACTIVE REQUEST')
1299 print(tostring(msg.arg))
1301 wmgr:window_request(msg.arg, a, 0)
1302 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1304 print('### ==> CHANGE_LAYER REQUEST')
1305 print(tostring(msg.arg))
1308 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1309 print("do not change layer for other than cursor or touch")
1313 wmgr:window_request(msg.arg, a, 0)
1314 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1315 local framerate = msg.arg.framerate
1316 if not framerate or framerate < 0 then
1321 print('### ==> MAP_THUMB REQUEST')
1323 print('framerate: '..framerate)
1325 wmgr:window_request(msg.arg, a, framerate)
1326 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1329 print('### ==> UNMAP_THUMB REQUEST')
1332 wmgr:window_request(msg.arg, a, 0)
1333 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1336 print('### ==> SHOW_LAYER REQUEST')
1339 wmgr:layer_request(msg.arg)
1340 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1343 print('### ==> HIDE_LAYER REQUEST')
1346 wmgr:layer_request(msg.arg)
1350 sc.input_handler = function (self, cid, msg)
1352 print('### ==> input handler: ' .. command_name(msg.command))
1357 if msg.command == 0x20001 then -- add_input
1358 msg.arg.appid = msg.appid
1360 print('### ==> ADD_INPUT REQUEST')
1361 print(tostring(msg.arg))
1363 imgr:input_request(msg.arg)
1364 elseif msg.command == 0x20002 then -- del_input
1367 print('### ==> DEL_INPUT REQUEST')
1368 print(tostring(msg.arg))
1370 imgr:input_request(msg.arg)
1371 elseif msg.command == 0x20003 then -- send_input
1375 sc.user_handler = function (self, cid, msg)
1377 print('### ==> user handler: ' .. command_name(msg.command))
1384 print("User Manager not initialized")
1388 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1389 print("command CHANGE_USER")
1391 print("invalid message")
1395 username = msg.arg.user
1396 passwd = msg.arg.pass
1398 if not username then
1406 success = um:changeUser(username, passwd)
1413 if sc:send_message(msg.appid, reply) then
1414 print('*** sent authentication failed message')
1416 print('*** failed to send authentication failed message')
1420 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1421 print("command GET_USERLIST")
1422 if not msg.appid then
1423 print("invalid message")
1427 users, currentUser = um:getUserList()
1430 print("failed to get user list")
1436 for i,v in pairs(users) do
1440 if not currentUser then
1445 print("current user: " .. currentUser)
1447 for i,v in pairs(users) do
1458 user_login = currentUser
1463 print("### <== GetUserList reply: " .. tostring(reply))
1466 if sc:send_message(msg.appid, reply) then
1467 print('*** reply OK')
1469 print('*** reply FAILED')
1472 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1473 print("command GET_LASTINFO")
1474 if not msg.appid then
1475 print("invalid message")
1479 lastInfo = um:getLastInfo(msg.appid)
1481 if not lastInfo then
1482 print("failed to get last info for app" .. msg.appid)
1494 if sc:send_message(msg.appid, reply) then
1495 print('*** reply OK')
1497 print('*** reply FAILED')
1500 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1501 print("command SET_LASTINFO")
1502 if not msg.arg or not msg.appid then
1503 print("invalid message")
1507 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1511 sc.resource_handler = function (self, cid, msg)
1513 print('### ==> resource handler: ' .. command_name(msg.command))
1519 createResourceSet = function (ctl, client, msg)
1520 cb = function(rset, data)
1521 print("> resource callback")
1523 -- type is either basic (0) or interrupt (1)
1525 if msg.res.type then
1526 requestType = msg.res.type
1529 if rset.acquired then
1530 cmd = 0x00040001 -- acquire
1532 cmd = 0x00040002 -- release
1536 appid = data.client,
1543 if rset.resources.audio_playback then
1552 if rset.resources.display then
1553 reply.res.window = {
1560 if rset.resources.input then
1566 print("sending message to client: " .. data.client)
1568 if sc:send_message(data.client, reply) then
1569 print('*** reply OK')
1571 print('*** reply FAILED')
1575 rset = m:ResourceSet({
1576 application_class = "player",
1577 zone = "driver", -- msg.zone ("full")
1586 if msg.res.sound then
1588 resource_name = "audio_playback"
1590 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1591 rset.resources.audio_playback.attributes.appid = msg.appid
1592 print("sound name: " .. msg.res.sound.name)
1593 print("sound zone:" .. msg.res.sound.zone)
1594 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1595 if msg.res.sound.id then
1596 print("sound id: " .. msg.res.sound.id)
1600 if msg.res.input then
1602 resource_name = "input"
1604 rset.resources.input.attributes.pid = tostring(msg.pid)
1605 rset.resources.input.attributes.appid = msg.appid
1606 print("input name: " .. msg.res.sound.name)
1607 print("input event:" .. tostring(msg.res.input.event))
1610 if msg.res.window then
1612 resource_name = "display"
1614 rset.resources.display.attributes.pid = tostring(msg.pid)
1615 rset.resources.display.attributes.appid = msg.appid
1616 print("display name: " .. msg.res.display.name)
1617 print("display zone:" .. msg.res.display.zone)
1618 if msg.res.display.id then
1619 print("display id: " .. msg.res.display.id)
1626 -- parse the message
1628 -- fields common to all messages:
1633 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1634 print("command CREATE")
1636 if not sets.cid then
1637 sets.cid = createResourceSet(self, cid, msg)
1640 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1641 print("command DESTROY")
1647 sets.cid = nil -- garbage collecting
1649 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1650 print("command ACQUIRE")
1652 if not sets.cid then
1653 sets.cid = createResourceSet(self, cid, msg)
1658 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1659 print("command RELEASE")
1665 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1666 print("command DEPRIVE")
1668 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1669 print("command WAITING")
1671 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1672 print("command REVERT")
1676 sc.inputdev_handler = function (self, cid, msg)
1678 print('*** inputdev handler: ' .. command_name(msg.command))