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))
352 -- tell homescreen that night mode was updated
353 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=2,state=data})}))
358 -- Driving mode processing chain
361 name = "drivingmode",
362 inputs = { speed = mdb.select.vehicle_speed },
366 name = "amb_drivingmode",
370 { "id", mdb.unsigned },
371 { "driving_mode", mdb.unsigned }
375 update = function(self)
377 speed = self.inputs.speed.single_value
389 if not (mode == self.oldmode) then
390 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
398 name = "select_driving_mode",
399 table = "amb_drivingmode",
400 columns = { "driving_mode" },
406 name = "driving_mode",
407 inputs = { owner = mdb.select.select_driving_mode },
408 property = "DrivingMode",
410 initiate = builtin.method.amb_initiate,
411 update = builtin.method.amb_update
415 -- turn signals (left, right)
419 table = "amb_turn_signal",
420 columns = { "value" },
421 condition = "key = 'TurnSignal'"
424 -- regulation (on), use "select_driving_mode"
427 name = "driving_regulation",
428 inputs = { owner = mdb.select.select_driving_mode },
429 initiate = function(self)
430 data = mdb.select.select_driving_mode.single_value
431 print("Driving mode initiated: " .. tostring(data))
434 update = function(self)
435 data = mdb.select.select_driving_mode.single_value
436 print("Driving mode updated: " .. tostring(data))
438 -- tell homescreen that driving mode was updated
439 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=1,state=data})}))
444 -- shift position (parking, reverse, other)
447 name = "gear_position",
448 table = "amb_gear_position",
449 columns = { "value" },
450 condition = "key = 'GearPosition'"
453 -- cameras (back, front, left, right)
456 name = "camera_state",
457 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
461 name = "target_camera_state",
465 { "id", mdb.unsigned },
466 { "front_camera", mdb.unsigned },
467 { "back_camera", mdb.unsigned },
468 { "right_camera", mdb.unsigned },
469 { "left_camera", mdb.unsigned }
473 update = function(self)
480 if self.inputs.gear == 128 then
482 elseif self.inputs.winker == 1 then
484 elseif self.inputs.winker == 2 then
488 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
493 -- load the telephony plugin
494 m:try_load_plugin('telephony')
497 -- system controller test setup
499 if not with_system_controller then
503 m:load_plugin('system-controller')
505 window_manager_operation_names = {
510 function window_manager_operation_name(oper)
511 local name = window_manager_operation_names[oper]
512 if name then return name end
513 return "<unknown " .. tostring(oper) .. ">"
516 window_operation_names = {
525 function window_operation_name(oper)
526 local name = window_operation_names[oper]
527 if name then return name end
528 return "<unknown " .. tostring(oper) .. ">"
531 layer_operation_names = {
537 function layer_operation_name(oper)
538 local name = layer_operation_names[oper]
539 if name then return name end
540 return "<unknown " .. tostring(oper) .. ">"
543 input_manager_operation_names = {
549 function input_manager_operation_name(oper)
550 local name = input_manager_operation_names[oper]
551 if name then return name end
552 return "<unknown " .. tostring(oper) .. ">"
555 input_operation_names = {
561 function input_operation_name(oper)
562 local name = input_operation_names[oper]
563 if name then return name end
564 return "<unknown " .. tostring(oper) .. ">"
567 code_operation_names = {
573 function code_operation_name(oper)
574 local name = code_operation_names[oper]
575 if name then return name end
576 return "<unknown " .. tostring(oper) .. ">"
580 [0x00001] = "send_appid",
581 [0x10001] = "create",
582 [0x10002] = "destroy",
586 [0x10006] = "change_active",
587 [0x10007] = "change_layer",
588 [0x10008] = "change_attr",
590 [0x10011] = "map_thumb",
591 [0x10012] = "unmap_thumb",
592 [0x10020] = "show layer",
593 [0x10021] = "hide_layer",
594 [0x10022] = "change_layer_attr",
595 [0x20001] = "add_input",
596 [0x20002] = "del_input",
597 [0x20003] = "send_input",
598 [0x40001] = "acquire_res",
599 [0x40002] = "release_res",
600 [0x40003] = "deprive_res",
601 [0x40004] = "waiting_res",
602 [0x40005] = "revert_res",
603 [0x40011] = "create_res",
604 [0x40012] = "destroy_res",
605 [0x50001] = "set_region",
606 [0x50002] = "unset_region",
607 [0x60001] = "change_state"
610 function command_name(command)
611 local name = command_names[command]
612 if name then return name end
613 return "<unknown " .. tostring(command) .. ">"
622 resmgr = resource_manager {
623 screen_event_handler = function(self, ev)
624 local event = ev.event
625 local surface = ev.surface
627 if event == "grant" then
629 print("*** make visible surface "..surface)
631 local a = animation({})
632 local r = m:JSON({surface = surface,
635 wmgr:window_request(r,a,0)
636 elseif event == "revoke" then
638 print("*** hide surface "..surface)
640 local a = animation({})
641 local r = m:JSON({surface = ev.surface,
643 wmgr:window_request(r,a,0)
646 print("*** screen resource event: " ..
651 audio_event_handler = function(self, ev)
652 local event = ev.event
653 local appid = ev.appid
654 local audioid = ev.audioid
656 if event == "grant" then
657 if verbose > 0 or true then
658 print("*** grant audio to "..appid..
659 " ("..audioid..") in '" ..
662 elseif event == "revoke" then
663 if verbose > 0 or true then
664 print("*** revoke audio from "..appid..
665 " ("..audioid..") in '" ..
669 if verbose > 0 or true then
670 print("*** audio resource event: " ..
677 resclnt = resource_client {}
679 wmgr = window_manager {
680 geometry = function(self, w,h, v)
681 if type(v) == "function" then
687 application = function(self, appid)
689 local app = application_lookup(appid)
691 app = application_lookup("default")
695 return { privileges = {screen="none", audio="none"} }
698 outputs = { { name = "Center",
705 width = function(w,h) return w end,
712 width = function(w,h) return w end,
713 height = function(w,h) return h-64-128 end
719 width = function(w,h) return w end,
720 height = function(w,h) return (h-64-128)/2 end
725 pos_y = function(w,h) return (h-64-128)/2+64 end,
726 width = function(w,h) return w end,
727 height = function(w,h) return (h-64-128)/2 end
733 width = function(w,h) return w/2 end,
734 height = function(w,h) return (h-64-128)/2 end
738 pos_x = function(w,h) return w/2 end,
740 width = function(w,h) return w/2 end,
741 height = function(w,h) return (h-64-128)/2 end
746 pos_y = function(w,h) return (h-64-128/2)+64 end,
747 width = function(w,h) return w/2 end,
748 height = function(w,h) return (h-64-128)/2 end
752 pos_x = function(w,h) return w/2 end,
753 pos_y = function(w,h) return (h-64-128/2)+64 end,
754 width = function(w,h) return w/2 end,
755 height = function(w,h) return (h-64-128)/2 end
761 width = function(w,h) return w end,
762 height = function(w,h) return h-64-128 end
768 width = function(w,h) return w/2-181 end,
769 height = function(w,h) return h-64-128 end
773 pos_x = function(w,h) return w/2+181 end,
775 width = function(w,h) return w/2-181 end,
776 height = function(w,h) return h-64-128 end
786 layers = { { 0, "Background" , 1 },
787 { 1, "Application" , 2 },
788 { 2, "Softkeyboard" , 4 },
789 { 3, "HomeScreen" , 2 },
790 { 4, "ControlBar" , 2 },
791 { 5, "InterruptApp" , 2 },
792 { 6, "OnScreen" , 2 },
793 { 101, "Input" , 3 },
794 { 102, "Cursor" , 5 },
795 { 103, "Startup" , 6 },
796 { 0x1000, "Background" , 1 },
797 { 0x2000, "Normal" , 2 },
798 { 0x3000, "Fullscreen" , 2 },
799 { 0x4000, "InputPanel" , 3 },
800 { 0xA000, "Touch" , 4 },
801 { 0xB000, "Cursor" , 5 },
802 { 0xC000, "Startup" , 6 }
806 manager_update = function(self, oper)
808 print("### <== WINDOW MANAGER UPDATE:" ..
809 window_manager_operation_name(oper))
812 local umask = window_mask { raise = true,
815 local rmask = window_mask { active = true }
817 passthrough_update = umask:tointeger(),
818 passthrough_request = rmask:tointeger()
820 self:manager_request(req)
824 window_update = function(self, oper, win, mask)
826 print("### <== WINDOW UPDATE oper:" ..
827 window_operation_name(oper) ..
828 " mask: " .. tostring(mask))
834 local arg = m:JSON({ surface = win.surface,
839 if oper == 1 then -- create
840 local layertype = win.layertype
841 if layertype and input_layer[layertype] then
843 print("ignoring input panel creation")
848 elseif oper == 2 then -- destroy
850 elseif oper == 3 then -- namechange
852 elseif oper == 4 or oper == 5 then --visible or configure
856 arg.layer = win.layer
857 arg.pos_x = win.pos_x
858 arg.pos_y = win.pos_y
859 arg.width = win.width
860 arg.height = win.height
861 arg.raise = win.raise
862 arg.visible = win.visible
863 arg.active = win.active
864 elseif oper == 6 then -- active
866 arg.active = win.active
869 print("### nothing to do")
874 local msg = m:JSON({ command = command,
880 print("### <== sending " ..
881 command_name(msg.command) ..
882 " window message to '" .. win.name .. "'")
887 sc:send_message(homescreen, msg)
889 if oper == 1 then -- create
890 local i = input_layer[win.layertype]
891 local p = self:application(win.appid)
892 local s = p.privileges.screen
894 if s == "system" then
895 local a = animation({})
896 local r = m:JSON({surface = win.surface,
899 self:window_request(r,a,0)
903 print("do not make resource for " ..
907 resclnt:resource_set_create("screen",
913 elseif oper == 2 then -- destroy
914 resclnt:resource_set_destroy("screen", win.surface)
915 elseif oper == 6 then -- active
917 local i = input_layer[win.layertype]
918 local p = self:application(win.appid)
919 local s = p.privileges.screen
920 local surface = win.surface
921 if not i and s ~= "system" then
922 resclnt:resource_set_acquire("screen",surface)
923 resmgr:window_raise(win.appid, surface, 1)
929 layer_update = function(self, oper, layer, mask)
931 print("### LAYER UPDATE:" ..
932 layer_operation_name(oper) ..
933 " mask: " .. tostring(mask))
938 if oper == 3 then -- visible
939 local command = 0x10022
943 arg = m:JSON({layer = layer.id,
944 visible = layer.visible
948 print("### <== sending "..command_name(command)..
954 sc:send_message(homescreen, msg)
957 print("### nothing to do")
962 output_update = function(self, oper, out, mask)
963 local idx = out.index
965 print("### OUTPUT UPDATE:" .. oper ..
966 " mask: "..tostring(mask))
969 local outdef = self.outputs[idx+1]
970 if (oper == 1) then -- create
972 self:output_request(m:JSON({index = idx,
977 elseif (oper == 5) then -- done
978 local ads = outdef.areas
979 local on = outdef.name
981 for name,ad in pairs(ads) do
982 local can = wmgr:canonical_name(on.."."..name)
983 local a = m:JSON({name = name,
985 for fld,val in pairs(ad) do
986 a[fld] = self:geometry(out.width,
991 resmgr:area_create(area[can], outdef.zone)
999 imgr = input_manager {
1000 inputs = {{ name = "G27 Racing Wheel",
1002 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1003 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1004 [4] = {appid="org.tizen.ico.app-soundsample" },
1005 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1009 manager_update = function(self, oper)
1011 print("### <== INPUT MANAGER UPDATE:" ..
1012 input_manager_operation_name(oper))
1016 input_update = function(self, oper, inp, mask)
1018 print("### INPUT UPDATE:" ..
1019 input_operation_name(oper) ..
1020 " mask: " .. tostring(mask))
1026 code_update = function(self, oper, code, mask)
1028 print("### CODE UPDATE: mask: " .. tostring(mask))
1033 local msg = m:JSON({ command = 1,
1034 appid = "org.tizen.ico.homescreen",
1035 arg = m:JSON({ device = code.device,
1043 print("### <== sending " ..
1044 command_name(msg.command) ..
1050 sc:send_message(homescreen, msg)
1054 sc = m:get_system_controller()
1060 um = m:UserManager()
1065 -- these shoud be before wmgr:connect() is called
1067 print("====== creating applications ======")
1071 area = "Center.Full",
1072 privileges = { screen = "none", audio = "none" },
1073 resource_class = "player",
1079 area = "Center.Full",
1080 privileges = { screen = "system", audio = "none" },
1081 resource_class = "implicit",
1082 screen_priority = 30
1086 appid = "org.tizen.ico.homescreen",
1087 area = "Center.Full",
1088 privileges = { screen = "system", audio = "system" },
1089 resource_class = "player",
1090 screen_priority = 20
1094 appid = "org.tizen.ico.statusbar",
1095 area = "Center.Status",
1096 privileges = { screen = "system", audio = "none" },
1097 resource_class = "player",
1098 screen_priority = 20
1102 appid = "org.tizen.ico.login",
1103 area = "Center.Full",
1104 privileges = { screen = "system", audio = "system" },
1105 resource_class = "player",
1106 screen_priority = 20
1111 sc.client_handler = function (self, cid, msg)
1112 local command = msg.command
1114 print('### ==> client handler:')
1119 if not connected then
1120 print('Setting homescreen='..msg.appid)
1121 homescreen = msg.appid
1122 print('Trying to connect to wayland...')
1123 connected = wmgr:connect()
1125 if connected and command then
1126 if command == 1 then -- send_appid
1127 local driving_mode = mdb.select.select_driving_mode.single_value
1128 local night_mode = mdb.select.select_night_mode.single_value
1130 if not driving_mode then driving_mode = 0 end
1131 if not night_mode then night_mode = 0 end
1133 local reply = m:JSON({ command = 0x60001,
1134 arg = m:JSON({ stateid = 1,
1135 state = driving_mode})
1138 print("### <== sending " ..
1139 command_name(command) .. " message")
1144 sc:send_message(homescreen, reply)
1146 reply = m:JSON({ command = 0x60001,
1147 arg = m:JSON({ stateid = 2,
1148 state = night_mode})
1151 print("### <== sending " ..
1152 command_name(command) .. " message")
1157 sc:send_message(homescreen, reply)
1162 sc.generic_handler = function (self, cid, msg)
1164 print('### ==> generic handler:')
1171 sc.window_handler = function (self, cid, msg)
1173 print('### ==> received ' ..
1174 command_name(msg.command) .. ' message')
1176 print(tostring(msg))
1180 local a = animation({})
1182 if msg.command == 0x10003 then -- ico SHOW command
1183 local raise_mask = 0x01000000
1184 local lower_mask = 0x02000000
1185 local nores_mask = 0x40000000
1186 local time_mask = 0x00ffffff
1190 if msg.arg.anim_time then
1191 local t = msg.arg.anim_time
1192 time = m:AND(t, time_mask)
1193 nores = m:AND(t, nores_mask)
1194 if m:AND(t, raise_mask) then
1196 elseif m:AND(t, lower_mask) then
1200 if msg.arg.anim_name then
1201 a.show = { msg.arg.anim_name, time }
1202 print('time: ' .. tostring(a.show[2]))
1206 local p = wmgr:application(msg.appid)
1207 local s = p.privileges.screen
1208 if s == "system" then
1213 print('### ==> SHOW')
1214 print(tostring(msg.arg))
1217 wmgr:window_request(msg.arg, a, 0)
1219 local surface = msg.arg.surface
1220 resclnt:resource_set_acquire("screen", surface)
1221 resmgr:window_raise(msg.appid, surface, 1)
1223 elseif msg.command == 0x10004 then -- ico HIDE command
1224 local raise_mask = 0x01000000
1225 local lower_mask = 0x02000000
1226 local nores_mask = 0x40000000
1227 local time_mask = 0x00ffffff
1231 if msg.arg.anim_time then
1232 local t = msg.arg.anim_time
1233 time = m:AND(t, time_mask)
1234 nores = m:AND(t, nores_mask)
1236 if msg.arg.anim_name then
1237 a.hide = { msg.arg.anim_name, time }
1238 print('hide animation time: ' .. tostring(a.hide[2]))
1242 local p = wmgr:application(msg.appid)
1243 local s = p.privileges.screen
1244 if s == "system" then
1249 print('### ==> HIDE REQUEST')
1250 print(tostring(msg.arg))
1253 wmgr:window_request(msg.arg, a, 0)
1255 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1257 elseif msg.command == 0x10005 then -- ico MOVE
1259 print('### ==> MOVE REQUEST')
1260 print(tostring(msg.arg))
1262 wmgr:window_request(msg.arg, a, 0)
1263 -- TODO: handle if area changed
1264 elseif msg.command == 0x10006 then -- ico ACTIVE
1265 if not msg.arg.active then
1266 msg.arg.active = 3 -- pointer + keyboard
1269 print('### ==> ACTIVE REQUEST')
1270 print(tostring(msg.arg))
1272 wmgr:window_request(msg.arg, a, 0)
1273 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1275 print('### ==> CHANGE_LAYER REQUEST')
1276 print(tostring(msg.arg))
1279 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1280 print("do not change layer for other than cursor or touch")
1284 wmgr:window_request(msg.arg, a, 0)
1285 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1286 local framerate = msg.arg.framerate
1287 if not framerate or framerate < 0 then
1292 print('### ==> MAP_THUMB REQUEST')
1294 print('framerate: '..framerate)
1296 wmgr:window_request(msg.arg, a, framerate)
1297 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1300 print('### ==> UNMAP_THUMB REQUEST')
1303 wmgr:window_request(msg.arg, a, 0)
1304 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1307 print('### ==> SHOW_LAYER REQUEST')
1310 wmgr:layer_request(msg.arg)
1311 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1314 print('### ==> HIDE_LAYER REQUEST')
1317 wmgr:layer_request(msg.arg)
1321 sc.input_handler = function (self, cid, msg)
1323 print('### ==> input handler: ' .. command_name(msg.command))
1328 if msg.command == 0x20001 then -- add_input
1329 msg.arg.appid = msg.appid
1331 print('### ==> ADD_INPUT REQUEST')
1332 print(tostring(msg.arg))
1334 imgr:input_request(msg.arg)
1335 elseif msg.command == 0x20002 then -- del_input
1338 print('### ==> DEL_INPUT REQUEST')
1339 print(tostring(msg.arg))
1341 imgr:input_request(msg.arg)
1342 elseif msg.command == 0x20003 then -- send_input
1346 sc.user_handler = function (self, cid, msg)
1348 print('### ==> user handler: ' .. command_name(msg.command))
1355 print("User Manager not initialized")
1359 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1360 print("command CHANGE_USER")
1362 print("invalid message")
1366 username = msg.arg.user
1367 passwd = msg.arg.pass
1369 if not username then
1377 success = um:changeUser(username, passwd)
1384 if sc:send_message(msg.appid, reply) then
1385 print('*** sent authentication failed message')
1387 print('*** failed to send authentication failed message')
1391 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1392 print("command GET_USERLIST")
1393 if not msg.appid then
1394 print("invalid message")
1398 users, currentUser = um:getUserList()
1401 print("failed to get user list")
1407 for i,v in pairs(users) do
1411 if not currentUser then
1416 print("current user: " .. currentUser)
1418 for i,v in pairs(users) do
1429 user_login = currentUser
1434 print("### <== GetUserList reply: " .. tostring(reply))
1437 if sc:send_message(msg.appid, reply) then
1438 print('*** reply OK')
1440 print('*** reply FAILED')
1443 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1444 print("command GET_LASTINFO")
1445 if not msg.appid then
1446 print("invalid message")
1450 lastInfo = um:getLastInfo(msg.appid)
1452 if not lastInfo then
1453 print("failed to get last info for app" .. msg.appid)
1465 if sc:send_message(msg.appid, reply) then
1466 print('*** reply OK')
1468 print('*** reply FAILED')
1471 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1472 print("command SET_LASTINFO")
1473 if not msg.arg or not msg.appid then
1474 print("invalid message")
1478 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1482 sc.resource_handler = function (self, cid, msg)
1484 print('### ==> resource handler: ' .. command_name(msg.command))
1490 createResourceSet = function (ctl, client, msg)
1491 cb = function(rset, data)
1492 print("> resource callback")
1494 -- type is either basic (0) or interrupt (1)
1496 if msg.res.type then
1497 requestType = msg.res.type
1500 if rset.acquired then
1501 cmd = 0x00040001 -- acquire
1503 cmd = 0x00040002 -- release
1507 appid = data.client,
1514 if rset.resources.audio_playback then
1523 if rset.resources.display then
1524 reply.res.window = {
1531 if rset.resources.input then
1537 print("sending message to client: " .. data.client)
1539 if sc:send_message(data.client, reply) then
1540 print('*** reply OK')
1542 print('*** reply FAILED')
1546 rset = m:ResourceSet({
1547 application_class = "player",
1548 zone = "driver", -- msg.zone ("full")
1557 if msg.res.sound then
1559 resource_name = "audio_playback"
1561 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1562 rset.resources.audio_playback.attributes.appid = msg.appid
1563 print("sound name: " .. msg.res.sound.name)
1564 print("sound zone:" .. msg.res.sound.zone)
1565 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1566 if msg.res.sound.id then
1567 print("sound id: " .. msg.res.sound.id)
1571 if msg.res.input then
1573 resource_name = "input"
1575 rset.resources.input.attributes.pid = tostring(msg.pid)
1576 rset.resources.input.attributes.appid = msg.appid
1577 print("input name: " .. msg.res.sound.name)
1578 print("input event:" .. tostring(msg.res.input.event))
1581 if msg.res.window then
1583 resource_name = "display"
1585 rset.resources.display.attributes.pid = tostring(msg.pid)
1586 rset.resources.display.attributes.appid = msg.appid
1587 print("display name: " .. msg.res.display.name)
1588 print("display zone:" .. msg.res.display.zone)
1589 if msg.res.display.id then
1590 print("display id: " .. msg.res.display.id)
1597 -- parse the message
1599 -- fields common to all messages:
1604 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1605 print("command CREATE")
1607 if not sets.cid then
1608 sets.cid = createResourceSet(self, cid, msg)
1611 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1612 print("command DESTROY")
1618 sets.cid = nil -- garbage collecting
1620 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1621 print("command ACQUIRE")
1623 if not sets.cid then
1624 sets.cid = createResourceSet(self, cid, msg)
1629 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1630 print("command RELEASE")
1636 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1637 print("command DEPRIVE")
1639 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1640 print("command WAITING")
1642 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1643 print("command REVERT")
1647 sc.inputdev_handler = function (self, cid, msg)
1649 print('*** inputdev handler: ' .. command_name(msg.command))