1 with_system_controller = true
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('ivi-resource-manager') then
72 m:load_plugin('ivi-resource-manager')
73 with_system_controller = false
76 -- define application classes
123 application_class { name="event" , priority=4 , modal=false, share=true , order="fifo" }
124 application_class { name="game" , priority=3 , modal=false, share=false, order="lifo" }
125 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
126 --#application_class { name="basic" , priority=2 , modal=false, share=false, order="lifo" }
127 application_class { name="player" , priority=1 , modal=false, share=true , order="lifo" }
128 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
130 -- define zone attributes
132 type = {mdb.string, "common", "rw"},
133 location = {mdb.string, "anywhere", "rw"}
141 location = "front-left"
149 location = "front-right"
157 location = "back-left"
165 location = "back-right"
173 location = "back-left"
178 -- define resource classes
179 if not m:plugin_exists('ivi-resource-manager') and
180 not with_system_controller
183 name = "audio_playback",
186 role = { mdb.string, "music", "rw" },
187 pid = { mdb.string, "<unknown>", "rw" },
188 policy = { mdb.string, "relaxed", "rw" }
194 name = "audio_recording",
197 role = { mdb.string, "music" , "rw" },
198 pid = { mdb.string, "<unknown>", "rw" },
199 policy = { mdb.string, "relaxed" , "rw" }
204 name = "video_playback",
209 name = "video_recording",
213 if not m:plugin_exists('ivi-resource-manager') and
214 not with_system_controller
216 resource.method.veto = {
217 function(zone, rset, grant, owners, req_set)
223 -- test for creating selections
225 name = "audio_owner",
226 table = "audio_playback_owner",
227 columns = {"application_class"},
228 condition = "zone_name = 'driver'"
232 name = "vehicle_speed",
233 table = "amb_vehicle_speed",
235 condition = "key = 'VehicleSpeed'"
239 name = "speed2volume",
240 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
241 outputs = { mdb.table { name = "speedvol",
242 index = {"zone", "device"},
243 columns = {{"zone", mdb.string, 16},
244 {"device", mdb.string, 16},
245 {"value", mdb.floating}},
250 update = function(self)
251 speed = self.inputs.speed.single_value
253 volume = (speed - 144.0) / 7.0
257 diff = volume - self.oldvolume
258 if (diff*diff > self.inputs.param) then
259 print("*** element "..self.name.." update "..volume)
260 self.oldvolume = volume
261 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
266 -- Night mode processing chain
269 name = "exterior_brightness",
270 table = "amb_exterior_brightness",
271 columns = { "value" },
272 condition = "key = 'ExteriorBrightness'"
277 inputs = { brightness = mdb.select.exterior_brightness },
281 name = "amb_nightmode",
285 { "id", mdb.unsigned },
286 { "night_mode", mdb.unsigned }
290 update = function(self)
291 -- This is a trivial function to calculate night mode. Later, we will
292 -- need a better threshold value and hysteresis to prevent oscillation.
294 brightness = self.inputs.brightness.single_value
296 if not brightness then
300 print("*** element "..self.name.." update brightness: "..brightness)
302 if brightness > 300 then
308 print("*** resulting mode: ".. mode)
310 if not (mode == self.oldmode) then
311 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
319 name = "select_night_mode",
320 table = "amb_nightmode",
321 columns = { "night_mode" },
328 inputs = { owner = mdb.select.select_night_mode },
329 property = "NightMode",
331 initiate = builtin.method.amb_initiate,
332 update = builtin.method.amb_update
336 -- Night mode general handlers
339 name = "nightmode_homescreen",
340 inputs = { owner = mdb.select.select_night_mode },
341 initiate = function(self)
342 data = mdb.select.select_night_mode.single_value
343 print("Night mode initiated: " .. tostring(data))
346 update = function(self)
347 data = mdb.select.select_night_mode.single_value
348 print("Night mode updated: " .. tostring(data))
350 -- tell homescreen that night mode was updated
351 sc:send_message(sysctlid, m:JSON({command=0x60001,arg=m:JSON({stateid=2,state=data})}))
356 -- Driving mode processing chain
359 name = "drivingmode",
360 inputs = { speed = mdb.select.vehicle_speed },
364 name = "amb_drivingmode",
368 { "id", mdb.unsigned },
369 { "driving_mode", mdb.unsigned }
373 update = function(self)
375 speed = self.inputs.speed.single_value
387 if not (mode == self.oldmode) then
388 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
396 name = "select_driving_mode",
397 table = "amb_drivingmode",
398 columns = { "driving_mode" },
404 name = "driving_mode",
405 inputs = { owner = mdb.select.select_driving_mode },
406 property = "DrivingMode",
408 initiate = builtin.method.amb_initiate,
409 update = builtin.method.amb_update
413 -- turn signals (left, right)
417 table = "amb_turn_signal",
418 columns = { "value" },
419 condition = "key = 'TurnSignal'"
422 -- regulation (on), use "select_driving_mode"
425 name = "driving_regulation",
426 inputs = { owner = mdb.select.select_driving_mode },
427 initiate = function(self)
428 data = mdb.select.select_driving_mode.single_value
429 print("Driving mode initiated: " .. tostring(data))
432 update = function(self)
433 data = mdb.select.select_driving_mode.single_value
434 print("Driving mode updated: " .. tostring(data))
436 -- tell homescreen that driving mode was updated
437 sc:send_message(sysctlid, m:JSON({command=0x60001,arg=m:JSON({stateid=1,state=data})}))
442 -- shift position (parking, reverse, other)
445 name = "gear_position",
446 table = "amb_gear_position",
447 columns = { "value" },
448 condition = "key = 'GearPosition'"
451 -- cameras (back, front, left, right)
454 name = "camera_state",
455 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
459 name = "target_camera_state",
463 { "id", mdb.unsigned },
464 { "front_camera", mdb.unsigned },
465 { "back_camera", mdb.unsigned },
466 { "right_camera", mdb.unsigned },
467 { "left_camera", mdb.unsigned }
471 update = function(self)
478 if self.inputs.gear == 128 then
480 elseif self.inputs.winker == 1 then
482 elseif self.inputs.winker == 2 then
486 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
491 -- load the telephony plugin
492 m:try_load_plugin('telephony')
495 -- system controller test setup
497 if not with_system_controller or not m:plugin_exists('system-controller') then
501 m:load_plugin('system-controller')
503 window_manager_operation_names = {
508 function window_manager_operation_name(oper)
509 local name = window_manager_operation_names[oper]
510 if name then return name end
511 return "<unknown " .. tostring(oper) .. ">"
514 window_operation_names = {
523 function window_operation_name(oper)
524 local name = window_operation_names[oper]
525 if name then return name end
526 return "<unknown " .. tostring(oper) .. ">"
529 layer_operation_names = {
535 function layer_operation_name(oper)
536 local name = layer_operation_names[oper]
537 if name then return name end
538 return "<unknown " .. tostring(oper) .. ">"
541 input_manager_operation_names = {
547 function input_manager_operation_name(oper)
548 local name = input_manager_operation_names[oper]
549 if name then return name end
550 return "<unknown " .. tostring(oper) .. ">"
553 input_operation_names = {
559 function input_operation_name(oper)
560 local name = input_operation_names[oper]
561 if name then return name end
562 return "<unknown " .. tostring(oper) .. ">"
565 code_operation_names = {
571 function code_operation_name(oper)
572 local name = code_operation_names[oper]
573 if name then return name end
574 return "<unknown " .. tostring(oper) .. ">"
578 [0x00001] = "send_appid",
579 [0x10001] = "create",
580 [0x10002] = "destroy",
584 [0x10006] = "change_active",
585 [0x10007] = "change_layer",
586 [0x10008] = "change_attr",
588 [0x10011] = "map_thumb",
589 [0x10012] = "unmap_thumb",
590 [0x10020] = "show layer",
591 [0x10021] = "hide_layer",
592 [0x10022] = "change_layer_attr",
593 [0x20001] = "add_input",
594 [0x20002] = "del_input",
595 [0x20003] = "send_input",
596 [0x40001] = "acquire_res",
597 [0x40002] = "release_res",
598 [0x40003] = "deprive_res",
599 [0x40004] = "waiting_res",
600 [0x40005] = "revert_res",
601 [0x40011] = "create_res",
602 [0x40012] = "destroy_res",
603 [0x50001] = "set_region",
604 [0x50002] = "unset_region",
605 [0x60001] = "change_state"
608 function command_name(command)
609 local name = command_names[command]
610 if name then return name end
611 return "<unknown " .. tostring(command) .. ">"
620 resmgr = resource_manager {
621 screen_event_handler = function(self, ev)
622 local event = ev.event
623 local surface = ev.surface
625 if event == "grant" then
627 print("*** make visible surface "..surface)
629 local a = animation({})
630 local r = m:JSON({surface = surface,
633 wmgr:window_request(r,a,0)
634 elseif event == "revoke" then
636 print("*** hide surface "..surface)
638 local a = animation({})
639 local r = m:JSON({surface = ev.surface,
641 wmgr:window_request(r,a,0)
644 print("*** screen resource event: " ..
649 audio_event_handler = function(self, ev)
650 local event = ev.event
651 local appid = ev.appid
652 local audioid = ev.audioid
654 if event == "grant" then
655 if verbose > 0 or true then
656 print("*** grant audio to "..appid..
657 " ("..audioid..") in '" ..
660 elseif event == "revoke" then
661 if verbose > 0 or true then
662 print("*** revoke audio from "..appid..
663 " ("..audioid..") in '" ..
667 if verbose > 0 or true then
668 print("*** audio resource event: " ..
675 resclnt = resource_client {}
677 wmgr = window_manager {
678 geometry = function(self, w,h, v)
679 if type(v) == "function" then
685 application = function(self, appid)
687 local app = application_lookup(appid)
689 app = application_lookup("default")
693 return { privileges = {screen="none", audio="none"} }
696 outputs = { { name = "Center",
703 width = function(w,h) return w end,
710 width = function(w,h) return w end,
711 height = function(w,h) return h-64-128 end
717 width = function(w,h) return w end,
718 height = function(w,h) return (h-64-128)/2 end
723 pos_y = function(w,h) return (h-64-128)/2+64 end,
724 width = function(w,h) return w end,
725 height = function(w,h) return (h-64-128)/2 end
731 width = function(w,h) return w/2 end,
732 height = function(w,h) return (h-64-128)/2 end
736 pos_x = function(w,h) return w/2 end,
738 width = function(w,h) return w/2 end,
739 height = function(w,h) return (h-64-128)/2 end
744 pos_y = function(w,h) return (h-64-128/2)+64 end,
745 width = function(w,h) return w/2 end,
746 height = function(w,h) return (h-64-128)/2 end
750 pos_x = function(w,h) return w/2 end,
751 pos_y = function(w,h) return (h-64-128/2)+64 end,
752 width = function(w,h) return w/2 end,
753 height = function(w,h) return (h-64-128)/2 end
759 width = function(w,h) return w end,
760 height = function(w,h) return h-64-128 end
766 width = function(w,h) return w/2-181 end,
767 height = function(w,h) return h-64-128 end
771 pos_x = function(w,h) return w/2+181 end,
773 width = function(w,h) return w/2-181 end,
774 height = function(w,h) return h-64-128 end
784 layers = { { 0, "Background" , 1 },
785 { 1, "Application" , 2 },
786 { 2, "Softkeyboard" , 4 },
787 { 3, "HomeScreen" , 2 },
788 { 4, "ControlBar" , 2 },
789 { 5, "InterruptApp" , 2 },
790 { 6, "OnScreen" , 2 },
791 { 101, "Input" , 3 },
792 { 102, "Cursor" , 5 },
793 { 103, "Startup" , 6 },
794 { 0x1000, "Background" , 1 },
795 { 0x2000, "Normal" , 2 },
796 { 0x3000, "Fullscreen" , 2 },
797 { 0x4000, "InputPanel" , 3 },
798 { 0xA000, "Touch" , 4 },
799 { 0xB000, "Cursor" , 5 },
800 { 0xC000, "Startup" , 6 }
804 manager_update = function(self, oper)
806 print("### <== WINDOW MANAGER UPDATE:" ..
807 window_manager_operation_name(oper))
810 local umask = window_mask { raise = true,
813 local rmask = window_mask { active = true }
815 passthrough_update = umask:tointeger(),
816 passthrough_request = rmask:tointeger()
818 self:manager_request(req)
822 window_update = function(self, oper, win, mask)
824 print("### <== WINDOW UPDATE oper:" ..
825 window_operation_name(oper) ..
826 " mask: " .. tostring(mask))
832 local arg = m:JSON({ surface = win.surface,
837 if oper == 1 then -- create
838 local layertype = win.layertype
839 if layertype and input_layer[layertype] then
841 print("ignoring input panel creation")
846 elseif oper == 2 then -- destroy
848 elseif oper == 3 then -- namechange
850 elseif oper == 4 or oper == 5 then --visible or configure
854 arg.layer = win.layer
855 arg.pos_x = win.pos_x
856 arg.pos_y = win.pos_y
857 arg.width = win.width
858 arg.height = win.height
859 arg.raise = win.raise
860 arg.visible = win.visible
861 arg.active = win.active
862 elseif oper == 6 then -- active
864 arg.active = win.active
867 print("### nothing to do")
872 local msg = m:JSON({ command = command,
878 print("### <== sending " ..
879 command_name(msg.command) ..
880 " window message to '" .. win.name .. "'")
885 sc:send_message(homescreen, msg)
887 if oper == 1 then -- create
888 local i = input_layer[win.layertype]
889 local p = self:application(win.appid)
890 local s = p.privileges.screen
892 if s == "system" then
893 local a = animation({})
894 local r = m:JSON({surface = win.surface,
897 self:window_request(r,a,0)
901 print("do not make resource for " ..
905 resclnt:resource_set_create("screen",
911 elseif oper == 2 then -- destroy
912 resclnt:resource_set_destroy("screen", win.surface)
913 elseif oper == 6 then -- active
915 local i = input_layer[win.layertype]
916 local p = self:application(win.appid)
917 local s = p.privileges.screen
918 local surface = win.surface
919 if not i and s ~= "system" then
920 resclnt:resource_set_acquire("screen",surface)
921 resmgr:window_raise(win.appid, surface, 1)
927 layer_update = function(self, oper, layer, mask)
929 print("### LAYER UPDATE:" ..
930 layer_operation_name(oper) ..
931 " mask: " .. tostring(mask))
936 if oper == 3 then -- visible
937 local command = 0x10022
941 arg = m:JSON({layer = layer.id,
942 visible = layer.visible
946 print("### <== sending "..command_name(command)..
952 sc:send_message(homescreen, msg)
955 print("### nothing to do")
960 output_update = function(self, oper, out, mask)
961 local idx = out.index
963 print("### OUTPUT UPDATE:" .. oper ..
964 " mask: "..tostring(mask))
967 local outdef = self.outputs[idx+1]
968 if (oper == 1) then -- create
970 self:output_request(m:JSON({index = idx,
975 elseif (oper == 5) then -- done
976 local ads = outdef.areas
977 local on = outdef.name
979 for name,ad in pairs(ads) do
980 local can = wmgr:canonical_name(on.."."..name)
981 local a = m:JSON({name = name,
983 for fld,val in pairs(ad) do
984 a[fld] = self:geometry(out.width,
989 resmgr:area_create(area[can], outdef.zone)
997 imgr = input_manager {
998 inputs = {{ name = "G27 Racing Wheel",
1000 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1001 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1002 [4] = {appid="org.tizen.ico.app-soundsample" },
1003 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1007 manager_update = function(self, oper)
1009 print("### <== INPUT MANAGER UPDATE:" ..
1010 input_manager_operation_name(oper))
1014 input_update = function(self, oper, inp, mask)
1016 print("### INPUT UPDATE:" ..
1017 input_operation_name(oper) ..
1018 " mask: " .. tostring(mask))
1024 code_update = function(self, oper, code, mask)
1026 print("### CODE UPDATE: mask: " .. tostring(mask))
1031 local msg = m:JSON({ command = 1,
1032 appid = "org.tizen.ico.homescreen",
1033 arg = m:JSON({ device = code.device,
1041 print("### <== sending " ..
1042 command_name(msg.command) ..
1048 sc:send_message(homescreen, msg)
1052 sc = m:get_system_controller()
1058 um = m:UserManager()
1063 -- these shoud be before wmgr:connect() is called
1065 print("====== creating applications ======")
1069 area = "Center.Full",
1070 privileges = { screen = "none", audio = "none" },
1071 resource_class = "player",
1077 area = "Center.Full",
1078 privileges = { screen = "system", audio = "none" },
1079 resource_class = "implicit",
1080 screen_priority = 30
1084 appid = "org.tizen.ico.homescreen",
1085 area = "Center.Full",
1086 privileges = { screen = "system", audio = "system" },
1087 resource_class = "player",
1088 screen_priority = 20
1092 appid = "org.tizen.ico.statusbar",
1093 area = "Center.Status",
1094 privileges = { screen = "system", audio = "none" },
1095 resource_class = "player",
1096 screen_priority = 20
1100 appid = "org.tizen.ico.login",
1101 area = "Center.Full",
1102 privileges = { screen = "system", audio = "system" },
1103 resource_class = "player",
1104 screen_priority = 20
1109 sc.client_handler = function (self, cid, msg)
1110 local command = msg.command
1112 print('### ==> client handler:')
1117 if not connected then
1118 print('Setting homescreen='..msg.appid)
1119 homescreen = msg.appid
1120 print('Trying to connect to wayland...')
1121 connected = wmgr:connect()
1123 if connected and command then
1124 if command == 1 then -- send_appid
1125 local driving_mode = mdb.select.select_driving_mode.single_value
1126 local night_mode = mdb.select.select_night_mode.single_value
1128 if not driving_mode then driving_mode = 0 end
1129 if not night_mode then night_mode = 0 end
1131 local reply = m:JSON({ command = 0x60001,
1132 arg = m:JSON({ stateid = 1,
1133 state = driving_mode})
1136 print("### <== sending " ..
1137 command_name(command) .. " message")
1142 sc:send_message(homescreen, reply)
1144 reply = m:JSON({ command = 0x60001,
1145 arg = m:JSON({ stateid = 2,
1146 state = night_mode})
1149 print("### <== sending " ..
1150 command_name(command) .. " message")
1155 sc:send_message(homescreen, reply)
1160 sc.generic_handler = function (self, cid, msg)
1162 print('### ==> generic handler:')
1169 sc.window_handler = function (self, cid, msg)
1171 print('### ==> received ' ..
1172 command_name(msg.command) .. ' message')
1174 print(tostring(msg))
1178 local a = animation({})
1180 if msg.command == 0x10003 then -- ico SHOW command
1181 local raise_mask = 0x01000000
1182 local lower_mask = 0x02000000
1183 local nores_mask = 0x40000000
1184 local time_mask = 0x00ffffff
1188 if msg.arg.anim_time then
1189 local t = msg.arg.anim_time
1190 time = m:AND(t, time_mask)
1191 nores = m:AND(t, nores_mask)
1192 if m:AND(t, raise_mask) then
1194 elseif m:AND(t, lower_mask) then
1198 if msg.arg.anim_name then
1199 a.show = { msg.arg.anim_name, time }
1200 print('time: ' .. tostring(a.show[2]))
1204 local p = wmgr:application(msg.appid)
1205 local s = p.privileges.screen
1206 if s == "system" then
1211 print('### ==> SHOW')
1212 print(tostring(msg.arg))
1215 wmgr:window_request(msg.arg, a, 0)
1217 local surface = msg.arg.surface
1218 resclnt:resource_set_acquire("screen", surface)
1219 resmgr:window_raise(msg.appid, surface, 1)
1221 elseif msg.command == 0x10004 then -- ico HIDE command
1222 local raise_mask = 0x01000000
1223 local lower_mask = 0x02000000
1224 local nores_mask = 0x40000000
1225 local time_mask = 0x00ffffff
1229 if msg.arg.anim_time then
1230 local t = msg.arg.anim_time
1231 time = m:AND(t, time_mask)
1232 nores = m:AND(t, nores_mask)
1234 if msg.arg.anim_name then
1235 a.hide = { msg.arg.anim_name, time }
1236 print('hide animation time: ' .. tostring(a.hide[2]))
1240 local p = wmgr:application(msg.appid)
1241 local s = p.privileges.screen
1242 if s == "system" then
1247 print('### ==> HIDE REQUEST')
1248 print(tostring(msg.arg))
1251 wmgr:window_request(msg.arg, a, 0)
1253 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1255 elseif msg.command == 0x10005 then -- ico MOVE
1257 print('### ==> MOVE REQUEST')
1258 print(tostring(msg.arg))
1260 wmgr:window_request(msg.arg, a, 0)
1261 -- TODO: handle if area changed
1262 elseif msg.command == 0x10006 then -- ico ACTIVE
1263 if not msg.arg.active then
1264 msg.arg.active = 3 -- pointer + keyboard
1267 print('### ==> ACTIVE REQUEST')
1268 print(tostring(msg.arg))
1270 wmgr:window_request(msg.arg, a, 0)
1271 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1273 print('### ==> CHANGE_LAYER REQUEST')
1274 print(tostring(msg.arg))
1277 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1278 print("do not change layer for other than cursor or touch")
1282 wmgr:window_request(msg.arg, a, 0)
1283 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1284 local framerate = msg.arg.framerate
1285 if not framerate or framerate < 0 then
1290 print('### ==> MAP_THUMB REQUEST')
1292 print('framerate: '..framerate)
1294 wmgr:window_request(msg.arg, a, framerate)
1295 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1298 print('### ==> UNMAP_THUMB REQUEST')
1301 wmgr:window_request(msg.arg, a, 0)
1302 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1305 print('### ==> SHOW_LAYER REQUEST')
1308 wmgr:layer_request(msg.arg)
1309 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1312 print('### ==> HIDE_LAYER REQUEST')
1315 wmgr:layer_request(msg.arg)
1319 sc.input_handler = function (self, cid, msg)
1321 print('### ==> input handler: ' .. command_name(msg.command))
1326 if msg.command == 0x20001 then -- add_input
1327 msg.arg.appid = msg.appid
1329 print('### ==> ADD_INPUT REQUEST')
1330 print(tostring(msg.arg))
1332 imgr:input_request(msg.arg)
1333 elseif msg.command == 0x20002 then -- del_input
1336 print('### ==> DEL_INPUT REQUEST')
1337 print(tostring(msg.arg))
1339 imgr:input_request(msg.arg)
1340 elseif msg.command == 0x20003 then -- send_input
1344 sc.user_handler = function (self, cid, msg)
1346 print('### ==> user handler: ' .. command_name(msg.command))
1353 print("User Manager not initialized")
1357 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1358 print("command CHANGE_USER")
1360 print("invalid message")
1364 username = msg.arg.user
1365 passwd = msg.arg.pass
1367 if not username then
1375 success = um:changeUser(username, passwd)
1382 if sc:send_message(msg.appid, reply) then
1383 print('*** sent authentication failed message')
1385 print('*** failed to send authentication failed message')
1389 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1390 print("command GET_USERLIST")
1391 if not msg.appid then
1392 print("invalid message")
1396 users, currentUser = um:getUserList()
1399 print("failed to get user list")
1405 for i,v in pairs(users) do
1409 if not currentUser then
1414 print("current user: " .. currentUser)
1416 for i,v in pairs(users) do
1427 user_login = currentUser
1432 print("### <== GetUserList reply: " .. tostring(reply))
1435 if sc:send_message(msg.appid, reply) then
1436 print('*** reply OK')
1438 print('*** reply FAILED')
1441 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1442 print("command GET_LASTINFO")
1443 if not msg.appid then
1444 print("invalid message")
1448 lastInfo = um:getLastInfo(msg.appid)
1450 if not lastInfo then
1451 print("failed to get last info for app" .. msg.appid)
1463 if sc:send_message(msg.appid, reply) then
1464 print('*** reply OK')
1466 print('*** reply FAILED')
1469 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1470 print("command SET_LASTINFO")
1471 if not msg.arg or not msg.appid then
1472 print("invalid message")
1476 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1480 sc.resource_handler = function (self, cid, msg)
1482 print('### ==> resource handler: ' .. command_name(msg.command))
1488 createResourceSet = function (ctl, client, msg)
1489 cb = function(rset, data)
1490 print("> resource callback")
1492 -- type is either basic (0) or interrupt (1)
1494 if msg.res.type then
1495 requestType = msg.res.type
1498 if rset.acquired then
1499 cmd = 0x00040001 -- acquire
1501 cmd = 0x00040002 -- release
1505 appid = data.client,
1512 if rset.resources.audio_playback then
1521 if rset.resources.display then
1522 reply.res.window = {
1529 if rset.resources.input then
1535 print("sending message to client: " .. data.client)
1537 if sc:send_message(data.client, reply) then
1538 print('*** reply OK')
1540 print('*** reply FAILED')
1544 rset = m:ResourceSet({
1545 application_class = "player",
1546 zone = "driver", -- msg.zone ("full")
1555 if msg.res.sound then
1557 resource_name = "audio_playback"
1559 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1560 rset.resources.audio_playback.attributes.appid = msg.appid
1561 print("sound name: " .. msg.res.sound.name)
1562 print("sound zone:" .. msg.res.sound.zone)
1563 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1564 if msg.res.sound.id then
1565 print("sound id: " .. msg.res.sound.id)
1569 if msg.res.input then
1571 resource_name = "input"
1573 rset.resources.input.attributes.pid = tostring(msg.pid)
1574 rset.resources.input.attributes.appid = msg.appid
1575 print("input name: " .. msg.res.sound.name)
1576 print("input event:" .. tostring(msg.res.input.event))
1579 if msg.res.window then
1581 resource_name = "display"
1583 rset.resources.display.attributes.pid = tostring(msg.pid)
1584 rset.resources.display.attributes.appid = msg.appid
1585 print("display name: " .. msg.res.display.name)
1586 print("display zone:" .. msg.res.display.zone)
1587 if msg.res.display.id then
1588 print("display id: " .. msg.res.display.id)
1595 -- parse the message
1597 -- fields common to all messages:
1602 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1603 print("command CREATE")
1605 if not sets.cid then
1606 sets.cid = createResourceSet(self, cid, msg)
1609 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1610 print("command DESTROY")
1616 sets.cid = nil -- garbage collecting
1618 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1619 print("command ACQUIRE")
1621 if not sets.cid then
1622 sets.cid = createResourceSet(self, cid, msg)
1627 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1628 print("command RELEASE")
1634 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1635 print("command DEPRIVE")
1637 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1638 print("command WAITING")
1640 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1641 print("command REVERT")
1645 sc.inputdev_handler = function (self, cid, msg)
1647 print('*** inputdev handler: ' .. command_name(msg.command))