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",
222 name = "speech_recognition",
227 name = "speech_synthesis",
231 if not m:plugin_exists('ivi-resource-manager') and
232 not with_system_controller
234 resource.method.veto = {
235 function(zone, rset, grant, owners, req_set)
241 -- test for creating selections
243 name = "audio_owner",
244 table = "audio_playback_owner",
245 columns = {"application_class"},
246 condition = "zone_name = 'driver'"
250 name = "vehicle_speed",
251 table = "amb_vehicle_speed",
253 condition = "key = 'VehicleSpeed'"
257 name = "speed2volume",
258 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
259 outputs = { mdb.table { name = "speedvol",
260 index = {"zone", "device"},
261 columns = {{"zone", mdb.string, 16},
262 {"device", mdb.string, 16},
263 {"value", mdb.floating}},
268 update = function(self)
269 speed = self.inputs.speed.single_value
271 volume = (speed - 144.0) / 7.0
275 diff = volume - self.oldvolume
276 if (diff*diff > self.inputs.param) then
277 print("*** element "..self.name.." update "..volume)
278 self.oldvolume = volume
279 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
284 -- Night mode processing chain
287 name = "exterior_brightness",
288 table = "amb_exterior_brightness",
289 columns = { "value" },
290 condition = "key = 'ExteriorBrightness'"
295 inputs = { brightness = mdb.select.exterior_brightness },
299 name = "amb_nightmode",
303 { "id", mdb.unsigned },
304 { "night_mode", mdb.unsigned }
308 update = function(self)
309 -- This is a trivial function to calculate night mode. Later, we will
310 -- need a better threshold value and hysteresis to prevent oscillation.
312 brightness = self.inputs.brightness.single_value
314 if not brightness then
318 print("*** element "..self.name.." update brightness: "..brightness)
320 if brightness > 300 then
326 print("*** resulting mode: ".. mode)
328 if not (mode == self.oldmode) then
329 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
337 name = "select_night_mode",
338 table = "amb_nightmode",
339 columns = { "night_mode" },
346 inputs = { owner = mdb.select.select_night_mode },
347 property = "NightMode",
349 initiate = builtin.method.amb_initiate,
350 update = builtin.method.amb_update
354 -- Night mode general handlers
357 name = "nightmode_homescreen",
358 inputs = { owner = mdb.select.select_night_mode },
359 initiate = function(self)
360 -- data = mdb.select.select_night_mode.single_value
363 update = function(self)
364 data = mdb.select.select_night_mode.single_value
367 print("Night mode updated: " .. tostring(data))
371 -- tell homescreen that night mode was updated
372 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=2,state=data})}))
378 -- Driving mode processing chain
381 name = "drivingmode",
382 inputs = { speed = mdb.select.vehicle_speed },
386 name = "amb_drivingmode",
390 { "id", mdb.unsigned },
391 { "driving_mode", mdb.unsigned }
395 update = function(self)
397 speed = self.inputs.speed.single_value
409 if not (mode == self.oldmode) then
410 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
418 name = "select_driving_mode",
419 table = "amb_drivingmode",
420 columns = { "driving_mode" },
426 name = "driving_mode",
427 inputs = { owner = mdb.select.select_driving_mode },
428 property = "DrivingMode",
430 initiate = builtin.method.amb_initiate,
431 update = builtin.method.amb_update
435 -- turn signals (left, right)
439 table = "amb_turn_signal",
440 columns = { "value" },
441 condition = "key = 'TurnSignal'"
444 -- define three categories
447 name = "undefined_applications",
448 table = "aul_applications",
449 columns = { "appid" },
450 condition = "category = '<undefined>'"
454 name = "basic_applications",
455 table = "aul_applications",
456 columns = { "appid" },
457 condition = "category = 'basic'"
461 name = "entertainment_applications",
462 table = "aul_applications",
463 columns = { "appid" },
464 condition = "category = 'entertainment'"
468 -- filter the object garbage out of the tables
471 for k,v in pairs(t) do
472 if k ~= "userdata" and k ~= "new" then
480 function getApplication(appid)
483 -- find the correct local application definition
485 for k,v in pairs(ft(application)) do
486 if appid == v.appid then
495 function regulateApplications(t, regulation)
496 for k,v in pairs(ft(t)) do
498 -- iterate through the undefined and entertainment apps, see if
499 -- they have been overruled in local config
501 local conf = getApplication(v.appid)
503 if conf and conf.resource_class ~= "player" then
504 -- override, don't disable
505 resmgr:disable_screen_by_appid("*", "*", v.appid, false)
507 resmgr:disable_screen_by_appid("*", "*", v.appid, regulation == 1)
512 -- regulation (on), use "select_driving_mode"
515 name = "driving_regulation",
516 inputs = { owner = mdb.select.select_driving_mode },
517 initiate = function(self)
518 -- local data = mdb.select.select_driving_mode.single_value
521 update = function(self)
522 local data = mdb.select.select_driving_mode.single_value
525 print("Driving mode updated: " .. tostring(data))
532 -- tell homescreen that driving mode was updated
533 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=1,state=data})}))
536 -- bulk handle the applications that need requisites
537 r = requisite { driving = true }
538 resmgr:disable_screen_by_requisite("*", "*", r, data == 1)
541 regulateApplications(ft(mdb.select.entertainment_applications), data)
542 regulateApplications(ft(mdb.select.undefined_applications), data)
549 name = "regulated_app_change",
550 inputs = { undef = mdb.select.undefined_applications,
551 entertainment = mdb.select.entertainment_applications },
552 initiate = function(self)
555 update = function(self)
556 local data = mdb.select.select_driving_mode.single_value
563 print("regulated application list was changed")
566 regulateApplications(ft(mdb.select.entertainment_applications), data)
567 regulateApplications(ft(mdb.select.undefined_applications), data)
574 -- shift position (parking, reverse, other)
577 name = "gear_position",
578 table = "amb_gear_position",
579 columns = { "value" },
580 condition = "key = 'GearPosition'"
583 -- cameras (back, front, left, right)
586 name = "camera_state",
587 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
591 name = "target_camera_state",
595 { "id", mdb.unsigned },
596 { "front_camera", mdb.unsigned },
597 { "back_camera", mdb.unsigned },
598 { "right_camera", mdb.unsigned },
599 { "left_camera", mdb.unsigned }
603 update = function(self)
610 if self.inputs.gear == 128 then
612 elseif self.inputs.winker == 1 then
614 elseif self.inputs.winker == 2 then
618 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
623 -- load the telephony plugin
624 m:try_load_plugin('telephony')
627 -- system controller test setup
629 if not with_system_controller then
633 m:load_plugin('system-controller')
635 window_manager_operation_names = {
640 function window_manager_operation_name(oper)
641 local name = window_manager_operation_names[oper]
642 if name then return name end
643 return "<unknown " .. tostring(oper) .. ">"
646 window_operation_names = {
655 function window_operation_name(oper)
656 local name = window_operation_names[oper]
657 if name then return name end
658 return "<unknown " .. tostring(oper) .. ">"
661 layer_operation_names = {
667 function layer_operation_name(oper)
668 local name = layer_operation_names[oper]
669 if name then return name end
670 return "<unknown " .. tostring(oper) .. ">"
673 input_manager_operation_names = {
679 function input_manager_operation_name(oper)
680 local name = input_manager_operation_names[oper]
681 if name then return name end
682 return "<unknown " .. tostring(oper) .. ">"
685 input_operation_names = {
691 function input_operation_name(oper)
692 local name = input_operation_names[oper]
693 if name then return name end
694 return "<unknown " .. tostring(oper) .. ">"
697 code_operation_names = {
703 function code_operation_name(oper)
704 local name = code_operation_names[oper]
705 if name then return name end
706 return "<unknown " .. tostring(oper) .. ">"
710 [0x00001] = "send_appid",
711 [0x10001] = "create",
712 [0x10002] = "destroy",
716 [0x10006] = "change_active",
717 [0x10007] = "change_layer",
718 [0x10008] = "change_attr",
720 [0x10011] = "map_thumb",
721 [0x10012] = "unmap_thumb",
722 [0x10020] = "show layer",
723 [0x10021] = "hide_layer",
724 [0x10022] = "change_layer_attr",
725 [0x20001] = "add_input",
726 [0x20002] = "del_input",
727 [0x20003] = "send_input",
728 [0x40001] = "acquire_res",
729 [0x40002] = "release_res",
730 [0x40003] = "deprive_res",
731 [0x40004] = "waiting_res",
732 [0x40005] = "revert_res",
733 [0x40011] = "create_res",
734 [0x40012] = "destroy_res",
735 [0x50001] = "set_region",
736 [0x50002] = "unset_region",
737 [0x60001] = "change_state"
740 function command_name(command)
741 local name = command_names[command]
742 if name then return name end
743 return "<unknown " .. tostring(command) .. ">"
752 resmgr = resource_manager {
753 screen_event_handler = function(self, ev)
754 local event = ev.event
755 local surface = ev.surface
757 if event == "grant" then
759 print("*** make visible surface "..surface)
761 local a = animation({})
762 local r = m:JSON({surface = surface,
765 wmgr:window_request(r,a,0)
766 elseif event == "revoke" then
768 print("*** hide surface "..surface)
770 local a = animation({})
771 local r = m:JSON({surface = ev.surface,
773 wmgr:window_request(r,a,0)
775 elseif event == "create" then
778 print("*** screen resource event: " ..
782 -- For now, consider every application to be an "entertainment"
783 -- application. Whitelist those applications that we know. Later
784 -- check the aul_applications table for actual category (when
785 -- we get the categories there).
787 local regulation = mdb.select.select_driving_mode.single_value
789 if regulation == 1 then
790 conf = getApplication(ev.appid)
792 -- disable only non-whitelisted applications
793 if not conf or conf.resource_class == "player" then
794 resmgr:disable_screen_by_appid("*", "*", ev.appid, true)
798 elseif event == "destroy" then
800 print("*** screen resource event: " ..
805 print("*** screen resource event: " ..
810 audio_event_handler = function(self, ev)
811 local event = ev.event
812 local appid = ev.appid
813 local audioid = ev.audioid
815 if event == "grant" then
816 if verbose > 0 or true then
817 print("*** grant audio to "..appid..
818 " ("..audioid..") in '" ..
821 elseif event == "revoke" then
822 if verbose > 0 or true then
823 print("*** revoke audio from "..appid..
824 " ("..audioid..") in '" ..
828 if verbose > 0 or true then
829 print("*** audio resource event: " ..
836 resclnt = resource_client {}
838 wmgr = window_manager {
839 geometry = function(self, w,h, v)
840 if type(v) == "function" then
846 application = function(self, appid)
848 local app = application_lookup(appid)
850 app = application_lookup("default")
854 return { privileges = {screen="none", audio="none"} }
857 outputs = { { name = "Center",
864 width = function(w,h) return w end,
871 width = function(w,h) return w end,
872 height = function(w,h) return h-64-128 end
878 width = function(w,h) return w end,
879 height = function(w,h) return (h-64-128)/2 end
884 pos_y = function(w,h) return (h-64-128)/2+64 end,
885 width = function(w,h) return w end,
886 height = function(w,h) return (h-64-128)/2 end
892 width = function(w,h) return w/2 end,
893 height = function(w,h) return (h-64-128)/2 end
897 pos_x = function(w,h) return w/2 end,
899 width = function(w,h) return w/2 end,
900 height = function(w,h) return (h-64-128)/2 end
905 pos_y = function(w,h) return (h-64-128/2)+64 end,
906 width = function(w,h) return w/2 end,
907 height = function(w,h) return (h-64-128)/2 end
911 pos_x = function(w,h) return w/2 end,
912 pos_y = function(w,h) return (h-64-128/2)+64 end,
913 width = function(w,h) return w/2 end,
914 height = function(w,h) return (h-64-128)/2 end
920 width = function(w,h) return w end,
921 height = function(w,h) return h-64-128 end
927 width = function(w,h) return w/2-181 end,
928 height = function(w,h) return h-64-128 end
932 pos_x = function(w,h) return w/2+181 end,
934 width = function(w,h) return w/2-181 end,
935 height = function(w,h) return h-64-128 end
945 layers = { { 0, "Background" , 1 },
946 { 1, "Application" , 2 },
947 { 2, "Softkeyboard" , 4 },
948 { 3, "HomeScreen" , 2 },
949 { 4, "ControlBar" , 2 },
950 { 5, "InterruptApp" , 2 },
951 { 6, "OnScreen" , 2 },
952 { 101, "Input" , 3 },
953 { 102, "Cursor" , 5 },
954 { 103, "Startup" , 6 },
955 { 0x1000, "Background" , 1 },
956 { 0x2000, "Normal" , 2 },
957 { 0x3000, "Fullscreen" , 2 },
958 { 0x4000, "InputPanel" , 3 },
959 { 0xA000, "Touch" , 4 },
960 { 0xB000, "Cursor" , 5 },
961 { 0xC000, "Startup" , 6 }
965 manager_update = function(self, oper)
967 print("### <== WINDOW MANAGER UPDATE:" ..
968 window_manager_operation_name(oper))
971 local umask = window_mask { raise = true,
974 local rmask = window_mask { active = true }
976 passthrough_update = umask:tointeger(),
977 passthrough_request = rmask:tointeger()
979 self:manager_request(req)
983 window_update = function(self, oper, win, mask)
985 print("### <== WINDOW UPDATE oper:" ..
986 window_operation_name(oper) ..
987 " mask: " .. tostring(mask))
993 local arg = m:JSON({ surface = win.surface,
998 if oper == 1 then -- create
999 local layertype = win.layertype
1000 if layertype and input_layer[layertype] then
1002 print("ignoring input panel creation")
1007 elseif oper == 2 then -- destroy
1009 elseif oper == 3 then -- namechange
1011 elseif oper == 4 or oper == 5 then --visible or configure
1015 arg.layer = win.layer
1016 arg.pos_x = win.pos_x
1017 arg.pos_y = win.pos_y
1018 arg.width = win.width
1019 arg.height = win.height
1020 arg.raise = win.raise
1021 arg.visible = win.visible
1022 arg.active = win.active
1023 elseif oper == 6 then -- active
1025 arg.active = win.active
1028 print("### nothing to do")
1033 local msg = m:JSON({ command = command,
1039 print("### <== sending " ..
1040 command_name(msg.command) ..
1041 " window message to '" .. win.name .. "'")
1046 sc:send_message(homescreen, msg)
1048 if oper == 1 then -- create
1049 local i = input_layer[win.layertype]
1050 local p = self:application(win.appid)
1051 local s = p.privileges.screen
1053 if s == "system" then
1054 local a = animation({})
1055 local r = m:JSON({surface = win.surface,
1058 self:window_request(r,a,0)
1062 print("do not make resource for " ..
1066 resclnt:resource_set_create("screen",
1072 elseif oper == 2 then -- destroy
1073 resclnt:resource_set_destroy("screen", win.surface)
1074 elseif oper == 6 then -- active
1076 local i = input_layer[win.layertype]
1077 local p = self:application(win.appid)
1078 local s = p.privileges.screen
1079 local surface = win.surface
1080 if not i and s ~= "system" then
1081 resclnt:resource_set_acquire("screen",surface)
1082 resmgr:window_raise(win.appid, surface, 1)
1088 layer_update = function(self, oper, layer, mask)
1090 print("### LAYER UPDATE:" ..
1091 layer_operation_name(oper) ..
1092 " mask: " .. tostring(mask))
1097 if oper == 3 then -- visible
1098 local command = 0x10022
1099 local msg = m:JSON({
1102 arg = m:JSON({layer = layer.id,
1103 visible = layer.visible
1107 print("### <== sending "..command_name(command)..
1113 sc:send_message(homescreen, msg)
1116 print("### nothing to do")
1121 output_update = function(self, oper, out, mask)
1122 local idx = out.index
1124 print("### OUTPUT UPDATE:" .. oper ..
1125 " mask: "..tostring(mask))
1128 local outdef = self.outputs[idx+1]
1129 if (oper == 1) then -- create
1131 self:output_request(m:JSON({index = idx,
1136 elseif (oper == 5) then -- done
1137 local ads = outdef.areas
1138 local on = outdef.name
1140 for name,ad in pairs(ads) do
1141 local can = wmgr:canonical_name(on.."."..name)
1142 local a = m:JSON({name = name,
1143 output = out.index})
1144 for fld,val in pairs(ad) do
1145 a[fld] = self:geometry(out.width,
1150 resmgr:area_create(area[can], outdef.zone)
1158 imgr = input_manager {
1159 inputs = {{ name = "G27 Racing Wheel",
1161 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1162 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1163 [4] = {appid="org.tizen.ico.app-soundsample" },
1164 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1168 manager_update = function(self, oper)
1170 print("### <== INPUT MANAGER UPDATE:" ..
1171 input_manager_operation_name(oper))
1175 input_update = function(self, oper, inp, mask)
1177 print("### INPUT UPDATE:" ..
1178 input_operation_name(oper) ..
1179 " mask: " .. tostring(mask))
1185 code_update = function(self, oper, code, mask)
1187 print("### CODE UPDATE: mask: " .. tostring(mask))
1192 local msg = m:JSON({ command = 1,
1193 appid = "org.tizen.ico.homescreen",
1194 arg = m:JSON({ device = code.device,
1202 print("### <== sending " ..
1203 command_name(msg.command) ..
1209 sc:send_message(homescreen, msg)
1213 sc = m:get_system_controller()
1219 um = m:UserManager()
1224 -- these shoud be before wmgr:connect() is called
1226 print("====== creating applications ======")
1230 area = "Center.Full",
1231 privileges = { screen = "none", audio = "none" },
1232 resource_class = "player",
1238 area = "Center.Full",
1239 privileges = { screen = "system", audio = "none" },
1240 resource_class = "implicit",
1241 screen_priority = 30
1245 appid = "org.tizen.ico.homescreen",
1246 area = "Center.Full",
1247 privileges = { screen = "system", audio = "system" },
1248 resource_class = "player",
1249 screen_priority = 20
1253 appid = "org.tizen.ico.statusbar",
1254 area = "Center.Status",
1255 privileges = { screen = "system", audio = "none" },
1256 resource_class = "player",
1257 screen_priority = 20
1261 appid = "org.tizen.ico.login",
1262 area = "Center.Full",
1263 privileges = { screen = "system", audio = "system" },
1264 resource_class = "player",
1265 screen_priority = 20
1269 appid = "org.tizen.ico.camera_left",
1270 area = "Center.SysApp.Left",
1271 privileges = { screen = "system", audio = "none" },
1272 requisites = { screen = "blinker_left", audio = "none" },
1273 resource_class = "player",
1274 screen_priority = 30
1278 appid = "org.tizen.ico.camera_right",
1279 area = "Center.SysApp.Right",
1280 privileges = { screen = "system", audio = "none" },
1281 requisites = { screen = "blinker_right", audio = "none" },
1282 resource_class = "player",
1283 screen_priority = 30
1287 appid = "net.zmap.navi",
1288 area = "Center.Full",
1289 privileges = { screen = "none", audio = "none" },
1290 resource_class = "navigator",
1291 screen_priority = 30
1295 sc.client_handler = function (self, cid, msg)
1296 local command = msg.command
1298 print('### ==> client handler:')
1303 if not connected then
1304 print('Setting homescreen='..msg.appid)
1305 homescreen = msg.appid
1306 print('Trying to connect to wayland...')
1307 connected = wmgr:connect()
1309 if connected and command then
1310 if command == 1 then -- send_appid
1311 local driving_mode = mdb.select.select_driving_mode.single_value
1312 local night_mode = mdb.select.select_night_mode.single_value
1314 if not driving_mode then driving_mode = 0 end
1315 if not night_mode then night_mode = 0 end
1317 local reply = m:JSON({ command = 0x60001,
1318 arg = m:JSON({ stateid = 1,
1319 state = driving_mode})
1322 print("### <== sending " ..
1323 command_name(command) .. " message")
1328 sc:send_message(homescreen, reply)
1330 reply = m:JSON({ command = 0x60001,
1331 arg = m:JSON({ stateid = 2,
1332 state = night_mode})
1335 print("### <== sending " ..
1336 command_name(command) .. " message")
1341 sc:send_message(homescreen, reply)
1346 sc.generic_handler = function (self, cid, msg)
1348 print('### ==> generic handler:')
1355 sc.window_handler = function (self, cid, msg)
1357 print('### ==> received ' ..
1358 command_name(msg.command) .. ' message')
1360 print(tostring(msg))
1364 local a = animation({})
1366 if msg.command == 0x10003 then -- ico SHOW command
1367 local raise_mask = 0x01000000
1368 local lower_mask = 0x02000000
1369 local nores_mask = 0x40000000
1370 local time_mask = 0x00ffffff
1374 if msg.arg.anim_time then
1375 local t = msg.arg.anim_time
1376 time = m:AND(t, time_mask)
1377 nores = not m:AND(t, nores_mask)
1378 if m:AND(t, raise_mask) then
1380 elseif m:AND(t, lower_mask) then
1384 if msg.arg.anim_name then
1385 a.show = { msg.arg.anim_name, time }
1386 print('time: ' .. tostring(a.show[2]))
1390 local p = wmgr:application(msg.appid)
1391 local s = p.privileges.screen
1392 if s == "system" then
1397 print('### ==> SHOW')
1398 print(tostring(msg.arg))
1401 wmgr:window_request(msg.arg, a, 0)
1403 local surface = msg.arg.surface
1404 resclnt:resource_set_acquire("screen", surface)
1405 resmgr:window_raise(msg.appid, surface, 1)
1407 elseif msg.command == 0x10004 then -- ico HIDE command
1408 local raise_mask = 0x01000000
1409 local lower_mask = 0x02000000
1410 local nores_mask = 0x40000000
1411 local time_mask = 0x00ffffff
1415 if msg.arg.anim_time then
1416 local t = msg.arg.anim_time
1417 time = m:AND(t, time_mask)
1418 nores = not m:AND(t, nores_mask)
1420 if msg.arg.anim_name then
1421 a.hide = { msg.arg.anim_name, time }
1422 print('hide animation time: ' .. tostring(a.hide[2]))
1426 local p = wmgr:application(msg.appid)
1427 local s = p.privileges.screen
1428 if s == "system" then
1433 print('### ==> HIDE REQUEST')
1434 print(tostring(msg.arg))
1437 wmgr:window_request(msg.arg, a, 0)
1439 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1441 elseif msg.command == 0x10005 then -- ico MOVE
1443 print('### ==> MOVE REQUEST')
1444 print(tostring(msg.arg))
1446 wmgr:window_request(msg.arg, a, 0)
1447 -- TODO: handle if area changed
1448 elseif msg.command == 0x10006 then -- ico ACTIVE
1449 if not msg.arg.active then
1450 msg.arg.active = 3 -- pointer + keyboard
1453 print('### ==> ACTIVE REQUEST')
1454 print(tostring(msg.arg))
1456 wmgr:window_request(msg.arg, a, 0)
1457 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1459 print('### ==> CHANGE_LAYER REQUEST')
1460 print(tostring(msg.arg))
1463 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1464 print("do not change layer for other than cursor or touch")
1468 wmgr:window_request(msg.arg, a, 0)
1469 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1470 local framerate = msg.arg.framerate
1471 if not framerate or framerate < 0 then
1476 print('### ==> MAP_THUMB REQUEST')
1478 print('framerate: '..framerate)
1480 wmgr:window_request(msg.arg, a, framerate)
1481 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1484 print('### ==> UNMAP_THUMB REQUEST')
1487 wmgr:window_request(msg.arg, a, 0)
1488 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1491 print('### ==> SHOW_LAYER REQUEST')
1494 wmgr:layer_request(msg.arg)
1495 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1498 print('### ==> HIDE_LAYER REQUEST')
1501 wmgr:layer_request(msg.arg)
1505 sc.input_handler = function (self, cid, msg)
1507 print('### ==> input handler: ' .. command_name(msg.command))
1512 if msg.command == 0x20001 then -- add_input
1513 msg.arg.appid = msg.appid
1515 print('### ==> ADD_INPUT REQUEST')
1516 print(tostring(msg.arg))
1518 imgr:input_request(msg.arg)
1519 elseif msg.command == 0x20002 then -- del_input
1522 print('### ==> DEL_INPUT REQUEST')
1523 print(tostring(msg.arg))
1525 imgr:input_request(msg.arg)
1526 elseif msg.command == 0x20003 then -- send_input
1530 sc.user_handler = function (self, cid, msg)
1532 print('### ==> user handler: ' .. command_name(msg.command))
1539 print("User Manager not initialized")
1543 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1544 print("command CHANGE_USER")
1546 print("invalid message")
1550 username = msg.arg.user
1551 passwd = msg.arg.pass
1553 if not username then
1561 success = um:changeUser(username, passwd)
1568 if sc:send_message(msg.appid, reply) then
1569 print('*** sent authentication failed message')
1571 print('*** failed to send authentication failed message')
1575 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1576 print("command GET_USERLIST")
1577 if not msg.appid then
1578 print("invalid message")
1582 users, currentUser = um:getUserList()
1585 print("failed to get user list")
1591 for i,v in pairs(users) do
1595 if not currentUser then
1600 print("current user: " .. currentUser)
1602 for i,v in pairs(users) do
1613 user_login = currentUser
1618 print("### <== GetUserList reply: " .. tostring(reply))
1621 if sc:send_message(msg.appid, reply) then
1622 print('*** reply OK')
1624 print('*** reply FAILED')
1627 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1628 print("command GET_LASTINFO")
1629 if not msg.appid then
1630 print("invalid message")
1634 lastInfo = um:getLastInfo(msg.appid)
1636 if not lastInfo then
1637 print("failed to get last info for app" .. msg.appid)
1649 if sc:send_message(msg.appid, reply) then
1650 print('*** reply OK')
1652 print('*** reply FAILED')
1655 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1656 print("command SET_LASTINFO")
1657 if not msg.arg or not msg.appid then
1658 print("invalid message")
1662 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1666 sc.resource_handler = function (self, cid, msg)
1668 print('### ==> resource handler: ' .. command_name(msg.command))
1674 createResourceSet = function (ctl, client, msg)
1675 cb = function(rset, data)
1676 print("> resource callback")
1678 -- type is either basic (0) or interrupt (1)
1680 if msg.res.type then
1681 requestType = msg.res.type
1684 if rset.acquired then
1685 cmd = 0x00040001 -- acquire
1687 cmd = 0x00040002 -- release
1691 appid = data.client,
1698 if rset.resources.audio_playback then
1707 if rset.resources.display then
1708 reply.res.window = {
1715 if rset.resources.input then
1721 print("sending message to client: " .. data.client)
1723 if sc:send_message(data.client, reply) then
1724 print('*** reply OK')
1726 print('*** reply FAILED')
1730 rset = m:ResourceSet({
1731 application_class = "player",
1732 zone = "driver", -- msg.zone ("full")
1741 if msg.res.sound then
1743 resource_name = "audio_playback"
1745 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1746 rset.resources.audio_playback.attributes.appid = msg.appid
1747 print("sound name: " .. msg.res.sound.name)
1748 print("sound zone:" .. msg.res.sound.zone)
1749 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1750 if msg.res.sound.id then
1751 print("sound id: " .. msg.res.sound.id)
1755 if msg.res.input then
1757 resource_name = "input"
1759 rset.resources.input.attributes.pid = tostring(msg.pid)
1760 rset.resources.input.attributes.appid = msg.appid
1761 print("input name: " .. msg.res.sound.name)
1762 print("input event:" .. tostring(msg.res.input.event))
1765 if msg.res.window then
1767 resource_name = "display"
1769 rset.resources.display.attributes.pid = tostring(msg.pid)
1770 rset.resources.display.attributes.appid = msg.appid
1771 print("display name: " .. msg.res.display.name)
1772 print("display zone:" .. msg.res.display.zone)
1773 if msg.res.display.id then
1774 print("display id: " .. msg.res.display.id)
1781 -- parse the message
1783 -- fields common to all messages:
1788 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1789 print("command CREATE")
1791 if not sets.cid then
1792 sets.cid = createResourceSet(self, cid, msg)
1795 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1796 print("command DESTROY")
1802 sets.cid = nil -- garbage collecting
1804 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1805 print("command ACQUIRE")
1807 if not sets.cid then
1808 sets.cid = createResourceSet(self, cid, msg)
1813 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1814 print("command RELEASE")
1820 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1821 print("command DEPRIVE")
1823 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1824 print("command WAITING")
1826 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1827 print("command REVERT")
1831 sc.inputdev_handler = function (self, cid, msg)
1833 print('*** inputdev handler: ' .. command_name(msg.command))