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 -- load the AMB plugin
48 if m:plugin_exists('amb') then
49 m:try_load_plugin('amb')
51 if builtin.method.amb_initiate and
52 builtin.method.amb_update
57 m:info("No amb plugin found...")
60 -- load the ASM resource plugin
61 if m:plugin_exists('resource-asm') then
62 m:try_load_plugin('resource-asm', {
64 share_mmplayer = "player:AVP,mandatory,exclusive,strict",
65 ignored_argv0 = "WebProcess"
68 m:info("No audio session manager plugin found...")
71 if m:plugin_exists('system-controller') then
72 with_system_controller = true
73 elseif m:plugin_exists('ivi-resource-manager') then
74 m:load_plugin('ivi-resource-manager')
75 with_system_controller = false
78 -- define application classes
125 application_class { name="event" , priority=4 , modal=false, share=true , order="fifo" }
126 application_class { name="game" , priority=3 , modal=false, share=false, order="lifo" }
127 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
128 --#application_class { name="basic" , priority=2 , modal=false, share=false, order="lifo" }
129 application_class { name="player" , priority=1 , modal=false, share=true , order="lifo" }
130 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
132 -- define zone attributes
134 type = {mdb.string, "common", "rw"},
135 location = {mdb.string, "anywhere", "rw"}
143 location = "front-left"
151 location = "front-right"
159 location = "back-left"
167 location = "back-right"
175 location = "back-left"
180 -- define resource classes
181 if not m:plugin_exists('ivi-resource-manager') and
182 not with_system_controller
185 name = "audio_playback",
188 role = { mdb.string, "music", "rw" },
189 pid = { mdb.string, "<unknown>", "rw" },
190 policy = { mdb.string, "relaxed", "rw" }
196 name = "audio_recording",
199 role = { mdb.string, "music" , "rw" },
200 pid = { mdb.string, "<unknown>", "rw" },
201 policy = { mdb.string, "relaxed" , "rw" }
206 name = "video_playback",
211 name = "video_recording",
215 if not m:plugin_exists('ivi-resource-manager') and
216 not with_system_controller
218 resource.method.veto = {
219 function(zone, rset, grant, owners, req_set)
225 -- test for creating selections
227 name = "audio_owner",
228 table = "audio_playback_owner",
229 columns = {"application_class"},
230 condition = "zone_name = 'driver'"
234 name = "vehicle_speed",
235 table = "amb_vehicle_speed",
237 condition = "key = 'VehicleSpeed'"
241 name = "speed2volume",
242 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
243 outputs = { mdb.table { name = "speedvol",
244 index = {"zone", "device"},
245 columns = {{"zone", mdb.string, 16},
246 {"device", mdb.string, 16},
247 {"value", mdb.floating}},
252 update = function(self)
253 speed = self.inputs.speed.single_value
255 volume = (speed - 144.0) / 7.0
259 diff = volume - self.oldvolume
260 if (diff*diff > self.inputs.param) then
261 print("*** element "..self.name.." update "..volume)
262 self.oldvolume = volume
263 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
268 -- Night mode processing chain
271 name = "exterior_brightness",
272 table = "amb_exterior_brightness",
273 columns = { "value" },
274 condition = "key = 'ExteriorBrightness'"
279 inputs = { brightness = mdb.select.exterior_brightness },
283 name = "amb_nightmode",
287 { "id", mdb.unsigned },
288 { "night_mode", mdb.unsigned }
292 update = function(self)
293 -- This is a trivial function to calculate night mode. Later, we will
294 -- need a better threshold value and hysteresis to prevent oscillation.
296 brightness = self.inputs.brightness.single_value
298 if not brightness then
302 print("*** element "..self.name.." update brightness: "..brightness)
304 if brightness > 300 then
310 print("*** resulting mode: ".. mode)
312 if not (mode == self.oldmode) then
313 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
321 name = "select_night_mode",
322 table = "amb_nightmode",
323 columns = { "night_mode" },
330 inputs = { owner = mdb.select.select_night_mode },
331 property = "NightMode",
333 initiate = builtin.method.amb_initiate,
334 update = builtin.method.amb_update
338 -- Night mode general handlers
341 name = "nightmode_homescreen",
342 inputs = { owner = mdb.select.select_night_mode },
343 initiate = function(self)
344 data = mdb.select.select_night_mode.single_value
345 print("Night mode initiated: " .. tostring(data))
348 update = function(self)
349 data = mdb.select.select_night_mode.single_value
350 print("Night mode updated: " .. tostring(data))
353 -- tell homescreen that night mode was updated
354 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=2,state=data})}))
360 -- Driving mode processing chain
363 name = "drivingmode",
364 inputs = { speed = mdb.select.vehicle_speed },
368 name = "amb_drivingmode",
372 { "id", mdb.unsigned },
373 { "driving_mode", mdb.unsigned }
377 update = function(self)
379 speed = self.inputs.speed.single_value
391 if not (mode == self.oldmode) then
392 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
400 name = "select_driving_mode",
401 table = "amb_drivingmode",
402 columns = { "driving_mode" },
408 name = "driving_mode",
409 inputs = { owner = mdb.select.select_driving_mode },
410 property = "DrivingMode",
412 initiate = builtin.method.amb_initiate,
413 update = builtin.method.amb_update
417 -- turn signals (left, right)
421 table = "amb_turn_signal",
422 columns = { "value" },
423 condition = "key = 'TurnSignal'"
426 -- regulation (on), use "select_driving_mode"
429 name = "driving_regulation",
430 inputs = { owner = mdb.select.select_driving_mode },
431 initiate = function(self)
432 data = mdb.select.select_driving_mode.single_value
433 print("Driving mode initiated: " .. tostring(data))
436 update = function(self)
437 data = mdb.select.select_driving_mode.single_value
438 print("Driving mode updated: " .. tostring(data))
441 -- tell homescreen that driving mode was updated
442 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=1,state=data})}))
448 -- shift position (parking, reverse, other)
451 name = "gear_position",
452 table = "amb_gear_position",
453 columns = { "value" },
454 condition = "key = 'GearPosition'"
457 -- cameras (back, front, left, right)
460 name = "camera_state",
461 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
465 name = "target_camera_state",
469 { "id", mdb.unsigned },
470 { "front_camera", mdb.unsigned },
471 { "back_camera", mdb.unsigned },
472 { "right_camera", mdb.unsigned },
473 { "left_camera", mdb.unsigned }
477 update = function(self)
484 if self.inputs.gear == 128 then
486 elseif self.inputs.winker == 1 then
488 elseif self.inputs.winker == 2 then
492 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
497 -- load the telephony plugin
498 m:try_load_plugin('telephony')
501 -- system controller test setup
503 if not with_system_controller then
507 m:load_plugin('system-controller')
509 window_manager_operation_names = {
514 function window_manager_operation_name(oper)
515 local name = window_manager_operation_names[oper]
516 if name then return name end
517 return "<unknown " .. tostring(oper) .. ">"
520 window_operation_names = {
529 function window_operation_name(oper)
530 local name = window_operation_names[oper]
531 if name then return name end
532 return "<unknown " .. tostring(oper) .. ">"
535 layer_operation_names = {
541 function layer_operation_name(oper)
542 local name = layer_operation_names[oper]
543 if name then return name end
544 return "<unknown " .. tostring(oper) .. ">"
547 input_manager_operation_names = {
553 function input_manager_operation_name(oper)
554 local name = input_manager_operation_names[oper]
555 if name then return name end
556 return "<unknown " .. tostring(oper) .. ">"
559 input_operation_names = {
565 function input_operation_name(oper)
566 local name = input_operation_names[oper]
567 if name then return name end
568 return "<unknown " .. tostring(oper) .. ">"
571 code_operation_names = {
577 function code_operation_name(oper)
578 local name = code_operation_names[oper]
579 if name then return name end
580 return "<unknown " .. tostring(oper) .. ">"
584 [0x00001] = "send_appid",
585 [0x10001] = "create",
586 [0x10002] = "destroy",
590 [0x10006] = "change_active",
591 [0x10007] = "change_layer",
592 [0x10008] = "change_attr",
594 [0x10011] = "map_thumb",
595 [0x10012] = "unmap_thumb",
596 [0x10020] = "show layer",
597 [0x10021] = "hide_layer",
598 [0x10022] = "change_layer_attr",
599 [0x20001] = "add_input",
600 [0x20002] = "del_input",
601 [0x20003] = "send_input",
602 [0x40001] = "acquire_res",
603 [0x40002] = "release_res",
604 [0x40003] = "deprive_res",
605 [0x40004] = "waiting_res",
606 [0x40005] = "revert_res",
607 [0x40011] = "create_res",
608 [0x40012] = "destroy_res",
609 [0x50001] = "set_region",
610 [0x50002] = "unset_region",
611 [0x60001] = "change_state"
614 function command_name(command)
615 local name = command_names[command]
616 if name then return name end
617 return "<unknown " .. tostring(command) .. ">"
626 resmgr = resource_manager {
627 screen_event_handler = function(self, ev)
628 local event = ev.event
629 local surface = ev.surface
631 if event == "grant" then
633 print("*** make visible surface "..surface)
635 local a = animation({})
636 local r = m:JSON({surface = surface,
639 wmgr:window_request(r,a,0)
640 elseif event == "revoke" then
642 print("*** hide surface "..surface)
644 local a = animation({})
645 local r = m:JSON({surface = ev.surface,
647 wmgr:window_request(r,a,0)
650 print("*** screen resource event: " ..
655 audio_event_handler = function(self, ev)
656 local event = ev.event
657 local appid = ev.appid
658 local audioid = ev.audioid
660 if event == "grant" then
661 if verbose > 0 or true then
662 print("*** grant audio to "..appid..
663 " ("..audioid..") in '" ..
666 elseif event == "revoke" then
667 if verbose > 0 or true then
668 print("*** revoke audio from "..appid..
669 " ("..audioid..") in '" ..
673 if verbose > 0 or true then
674 print("*** audio resource event: " ..
681 resclnt = resource_client {}
683 wmgr = window_manager {
684 geometry = function(self, w,h, v)
685 if type(v) == "function" then
691 application = function(self, appid)
693 local app = application_lookup(appid)
695 app = application_lookup("default")
699 return { privileges = {screen="none", audio="none"} }
702 outputs = { { name = "Center",
709 width = function(w,h) return w end,
716 width = function(w,h) return w end,
717 height = function(w,h) return h-64-128 end
723 width = function(w,h) return w end,
724 height = function(w,h) return (h-64-128)/2 end
729 pos_y = function(w,h) return (h-64-128)/2+64 end,
730 width = function(w,h) return w end,
731 height = function(w,h) return (h-64-128)/2 end
737 width = function(w,h) return w/2 end,
738 height = function(w,h) return (h-64-128)/2 end
742 pos_x = function(w,h) return w/2 end,
744 width = function(w,h) return w/2 end,
745 height = function(w,h) return (h-64-128)/2 end
750 pos_y = function(w,h) return (h-64-128/2)+64 end,
751 width = function(w,h) return w/2 end,
752 height = function(w,h) return (h-64-128)/2 end
756 pos_x = function(w,h) return w/2 end,
757 pos_y = function(w,h) return (h-64-128/2)+64 end,
758 width = function(w,h) return w/2 end,
759 height = function(w,h) return (h-64-128)/2 end
765 width = function(w,h) return w end,
766 height = function(w,h) return h-64-128 end
772 width = function(w,h) return w/2-181 end,
773 height = function(w,h) return h-64-128 end
777 pos_x = function(w,h) return w/2+181 end,
779 width = function(w,h) return w/2-181 end,
780 height = function(w,h) return h-64-128 end
790 layers = { { 0, "Background" , 1 },
791 { 1, "Application" , 2 },
792 { 2, "Softkeyboard" , 4 },
793 { 3, "HomeScreen" , 2 },
794 { 4, "ControlBar" , 2 },
795 { 5, "InterruptApp" , 2 },
796 { 6, "OnScreen" , 2 },
797 { 101, "Input" , 3 },
798 { 102, "Cursor" , 5 },
799 { 103, "Startup" , 6 },
800 { 0x1000, "Background" , 1 },
801 { 0x2000, "Normal" , 2 },
802 { 0x3000, "Fullscreen" , 2 },
803 { 0x4000, "InputPanel" , 3 },
804 { 0xA000, "Touch" , 4 },
805 { 0xB000, "Cursor" , 5 },
806 { 0xC000, "Startup" , 6 }
810 manager_update = function(self, oper)
812 print("### <== WINDOW MANAGER UPDATE:" ..
813 window_manager_operation_name(oper))
816 local umask = window_mask { raise = true,
819 local rmask = window_mask { active = true }
821 passthrough_update = umask:tointeger(),
822 passthrough_request = rmask:tointeger()
824 self:manager_request(req)
828 window_update = function(self, oper, win, mask)
830 print("### <== WINDOW UPDATE oper:" ..
831 window_operation_name(oper) ..
832 " mask: " .. tostring(mask))
838 local arg = m:JSON({ surface = win.surface,
843 if oper == 1 then -- create
844 local layertype = win.layertype
845 if layertype and input_layer[layertype] then
847 print("ignoring input panel creation")
852 elseif oper == 2 then -- destroy
854 elseif oper == 3 then -- namechange
856 elseif oper == 4 or oper == 5 then --visible or configure
860 arg.layer = win.layer
861 arg.pos_x = win.pos_x
862 arg.pos_y = win.pos_y
863 arg.width = win.width
864 arg.height = win.height
865 arg.raise = win.raise
866 arg.visible = win.visible
867 arg.active = win.active
868 elseif oper == 6 then -- active
870 arg.active = win.active
873 print("### nothing to do")
878 local msg = m:JSON({ command = command,
884 print("### <== sending " ..
885 command_name(msg.command) ..
886 " window message to '" .. win.name .. "'")
891 sc:send_message(homescreen, msg)
893 if oper == 1 then -- create
894 local i = input_layer[win.layertype]
895 local p = self:application(win.appid)
896 local s = p.privileges.screen
898 if s == "system" then
899 local a = animation({})
900 local r = m:JSON({surface = win.surface,
903 self:window_request(r,a,0)
907 print("do not make resource for " ..
911 resclnt:resource_set_create("screen",
917 elseif oper == 2 then -- destroy
918 resclnt:resource_set_destroy("screen", win.surface)
919 elseif oper == 6 then -- active
921 local i = input_layer[win.layertype]
922 local p = self:application(win.appid)
923 local s = p.privileges.screen
924 local surface = win.surface
925 if not i and s ~= "system" then
926 resclnt:resource_set_acquire("screen",surface)
927 resmgr:window_raise(win.appid, surface, 1)
933 layer_update = function(self, oper, layer, mask)
935 print("### LAYER UPDATE:" ..
936 layer_operation_name(oper) ..
937 " mask: " .. tostring(mask))
942 if oper == 3 then -- visible
943 local command = 0x10022
947 arg = m:JSON({layer = layer.id,
948 visible = layer.visible
952 print("### <== sending "..command_name(command)..
958 sc:send_message(homescreen, msg)
961 print("### nothing to do")
966 output_update = function(self, oper, out, mask)
967 local idx = out.index
969 print("### OUTPUT UPDATE:" .. oper ..
970 " mask: "..tostring(mask))
973 local outdef = self.outputs[idx+1]
974 if (oper == 1) then -- create
976 self:output_request(m:JSON({index = idx,
981 elseif (oper == 5) then -- done
982 local ads = outdef.areas
983 local on = outdef.name
985 for name,ad in pairs(ads) do
986 local can = wmgr:canonical_name(on.."."..name)
987 local a = m:JSON({name = name,
989 for fld,val in pairs(ad) do
990 a[fld] = self:geometry(out.width,
995 resmgr:area_create(area[can], outdef.zone)
1003 imgr = input_manager {
1004 inputs = {{ name = "G27 Racing Wheel",
1006 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1007 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1008 [4] = {appid="org.tizen.ico.app-soundsample" },
1009 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1013 manager_update = function(self, oper)
1015 print("### <== INPUT MANAGER UPDATE:" ..
1016 input_manager_operation_name(oper))
1020 input_update = function(self, oper, inp, mask)
1022 print("### INPUT UPDATE:" ..
1023 input_operation_name(oper) ..
1024 " mask: " .. tostring(mask))
1030 code_update = function(self, oper, code, mask)
1032 print("### CODE UPDATE: mask: " .. tostring(mask))
1037 local msg = m:JSON({ command = 1,
1038 appid = "org.tizen.ico.homescreen",
1039 arg = m:JSON({ device = code.device,
1047 print("### <== sending " ..
1048 command_name(msg.command) ..
1054 sc:send_message(homescreen, msg)
1058 sc = m:get_system_controller()
1064 um = m:UserManager()
1069 -- these shoud be before wmgr:connect() is called
1071 print("====== creating applications ======")
1075 area = "Center.Full",
1076 privileges = { screen = "none", audio = "none" },
1077 resource_class = "player",
1083 area = "Center.Full",
1084 privileges = { screen = "system", audio = "none" },
1085 resource_class = "implicit",
1086 screen_priority = 30
1090 appid = "org.tizen.ico.homescreen",
1091 area = "Center.Full",
1092 privileges = { screen = "system", audio = "system" },
1093 resource_class = "player",
1094 screen_priority = 20
1098 appid = "org.tizen.ico.statusbar",
1099 area = "Center.Status",
1100 privileges = { screen = "system", audio = "none" },
1101 resource_class = "player",
1102 screen_priority = 20
1106 appid = "org.tizen.ico.login",
1107 area = "Center.Full",
1108 privileges = { screen = "system", audio = "system" },
1109 resource_class = "player",
1110 screen_priority = 20
1114 appid = "org.tizen.ico.camera_left",
1115 area = "Center.SysApp.Left",
1116 privileges = { screen = "system", audio = "none" },
1117 requisites = { screen = "blinker_left", audio = "none" },
1118 resource_class = "player",
1119 screen_priority = 30
1124 appid = "org.tizen.ico.camera_right",
1125 area = "Center.SysApp.Right",
1126 privileges = { screen = "system", audio = "none" },
1127 requisites = { screen = "blinker_right", audio = "none" },
1128 resource_class = "player",
1129 screen_priority = 30
1134 sc.client_handler = function (self, cid, msg)
1135 local command = msg.command
1137 print('### ==> client handler:')
1142 if not connected then
1143 print('Setting homescreen='..msg.appid)
1144 homescreen = msg.appid
1145 print('Trying to connect to wayland...')
1146 connected = wmgr:connect()
1148 if connected and command then
1149 if command == 1 then -- send_appid
1150 local driving_mode = mdb.select.select_driving_mode.single_value
1151 local night_mode = mdb.select.select_night_mode.single_value
1153 if not driving_mode then driving_mode = 0 end
1154 if not night_mode then night_mode = 0 end
1156 local reply = m:JSON({ command = 0x60001,
1157 arg = m:JSON({ stateid = 1,
1158 state = driving_mode})
1161 print("### <== sending " ..
1162 command_name(command) .. " message")
1167 sc:send_message(homescreen, reply)
1169 reply = m:JSON({ command = 0x60001,
1170 arg = m:JSON({ stateid = 2,
1171 state = night_mode})
1174 print("### <== sending " ..
1175 command_name(command) .. " message")
1180 sc:send_message(homescreen, reply)
1185 sc.generic_handler = function (self, cid, msg)
1187 print('### ==> generic handler:')
1194 sc.window_handler = function (self, cid, msg)
1196 print('### ==> received ' ..
1197 command_name(msg.command) .. ' message')
1199 print(tostring(msg))
1203 local a = animation({})
1205 if msg.command == 0x10003 then -- ico SHOW command
1206 local raise_mask = 0x01000000
1207 local lower_mask = 0x02000000
1208 local nores_mask = 0x40000000
1209 local time_mask = 0x00ffffff
1213 if msg.arg.anim_time then
1214 local t = msg.arg.anim_time
1215 time = m:AND(t, time_mask)
1216 nores = m:AND(t, nores_mask)
1217 if m:AND(t, raise_mask) then
1219 elseif m:AND(t, lower_mask) then
1223 if msg.arg.anim_name then
1224 a.show = { msg.arg.anim_name, time }
1225 print('time: ' .. tostring(a.show[2]))
1229 local p = wmgr:application(msg.appid)
1230 local s = p.privileges.screen
1231 if s == "system" then
1236 print('### ==> SHOW')
1237 print(tostring(msg.arg))
1240 wmgr:window_request(msg.arg, a, 0)
1242 local surface = msg.arg.surface
1243 resclnt:resource_set_acquire("screen", surface)
1244 resmgr:window_raise(msg.appid, surface, 1)
1246 elseif msg.command == 0x10004 then -- ico HIDE command
1247 local raise_mask = 0x01000000
1248 local lower_mask = 0x02000000
1249 local nores_mask = 0x40000000
1250 local time_mask = 0x00ffffff
1254 if msg.arg.anim_time then
1255 local t = msg.arg.anim_time
1256 time = m:AND(t, time_mask)
1257 nores = m:AND(t, nores_mask)
1259 if msg.arg.anim_name then
1260 a.hide = { msg.arg.anim_name, time }
1261 print('hide animation time: ' .. tostring(a.hide[2]))
1265 local p = wmgr:application(msg.appid)
1266 local s = p.privileges.screen
1267 if s == "system" then
1272 print('### ==> HIDE REQUEST')
1273 print(tostring(msg.arg))
1276 wmgr:window_request(msg.arg, a, 0)
1278 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1280 elseif msg.command == 0x10005 then -- ico MOVE
1282 print('### ==> MOVE REQUEST')
1283 print(tostring(msg.arg))
1285 wmgr:window_request(msg.arg, a, 0)
1286 -- TODO: handle if area changed
1287 elseif msg.command == 0x10006 then -- ico ACTIVE
1288 if not msg.arg.active then
1289 msg.arg.active = 3 -- pointer + keyboard
1292 print('### ==> ACTIVE REQUEST')
1293 print(tostring(msg.arg))
1295 wmgr:window_request(msg.arg, a, 0)
1296 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1298 print('### ==> CHANGE_LAYER REQUEST')
1299 print(tostring(msg.arg))
1302 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1303 print("do not change layer for other than cursor or touch")
1307 wmgr:window_request(msg.arg, a, 0)
1308 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1309 local framerate = msg.arg.framerate
1310 if not framerate or framerate < 0 then
1315 print('### ==> MAP_THUMB REQUEST')
1317 print('framerate: '..framerate)
1319 wmgr:window_request(msg.arg, a, framerate)
1320 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1323 print('### ==> UNMAP_THUMB REQUEST')
1326 wmgr:window_request(msg.arg, a, 0)
1327 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1330 print('### ==> SHOW_LAYER REQUEST')
1333 wmgr:layer_request(msg.arg)
1334 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1337 print('### ==> HIDE_LAYER REQUEST')
1340 wmgr:layer_request(msg.arg)
1344 sc.input_handler = function (self, cid, msg)
1346 print('### ==> input handler: ' .. command_name(msg.command))
1351 if msg.command == 0x20001 then -- add_input
1352 msg.arg.appid = msg.appid
1354 print('### ==> ADD_INPUT REQUEST')
1355 print(tostring(msg.arg))
1357 imgr:input_request(msg.arg)
1358 elseif msg.command == 0x20002 then -- del_input
1361 print('### ==> DEL_INPUT REQUEST')
1362 print(tostring(msg.arg))
1364 imgr:input_request(msg.arg)
1365 elseif msg.command == 0x20003 then -- send_input
1369 sc.user_handler = function (self, cid, msg)
1371 print('### ==> user handler: ' .. command_name(msg.command))
1378 print("User Manager not initialized")
1382 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1383 print("command CHANGE_USER")
1385 print("invalid message")
1389 username = msg.arg.user
1390 passwd = msg.arg.pass
1392 if not username then
1400 success = um:changeUser(username, passwd)
1407 if sc:send_message(msg.appid, reply) then
1408 print('*** sent authentication failed message')
1410 print('*** failed to send authentication failed message')
1414 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1415 print("command GET_USERLIST")
1416 if not msg.appid then
1417 print("invalid message")
1421 users, currentUser = um:getUserList()
1424 print("failed to get user list")
1430 for i,v in pairs(users) do
1434 if not currentUser then
1439 print("current user: " .. currentUser)
1441 for i,v in pairs(users) do
1452 user_login = currentUser
1457 print("### <== GetUserList reply: " .. tostring(reply))
1460 if sc:send_message(msg.appid, reply) then
1461 print('*** reply OK')
1463 print('*** reply FAILED')
1466 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1467 print("command GET_LASTINFO")
1468 if not msg.appid then
1469 print("invalid message")
1473 lastInfo = um:getLastInfo(msg.appid)
1475 if not lastInfo then
1476 print("failed to get last info for app" .. msg.appid)
1488 if sc:send_message(msg.appid, reply) then
1489 print('*** reply OK')
1491 print('*** reply FAILED')
1494 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1495 print("command SET_LASTINFO")
1496 if not msg.arg or not msg.appid then
1497 print("invalid message")
1501 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1505 sc.resource_handler = function (self, cid, msg)
1507 print('### ==> resource handler: ' .. command_name(msg.command))
1513 createResourceSet = function (ctl, client, msg)
1514 cb = function(rset, data)
1515 print("> resource callback")
1517 -- type is either basic (0) or interrupt (1)
1519 if msg.res.type then
1520 requestType = msg.res.type
1523 if rset.acquired then
1524 cmd = 0x00040001 -- acquire
1526 cmd = 0x00040002 -- release
1530 appid = data.client,
1537 if rset.resources.audio_playback then
1546 if rset.resources.display then
1547 reply.res.window = {
1554 if rset.resources.input then
1560 print("sending message to client: " .. data.client)
1562 if sc:send_message(data.client, reply) then
1563 print('*** reply OK')
1565 print('*** reply FAILED')
1569 rset = m:ResourceSet({
1570 application_class = "player",
1571 zone = "driver", -- msg.zone ("full")
1580 if msg.res.sound then
1582 resource_name = "audio_playback"
1584 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1585 rset.resources.audio_playback.attributes.appid = msg.appid
1586 print("sound name: " .. msg.res.sound.name)
1587 print("sound zone:" .. msg.res.sound.zone)
1588 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1589 if msg.res.sound.id then
1590 print("sound id: " .. msg.res.sound.id)
1594 if msg.res.input then
1596 resource_name = "input"
1598 rset.resources.input.attributes.pid = tostring(msg.pid)
1599 rset.resources.input.attributes.appid = msg.appid
1600 print("input name: " .. msg.res.sound.name)
1601 print("input event:" .. tostring(msg.res.input.event))
1604 if msg.res.window then
1606 resource_name = "display"
1608 rset.resources.display.attributes.pid = tostring(msg.pid)
1609 rset.resources.display.attributes.appid = msg.appid
1610 print("display name: " .. msg.res.display.name)
1611 print("display zone:" .. msg.res.display.zone)
1612 if msg.res.display.id then
1613 print("display id: " .. msg.res.display.id)
1620 -- parse the message
1622 -- fields common to all messages:
1627 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1628 print("command CREATE")
1630 if not sets.cid then
1631 sets.cid = createResourceSet(self, cid, msg)
1634 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1635 print("command DESTROY")
1641 sets.cid = nil -- garbage collecting
1643 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1644 print("command ACQUIRE")
1646 if not sets.cid then
1647 sets.cid = createResourceSet(self, cid, msg)
1652 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1653 print("command RELEASE")
1659 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1660 print("command DEPRIVE")
1662 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1663 print("command WAITING")
1665 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1666 print("command REVERT")
1670 sc.inputdev_handler = function (self, cid, msg)
1672 print('*** inputdev handler: ' .. command_name(msg.command))