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})
287 columns = { "state" },
291 -- Night mode processing chain
294 name = "exterior_brightness",
295 table = "amb_exterior_brightness",
296 columns = { "value" },
297 condition = "key = 'ExteriorBrightness'"
302 inputs = { brightness = mdb.select.exterior_brightness },
306 name = "amb_nightmode",
310 { "id", mdb.unsigned },
311 { "night_mode", mdb.unsigned }
315 update = function(self)
316 -- This is a trivial function to calculate night mode. Later, we will
317 -- need a better threshold value and hysteresis to prevent oscillation.
319 brightness = self.inputs.brightness.single_value
321 if not brightness then
325 print("*** element "..self.name.." update brightness: "..brightness)
327 if brightness > 300 then
333 print("*** resulting mode: ".. mode)
335 if not (mode == self.oldmode) then
336 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
344 name = "select_night_mode",
345 table = "amb_nightmode",
346 columns = { "night_mode" },
353 inputs = { NightMode = mdb.select.select_night_mode,
354 amb_state = mdb.select.amb_state },
355 property = "NightMode",
357 initiate = builtin.method.amb_initiate,
358 update = builtin.method.amb_update
362 -- Night mode general handlers
365 name = "nightmode_homescreen",
366 inputs = { owner = mdb.select.select_night_mode },
367 initiate = function(self)
368 -- data = mdb.select.select_night_mode.single_value
371 update = function(self)
372 data = mdb.select.select_night_mode.single_value
375 print("Night mode updated: " .. tostring(data))
379 -- tell homescreen that night mode was updated
380 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=2,state=data})}))
386 -- Driving mode processing chain
389 name = "drivingmode",
390 inputs = { speed = mdb.select.vehicle_speed },
394 name = "amb_drivingmode",
398 { "id", mdb.unsigned },
399 { "driving_mode", mdb.unsigned }
403 update = function(self)
405 speed = self.inputs.speed.single_value
417 if not (mode == self.oldmode) then
418 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
426 name = "select_driving_mode",
427 table = "amb_drivingmode",
428 columns = { "driving_mode" },
434 name = "driving_mode",
435 inputs = { DrivingMode = mdb.select.select_driving_mode,
436 amb_state = mdb.select.amb_state },
437 property = "DrivingMode",
439 initiate = builtin.method.amb_initiate,
440 update = builtin.method.amb_update
444 -- turn signals (left, right)
448 table = "amb_turn_signal",
449 columns = { "value" },
450 condition = "key = 'TurnSignal'"
453 -- define three categories
456 name = "undefined_applications",
457 table = "aul_applications",
458 columns = { "appid" },
459 condition = "category = '<undefined>'"
463 name = "basic_applications",
464 table = "aul_applications",
465 columns = { "appid" },
466 condition = "category = 'basic'"
470 name = "entertainment_applications",
471 table = "aul_applications",
472 columns = { "appid" },
473 condition = "category = 'entertainment'"
477 -- filter the object garbage out of the tables
480 for k,v in pairs(t) do
481 if k ~= "userdata" and k ~= "new" then
489 function getApplication(appid)
492 -- find the correct local application definition
494 for k,v in pairs(ft(application)) do
495 if appid == v.appid then
504 function regulateApplications(t, regulation)
505 for k,v in pairs(ft(t)) do
507 -- iterate through the undefined and entertainment apps, see if
508 -- they have been overruled in local config
510 local conf = getApplication(v.appid)
512 if conf and conf.resource_class ~= "player" then
513 -- override, don't disable
514 resmgr:disable_screen_by_appid("*", "*", v.appid, false)
516 resmgr:disable_screen_by_appid("*", "*", v.appid, regulation == 1)
521 -- regulation (on), use "select_driving_mode"
524 name = "driving_regulation",
525 inputs = { owner = mdb.select.select_driving_mode },
526 initiate = function(self)
527 -- local data = mdb.select.select_driving_mode.single_value
530 update = function(self)
531 local data = mdb.select.select_driving_mode.single_value
534 print("Driving mode updated: " .. tostring(data))
541 -- tell homescreen that driving mode was updated
542 sc:send_message(homescreen, m:JSON({command=0x60001,arg=m:JSON({stateid=1,state=data})}))
545 -- bulk handle the applications that need requisites
546 r = requisite { driving = true }
547 resmgr:disable_screen_by_requisite("*", "*", r, data == 1)
550 regulateApplications(ft(mdb.select.entertainment_applications), data)
551 regulateApplications(ft(mdb.select.undefined_applications), data)
558 name = "regulated_app_change",
559 inputs = { undef = mdb.select.undefined_applications,
560 entertainment = mdb.select.entertainment_applications },
561 initiate = function(self)
564 update = function(self)
565 local data = mdb.select.select_driving_mode.single_value
572 print("regulated application list was changed")
575 regulateApplications(ft(mdb.select.entertainment_applications), data)
576 regulateApplications(ft(mdb.select.undefined_applications), data)
583 -- shift position (parking, reverse, other)
586 name = "gear_position",
587 table = "amb_gear_position",
588 columns = { "value" },
589 condition = "key = 'GearPosition'"
592 -- cameras (back, front, left, right)
595 name = "camera_state",
596 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
600 name = "target_camera_state",
604 { "id", mdb.unsigned },
605 { "front_camera", mdb.unsigned },
606 { "back_camera", mdb.unsigned },
607 { "right_camera", mdb.unsigned },
608 { "left_camera", mdb.unsigned }
612 update = function(self)
619 if self.inputs.gear == 128 then
621 elseif self.inputs.winker == 1 then
623 elseif self.inputs.winker == 2 then
627 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
632 -- load the telephony plugin
633 m:try_load_plugin('telephony')
636 -- system controller test setup
638 if not with_system_controller then
642 m:load_plugin('system-controller')
644 window_manager_operation_names = {
649 function window_manager_operation_name(oper)
650 local name = window_manager_operation_names[oper]
651 if name then return name end
652 return "<unknown " .. tostring(oper) .. ">"
655 window_operation_names = {
664 function window_operation_name(oper)
665 local name = window_operation_names[oper]
666 if name then return name end
667 return "<unknown " .. tostring(oper) .. ">"
670 layer_operation_names = {
676 function layer_operation_name(oper)
677 local name = layer_operation_names[oper]
678 if name then return name end
679 return "<unknown " .. tostring(oper) .. ">"
682 input_manager_operation_names = {
688 function input_manager_operation_name(oper)
689 local name = input_manager_operation_names[oper]
690 if name then return name end
691 return "<unknown " .. tostring(oper) .. ">"
694 input_operation_names = {
700 function input_operation_name(oper)
701 local name = input_operation_names[oper]
702 if name then return name end
703 return "<unknown " .. tostring(oper) .. ">"
706 code_operation_names = {
712 function code_operation_name(oper)
713 local name = code_operation_names[oper]
714 if name then return name end
715 return "<unknown " .. tostring(oper) .. ">"
719 [0x00001] = "send_appid",
720 [0x10001] = "create",
721 [0x10002] = "destroy",
725 [0x10006] = "change_active",
726 [0x10007] = "change_layer",
727 [0x10008] = "change_attr",
729 [0x10011] = "map_thumb",
730 [0x10012] = "unmap_thumb",
731 [0x10020] = "show layer",
732 [0x10021] = "hide_layer",
733 [0x10022] = "change_layer_attr",
734 [0x20001] = "add_input",
735 [0x20002] = "del_input",
736 [0x20003] = "send_input",
737 [0x40001] = "acquire_res",
738 [0x40002] = "release_res",
739 [0x40003] = "deprive_res",
740 [0x40004] = "waiting_res",
741 [0x40005] = "revert_res",
742 [0x40011] = "create_res",
743 [0x40012] = "destroy_res",
744 [0x50001] = "set_region",
745 [0x50002] = "unset_region",
746 [0x60001] = "change_state"
749 function command_name(command)
750 local name = command_names[command]
751 if name then return name end
752 return "<unknown " .. tostring(command) .. ">"
761 resmgr = resource_manager {
762 screen_event_handler = function(self, ev)
763 local event = ev.event
764 local surface = ev.surface
766 if event == "grant" then
768 print("*** make visible surface "..surface)
770 local a = animation({})
771 local r = m:JSON({surface = surface,
774 wmgr:window_request(r,a,0)
775 elseif event == "revoke" then
777 print("*** hide surface "..surface)
779 local a = animation({})
780 local r = m:JSON({surface = ev.surface,
782 wmgr:window_request(r,a,0)
784 elseif event == "create" then
787 print("*** screen resource event: " ..
791 -- For now, consider every application to be an "entertainment"
792 -- application. Whitelist those applications that we know. Later
793 -- check the aul_applications table for actual category (when
794 -- we get the categories there).
796 local regulation = mdb.select.select_driving_mode.single_value
798 if regulation == 1 then
799 conf = getApplication(ev.appid)
801 -- disable only non-whitelisted applications
802 if not conf or conf.resource_class == "player" then
803 resmgr:disable_screen_by_appid("*", "*", ev.appid, true)
807 elseif event == "destroy" then
809 print("*** screen resource event: " ..
814 print("*** screen resource event: " ..
819 audio_event_handler = function(self, ev)
820 local event = ev.event
821 local appid = ev.appid
822 local audioid = ev.audioid
824 if event == "grant" then
825 if verbose > 0 or true then
826 print("*** grant audio to "..appid..
827 " ("..audioid..") in '" ..
830 elseif event == "revoke" then
831 if verbose > 0 or true then
832 print("*** revoke audio from "..appid..
833 " ("..audioid..") in '" ..
837 if verbose > 0 or true then
838 print("*** audio resource event: " ..
845 resclnt = resource_client {}
847 wmgr = window_manager {
848 geometry = function(self, w,h, v)
849 if type(v) == "function" then
855 application = function(self, appid)
857 local app = application_lookup(appid)
859 app = application_lookup("default")
863 return { privileges = {screen="none", audio="none"} }
866 outputs = { { name = "Center",
873 width = function(w,h) return w end,
880 width = function(w,h) return w end,
881 height = function(w,h) return h-64-128 end
887 width = function(w,h) return w end,
888 height = function(w,h) return (h-64-128)/2 end
893 pos_y = function(w,h) return (h-64-128)/2+64 end,
894 width = function(w,h) return w end,
895 height = function(w,h) return (h-64-128)/2 end
901 width = function(w,h) return w/2 end,
902 height = function(w,h) return (h-64-128)/2 end
906 pos_x = function(w,h) return w/2 end,
908 width = function(w,h) return w/2 end,
909 height = function(w,h) return (h-64-128)/2 end
914 pos_y = function(w,h) return (h-64-128/2)+64 end,
915 width = function(w,h) return w/2 end,
916 height = function(w,h) return (h-64-128)/2 end
920 pos_x = function(w,h) return w/2 end,
921 pos_y = function(w,h) return (h-64-128/2)+64 end,
922 width = function(w,h) return w/2 end,
923 height = function(w,h) return (h-64-128)/2 end
929 width = function(w,h) return w end,
930 height = function(w,h) return h-64-128 end
936 width = function(w,h) return w/2-181 end,
937 height = function(w,h) return h-64-128 end
941 pos_x = function(w,h) return w/2+181 end,
943 width = function(w,h) return w/2-181 end,
944 height = function(w,h) return h-64-128 end
954 layers = { { 0, "Background" , 1 },
955 { 1, "Application" , 2 },
956 { 2, "Softkeyboard" , 4 },
957 { 3, "HomeScreen" , 2 },
958 { 4, "ControlBar" , 2 },
959 { 5, "InterruptApp" , 2 },
960 { 6, "OnScreen" , 2 },
961 { 101, "Input" , 3 },
962 { 102, "Cursor" , 5 },
963 { 103, "Startup" , 6 },
964 { 0x1000, "Background" , 1 },
965 { 0x2000, "Normal" , 2 },
966 { 0x3000, "Fullscreen" , 2 },
967 { 0x4000, "InputPanel" , 3 },
968 { 0xA000, "Touch" , 4 },
969 { 0xB000, "Cursor" , 5 },
970 { 0xC000, "Startup" , 6 }
974 manager_update = function(self, oper)
976 print("### <== WINDOW MANAGER UPDATE:" ..
977 window_manager_operation_name(oper))
980 local umask = window_mask { raise = true,
983 local rmask = window_mask { active = true }
985 passthrough_update = umask:tointeger(),
986 passthrough_request = rmask:tointeger()
988 self:manager_request(req)
992 window_update = function(self, oper, win, mask)
994 print("### <== WINDOW UPDATE oper:" ..
995 window_operation_name(oper) ..
996 " mask: " .. tostring(mask))
1002 local arg = m:JSON({ surface = win.surface,
1007 if oper == 1 then -- create
1008 local layertype = win.layertype
1009 if layertype and input_layer[layertype] then
1011 print("ignoring input panel creation")
1016 elseif oper == 2 then -- destroy
1018 elseif oper == 3 then -- namechange
1020 elseif oper == 4 or oper == 5 then --visible or configure
1024 arg.layer = win.layer
1025 arg.pos_x = win.pos_x
1026 arg.pos_y = win.pos_y
1027 arg.width = win.width
1028 arg.height = win.height
1029 arg.raise = win.raise
1030 arg.visible = win.visible
1031 arg.active = win.active
1032 elseif oper == 6 then -- active
1034 arg.active = win.active
1037 print("### nothing to do")
1042 local msg = m:JSON({ command = command,
1048 print("### <== sending " ..
1049 command_name(msg.command) ..
1050 " window message to '" .. win.name .. "'")
1055 sc:send_message(homescreen, msg)
1057 if oper == 1 then -- create
1058 local i = input_layer[win.layertype]
1059 local p = self:application(win.appid)
1060 local s = p.privileges.screen
1062 if s == "system" then
1063 local a = animation({})
1064 local r = m:JSON({surface = win.surface,
1067 self:window_request(r,a,0)
1071 print("do not make resource for " ..
1075 resclnt:resource_set_create("screen",
1081 elseif oper == 2 then -- destroy
1082 resclnt:resource_set_destroy("screen", win.surface)
1083 elseif oper == 6 then -- active
1085 local i = input_layer[win.layertype]
1086 local p = self:application(win.appid)
1087 local s = p.privileges.screen
1088 local surface = win.surface
1089 if not i and s ~= "system" then
1090 resclnt:resource_set_acquire("screen",surface)
1091 resmgr:window_raise(win.appid, surface, 1)
1097 layer_update = function(self, oper, layer, mask)
1099 print("### LAYER UPDATE:" ..
1100 layer_operation_name(oper) ..
1101 " mask: " .. tostring(mask))
1106 if oper == 3 then -- visible
1107 local command = 0x10022
1108 local msg = m:JSON({
1111 arg = m:JSON({layer = layer.id,
1112 visible = layer.visible
1116 print("### <== sending "..command_name(command)..
1122 sc:send_message(homescreen, msg)
1125 print("### nothing to do")
1130 output_update = function(self, oper, out, mask)
1131 local idx = out.index
1133 print("### OUTPUT UPDATE:" .. oper ..
1134 " mask: "..tostring(mask))
1137 local outdef = self.outputs[idx+1]
1138 if (oper == 1) then -- create
1140 self:output_request(m:JSON({index = idx,
1145 elseif (oper == 5) then -- done
1146 local ads = outdef.areas
1147 local on = outdef.name
1149 for name,ad in pairs(ads) do
1150 local can = wmgr:canonical_name(on.."."..name)
1151 local a = m:JSON({name = name,
1152 output = out.index})
1153 for fld,val in pairs(ad) do
1154 a[fld] = self:geometry(out.width,
1159 resmgr:area_create(area[can], outdef.zone)
1167 imgr = input_manager {
1168 inputs = {{ name = "G27 Racing Wheel",
1170 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1171 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1172 [4] = {appid="org.tizen.ico.app-soundsample" },
1173 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1177 manager_update = function(self, oper)
1179 print("### <== INPUT MANAGER UPDATE:" ..
1180 input_manager_operation_name(oper))
1184 input_update = function(self, oper, inp, mask)
1186 print("### INPUT UPDATE:" ..
1187 input_operation_name(oper) ..
1188 " mask: " .. tostring(mask))
1194 code_update = function(self, oper, code, mask)
1196 print("### CODE UPDATE: mask: " .. tostring(mask))
1201 local msg = m:JSON({ command = 1,
1202 appid = "org.tizen.ico.homescreen",
1203 arg = m:JSON({ device = code.device,
1211 print("### <== sending " ..
1212 command_name(msg.command) ..
1218 sc:send_message(homescreen, msg)
1222 sc = m:get_system_controller()
1228 um = m:UserManager()
1233 -- these shoud be before wmgr:connect() is called
1235 print("====== creating applications ======")
1239 area = "Center.Full",
1240 privileges = { screen = "none", audio = "none" },
1241 resource_class = "player",
1247 area = "Center.Full",
1248 privileges = { screen = "system", audio = "none" },
1249 resource_class = "implicit",
1250 screen_priority = 30
1254 appid = "org.tizen.ico.homescreen",
1255 area = "Center.Full",
1256 privileges = { screen = "system", audio = "system" },
1257 resource_class = "player",
1258 screen_priority = 20
1262 appid = "org.tizen.ico.statusbar",
1263 area = "Center.Status",
1264 privileges = { screen = "system", audio = "none" },
1265 resource_class = "player",
1266 screen_priority = 20
1270 appid = "org.tizen.ico.login",
1271 area = "Center.Full",
1272 privileges = { screen = "system", audio = "system" },
1273 resource_class = "player",
1274 screen_priority = 20
1278 appid = "org.tizen.ico.camera_left",
1279 area = "Center.SysApp.Left",
1280 privileges = { screen = "system", audio = "none" },
1281 requisites = { screen = "blinker_left", audio = "none" },
1282 resource_class = "player",
1283 screen_priority = 30
1287 appid = "org.tizen.ico.camera_right",
1288 area = "Center.SysApp.Right",
1289 privileges = { screen = "system", audio = "none" },
1290 requisites = { screen = "blinker_right", audio = "none" },
1291 resource_class = "player",
1292 screen_priority = 30
1296 appid = "net.zmap.navi",
1297 area = "Center.Full",
1298 privileges = { screen = "none", audio = "none" },
1299 resource_class = "navigator",
1300 screen_priority = 30
1304 sc.client_handler = function (self, cid, msg)
1305 local command = msg.command
1307 print('### ==> client handler:')
1312 if not connected then
1313 print('Setting homescreen='..msg.appid)
1314 homescreen = msg.appid
1315 print('Trying to connect to wayland...')
1316 connected = wmgr:connect()
1318 if connected and command then
1319 if command == 1 then -- send_appid
1320 local driving_mode = mdb.select.select_driving_mode.single_value
1321 local night_mode = mdb.select.select_night_mode.single_value
1323 if not driving_mode then driving_mode = 0 end
1324 if not night_mode then night_mode = 0 end
1326 local reply = m:JSON({ command = 0x60001,
1327 arg = m:JSON({ stateid = 1,
1328 state = driving_mode})
1331 print("### <== sending " ..
1332 command_name(command) .. " message")
1337 sc:send_message(homescreen, reply)
1339 reply = m:JSON({ command = 0x60001,
1340 arg = m:JSON({ stateid = 2,
1341 state = night_mode})
1344 print("### <== sending " ..
1345 command_name(command) .. " message")
1350 sc:send_message(homescreen, reply)
1355 sc.generic_handler = function (self, cid, msg)
1357 print('### ==> generic handler:')
1364 sc.window_handler = function (self, cid, msg)
1366 print('### ==> received ' ..
1367 command_name(msg.command) .. ' message')
1369 print(tostring(msg))
1373 local a = animation({})
1375 if msg.command == 0x10003 then -- ico SHOW command
1376 local raise_mask = 0x01000000
1377 local lower_mask = 0x02000000
1378 local nores_mask = 0x40000000
1379 local time_mask = 0x00ffffff
1383 if msg.arg.anim_time then
1384 local t = msg.arg.anim_time
1385 time = m:AND(t, time_mask)
1386 nores = not m:AND(t, nores_mask)
1387 if m:AND(t, raise_mask) then
1389 elseif m:AND(t, lower_mask) then
1393 if msg.arg.anim_name then
1394 a.show = { msg.arg.anim_name, time }
1395 print('time: ' .. tostring(a.show[2]))
1399 local p = wmgr:application(msg.appid)
1400 local s = p.privileges.screen
1401 if s == "system" then
1406 print('### ==> SHOW')
1407 print(tostring(msg.arg))
1410 wmgr:window_request(msg.arg, a, 0)
1412 local surface = msg.arg.surface
1413 resclnt:resource_set_acquire("screen", surface)
1414 resmgr:window_raise(msg.appid, surface, 1)
1416 elseif msg.command == 0x10004 then -- ico HIDE command
1417 local raise_mask = 0x01000000
1418 local lower_mask = 0x02000000
1419 local nores_mask = 0x40000000
1420 local time_mask = 0x00ffffff
1424 if msg.arg.anim_time then
1425 local t = msg.arg.anim_time
1426 time = m:AND(t, time_mask)
1427 nores = not m:AND(t, nores_mask)
1429 if msg.arg.anim_name then
1430 a.hide = { msg.arg.anim_name, time }
1431 print('hide animation time: ' .. tostring(a.hide[2]))
1435 local p = wmgr:application(msg.appid)
1436 local s = p.privileges.screen
1437 if s == "system" then
1442 print('### ==> HIDE REQUEST')
1443 print(tostring(msg.arg))
1446 wmgr:window_request(msg.arg, a, 0)
1448 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1450 elseif msg.command == 0x10005 then -- ico MOVE
1452 print('### ==> MOVE REQUEST')
1453 print(tostring(msg.arg))
1455 wmgr:window_request(msg.arg, a, 0)
1456 -- TODO: handle if area changed
1457 elseif msg.command == 0x10006 then -- ico ACTIVE
1458 if not msg.arg.active then
1459 msg.arg.active = 3 -- pointer + keyboard
1462 print('### ==> ACTIVE REQUEST')
1463 print(tostring(msg.arg))
1465 wmgr:window_request(msg.arg, a, 0)
1466 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1468 print('### ==> CHANGE_LAYER REQUEST')
1469 print(tostring(msg.arg))
1472 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1473 print("do not change layer for other than cursor or touch")
1477 wmgr:window_request(msg.arg, a, 0)
1478 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1479 local framerate = msg.arg.framerate
1480 if not framerate or framerate < 0 then
1485 print('### ==> MAP_THUMB REQUEST')
1487 print('framerate: '..framerate)
1489 wmgr:window_request(msg.arg, a, framerate)
1490 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1493 print('### ==> UNMAP_THUMB REQUEST')
1496 wmgr:window_request(msg.arg, a, 0)
1497 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1500 print('### ==> SHOW_LAYER REQUEST')
1503 wmgr:layer_request(msg.arg)
1504 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1507 print('### ==> HIDE_LAYER REQUEST')
1510 wmgr:layer_request(msg.arg)
1514 sc.input_handler = function (self, cid, msg)
1516 print('### ==> input handler: ' .. command_name(msg.command))
1521 if msg.command == 0x20001 then -- add_input
1522 msg.arg.appid = msg.appid
1524 print('### ==> ADD_INPUT REQUEST')
1525 print(tostring(msg.arg))
1527 imgr:input_request(msg.arg)
1528 elseif msg.command == 0x20002 then -- del_input
1531 print('### ==> DEL_INPUT REQUEST')
1532 print(tostring(msg.arg))
1534 imgr:input_request(msg.arg)
1535 elseif msg.command == 0x20003 then -- send_input
1539 sc.user_handler = function (self, cid, msg)
1541 print('### ==> user handler: ' .. command_name(msg.command))
1548 print("User Manager not initialized")
1552 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1553 print("command CHANGE_USER")
1555 print("invalid message")
1559 username = msg.arg.user
1560 passwd = msg.arg.pass
1562 if not username then
1570 success = um:changeUser(username, passwd)
1577 if sc:send_message(msg.appid, reply) then
1578 print('*** sent authentication failed message')
1580 print('*** failed to send authentication failed message')
1584 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1585 print("command GET_USERLIST")
1586 if not msg.appid then
1587 print("invalid message")
1591 users, currentUser = um:getUserList()
1594 print("failed to get user list")
1600 for i,v in pairs(users) do
1604 if not currentUser then
1609 print("current user: " .. currentUser)
1611 for i,v in pairs(users) do
1622 user_login = currentUser
1627 print("### <== GetUserList reply: " .. tostring(reply))
1630 if sc:send_message(msg.appid, reply) then
1631 print('*** reply OK')
1633 print('*** reply FAILED')
1636 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1637 print("command GET_LASTINFO")
1638 if not msg.appid then
1639 print("invalid message")
1643 lastInfo = um:getLastInfo(msg.appid)
1645 if not lastInfo then
1646 print("failed to get last info for app" .. msg.appid)
1658 if sc:send_message(msg.appid, reply) then
1659 print('*** reply OK')
1661 print('*** reply FAILED')
1664 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1665 print("command SET_LASTINFO")
1666 if not msg.arg or not msg.appid then
1667 print("invalid message")
1671 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1675 sc.resource_handler = function (self, cid, msg)
1677 print('### ==> resource handler: ' .. command_name(msg.command))
1683 createResourceSet = function (ctl, client, msg)
1684 cb = function(rset, data)
1685 print("> resource callback")
1687 -- type is either basic (0) or interrupt (1)
1689 if msg.res.type then
1690 requestType = msg.res.type
1693 if rset.acquired then
1694 cmd = 0x00040001 -- acquire
1696 cmd = 0x00040002 -- release
1700 appid = data.client,
1707 if rset.resources.audio_playback then
1716 if rset.resources.display then
1717 reply.res.window = {
1724 if rset.resources.input then
1730 print("sending message to client: " .. data.client)
1732 if sc:send_message(data.client, reply) then
1733 print('*** reply OK')
1735 print('*** reply FAILED')
1739 rset = m:ResourceSet({
1740 application_class = "player",
1741 zone = "driver", -- msg.zone ("full")
1750 if msg.res.sound then
1752 resource_name = "audio_playback"
1754 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1755 rset.resources.audio_playback.attributes.appid = msg.appid
1756 print("sound name: " .. msg.res.sound.name)
1757 print("sound zone:" .. msg.res.sound.zone)
1758 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1759 if msg.res.sound.id then
1760 print("sound id: " .. msg.res.sound.id)
1764 if msg.res.input then
1766 resource_name = "input"
1768 rset.resources.input.attributes.pid = tostring(msg.pid)
1769 rset.resources.input.attributes.appid = msg.appid
1770 print("input name: " .. msg.res.sound.name)
1771 print("input event:" .. tostring(msg.res.input.event))
1774 if msg.res.window then
1776 resource_name = "display"
1778 rset.resources.display.attributes.pid = tostring(msg.pid)
1779 rset.resources.display.attributes.appid = msg.appid
1780 print("display name: " .. msg.res.display.name)
1781 print("display zone:" .. msg.res.display.zone)
1782 if msg.res.display.id then
1783 print("display id: " .. msg.res.display.id)
1790 -- parse the message
1792 -- fields common to all messages:
1797 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1798 print("command CREATE")
1800 if not sets.cid then
1801 sets.cid = createResourceSet(self, cid, msg)
1804 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1805 print("command DESTROY")
1811 sets.cid = nil -- garbage collecting
1813 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1814 print("command ACQUIRE")
1816 if not sets.cid then
1817 sets.cid = createResourceSet(self, cid, msg)
1822 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1823 print("command RELEASE")
1829 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1830 print("command DEPRIVE")
1832 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1833 print("command WAITING")
1835 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1836 print("command REVERT")
1840 sc.inputdev_handler = function (self, cid, msg)
1842 print('*** inputdev handler: ' .. command_name(msg.command))