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 -- PulseAudio volume context
240 name = "volume_context",
244 { "id", mdb.unsigned },
245 { "value", mdb.string, 64 },
249 -- put default volume context to the table
250 mdb.table.volume_context:insert({ id = 1, value = "default" })
252 if not m:plugin_exists('ivi-resource-manager') and
253 not with_system_controller
255 resource.method.veto = {
256 function(zone, rset, grant, owners, req_set)
262 -- test for creating selections
264 name = "audio_owner",
265 table = "audio_playback_owner",
266 columns = {"application_class"},
267 condition = "zone_name = 'driver'"
271 name = "vehicle_speed",
272 table = "amb_vehicle_speed",
274 condition = "key = 'VehicleSpeed'"
278 name = "speed2volume",
279 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
280 outputs = { mdb.table { name = "speedvol",
281 index = {"zone", "device"},
282 columns = {{"zone", mdb.string, 16},
283 {"device", mdb.string, 16},
284 {"value", mdb.floating}},
289 update = function(self)
290 speed = self.inputs.speed.single_value
292 volume = (speed - 144.0) / 7.0
296 diff = volume - self.oldvolume
297 if (diff*diff > self.inputs.param) then
298 print("*** element "..self.name.." update "..volume)
299 self.oldvolume = volume
300 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
308 columns = { "state" },
312 -- Night mode processing chain
315 name = "exterior_brightness",
316 table = "amb_exterior_brightness",
317 columns = { "value" },
318 condition = "key = 'ExteriorBrightness'"
323 inputs = { brightness = mdb.select.exterior_brightness },
327 name = "amb_nightmode",
331 { "id", mdb.unsigned },
332 { "night_mode", mdb.unsigned }
336 update = function(self)
337 -- This is a trivial function to calculate night mode. Later, we will
338 -- need a better threshold value and hysteresis to prevent oscillation.
340 brightness = self.inputs.brightness.single_value
342 if not brightness then
346 print("*** element "..self.name.." update brightness: "..brightness)
348 if brightness > 300 then
354 print("*** resulting mode: ".. mode)
356 if not (mode == self.oldmode) then
357 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
365 name = "select_night_mode",
366 table = "amb_nightmode",
367 columns = { "night_mode" },
374 inputs = { NightMode = mdb.select.select_night_mode,
375 amb_state = mdb.select.amb_state },
376 property = "NightMode",
378 initiate = builtin.method.amb_initiate,
379 update = builtin.method.amb_update
383 -- Night mode general handlers
385 if with_system_controller then
387 name = "nightmode_homescreen",
388 inputs = { owner = mdb.select.select_night_mode },
389 initiate = function(self)
390 -- data = mdb.select.select_night_mode.single_value
393 update = function(self)
394 send_night_mode_to(homescreen)
399 -- Driving mode processing chain
402 name = "drivingmode",
403 inputs = { speed = mdb.select.vehicle_speed },
407 name = "amb_drivingmode",
411 { "id", mdb.unsigned },
412 { "driving_mode", mdb.unsigned }
416 update = function(self)
418 speed = self.inputs.speed.single_value
430 if not (mode == self.oldmode) then
431 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
439 name = "select_driving_mode",
440 table = "amb_drivingmode",
441 columns = { "driving_mode" },
447 name = "driving_mode",
448 inputs = { DrivingMode = mdb.select.select_driving_mode,
449 amb_state = mdb.select.amb_state },
450 property = "DrivingMode",
452 initiate = builtin.method.amb_initiate,
453 update = builtin.method.amb_update
457 -- turn signals (left, right)
461 table = "amb_turn_signal",
462 columns = { "value" },
463 condition = "key = 'TurnSignal'"
466 -- define three categories
469 name = "undefined_applications",
470 table = "aul_applications",
471 columns = { "appid" },
472 condition = "category = '<undefined>'"
476 name = "basic_applications",
477 table = "aul_applications",
478 columns = { "appid" },
479 condition = "category = 'basic'"
483 name = "entertainment_applications",
484 table = "aul_applications",
485 columns = { "appid" },
486 condition = "category = 'entertainment'"
490 -- filter the object garbage out of the tables
493 for k,v in pairs(t) do
494 if k ~= "userdata" and k ~= "new" then
502 function getApplication(appid)
505 -- find the correct local application definition
507 for k,v in pairs(ft(application)) do
508 if appid == v.appid then
517 function regulateApplications(t, regulation)
518 for k,v in pairs(ft(t)) do
520 -- iterate through the undefined and entertainment apps, see if
521 -- they have been overruled in local config
523 local conf = getApplication(v.appid)
525 if conf and conf.resource_class ~= "player" then
526 -- override, don't disable
527 resmgr:disable_screen_by_appid("*", "*", v.appid, false, false)
529 resmgr:disable_screen_by_appid("*", "*", v.appid, regulation == 1, false)
532 resource.method.recalc("driver")
535 -- regulation (on), use "select_driving_mode"
538 name = "driving_regulation",
539 inputs = { owner = mdb.select.select_driving_mode },
540 initiate = function(self)
541 -- local data = mdb.select.select_driving_mode.single_value
544 update = function(self)
545 local data = mdb.select.select_driving_mode.single_value
548 print("Driving mode updated: " .. tostring(data))
555 -- tell homescreen that driving mode was updated
556 send_driving_mode_to(homescreen)
558 regulateApplications(ft(mdb.select.entertainment_applications), data)
559 regulateApplications(ft(mdb.select.undefined_applications), data)
566 name = "regulated_app_change",
567 inputs = { undef = mdb.select.undefined_applications,
568 entertainment = mdb.select.entertainment_applications },
569 initiate = function(self)
572 update = function(self)
573 local data = mdb.select.select_driving_mode.single_value
580 print("regulated application list was changed")
583 regulateApplications(ft(mdb.select.entertainment_applications), data)
584 regulateApplications(ft(mdb.select.undefined_applications), data)
591 -- shift position (parking, reverse, other)
594 name = "gear_position",
595 table = "amb_gear_position",
596 columns = { "value" },
597 condition = "key = 'GearPosition'"
600 -- cameras (back, front, left, right)
603 name = "camera_state",
604 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
608 name = "target_camera_state",
612 { "id", mdb.unsigned },
613 { "front_camera", mdb.unsigned },
614 { "back_camera", mdb.unsigned },
615 { "right_camera", mdb.unsigned },
616 { "left_camera", mdb.unsigned }
620 update = function(self)
627 if self.inputs.gear == 128 then
629 elseif self.inputs.winker == 1 then
631 elseif self.inputs.winker == 2 then
635 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
640 -- system controller test setup
642 if not with_system_controller then
643 -- ok, we should have 'audio_playback' defined by now
644 m:try_load_plugin('telephony')
648 m:load_plugin('system-controller')
650 window_manager_operation_names = {
655 function window_manager_operation_name(oper)
656 local name = window_manager_operation_names[oper]
657 if name then return name end
658 return "<unknown " .. tostring(oper) .. ">"
661 window_operation_names = {
672 function window_operation_name(oper)
673 local name = window_operation_names[oper]
674 if name then return name end
675 return "<unknown " .. tostring(oper) .. ">"
678 layer_operation_names = {
684 function layer_operation_name(oper)
685 local name = layer_operation_names[oper]
686 if name then return name end
687 return "<unknown " .. tostring(oper) .. ">"
690 input_manager_operation_names = {
696 function input_manager_operation_name(oper)
697 local name = input_manager_operation_names[oper]
698 if name then return name end
699 return "<unknown " .. tostring(oper) .. ">"
702 input_operation_names = {
708 function input_operation_name(oper)
709 local name = input_operation_names[oper]
710 if name then return name end
711 return "<unknown " .. tostring(oper) .. ">"
714 code_operation_names = {
720 function code_operation_name(oper)
721 local name = code_operation_names[oper]
722 if name then return name end
723 return "<unknown " .. tostring(oper) .. ">"
727 [0x00001] = "send_appid",
728 [0x10001] = "create",
729 [0x10002] = "destroy",
733 [0x10006] = "animation",
734 [0x10007] = "change_active",
735 [0x10008] = "change_layer",
736 [0x10009] = "change_attr",
738 [0x10020] = "map_thumb",
739 [0x10021] = "unmap_thumb",
740 [0x10022] = "map_get",
741 [0x10030] = "show layer",
742 [0x10031] = "hide_layer",
743 [0x10032] = "change_layer_attr",
744 [0x20001] = "add_input",
745 [0x20002] = "del_input",
746 [0x30001] = "change_user",
747 [0x30002] = "get_userlist",
748 [0x30003] = "get_lastinfo",
749 [0x30004] = "set_lastinfo",
750 [0x40001] = "acquire_res",
751 [0x40002] = "release_res",
752 [0x40003] = "deprive_res",
753 [0x40004] = "waiting_res",
754 [0x40005] = "revert_res",
755 [0x40006] = "window_id_res",
756 [0x40011] = "create_res",
757 [0x40012] = "destroy_res",
758 [0x50001] = "set_region",
759 [0x50002] = "unset_region",
760 [0x60001] = "change_state"
763 function command_name(command)
764 local name = command_names[command]
765 if name then return name end
766 return "<unknown " .. tostring(command) .. ">"
770 [101] = true, -- input
771 [102] = true, -- touch
772 [103] = true -- cursor
775 -- some day this should be merged with wmgr.layers
777 [1] = 0x1000, -- background
778 [2] = 0x2000, -- application
779 [3] = 0x2000, -- homescreen
780 [4] = 0x2000, -- interrupt application
781 [5] = 0x2000, -- onscreen application
782 [6] = 0xc000, -- startup
783 [7] = 0x3000, -- fullscreen
784 [101] = 0x4000, -- input
785 [102] = 0xa000, -- touch
786 [103] = 0xb000 -- cursor
789 resmgr = resource_manager {
790 screen_event_handler = function(self, ev)
791 local event = ev.event
792 local surface = ev.surface
794 if event == "init" then
796 print("*** init screen resource allocation -- disable all 'player'")
798 resmgr:disable_audio_by_appid("*", "player", "*", true, false)
799 elseif event == "preallocate" then
801 print("*** preallocate screen resource "..
802 "for '" .. ev.appid .. "' -- enable 'player', if any")
804 resmgr:disable_audio_by_appid("*", "player", ev.appid, false, false)
805 elseif event == "grant" then
807 print("*** make visible surface "..surface)
809 local a = animation({})
810 local r = m:JSON({surface = surface,
813 wmgr:window_request(r,a,0)
814 elseif event == "revoke" then
816 print("*** hide surface "..surface)
818 local a = animation({})
819 local r = m:JSON({surface = ev.surface,
821 wmgr:window_request(r,a,0)
823 elseif event == "create" then
826 print("*** screen resource event: " ..
830 local regulation = mdb.select.select_driving_mode.single_value
832 if regulation == 1 then
834 local blacklisted = false
836 -- applications which have their category set to "entertainment"
837 -- or "undefined" are blacklisted, meaning they should be regulated
839 for i,v in pairs(ft(mdb.select.undefined_applications)) do
840 if v.appid == ev.appid then
842 print(ev.appid .. " was blacklisted (undefined)")
849 if not blacklisted then
850 for i,v in pairs(ft(mdb.select.entertainment_applications)) do
851 if v.appid == ev.appid then
853 print(ev.appid .. " was blacklisted (entertainment)")
861 -- our local application config, which takes precedence
862 local conf = getApplication(ev.appid)
864 -- disable only non-whitelisted applications
865 if not conf or conf.resource_class == "player" then
868 print("disabling screen for " .. ev.appid)
870 resmgr:disable_screen_by_appid("*", "*", ev.appid, true, true)
875 elseif event == "destroy" then
877 print("*** screen resource event: " ..
882 print("*** screen resource event: " ..
887 audio_event_handler = function(self, ev)
888 local event = ev.event
889 local appid = ev.appid
890 local audioid = ev.audioid
892 if event == "grant" then
894 print("*** grant audio to "..appid..
895 " ("..audioid..") in '" ..
898 elseif event == "revoke" then
900 print("*** revoke audio from "..appid..
901 " ("..audioid..") in '" ..
906 print("*** audio resource event: " ..
913 resclnt = resource_client {}
915 wmgr = window_manager {
916 geometry = function(self, w,h, v)
917 if type(v) == "function" then
923 application = function(self, appid)
925 local app = application_lookup(appid)
927 app = application_lookup("default")
931 return { privileges = {screen="none", audio="none"} }
934 output_order = { 1, 0 },
936 outputs = { { name = "Mid",
943 width = function(w,h) return w end,
944 height = function(w,h) return h end
951 height = function(w,h) return h end
955 pos_x = function(w,h) return w-320 end,
958 height = function(w,h) return h end
969 width = function(w,h) return w end,
976 width = function(w,h) return w end,
977 height = function(w,h) return h-64-128 end
983 width = function(w,h) return w end,
984 height = function(w,h) return (h-64-128)/2 end
989 pos_y = function(w,h) return (h-64-128)/2+64 end,
990 width = function(w,h) return w end,
991 height = function(w,h) return (h-64-128)/2 end
997 width = function(w,h) return w/2 end,
998 height = function(w,h) return (h-64-128)/2 end
1002 pos_x = function(w,h) return w/2 end,
1004 width = function(w,h) return w/2 end,
1005 height = function(w,h) return (h-64-128)/2 end
1010 pos_y = function(w,h) return (h-64-128/2)+64 end,
1011 width = function(w,h) return w/2 end,
1012 height = function(w,h) return (h-64-128)/2 end
1016 pos_x = function(w,h) return w/2 end,
1017 pos_y = function(w,h) return (h-64-128/2)+64 end,
1018 width = function(w,h) return w/2 end,
1019 height = function(w,h) return (h-64-128)/2 end
1025 width = function(w,h) return w end,
1026 height = function(w,h) return h-64-128 end
1032 width = function(w,h) return w/2-181 end,
1033 height = function(w,h) return h-64-128 end
1035 ["SysApp.Right"] = {
1037 pos_x = function(w,h) return w/2+181 end,
1039 width = function(w,h) return w/2-181 end,
1040 height = function(w,h) return h-64-128 end
1046 width = function(w,h) return w end,
1047 height = function(w,h) return h-64-128 end
1053 width = function(w,h) return w end,
1054 height = function(w,h) return (h-64-128)/2 end
1059 pos_y = function(w,h) return (h-64-128)/2+64 end,
1060 width = function(w,h) return w end,
1061 height = function(w,h) return (h-64-128)/2 end
1066 pos_y = function(w,h) return h-128 end,
1067 width = function(w,h) return w end,
1073 -- id name type output
1074 layers = { { 0, "BackGround" , 1, "Center" },
1075 { 1, "Application" , 2, "Center" },
1076 { 2, "HomeScreen" , 3, "Center" },
1077 { 3, "ControlBar" , 3, "Center" },
1078 { 4, "InterruptApp" , 4, "Center" },
1079 { 5, "OnScreen" , 5, "Center" },
1080 { 6, "Touch" , 102, "Center" },
1081 { 7, "Cursor" , 103, "Center" }
1085 manager_update = function(self, oper)
1087 print("### <== WINDOW MANAGER UPDATE:" ..
1088 window_manager_operation_name(oper))
1091 local wumask = window_mask { --raise = true,
1094 local wrmask = window_mask { raise = true,
1097 local lumask = layer_mask { visible = true }
1098 local lrmask = layer_mask { visible = true }
1099 local req = m:JSON({
1100 passthrough_window_update = wumask:tointeger(),
1101 passthrough_window_request = wrmask:tointeger(),
1102 passthrough_layer_update = lumask:tointeger(),
1103 passthrough_layer_request = lrmask:tointeger()
1105 self:manager_request(req)
1109 window_update = function(self, oper, win, mask)
1111 print("### <== WINDOW UPDATE oper:" ..
1112 window_operation_name(oper) ..
1113 " mask: " .. tostring(mask))
1119 local arg = m:JSON({ surface = win.surface,
1124 if oper == 1 then -- create
1125 local layertype = win.layertype
1126 if layertype and input_layer[layertype] then
1128 print("ignoring input panel creation")
1133 elseif oper == 2 then -- destroy
1135 elseif oper == 3 then -- namechange
1137 elseif oper == 4 or oper == 5 then -- visible/configure
1141 if win.layertype then
1142 arg.layertype = win.layertype
1144 arg.layer = win.layer
1145 arg.pos_x = win.pos_x
1146 arg.pos_y = win.pos_y
1147 arg.width = win.width
1148 arg.height = win.height
1149 arg.raise = win.raise
1150 arg.visible = win.visible
1151 if win.active == 0 then
1156 elseif oper == 6 then -- active
1157 if win.active == 0 then
1159 print("ignoring inactive event")
1164 elseif oper == 7 then -- map
1169 if win.mapped == 0 then
1175 --arg.name = map.target
1176 arg.width = map.width
1177 arg.height = map.height
1178 arg.stride = map.stride
1179 arg.format = map.format
1182 print("### nothing to do")
1187 local msg = m:JSON({ command = command,
1193 print("### <== sending " ..
1194 command_name(msg.command) ..
1195 " window message to '" .. homescreen .. "'")
1200 sc:send_message(homescreen, msg)
1202 if oper == 1 then -- create
1203 local i = input_layer[win.layertype]
1204 local p = self:application(win.appid)
1205 local s = p.privileges.screen
1207 if s == "system" then
1208 local a = animation({})
1209 local r = m:JSON({surface = win.surface,
1212 self:window_request(r,a,0)
1216 print("do not make resource for " ..
1220 resclnt:resource_set_create("screen",
1224 special_screen_sets[win.surface] = true
1228 if onscreen and win.appid == onscreen then
1229 local resmsg = m:JSON({
1230 command = 0x40006, -- window_id_res
1242 resourceId = win.surface
1247 print("### <== sending " ..
1248 command_name(resmsg.command) ..
1249 " message to '" .. onscreen .. "'")
1254 sc:send_message(onscreen, resmsg);
1256 elseif oper == 2 then -- destroy
1257 resclnt:resource_set_destroy("screen", win.surface)
1258 special_screen_sets[win.surface] = nil
1259 elseif oper == 6 then -- active
1261 local i = input_layer[win.layertype]
1262 local p = self:application(win.appid)
1263 local s = p.privileges.screen
1264 local surface = win.surface
1265 if not i and s ~= "system" then
1266 resclnt:resource_set_acquire("screen",surface)
1267 resmgr:window_raise(win.appid, surface, 1)
1273 layer_update = function(self, oper, layer, mask)
1275 print("### LAYER UPDATE:" ..
1276 layer_operation_name(oper) ..
1277 " mask: " .. tostring(mask))
1282 if oper == 3 then -- visible
1283 local command = 0x10008 -- change_layer
1284 local msg = m:JSON({
1287 arg = m:JSON({layer = layer.id,
1288 visible = layer.visible
1292 print("### <== sending "..command_name(command)..
1298 sc:send_message(homescreen, msg)
1301 print("### nothing to do")
1306 output_update = function(self, oper, out, mask)
1307 local idx = out.index
1308 local defidx = self.output_order[idx+1]
1310 print("### OUTPUT UPDATE:" .. oper ..
1311 " mask: "..tostring(mask))
1317 local outdef = self.outputs[defidx+1]
1318 if (oper == 1) then -- create
1320 self:output_request(m:JSON({index = idx,
1325 elseif (oper == 5) then -- done
1326 local ads = outdef.areas
1327 local on = outdef.name
1329 for name,ad in pairs(ads) do
1330 local can = wmgr:canonical_name(on.."."..name)
1331 local a = m:JSON({name = name,
1332 output = out.index})
1333 for fld,val in pairs(ad) do
1334 a[fld] = self:geometry(out.width,
1339 resmgr:area_create(area[can], outdef.zone)
1347 imgr = input_manager {
1348 inputs = {{ name = "G27 Racing Wheel",
1350 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1351 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1352 [4] = {appid="org.tizen.ico.app-soundsample" },
1353 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1357 manager_update = function(self, oper)
1359 print("### <== INPUT MANAGER UPDATE:" ..
1360 input_manager_operation_name(oper))
1364 input_update = function(self, oper, inp, mask)
1366 print("### INPUT UPDATE:" ..
1367 input_operation_name(oper) ..
1368 " mask: " .. tostring(mask))
1374 code_update = function(self, oper, code, mask)
1376 print("### CODE UPDATE: mask: " .. tostring(mask))
1381 local msg = m:JSON({ command = 1,
1382 appid = "org.tizen.ico.homescreen",
1383 arg = m:JSON({ device = code.device,
1391 print("### <== sending " ..
1392 command_name(msg.command) ..
1398 sc:send_message(homescreen, msg)
1402 sc = m:get_system_controller()
1407 -- special screen resource sets
1408 -- TODO: just rewrite screen resource handling to use regular resource API
1410 special_screen_sets = {}
1413 um = m:UserManager()
1419 -- these shoud be before wmgr:connect() is called
1421 print("====== creating applications ======")
1425 area = "Center.Full",
1426 privileges = { screen = "none", audio = "none" },
1427 resource_class = "player",
1433 area = "Center.Full",
1434 privileges = { screen = "system", audio = "none" },
1435 resource_class = "implicit",
1436 screen_priority = 30
1440 appid = "org.tizen.ico.homescreen",
1441 area = "Center.Full",
1442 windows = { {'ico_hs_controlbarwindow', 'Center.Control'} },
1443 privileges = { screen = "system", audio = "system" },
1444 resource_class = "player",
1445 screen_priority = 20
1449 appid = "org.tizen.ico.statusbar",
1450 area = "Center.Status",
1451 privileges = { screen = "system", audio = "none" },
1452 resource_class = "player",
1453 screen_priority = 20
1457 appid = "org.tizen.ico.onscreen",
1458 area = "Center.Full",
1459 privileges = { screen = "system", audio = "system" },
1460 resource_class = "player",
1461 screen_priority = 20
1465 appid = "org.tizen.ico.login",
1466 area = "Center.Full",
1467 privileges = { screen = "system", audio = "system" },
1468 resource_class = "player",
1469 screen_priority = 20
1473 appid = "org.tizen.ico.camera_left",
1474 area = "Center.SysApp.Left",
1475 privileges = { screen = "system", audio = "none" },
1476 requisites = { screen = "blinker_left", audio = "none" },
1477 resource_class = "player",
1478 screen_priority = 30
1482 appid = "org.tizen.ico.camera_right",
1483 area = "Center.SysApp.Right",
1484 privileges = { screen = "system", audio = "none" },
1485 requisites = { screen = "blinker_right", audio = "none" },
1486 resource_class = "player",
1487 screen_priority = 30
1491 appid = "net.zmap.navi",
1492 area = "Center.Full",
1493 privileges = { screen = "none", audio = "none" },
1494 resource_class = "navigator",
1495 screen_priority = 30
1499 appid = "GV3ySIINq7.GhostCluster",
1500 area = "Center.Full",
1501 privileges = { screen = "none", audio = "none" },
1502 resource_class = "system",
1503 screen_priority = 30
1507 sc.client_handler = function (self, cid, msg)
1508 local command = msg.command
1509 local appid = msg.appid
1511 print('### ==> client handler:')
1517 -- known commands: 1 for SEND_APPID, synthetic command 0xFFFF for
1520 if command == 0xFFFF then
1522 print('client ' .. cid .. ' disconnected')
1524 if msg.appid == homescreen then
1526 for i,v in pairs(special_screen_sets) do
1527 resclnt:resource_set_destroy("screen", i)
1528 special_screen_sets[i] = nil
1534 -- handle the connection to weston
1537 if appid == "org.tizen.ico.homescreen" then
1538 print('Setting homescreen='..appid)
1540 if command and command == 1 then
1541 send_driving_mode_to(homescreen)
1542 send_night_mode_to(homescreen)
1544 elseif appid == "org.tizen.ico.onscreen" then
1546 if command and command == 1 then
1547 send_driving_mode_to(onscreen)
1548 send_night_mode_to(onscreen)
1552 if not connected and appid == "org.tizen.ico.homescreen" then
1553 print('Trying to connect to weston...')
1554 connected = wmgr:connect()
1559 sc.generic_handler = function (self, cid, msg)
1561 print('### ==> generic handler:')
1568 sc.window_handler = function (self, cid, msg)
1570 print('### ==> received ' ..
1571 command_name(msg.command) .. ' message')
1573 print(tostring(msg))
1577 local a = animation({})
1579 if msg.command == 0x10003 then -- ico SHOW command
1580 local raise_mask = 0x01000000
1581 local lower_mask = 0x02000000
1582 local nores_mask = 0x40000000
1583 local time_mask = 0x00ffffff
1587 if msg.arg.anim_time then
1588 local t = msg.arg.anim_time
1589 time = m:AND(t, time_mask)
1590 nores = not m:AND(t, nores_mask)
1591 if m:AND(t, raise_mask) then
1593 elseif m:AND(t, lower_mask) then
1597 if msg.arg.anim_name then
1598 a.show = { msg.arg.anim_name, time }
1599 print('time: ' .. tostring(a.show[2]))
1603 local p = wmgr:application(msg.appid)
1604 local s = p.privileges.screen
1605 if s == "system" then
1607 if not msg.arg.raise then
1613 print('### ==> SHOW')
1614 print(tostring(msg.arg))
1617 wmgr:window_request(msg.arg, a, 0)
1619 local surface = msg.arg.surface
1620 resclnt:resource_set_acquire("screen", surface)
1621 resmgr:window_raise(msg.appid, surface, 1)
1623 elseif msg.command == 0x10004 then -- ico HIDE command
1624 local raise_mask = 0x01000000
1625 local lower_mask = 0x02000000
1626 local nores_mask = 0x40000000
1627 local time_mask = 0x00ffffff
1631 if msg.arg.anim_time then
1632 local t = msg.arg.anim_time
1633 time = m:AND(t, time_mask)
1634 nores = not m:AND(t, nores_mask)
1636 if msg.arg.anim_name then
1637 a.hide = { msg.arg.anim_name, time }
1638 print('hide animation time: ' .. tostring(a.hide[2]))
1642 local p = wmgr:application(msg.appid)
1643 local s = p.privileges.screen
1644 if s == "system" then
1650 print('### ==> HIDE REQUEST')
1651 print(tostring(msg.arg))
1654 wmgr:window_request(msg.arg, a, 0)
1656 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1658 elseif msg.command == 0x10005 then -- ico MOVE
1660 print('### ==> MOVE REQUEST')
1661 print(tostring(msg.arg))
1663 if msg.arg.zone then
1664 msg.arg.area = msg.arg.zone
1666 wmgr:window_request(msg.arg, a, 0)
1667 -- TODO: handle if area changed
1668 elseif msg.command == 0x10007 then -- ico CHANGE_ACTIVE
1669 if not msg.arg.active then
1670 msg.arg.active = 3 -- pointer + keyboard
1673 print('### ==> CHANGE_ACTIVE REQUEST')
1674 print(tostring(msg.arg))
1676 wmgr:window_request(msg.arg, a, 0)
1677 elseif msg.command == 0x10008 then -- ico CHANGE_LAYER
1679 print('### ==> CHANGE_LAYER REQUEST')
1680 print(tostring(msg.arg))
1683 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1684 print("do not change layer for other than cursor or touch")
1688 wmgr:window_request(msg.arg, a, 0)
1689 elseif msg.command == 0x10020 then -- ico MAP_THUMB
1690 local framerate = msg.arg.framerate
1691 local animname = msg.arg.anim_name
1693 a.map = { animname, 1 }
1694 if not framerate or framerate < 0 then
1699 print('### ==> MAP_THUMB REQUEST')
1701 print('framerate: '..framerate)
1703 wmgr:window_request(msg.arg, a, framerate)
1705 elseif msg.command == 0x10021 then -- ico UNMAP_THUMB
1708 print('### ==> UNMAP_THUMB REQUEST')
1711 wmgr:window_request(msg.arg, a, 0)
1713 elseif msg.command == 0x10013 then -- ico MAP_BUFFER command
1714 local shmname = msg.arg.anim_name
1715 local bufsize = msg.arg.width
1716 local bufnum = msg.arg.height
1717 if shmname and bufsize and bufnum then
1719 print('### ==> MAP_BUFFER REQUEST')
1720 print("shmaname='" .. shmname ..
1721 "' bufsize='" .. bufsize ..
1722 " bufnum=" .. bufnum)
1724 wmgr:buffer_request(shmname, bufsize, bufnum)
1727 elseif msg.command == 0x10030 then -- ico SHOW_LAYER command
1730 print('### ==> SHOW_LAYER REQUEST')
1733 wmgr:layer_request(msg.arg)
1734 elseif msg.command == 0x10031 then -- ico HIDE_LAYER command
1737 print('### ==> HIDE_LAYER REQUEST')
1740 wmgr:layer_request(msg.arg)
1744 sc.input_handler = function (self, cid, msg)
1746 print('### ==> input handler: ' .. command_name(msg.command))
1751 if msg.command == 0x20001 then -- add_input
1752 msg.arg.appid = msg.appid
1754 print('### ==> ADD_INPUT REQUEST')
1755 print(tostring(msg.arg))
1757 imgr:input_request(msg.arg)
1758 elseif msg.command == 0x20002 then -- del_input
1761 print('### ==> DEL_INPUT REQUEST')
1762 print(tostring(msg.arg))
1764 imgr:input_request(msg.arg)
1765 -- elseif msg.command == 0x20003 then -- send_input
1769 sc.user_handler = function (self, cid, msg)
1771 print('### ==> user handler: ' .. command_name(msg.command))
1778 print("User Manager not initialized")
1782 if msg.command == 0x30001 then -- change_user
1783 print("command CHANGE_USER")
1785 print("invalid message")
1789 username = msg.arg.user
1790 passwd = msg.arg.pass
1792 if not username then
1800 success = um:changeUser(username, passwd)
1807 if sc:send_message(msg.appid, reply) then
1808 print('*** sent authentication failed message')
1810 print('*** failed to send authentication failed message')
1814 elseif msg.command == 0x30002 then -- get_userlist
1815 print("command GET_USERLIST")
1816 if not msg.appid then
1817 print("invalid message")
1821 users, currentUser = um:getUserList()
1824 print("failed to get user list")
1830 for i,v in pairs(users) do
1834 if not currentUser then
1839 print("current user: " .. currentUser)
1841 for i,v in pairs(users) do
1852 user_login = currentUser
1857 print("### <== GetUserList reply: " .. tostring(reply))
1860 if sc:send_message(msg.appid, reply) then
1861 print('*** reply OK')
1863 print('*** reply FAILED')
1866 elseif msg.command == 0x30003 then -- get_lastinfo
1867 print("command GET_LASTINFO")
1868 if not msg.appid then
1869 print("invalid message")
1873 lastInfo = um:getLastInfo(msg.appid)
1875 if not lastInfo then
1876 print("failed to get last info for app" .. msg.appid)
1888 if sc:send_message(msg.appid, reply) then
1889 print('*** reply OK')
1891 print('*** reply FAILED')
1894 elseif msg.command == 0x30004 then -- set_lastinfo
1895 print("command SET_LASTINFO")
1896 if not msg.arg or not msg.appid then
1897 print("invalid message")
1901 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1905 sc.resource_handler = function (self, cid, msg)
1907 print('### ==> resource handler: ' .. command_name(msg.command))
1913 createResourceSet = function (ctl, client, msg)
1914 cb = function(rset, data)
1915 print("> resource callback")
1917 -- type is either basic (0) or interrupt (1)
1919 if msg.res.type then
1920 requestType = msg.res.type
1923 if rset.acquired then
1924 cmd = 0x00040001 -- acquire
1926 cmd = 0x00040002 -- release
1930 appid = data.client,
1937 if rset.resources.audio_playback then
1946 if rset.resources.display then
1947 reply.res.window = {
1954 if rset.resources.input then
1960 print("sending message to client: " .. data.client)
1962 if sc:send_message(data.client, reply) then
1963 print('*** reply OK')
1965 print('*** reply FAILED')
1969 rset = m:ResourceSet({
1970 application_class = "player",
1971 zone = "driver", -- msg.zone ("full")
1980 if msg.res.sound then
1982 resource_name = "audio_playback"
1984 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1985 rset.resources.audio_playback.attributes.appid = msg.appid
1986 print("sound name: " .. msg.res.sound.name)
1987 print("sound zone:" .. msg.res.sound.zone)
1988 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1989 if msg.res.sound.id then
1990 print("sound id: " .. msg.res.sound.id)
1994 if msg.res.input then
1996 resource_name = "input"
1998 rset.resources.input.attributes.pid = tostring(msg.pid)
1999 rset.resources.input.attributes.appid = msg.appid
2000 print("input name: " .. msg.res.sound.name)
2001 print("input event:" .. tostring(msg.res.input.event))
2004 if msg.res.window then
2006 resource_name = "display"
2008 rset.resources.display.attributes.pid = tostring(msg.pid)
2009 rset.resources.display.attributes.appid = msg.appid
2010 print("display name: " .. msg.res.display.name)
2011 print("display zone:" .. msg.res.display.zone)
2012 if msg.res.display.id then
2013 print("display id: " .. msg.res.display.id)
2020 -- parse the message
2022 -- fields common to all messages:
2027 if msg.command == 0x40011 then -- create_res
2028 print("command CREATE_RES")
2030 if not sets.cid then
2031 sets.cid = createResourceSet(self, cid, msg)
2034 elseif msg.command == 0x40012 then -- destroy_res
2035 print("command DESTROY_RES")
2041 sets.cid = nil -- garbage collecting
2043 elseif msg.command == 0x40001 then -- acquire_res
2044 print("command ACQUIRE_RES")
2046 if not sets.cid then
2047 sets.cid = createResourceSet(self, cid, msg)
2052 elseif msg.command == 0x40002 then -- release_res
2053 print("command RELEASE_RES")
2059 elseif msg.command == 0x40003 then -- deprive_res
2060 print("command DEPRIVE_RES")
2062 elseif msg.command == 0x40004 then -- waiting_res
2063 print("command WAITING_RES")
2065 elseif msg.command == 0x40005 then -- revert_res
2066 print("command REVERT_RES")
2070 sc.inputdev_handler = function (self, cid, msg)
2072 print('*** inputdev handler: ' .. command_name(msg.command))
2079 sc.notify_handler = function (self, cid, msg)
2081 print('### notify handler: ' .. command_name(msg.command))
2089 function send_driving_mode_to(client)
2090 if client == "" then
2094 local driving_mode = mdb.select.select_driving_mode.single_value
2096 if not driving_mode then driving_mode = 0 end
2098 local reply = m:JSON({ command = 0x60001,
2099 arg = m:JSON({ stateid = 1,
2100 state = driving_mode
2105 print("### <== sending " .. command_name(reply.command) .. " message")
2111 sc:send_message(client, reply)
2114 function send_night_mode_to(client)
2115 if client == "" then
2119 local night_mode = mdb.select.select_night_mode.single_value
2121 if not night_mode then night_mode = 0 end
2123 local reply = m:JSON({ command = 0x60001,
2124 arg = m:JSON({ stateid = 2,
2130 print("### <== sending " .. command_name(reply.command) .. " message")
2136 sc:send_message(client, reply)
2139 -- we should have 'audio_playback' defined by now
2140 m:try_load_plugin('telephony')