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
138 application_class { name="event" , priority=4 , modal=false, share=true , order="fifo" }
139 application_class { name="game" , priority=3 , modal=false, share=false, order="lifo" }
140 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
141 --#application_class { name="basic" , priority=2 , modal=false, share=false, order="lifo" }
142 application_class { name="player" , priority=1 , modal=false, share=true , order="lifo" }
143 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
145 -- define zone attributes
147 type = {mdb.string, "common", "rw"},
148 location = {mdb.string, "anywhere", "rw"}
156 location = "front-left"
164 location = "front-right"
172 location = "back-left"
180 location = "back-right"
188 location = "back-left"
193 -- define resource classes
194 if not m:plugin_exists('ivi-resource-manager') and
195 not with_system_controller
198 name = "audio_playback",
201 role = { mdb.string, "music", "rw" },
202 pid = { mdb.string, "<unknown>", "rw" },
203 policy = { mdb.string, "relaxed", "rw" }
209 name = "audio_recording",
212 role = { mdb.string, "music" , "rw" },
213 pid = { mdb.string, "<unknown>", "rw" },
214 policy = { mdb.string, "relaxed" , "rw" }
219 name = "video_playback",
224 name = "video_recording",
229 name = "speech_recognition",
234 name = "speech_synthesis",
238 if not m:plugin_exists('ivi-resource-manager') and
239 not with_system_controller
241 resource.method.veto = {
242 function(zone, rset, grant, owners, req_set)
248 -- test for creating selections
250 name = "audio_owner",
251 table = "audio_playback_owner",
252 columns = {"application_class"},
253 condition = "zone_name = 'driver'"
257 name = "vehicle_speed",
258 table = "amb_vehicle_speed",
260 condition = "key = 'VehicleSpeed'"
264 name = "speed2volume",
265 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
266 outputs = { mdb.table { name = "speedvol",
267 index = {"zone", "device"},
268 columns = {{"zone", mdb.string, 16},
269 {"device", mdb.string, 16},
270 {"value", mdb.floating}},
275 update = function(self)
276 speed = self.inputs.speed.single_value
278 volume = (speed - 144.0) / 7.0
282 diff = volume - self.oldvolume
283 if (diff*diff > self.inputs.param) then
284 print("*** element "..self.name.." update "..volume)
285 self.oldvolume = volume
286 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
294 columns = { "state" },
298 -- Night mode processing chain
301 name = "exterior_brightness",
302 table = "amb_exterior_brightness",
303 columns = { "value" },
304 condition = "key = 'ExteriorBrightness'"
309 inputs = { brightness = mdb.select.exterior_brightness },
313 name = "amb_nightmode",
317 { "id", mdb.unsigned },
318 { "night_mode", mdb.unsigned }
322 update = function(self)
323 -- This is a trivial function to calculate night mode. Later, we will
324 -- need a better threshold value and hysteresis to prevent oscillation.
326 brightness = self.inputs.brightness.single_value
328 if not brightness then
332 print("*** element "..self.name.." update brightness: "..brightness)
334 if brightness > 300 then
340 print("*** resulting mode: ".. mode)
342 if not (mode == self.oldmode) then
343 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
351 name = "select_night_mode",
352 table = "amb_nightmode",
353 columns = { "night_mode" },
360 inputs = { NightMode = mdb.select.select_night_mode,
361 amb_state = mdb.select.amb_state },
362 property = "NightMode",
364 initiate = builtin.method.amb_initiate,
365 update = builtin.method.amb_update
369 -- Night mode general handlers
371 if with_system_controller then
373 name = "nightmode_homescreen",
374 inputs = { owner = mdb.select.select_night_mode },
375 initiate = function(self)
376 -- data = mdb.select.select_night_mode.single_value
379 update = function(self)
380 send_night_mode_to_home_screen()
385 -- Driving mode processing chain
388 name = "drivingmode",
389 inputs = { speed = mdb.select.vehicle_speed },
393 name = "amb_drivingmode",
397 { "id", mdb.unsigned },
398 { "driving_mode", mdb.unsigned }
402 update = function(self)
404 speed = self.inputs.speed.single_value
416 if not (mode == self.oldmode) then
417 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
425 name = "select_driving_mode",
426 table = "amb_drivingmode",
427 columns = { "driving_mode" },
433 name = "driving_mode",
434 inputs = { DrivingMode = mdb.select.select_driving_mode,
435 amb_state = mdb.select.amb_state },
436 property = "DrivingMode",
438 initiate = builtin.method.amb_initiate,
439 update = builtin.method.amb_update
443 -- turn signals (left, right)
447 table = "amb_turn_signal",
448 columns = { "value" },
449 condition = "key = 'TurnSignal'"
452 -- define three categories
455 name = "undefined_applications",
456 table = "aul_applications",
457 columns = { "appid" },
458 condition = "category = '<undefined>'"
462 name = "basic_applications",
463 table = "aul_applications",
464 columns = { "appid" },
465 condition = "category = 'basic'"
469 name = "entertainment_applications",
470 table = "aul_applications",
471 columns = { "appid" },
472 condition = "category = 'entertainment'"
476 -- filter the object garbage out of the tables
479 for k,v in pairs(t) do
480 if k ~= "userdata" and k ~= "new" then
488 function getApplication(appid)
491 -- find the correct local application definition
493 for k,v in pairs(ft(application)) do
494 if appid == v.appid then
503 function regulateApplications(t, regulation)
504 for k,v in pairs(ft(t)) do
506 -- iterate through the undefined and entertainment apps, see if
507 -- they have been overruled in local config
509 local conf = getApplication(v.appid)
511 if conf and conf.resource_class ~= "player" then
512 -- override, don't disable
513 resmgr:disable_screen_by_appid("*", "*", v.appid, false, false)
515 resmgr:disable_screen_by_appid("*", "*", v.appid, regulation == 1, false)
518 resource.method.recalc("driver")
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 send_driving_mode_to_home_screen()
544 regulateApplications(ft(mdb.select.entertainment_applications), data)
545 regulateApplications(ft(mdb.select.undefined_applications), data)
552 name = "regulated_app_change",
553 inputs = { undef = mdb.select.undefined_applications,
554 entertainment = mdb.select.entertainment_applications },
555 initiate = function(self)
558 update = function(self)
559 local data = mdb.select.select_driving_mode.single_value
566 print("regulated application list was changed")
569 regulateApplications(ft(mdb.select.entertainment_applications), data)
570 regulateApplications(ft(mdb.select.undefined_applications), data)
577 -- shift position (parking, reverse, other)
580 name = "gear_position",
581 table = "amb_gear_position",
582 columns = { "value" },
583 condition = "key = 'GearPosition'"
586 -- cameras (back, front, left, right)
589 name = "camera_state",
590 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
594 name = "target_camera_state",
598 { "id", mdb.unsigned },
599 { "front_camera", mdb.unsigned },
600 { "back_camera", mdb.unsigned },
601 { "right_camera", mdb.unsigned },
602 { "left_camera", mdb.unsigned }
606 update = function(self)
613 if self.inputs.gear == 128 then
615 elseif self.inputs.winker == 1 then
617 elseif self.inputs.winker == 2 then
621 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
626 -- system controller test setup
628 if not with_system_controller then
629 -- ok, we should have 'audio_playback' defined by now
630 m:try_load_plugin('telephony')
634 m:load_plugin('system-controller')
636 window_manager_operation_names = {
641 function window_manager_operation_name(oper)
642 local name = window_manager_operation_names[oper]
643 if name then return name end
644 return "<unknown " .. tostring(oper) .. ">"
647 window_operation_names = {
657 function window_operation_name(oper)
658 local name = window_operation_names[oper]
659 if name then return name end
660 return "<unknown " .. tostring(oper) .. ">"
663 layer_operation_names = {
669 function layer_operation_name(oper)
670 local name = layer_operation_names[oper]
671 if name then return name end
672 return "<unknown " .. tostring(oper) .. ">"
675 input_manager_operation_names = {
681 function input_manager_operation_name(oper)
682 local name = input_manager_operation_names[oper]
683 if name then return name end
684 return "<unknown " .. tostring(oper) .. ">"
687 input_operation_names = {
693 function input_operation_name(oper)
694 local name = input_operation_names[oper]
695 if name then return name end
696 return "<unknown " .. tostring(oper) .. ">"
699 code_operation_names = {
705 function code_operation_name(oper)
706 local name = code_operation_names[oper]
707 if name then return name end
708 return "<unknown " .. tostring(oper) .. ">"
712 [0x00001] = "send_appid",
713 [0x10001] = "create",
714 [0x10002] = "destroy",
718 [0x10006] = "change_active",
719 [0x10007] = "change_layer",
720 [0x10008] = "change_attr",
722 [0x10011] = "map_thumb",
723 [0x10012] = "unmap_thumb",
724 [0x10020] = "show layer",
725 [0x10021] = "hide_layer",
726 [0x10022] = "change_layer_attr",
727 [0x20001] = "add_input",
728 [0x20002] = "del_input",
729 [0x20003] = "send_input",
730 [0x40001] = "acquire_res",
731 [0x40002] = "release_res",
732 [0x40003] = "deprive_res",
733 [0x40004] = "waiting_res",
734 [0x40005] = "revert_res",
735 [0x40011] = "create_res",
736 [0x40012] = "destroy_res",
737 [0x50001] = "set_region",
738 [0x50002] = "unset_region",
739 [0x60001] = "change_state"
742 function command_name(command)
743 local name = command_names[command]
744 if name then return name end
745 return "<unknown " .. tostring(command) .. ">"
754 -- some day this should be merged with wmgr.layers
756 [1] = 0x1000, -- background
757 [2] = 0x2000, -- application
758 [3] = 0x4000, -- input
759 [4] = 0xa000, -- touch
760 [5] = 0xb000, -- cursor
761 [6] = 0xc000, -- startup
762 [7] = 0x3000 -- fullscreen
765 resmgr = resource_manager {
766 screen_event_handler = function(self, ev)
767 local event = ev.event
768 local surface = ev.surface
770 if event == "init" then
772 print("*** init screen resource allocation -- disable all 'player'")
774 resmgr:disable_audio_by_appid("*", "player", "*", true, false)
775 elseif event == "preallocate" then
777 print("*** preallocate screen resource "..
778 "for '" .. ev.appid .. "' -- enable 'player', if any")
780 resmgr:disable_audio_by_appid("*", "player", ev.appid, false, false)
781 elseif event == "grant" then
783 print("*** make visible surface "..surface)
785 local a = animation({})
786 local r = m:JSON({surface = surface,
789 wmgr:window_request(r,a,0)
790 elseif event == "revoke" then
792 print("*** hide surface "..surface)
794 local a = animation({})
795 local r = m:JSON({surface = ev.surface,
797 wmgr:window_request(r,a,0)
799 elseif event == "create" then
802 print("*** screen resource event: " ..
806 local regulation = mdb.select.select_driving_mode.single_value
808 if regulation == 1 then
810 local blacklisted = false
812 -- applications which have their category set to "entertainment"
813 -- or "undefined" are blacklisted, meaning they should be regulated
815 for i,v in pairs(ft(mdb.select.undefined_applications)) do
816 if v.appid == ev.appid then
818 print(ev.appid .. " was blacklisted (undefined)")
825 if not blacklisted then
826 for i,v in pairs(ft(mdb.select.entertainment_applications)) do
827 if v.appid == ev.appid then
829 print(ev.appid .. " was blacklisted (entertainment)")
837 -- our local application config, which takes precedence
838 local conf = getApplication(ev.appid)
840 -- disable only non-whitelisted applications
841 if not conf or conf.resource_class == "player" then
844 print("disabling screen for " .. ev.appid)
846 resmgr:disable_screen_by_appid("*", "*", ev.appid, true, true)
851 elseif event == "destroy" then
853 print("*** screen resource event: " ..
858 print("*** screen resource event: " ..
863 audio_event_handler = function(self, ev)
864 local event = ev.event
865 local appid = ev.appid
866 local audioid = ev.audioid
868 if event == "grant" then
870 print("*** grant audio to "..appid..
871 " ("..audioid..") in '" ..
874 elseif event == "revoke" then
876 print("*** revoke audio from "..appid..
877 " ("..audioid..") in '" ..
882 print("*** audio resource event: " ..
889 resclnt = resource_client {}
891 wmgr = window_manager {
892 geometry = function(self, w,h, v)
893 if type(v) == "function" then
899 application = function(self, appid)
901 local app = application_lookup(appid)
903 app = application_lookup("default")
907 return { privileges = {screen="none", audio="none"} }
910 output_order = { 1, 0 },
912 outputs = { { name = "Mid",
919 width = function(w,h) return w end,
920 height = function(w,h) return h end
927 height = function(w,h) return h end
931 pos_x = function(w,h) return w-320 end,
934 height = function(w,h) return h end
945 width = function(w,h) return w end,
952 width = function(w,h) return w end,
953 height = function(w,h) return h-64-128 end
959 width = function(w,h) return w end,
960 height = function(w,h) return (h-64-128)/2 end
965 pos_y = function(w,h) return (h-64-128)/2+64 end,
966 width = function(w,h) return w end,
967 height = function(w,h) return (h-64-128)/2 end
973 width = function(w,h) return w/2 end,
974 height = function(w,h) return (h-64-128)/2 end
978 pos_x = function(w,h) return w/2 end,
980 width = function(w,h) return w/2 end,
981 height = function(w,h) return (h-64-128)/2 end
986 pos_y = function(w,h) return (h-64-128/2)+64 end,
987 width = function(w,h) return w/2 end,
988 height = function(w,h) return (h-64-128)/2 end
992 pos_x = function(w,h) return w/2 end,
993 pos_y = function(w,h) return (h-64-128/2)+64 end,
994 width = function(w,h) return w/2 end,
995 height = function(w,h) return (h-64-128)/2 end
1001 width = function(w,h) return w end,
1002 height = function(w,h) return h-64-128 end
1008 width = function(w,h) return w/2-181 end,
1009 height = function(w,h) return h-64-128 end
1011 ["SysApp.Right"] = {
1013 pos_x = function(w,h) return w/2+181 end,
1015 width = function(w,h) return w/2-181 end,
1016 height = function(w,h) return h-64-128 end
1021 pos_y = function(w,h) return h-128 end,
1022 width = function(w,h) return w end,
1028 layers = { { 0, "Background" , 1 },
1029 { 1, "Application" , 2 },
1030 { 2, "Softkeyboard" , 4 },
1031 { 3, "HomeScreen" , 2 },
1032 { 4, "ControlBar" , 2 },
1033 { 5, "InterruptApp" , 2 },
1034 { 6, "OnScreen" , 2 },
1035 { 101, "Input" , 3 },
1036 { 102, "Cursor" , 5 },
1037 { 103, "Startup" , 6 },
1038 { 0x1000, "Background" , 1 },
1039 { 0x2000, "Normal" , 2 },
1040 { 0x3000, "Fullscreen" , 7 },
1041 { 0x4000, "InputPanel" , 3 },
1042 { 0xA000, "Touch" , 4 },
1043 { 0xB000, "Cursor" , 5 },
1044 { 0xC000, "Startup" , 6 }
1048 manager_update = function(self, oper)
1050 print("### <== WINDOW MANAGER UPDATE:" ..
1051 window_manager_operation_name(oper))
1054 local wumask = window_mask { raise = true,
1057 local wrmask = window_mask { active = true }
1058 local lumask = layer_mask { visible = true }
1059 local lrmask = layer_mask { visible = true }
1060 local req = m:JSON({
1061 passthrough_window_update = wumask:tointeger(),
1062 passthrough_window_request = wrmask:tointeger(),
1063 passthrough_layer_update = lumask:tointeger(),
1064 passthrough_layer_request = lrmask:tointeger()
1066 self:manager_request(req)
1070 window_update = function(self, oper, win, mask)
1072 print("### <== WINDOW UPDATE oper:" ..
1073 window_operation_name(oper) ..
1074 " mask: " .. tostring(mask))
1080 local arg = m:JSON({ surface = win.surface,
1085 if oper == 1 then -- create
1086 local layertype = win.layertype
1087 if layertype and input_layer[layertype] then
1089 print("ignoring input panel creation")
1094 elseif oper == 2 then -- destroy
1096 elseif oper == 3 then -- namechange
1098 elseif oper == 4 or oper == 5 then --visible or configure
1099 local icolayer = ico_layer_type[win.layertype]
1104 arg.layertype = icolayer
1106 arg.layer = win.layer
1107 arg.pos_x = win.pos_x
1108 arg.pos_y = win.pos_y
1109 arg.width = win.width
1110 arg.height = win.height
1111 arg.raise = win.raise
1112 arg.visible = win.visible
1113 arg.active = win.active
1114 elseif oper == 6 then -- active
1116 arg.active = win.active
1117 elseif oper == 7 then -- map
1122 if win.mapped == 0 then
1128 arg.name = map.target
1129 arg.width = map.width
1130 arg.height = map.height
1131 arg.stride = map.stride
1132 arg.format = map.format
1135 print("### nothing to do")
1140 local msg = m:JSON({ command = command,
1146 print("### <== sending " ..
1147 command_name(msg.command) ..
1148 " window message to '" .. win.name .. "'")
1153 sc:send_message(homescreen, msg)
1155 if oper == 1 then -- create
1156 local i = input_layer[win.layertype]
1157 local p = self:application(win.appid)
1158 local s = p.privileges.screen
1160 if s == "system" then
1161 local a = animation({})
1162 local r = m:JSON({surface = win.surface,
1165 self:window_request(r,a,0)
1169 print("do not make resource for " ..
1173 resclnt:resource_set_create("screen",
1177 special_screen_sets[win.surface] = true
1180 elseif oper == 2 then -- destroy
1181 resclnt:resource_set_destroy("screen", win.surface)
1182 special_screen_sets[win.surface] = nil
1183 elseif oper == 6 then -- active
1185 local i = input_layer[win.layertype]
1186 local p = self:application(win.appid)
1187 local s = p.privileges.screen
1188 local surface = win.surface
1189 if not i and s ~= "system" then
1190 resclnt:resource_set_acquire("screen",surface)
1191 resmgr:window_raise(win.appid, surface, 1)
1197 layer_update = function(self, oper, layer, mask)
1199 print("### LAYER UPDATE:" ..
1200 layer_operation_name(oper) ..
1201 " mask: " .. tostring(mask))
1206 if oper == 3 then -- visible
1207 local command = 0x10022
1208 local msg = m:JSON({
1211 arg = m:JSON({layer = layer.id,
1212 visible = layer.visible
1216 print("### <== sending "..command_name(command)..
1222 sc:send_message(homescreen, msg)
1225 print("### nothing to do")
1230 output_update = function(self, oper, out, mask)
1231 local idx = out.index
1232 local defidx = self.output_order[idx+1]
1234 print("### OUTPUT UPDATE:" .. oper ..
1235 " mask: "..tostring(mask))
1241 local outdef = self.outputs[defidx+1]
1242 if (oper == 1) then -- create
1244 self:output_request(m:JSON({index = idx,
1249 elseif (oper == 5) then -- done
1250 local ads = outdef.areas
1251 local on = outdef.name
1253 for name,ad in pairs(ads) do
1254 local can = wmgr:canonical_name(on.."."..name)
1255 local a = m:JSON({name = name,
1256 output = out.index})
1257 for fld,val in pairs(ad) do
1258 a[fld] = self:geometry(out.width,
1263 resmgr:area_create(area[can], outdef.zone)
1271 imgr = input_manager {
1272 inputs = {{ name = "G27 Racing Wheel",
1274 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1275 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1276 [4] = {appid="org.tizen.ico.app-soundsample" },
1277 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1281 manager_update = function(self, oper)
1283 print("### <== INPUT MANAGER UPDATE:" ..
1284 input_manager_operation_name(oper))
1288 input_update = function(self, oper, inp, mask)
1290 print("### INPUT UPDATE:" ..
1291 input_operation_name(oper) ..
1292 " mask: " .. tostring(mask))
1298 code_update = function(self, oper, code, mask)
1300 print("### CODE UPDATE: mask: " .. tostring(mask))
1305 local msg = m:JSON({ command = 1,
1306 appid = "org.tizen.ico.homescreen",
1307 arg = m:JSON({ device = code.device,
1315 print("### <== sending " ..
1316 command_name(msg.command) ..
1322 sc:send_message(homescreen, msg)
1326 sc = m:get_system_controller()
1331 -- special screen resource sets
1332 -- TODO: just rewrite screen resource handling to use regular resource API
1334 special_screen_sets = {}
1337 um = m:UserManager()
1343 -- these shoud be before wmgr:connect() is called
1345 print("====== creating applications ======")
1349 area = "Center.Full",
1350 privileges = { screen = "none", audio = "none" },
1351 resource_class = "player",
1357 area = "Center.Full",
1358 privileges = { screen = "system", audio = "none" },
1359 resource_class = "implicit",
1360 screen_priority = 30
1364 appid = "org.tizen.ico.homescreen",
1365 area = "Center.Full",
1366 windows = { {'ico_hs_controlbarwindow', 'Center.Control'} },
1367 privileges = { screen = "system", audio = "system" },
1368 resource_class = "player",
1369 screen_priority = 20
1373 appid = "org.tizen.ico.statusbar",
1374 area = "Center.Status",
1375 privileges = { screen = "system", audio = "none" },
1376 resource_class = "player",
1377 screen_priority = 20
1381 appid = "org.tizen.ico.onscreen",
1382 area = "Center.Full",
1383 privileges = { screen = "system", audio = "system" },
1384 resource_class = "player",
1385 screen_priority = 20
1389 appid = "org.tizen.ico.login",
1390 area = "Center.Full",
1391 privileges = { screen = "system", audio = "system" },
1392 resource_class = "player",
1393 screen_priority = 20
1397 appid = "org.tizen.ico.camera_left",
1398 area = "Center.SysApp.Left",
1399 privileges = { screen = "system", audio = "none" },
1400 requisites = { screen = "blinker_left", audio = "none" },
1401 resource_class = "player",
1402 screen_priority = 30
1406 appid = "org.tizen.ico.camera_right",
1407 area = "Center.SysApp.Right",
1408 privileges = { screen = "system", audio = "none" },
1409 requisites = { screen = "blinker_right", audio = "none" },
1410 resource_class = "player",
1411 screen_priority = 30
1415 appid = "net.zmap.navi",
1416 area = "Center.Full",
1417 privileges = { screen = "none", audio = "none" },
1418 resource_class = "navigator",
1419 screen_priority = 30
1423 appid = "GV3ySIINq7.GhostCluster",
1425 privileges = { screen = "none", audio = "none" },
1426 resource_class = "system",
1427 screen_priority = 30
1431 sc.client_handler = function (self, cid, msg)
1432 local command = msg.command
1433 local appid = msg.appid
1435 print('### ==> client handler:')
1441 -- known commands: 1 for SEND_APPID, synthetic command 0xFFFF for
1444 if command == 0xFFFF then
1446 print('client ' .. cid .. ' (' .. msg.appid .. ') disconnected')
1448 if msg.appid == homescreen then
1450 for i,v in pairs(special_screen_sets) do
1451 resclnt:resource_set_destroy("screen", i)
1452 special_screen_sets[i] = nil
1458 -- handle the connection to weston
1461 if appid == "org.tizen.ico.homescreen" then
1462 print('Setting homescreen='..appid)
1464 if command and command == 1 then
1465 send_driving_mode_to_home_screen()
1466 send_night_mode_to_home_screen()
1468 elseif appid == "org.tizen.ico.onscreen" then
1472 if not connected and appid == "org.tizen.ico.homescreen" then
1473 print('Trying to connect to weston...')
1474 connected = wmgr:connect()
1479 sc.generic_handler = function (self, cid, msg)
1481 print('### ==> generic handler:')
1488 sc.window_handler = function (self, cid, msg)
1490 print('### ==> received ' ..
1491 command_name(msg.command) .. ' message')
1493 print(tostring(msg))
1497 local a = animation({})
1499 if msg.command == 0x10003 then -- ico SHOW command
1500 local raise_mask = 0x01000000
1501 local lower_mask = 0x02000000
1502 local nores_mask = 0x40000000
1503 local time_mask = 0x00ffffff
1507 if msg.arg.anim_time then
1508 local t = msg.arg.anim_time
1509 time = m:AND(t, time_mask)
1510 nores = not m:AND(t, nores_mask)
1511 if m:AND(t, raise_mask) then
1513 elseif m:AND(t, lower_mask) then
1517 if msg.arg.anim_name then
1518 a.show = { msg.arg.anim_name, time }
1519 print('time: ' .. tostring(a.show[2]))
1523 local p = wmgr:application(msg.appid)
1524 local s = p.privileges.screen
1525 if s == "system" then
1527 if not msg.arg.raise then
1533 print('### ==> SHOW')
1534 print(tostring(msg.arg))
1537 wmgr:window_request(msg.arg, a, 0)
1539 local surface = msg.arg.surface
1540 resclnt:resource_set_acquire("screen", surface)
1541 resmgr:window_raise(msg.appid, surface, 1)
1543 elseif msg.command == 0x10004 then -- ico HIDE command
1544 local raise_mask = 0x01000000
1545 local lower_mask = 0x02000000
1546 local nores_mask = 0x40000000
1547 local time_mask = 0x00ffffff
1551 if msg.arg.anim_time then
1552 local t = msg.arg.anim_time
1553 time = m:AND(t, time_mask)
1554 nores = not m:AND(t, nores_mask)
1556 if msg.arg.anim_name then
1557 a.hide = { msg.arg.anim_name, time }
1558 print('hide animation time: ' .. tostring(a.hide[2]))
1562 local p = wmgr:application(msg.appid)
1563 local s = p.privileges.screen
1564 if s == "system" then
1570 print('### ==> HIDE REQUEST')
1571 print(tostring(msg.arg))
1574 wmgr:window_request(msg.arg, a, 0)
1576 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1578 elseif msg.command == 0x10005 then -- ico MOVE
1580 print('### ==> MOVE REQUEST')
1581 print(tostring(msg.arg))
1583 if msg.arg.zone then
1584 msg.arg.area = msg.arg.zone
1586 wmgr:window_request(msg.arg, a, 0)
1587 -- TODO: handle if area changed
1588 elseif msg.command == 0x10006 then -- ico ACTIVE
1589 if not msg.arg.active then
1590 msg.arg.active = 3 -- pointer + keyboard
1593 print('### ==> ACTIVE REQUEST')
1594 print(tostring(msg.arg))
1596 wmgr:window_request(msg.arg, a, 0)
1597 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1599 print('### ==> CHANGE_LAYER REQUEST')
1600 print(tostring(msg.arg))
1603 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1604 print("do not change layer for other than cursor or touch")
1608 wmgr:window_request(msg.arg, a, 0)
1609 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1610 local framerate = msg.arg.framerate
1611 if not framerate or framerate < 0 then
1616 print('### ==> MAP_THUMB REQUEST')
1618 print('framerate: '..framerate)
1620 wmgr:window_request(msg.arg, a, framerate)
1621 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1624 print('### ==> UNMAP_THUMB REQUEST')
1627 wmgr:window_request(msg.arg, a, 0)
1628 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1631 print('### ==> SHOW_LAYER REQUEST')
1634 wmgr:layer_request(msg.arg)
1635 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1638 print('### ==> HIDE_LAYER REQUEST')
1641 wmgr:layer_request(msg.arg)
1645 sc.input_handler = function (self, cid, msg)
1647 print('### ==> input handler: ' .. command_name(msg.command))
1652 if msg.command == 0x20001 then -- add_input
1653 msg.arg.appid = msg.appid
1655 print('### ==> ADD_INPUT REQUEST')
1656 print(tostring(msg.arg))
1658 imgr:input_request(msg.arg)
1659 elseif msg.command == 0x20002 then -- del_input
1662 print('### ==> DEL_INPUT REQUEST')
1663 print(tostring(msg.arg))
1665 imgr:input_request(msg.arg)
1666 elseif msg.command == 0x20003 then -- send_input
1670 sc.user_handler = function (self, cid, msg)
1672 print('### ==> user handler: ' .. command_name(msg.command))
1679 print("User Manager not initialized")
1683 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1684 print("command CHANGE_USER")
1686 print("invalid message")
1690 username = msg.arg.user
1691 passwd = msg.arg.pass
1693 if not username then
1701 success = um:changeUser(username, passwd)
1708 if sc:send_message(msg.appid, reply) then
1709 print('*** sent authentication failed message')
1711 print('*** failed to send authentication failed message')
1715 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1716 print("command GET_USERLIST")
1717 if not msg.appid then
1718 print("invalid message")
1722 users, currentUser = um:getUserList()
1725 print("failed to get user list")
1731 for i,v in pairs(users) do
1735 if not currentUser then
1740 print("current user: " .. currentUser)
1742 for i,v in pairs(users) do
1753 user_login = currentUser
1758 print("### <== GetUserList reply: " .. tostring(reply))
1761 if sc:send_message(msg.appid, reply) then
1762 print('*** reply OK')
1764 print('*** reply FAILED')
1767 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1768 print("command GET_LASTINFO")
1769 if not msg.appid then
1770 print("invalid message")
1774 lastInfo = um:getLastInfo(msg.appid)
1776 if not lastInfo then
1777 print("failed to get last info for app" .. msg.appid)
1789 if sc:send_message(msg.appid, reply) then
1790 print('*** reply OK')
1792 print('*** reply FAILED')
1795 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1796 print("command SET_LASTINFO")
1797 if not msg.arg or not msg.appid then
1798 print("invalid message")
1802 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1806 sc.resource_handler = function (self, cid, msg)
1808 print('### ==> resource handler: ' .. command_name(msg.command))
1814 createResourceSet = function (ctl, client, msg)
1815 cb = function(rset, data)
1816 print("> resource callback")
1818 -- type is either basic (0) or interrupt (1)
1820 if msg.res.type then
1821 requestType = msg.res.type
1824 if rset.acquired then
1825 cmd = 0x00040001 -- acquire
1827 cmd = 0x00040002 -- release
1831 appid = data.client,
1838 if rset.resources.audio_playback then
1847 if rset.resources.display then
1848 reply.res.window = {
1855 if rset.resources.input then
1861 print("sending message to client: " .. data.client)
1863 if sc:send_message(data.client, reply) then
1864 print('*** reply OK')
1866 print('*** reply FAILED')
1870 rset = m:ResourceSet({
1871 application_class = "player",
1872 zone = "driver", -- msg.zone ("full")
1881 if msg.res.sound then
1883 resource_name = "audio_playback"
1885 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1886 rset.resources.audio_playback.attributes.appid = msg.appid
1887 print("sound name: " .. msg.res.sound.name)
1888 print("sound zone:" .. msg.res.sound.zone)
1889 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1890 if msg.res.sound.id then
1891 print("sound id: " .. msg.res.sound.id)
1895 if msg.res.input then
1897 resource_name = "input"
1899 rset.resources.input.attributes.pid = tostring(msg.pid)
1900 rset.resources.input.attributes.appid = msg.appid
1901 print("input name: " .. msg.res.sound.name)
1902 print("input event:" .. tostring(msg.res.input.event))
1905 if msg.res.window then
1907 resource_name = "display"
1909 rset.resources.display.attributes.pid = tostring(msg.pid)
1910 rset.resources.display.attributes.appid = msg.appid
1911 print("display name: " .. msg.res.display.name)
1912 print("display zone:" .. msg.res.display.zone)
1913 if msg.res.display.id then
1914 print("display id: " .. msg.res.display.id)
1921 -- parse the message
1923 -- fields common to all messages:
1928 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1929 print("command CREATE")
1931 if not sets.cid then
1932 sets.cid = createResourceSet(self, cid, msg)
1935 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1936 print("command DESTROY")
1942 sets.cid = nil -- garbage collecting
1944 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1945 print("command ACQUIRE")
1947 if not sets.cid then
1948 sets.cid = createResourceSet(self, cid, msg)
1953 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1954 print("command RELEASE")
1960 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1961 print("command DEPRIVE")
1963 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1964 print("command WAITING")
1966 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1967 print("command REVERT")
1971 sc.inputdev_handler = function (self, cid, msg)
1973 print('*** inputdev handler: ' .. command_name(msg.command))
1981 function send_driving_mode_to_home_screen()
1982 if homescreen == "" then
1986 local driving_mode = mdb.select.select_driving_mode.single_value
1988 if not driving_mode then driving_mode = 0 end
1990 local reply = m:JSON({ command = 0x60001,
1991 arg = m:JSON({ stateid = 1,
1992 state = driving_mode
1997 print("### <== sending " .. command_name(reply.command) .. " message")
2003 sc:send_message(homescreen, reply)
2006 function send_night_mode_to_home_screen()
2007 if homescreen == "" then
2011 local night_mode = mdb.select.select_night_mode.single_value
2013 if not night_mode then night_mode = 0 end
2015 local reply = m:JSON({ command = 0x60001,
2016 arg = m:JSON({ stateid = 2,
2022 print("### <== sending " .. command_name(reply.command) .. " message")
2028 sc:send_message(homescreen, reply)
2031 -- we should have 'audio_playback' defined by now
2032 m:try_load_plugin('telephony')