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 if m:plugin_exists("gam-resource-manager") then
55 function get_general_priorities(self)
56 print("*** get_general_priorities\n")
57 return { "USB Headset", "wiredHeadset", "speakers" }
60 function get_phone_priorities(self)
61 print("*** get_phone_priorities\n")
62 return { "wiredHeadset", "USB Headset" }
65 m:load_plugin('gam-resource-manager', {
66 config_dir = '/etc/murphy/gam',
67 decision_names = 'gam-wrtApplication-4',
70 ['t8j6HTRpuz.MediaPlayer'] = 'wrtApplication',
71 ['pacat'] = 'icoApplication'
73 app_default = 'icoApplication'
76 routing_sink_priority {
77 application_class = "player",
78 priority_queue = get_general_priorities
81 routing_sink_priority {
82 application_class = "game",
83 priority_queue = get_general_priorities
86 routing_sink_priority {
87 application_class = "implicit",
88 priority_queue = get_general_priorities
91 routing_sink_priority {
92 application_class = "phone",
93 priority_queue = get_phone_priorities
96 routing_sink_priority {
97 application_class = "basic",
98 priority_queue = get_phone_priorities
101 routing_sink_priority {
102 application_class = "event",
103 priority_queue = get_phone_priorities
107 -- load the AMB plugin
108 if m:plugin_exists('amb') then
109 m:try_load_plugin('amb')
111 if builtin.method.amb_initiate and
112 builtin.method.amb_update
117 m:info("No amb plugin found...")
120 -- load the ASM resource plugin
121 if m:plugin_exists('resource-asm') then
122 m:try_load_plugin('resource-asm', {
124 share_mmplayer = "player:AVP,mandatory,exclusive,strict",
125 ignored_argv0 = "WebProcess"
128 m:info("No audio session manager plugin found...")
131 if m:plugin_exists('system-controller') then
132 with_system_controller = true
133 elseif m:plugin_exists('ivi-resource-manager') then
134 m:load_plugin('ivi-resource-manager')
135 with_system_controller = false
138 -- define application classes
192 application_class { name="event" , priority=4 , modal=false, share=true , order="fifo" }
193 application_class { name="game" , priority=3 , modal=false, share=false, order="lifo" }
194 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
195 --#application_class { name="basic" , priority=2 , modal=false, share=false, order="lifo" }
196 application_class { name="player" , priority=1 , modal=false, share=true , order="lifo" }
197 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
199 -- define zone attributes
201 type = {mdb.string, "common", "rw"},
202 location = {mdb.string, "anywhere", "rw"}
210 location = "front-left"
218 location = "front-right"
226 location = "back-left"
234 location = "back-right"
242 location = "back-left"
247 -- define resource classes
248 if not m:plugin_exists('ivi-resource-manager') and
249 not with_system_controller and
250 not m:plugin_exists('gam-resource-manager')
253 name = "audio_playback",
256 role = { mdb.string, "music", "rw" },
257 pid = { mdb.string, "<unknown>", "rw" },
258 policy = { mdb.string, "relaxed", "rw" },
259 source = { mdb.string, "webkit", "rw" },
260 conn_id = { mdb.unsigned, 0, "rw" }
265 if not m:plugin_exists('gam-resource-manager') then
267 name = "audio_recording",
270 role = { mdb.string, "music" , "rw" },
271 pid = { mdb.string, "<unknown>", "rw" },
272 policy = { mdb.string, "relaxed" , "rw" }
278 name = "video_playback",
283 name = "video_recording",
288 name = "speech_recognition",
293 name = "speech_synthesis",
297 -- PulseAudio volume context
299 name = "volume_context",
303 { "id", mdb.unsigned },
304 { "value", mdb.string, 64 },
308 -- put default volume context to the table
309 mdb.table.volume_context:insert({ id = 1, value = "default" })
311 if not m:plugin_exists('ivi-resource-manager') and
312 not with_system_controller
314 resource.method.veto = {
315 function(zone, rset, grant, owners, req_set)
321 -- test for creating selections
323 name = "audio_owner",
324 table = "audio_playback_owner",
325 columns = {"application_class"},
326 condition = "zone_name = 'driver'"
330 name = "vehicle_speed",
331 table = "amb_vehicle_speed",
333 condition = "key = 'VehicleSpeed'"
337 name = "speed2volume",
338 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
339 outputs = { mdb.table { name = "speedvol",
340 index = {"zone", "device"},
341 columns = {{"zone", mdb.string, 16},
342 {"device", mdb.string, 16},
343 {"value", mdb.floating}},
348 update = function(self)
349 speed = self.inputs.speed.single_value
351 volume = (speed - 144.0) / 7.0
355 diff = volume - self.oldvolume
356 if (diff*diff > self.inputs.param) then
357 print("*** element "..self.name.." update "..volume)
358 self.oldvolume = volume
359 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
367 columns = { "state" },
371 -- Night mode processing chain
374 name = "exterior_brightness",
375 table = "amb_exterior_brightness",
376 columns = { "value" },
377 condition = "key = 'ExteriorBrightness'"
382 inputs = { brightness = mdb.select.exterior_brightness },
386 name = "amb_nightmode",
390 { "id", mdb.unsigned },
391 { "night_mode", mdb.unsigned }
395 update = function(self)
396 -- This is a trivial function to calculate night mode. Later, we will
397 -- need a better threshold value and hysteresis to prevent oscillation.
399 brightness = self.inputs.brightness.single_value
401 if not brightness then
405 print("*** element "..self.name.." update brightness: "..brightness)
407 if brightness > 300 then
413 print("*** resulting mode: ".. mode)
415 if not (mode == self.oldmode) then
416 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
424 name = "select_night_mode",
425 table = "amb_nightmode",
426 columns = { "night_mode" },
433 inputs = { NightMode = mdb.select.select_night_mode,
434 amb_state = mdb.select.amb_state },
435 property = "NightMode",
437 initiate = builtin.method.amb_initiate,
438 update = builtin.method.amb_update
442 -- Night mode general handlers
444 if with_system_controller then
446 name = "nightmode_homescreen",
447 inputs = { owner = mdb.select.select_night_mode },
448 initiate = function(self)
449 -- data = mdb.select.select_night_mode.single_value
452 update = function(self)
453 send_night_mode_to(homescreen)
458 -- Driving mode processing chain
461 name = "drivingmode",
462 inputs = { speed = mdb.select.vehicle_speed },
466 name = "amb_drivingmode",
470 { "id", mdb.unsigned },
471 { "driving_mode", mdb.unsigned }
475 update = function(self)
477 speed = self.inputs.speed.single_value
489 if not (mode == self.oldmode) then
490 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
498 name = "select_driving_mode",
499 table = "amb_drivingmode",
500 columns = { "driving_mode" },
506 name = "driving_mode",
507 inputs = { DrivingMode = mdb.select.select_driving_mode,
508 amb_state = mdb.select.amb_state },
509 property = "DrivingMode",
511 initiate = builtin.method.amb_initiate,
512 update = builtin.method.amb_update
516 -- turn signals (left, right)
520 table = "amb_turn_signal",
521 columns = { "value" },
522 condition = "key = 'TurnSignal'"
525 -- define three categories
528 name = "undefined_applications",
529 table = "aul_applications",
530 columns = { "appid" },
531 condition = "category = '<undefined>'"
535 name = "basic_applications",
536 table = "aul_applications",
537 columns = { "appid" },
538 condition = "category = 'basic'"
542 name = "entertainment_applications",
543 table = "aul_applications",
544 columns = { "appid" },
545 condition = "category = 'entertainment'"
549 -- filter the object garbage out of the tables
552 for k,v in pairs(t) do
553 if k ~= "userdata" and k ~= "new" then
561 function getApplication(appid)
564 -- find the correct local application definition
566 for k,v in pairs(ft(application)) do
567 if appid == v.appid then
576 function regulateApplications(t, regulation)
577 for k,v in pairs(ft(t)) do
579 -- iterate through the undefined and entertainment apps, see if
580 -- they have been overruled in local config
582 local conf = getApplication(v.appid)
584 if conf and conf.resource_class ~= "player" then
585 -- override, don't disable
586 resmgr:disable_screen_by_appid("*", "*", v.appid, false, false)
588 resmgr:disable_screen_by_appid("*", "*", v.appid, regulation == 1, false)
591 resource.method.recalc("driver")
594 -- regulation (on), use "select_driving_mode"
597 name = "driving_regulation",
598 inputs = { owner = mdb.select.select_driving_mode },
599 initiate = function(self)
600 -- local data = mdb.select.select_driving_mode.single_value
603 update = function(self)
604 local data = mdb.select.select_driving_mode.single_value
607 print("Driving mode updated: " .. tostring(data))
614 -- tell homescreen that driving mode was updated
615 send_driving_mode_to(homescreen)
617 regulateApplications(ft(mdb.select.entertainment_applications), data)
618 regulateApplications(ft(mdb.select.undefined_applications), data)
625 name = "regulated_app_change",
626 inputs = { undef = mdb.select.undefined_applications,
627 entertainment = mdb.select.entertainment_applications },
628 initiate = function(self)
631 update = function(self)
632 local data = mdb.select.select_driving_mode.single_value
639 print("regulated application list was changed")
642 regulateApplications(ft(mdb.select.entertainment_applications), data)
643 regulateApplications(ft(mdb.select.undefined_applications), data)
650 -- shift position (parking, reverse, other)
653 name = "gear_position",
654 table = "amb_gear_position",
655 columns = { "value" },
656 condition = "key = 'GearPosition'"
659 -- cameras (back, front, left, right)
662 name = "camera_state",
663 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
667 name = "target_camera_state",
671 { "id", mdb.unsigned },
672 { "front_camera", mdb.unsigned },
673 { "back_camera", mdb.unsigned },
674 { "right_camera", mdb.unsigned },
675 { "left_camera", mdb.unsigned }
679 update = function(self)
686 if self.inputs.gear == 128 then
688 elseif self.inputs.winker == 1 then
690 elseif self.inputs.winker == 2 then
694 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
699 -- system controller test setup
701 if not with_system_controller then
702 -- ok, we should have 'audio_playback' defined by now
703 m:try_load_plugin('telephony')
707 m:load_plugin('system-controller')
709 window_manager_operation_names = {
714 function window_manager_operation_name(oper)
715 local name = window_manager_operation_names[oper]
716 if name then return name end
717 return "<unknown " .. tostring(oper) .. ">"
720 window_operation_names = {
731 function window_operation_name(oper)
732 local name = window_operation_names[oper]
733 if name then return name end
734 return "<unknown " .. tostring(oper) .. ">"
737 layer_operation_names = {
743 function layer_operation_name(oper)
744 local name = layer_operation_names[oper]
745 if name then return name end
746 return "<unknown " .. tostring(oper) .. ">"
749 input_manager_operation_names = {
755 function input_manager_operation_name(oper)
756 local name = input_manager_operation_names[oper]
757 if name then return name end
758 return "<unknown " .. tostring(oper) .. ">"
761 input_operation_names = {
767 function input_operation_name(oper)
768 local name = input_operation_names[oper]
769 if name then return name end
770 return "<unknown " .. tostring(oper) .. ">"
773 code_operation_names = {
779 function code_operation_name(oper)
780 local name = code_operation_names[oper]
781 if name then return name end
782 return "<unknown " .. tostring(oper) .. ">"
786 [0x00001] = "send_appid",
787 [0x10001] = "create",
788 [0x10002] = "destroy",
792 [0x10006] = "animation",
793 [0x10007] = "change_active",
794 [0x10008] = "change_layer",
795 [0x10009] = "change_attr",
797 [0x10020] = "map_thumb",
798 [0x10021] = "unmap_thumb",
799 [0x10022] = "map_get",
800 [0x10030] = "show layer",
801 [0x10031] = "hide_layer",
802 [0x10032] = "change_layer_attr",
803 [0x20001] = "add_input",
804 [0x20002] = "del_input",
805 [0x30001] = "change_user",
806 [0x30002] = "get_userlist",
807 [0x30003] = "get_lastinfo",
808 [0x30004] = "set_lastinfo",
809 [0x40001] = "acquire_res",
810 [0x40002] = "release_res",
811 [0x40003] = "deprive_res",
812 [0x40004] = "waiting_res",
813 [0x40005] = "revert_res",
814 [0x40006] = "window_id_res",
815 [0x40011] = "create_res",
816 [0x40012] = "destroy_res",
817 [0x50001] = "set_region",
818 [0x50002] = "unset_region",
819 [0x60001] = "change_state"
822 function command_name(command)
823 local name = command_names[command]
824 if name then return name end
825 return "<unknown " .. tostring(command) .. ">"
829 [101] = true, -- input
830 [102] = true, -- touch
831 [103] = true -- cursor
834 -- some day this should be merged with wmgr.layers
836 [1] = 0x1000, -- background
837 [2] = 0x2000, -- application
838 [3] = 0x2000, -- homescreen
839 [4] = 0x2000, -- interrupt application
840 [5] = 0x2000, -- onscreen application
841 [6] = 0xc000, -- startup
842 [7] = 0x3000, -- fullscreen
843 [101] = 0x4000, -- input
844 [102] = 0xa000, -- touch
845 [103] = 0xb000 -- cursor
848 resmgr = resource_manager {
849 screen_event_handler = function(self, ev)
850 local event = ev.event
851 local surface = ev.surface
853 if event == "init" then
855 print("*** init screen resource allocation -- disable all 'player'")
857 resmgr:disable_audio_by_appid("*", "player", "*", true, false)
858 elseif event == "preallocate" then
860 print("*** preallocate screen resource "..
861 "for '" .. ev.appid .. "' -- enable 'player', if any")
863 resmgr:disable_audio_by_appid("*", "player", ev.appid, false, false)
864 elseif event == "grant" then
866 print("*** make visible surface "..surface)
868 local a = animation({})
869 local r = m:JSON({surface = surface,
872 wmgr:window_request(r,a,0)
873 elseif event == "revoke" then
875 print("*** hide surface "..surface)
877 local a = animation({})
878 local r = m:JSON({surface = ev.surface,
880 wmgr:window_request(r,a,0)
882 elseif event == "create" then
885 print("*** screen resource event: " ..
889 local regulation = mdb.select.select_driving_mode.single_value
891 if regulation == 1 then
893 local blacklisted = false
895 -- applications which have their category set to "entertainment"
896 -- or "undefined" are blacklisted, meaning they should be regulated
898 for i,v in pairs(ft(mdb.select.undefined_applications)) do
899 if v.appid == ev.appid then
901 print(ev.appid .. " was blacklisted (undefined)")
908 if not blacklisted then
909 for i,v in pairs(ft(mdb.select.entertainment_applications)) do
910 if v.appid == ev.appid then
912 print(ev.appid .. " was blacklisted (entertainment)")
920 -- our local application config, which takes precedence
921 local conf = getApplication(ev.appid)
923 -- disable only non-whitelisted applications
924 if not conf or conf.resource_class == "player" then
927 print("disabling screen for " .. ev.appid)
929 resmgr:disable_screen_by_appid("*", "*", ev.appid, true, true)
934 elseif event == "destroy" then
936 print("*** screen resource event: " ..
941 print("*** screen resource event: " ..
946 audio_event_handler = function(self, ev)
947 local event = ev.event
948 local appid = ev.appid
949 local audioid = ev.audioid
951 if event == "grant" then
953 print("*** grant audio to "..appid..
954 " ("..audioid..") in '" ..
957 elseif event == "revoke" then
959 print("*** revoke audio from "..appid..
960 " ("..audioid..") in '" ..
965 print("*** audio resource event: " ..
972 resclnt = resource_client {}
974 wmgr = window_manager {
975 geometry = function(self, w,h, v)
976 if type(v) == "function" then
982 application = function(self, appid)
984 local app = application_lookup(appid)
986 app = application_lookup("default")
990 return { privileges = {screen="none", audio="none"} }
993 output_order = { 1, 0 },
995 outputs = { { name = "Mid",
1002 width = function(w,h) return w end,
1003 height = function(w,h) return h end
1010 height = function(w,h) return h end
1014 pos_x = function(w,h) return w-320 end,
1017 height = function(w,h) return h end
1024 areas = { Status = {
1028 width = function(w,h) return w end,
1035 width = function(w,h) return w end,
1036 height = function(w,h) return h-64-128 end
1042 width = function(w,h) return w end,
1043 height = function(w,h) return (h-64-128)/2 end
1048 pos_y = function(w,h) return (h-64-128)/2+64 end,
1049 width = function(w,h) return w end,
1050 height = function(w,h) return (h-64-128)/2 end
1056 width = function(w,h) return w/2 end,
1057 height = function(w,h) return (h-64-128)/2 end
1061 pos_x = function(w,h) return w/2 end,
1063 width = function(w,h) return w/2 end,
1064 height = function(w,h) return (h-64-128)/2 end
1069 pos_y = function(w,h) return (h-64-128/2)+64 end,
1070 width = function(w,h) return w/2 end,
1071 height = function(w,h) return (h-64-128)/2 end
1075 pos_x = function(w,h) return w/2 end,
1076 pos_y = function(w,h) return (h-64-128/2)+64 end,
1077 width = function(w,h) return w/2 end,
1078 height = function(w,h) return (h-64-128)/2 end
1084 width = function(w,h) return w end,
1085 height = function(w,h) return h-64-128 end
1091 width = function(w,h) return w/2-181 end,
1092 height = function(w,h) return h-64-128 end
1094 ["SysApp.Right"] = {
1096 pos_x = function(w,h) return w/2+181 end,
1098 width = function(w,h) return w/2-181 end,
1099 height = function(w,h) return h-64-128 end
1105 width = function(w,h) return w end,
1106 height = function(w,h) return h-64-128 end
1112 width = function(w,h) return w end,
1113 height = function(w,h) return (h-64-128)/2 end
1118 pos_y = function(w,h) return (h-64-128)/2+64 end,
1119 width = function(w,h) return w end,
1120 height = function(w,h) return (h-64-128)/2 end
1125 pos_y = function(w,h) return h-128 end,
1126 width = function(w,h) return w end,
1132 -- id name type output
1133 layers = { { 0, "BackGround" , 1, "Center" },
1134 { 1, "Application" , 2, "Center" },
1135 { 2, "HomeScreen" , 3, "Center" },
1136 { 3, "ControlBar" , 3, "Center" },
1137 { 4, "InterruptApp" , 4, "Center" },
1138 { 5, "OnScreen" , 5, "Center" },
1139 { 6, "Touch" , 102, "Center" },
1140 { 7, "Cursor" , 103, "Center" }
1144 manager_update = function(self, oper)
1146 print("### <== WINDOW MANAGER UPDATE:" ..
1147 window_manager_operation_name(oper))
1150 local wumask = window_mask { --raise = true,
1153 local wrmask = window_mask { raise = true,
1156 local lumask = layer_mask { visible = true }
1157 local lrmask = layer_mask { visible = true }
1158 local req = m:JSON({
1159 passthrough_window_update = wumask:tointeger(),
1160 passthrough_window_request = wrmask:tointeger(),
1161 passthrough_layer_update = lumask:tointeger(),
1162 passthrough_layer_request = lrmask:tointeger()
1164 self:manager_request(req)
1168 window_update = function(self, oper, win, mask)
1170 print("### <== WINDOW UPDATE oper:" ..
1171 window_operation_name(oper) ..
1172 " mask: " .. tostring(mask))
1178 local arg = m:JSON({ surface = win.surface,
1183 if oper == 1 then -- create
1184 local layertype = win.layertype
1185 if layertype and input_layer[layertype] then
1187 print("ignoring input panel creation")
1192 elseif oper == 2 then -- destroy
1194 elseif oper == 3 then -- namechange
1196 elseif oper == 4 or oper == 5 then -- visible/configure
1200 if win.layertype then
1201 arg.layertype = win.layertype
1203 arg.layer = win.layer
1204 arg.pos_x = win.pos_x
1205 arg.pos_y = win.pos_y
1206 arg.width = win.width
1207 arg.height = win.height
1208 arg.raise = win.raise
1209 arg.visible = win.visible
1210 if win.active == 0 then
1215 elseif oper == 6 then -- active
1216 if win.active == 0 then
1218 print("ignoring inactive event")
1223 elseif oper == 7 then -- map
1228 if win.mapped == 0 then
1234 --arg.name = map.target
1235 arg.width = map.width
1236 arg.height = map.height
1237 arg.stride = map.stride
1238 arg.format = map.format
1241 print("### nothing to do")
1246 local msg = m:JSON({ command = command,
1252 print("### <== sending " ..
1253 command_name(msg.command) ..
1254 " window message to '" .. homescreen .. "'")
1259 sc:send_message(homescreen, msg)
1261 if oper == 1 then -- create
1262 local i = input_layer[win.layertype]
1263 local p = self:application(win.appid)
1264 local s = p.privileges.screen
1266 if s == "system" then
1267 local a = animation({})
1268 local r = m:JSON({surface = win.surface,
1271 self:window_request(r,a,0)
1275 print("do not make resource for " ..
1279 resclnt:resource_set_create("screen",
1283 special_screen_sets[win.surface] = true
1287 if onscreen and win.appid == onscreen then
1288 local resmsg = m:JSON({
1289 command = 0x40006, -- window_id_res
1301 resourceId = win.surface
1306 print("### <== sending " ..
1307 command_name(resmsg.command) ..
1308 " message to '" .. onscreen .. "'")
1313 sc:send_message(onscreen, resmsg);
1315 elseif oper == 2 then -- destroy
1316 resclnt:resource_set_destroy("screen", win.surface)
1317 special_screen_sets[win.surface] = nil
1318 elseif oper == 6 then -- active
1320 local i = input_layer[win.layertype]
1321 local p = self:application(win.appid)
1322 local s = p.privileges.screen
1323 local surface = win.surface
1324 if not i and s ~= "system" then
1325 resclnt:resource_set_acquire("screen",surface)
1326 resmgr:window_raise(win.appid, surface, 1)
1332 layer_update = function(self, oper, layer, mask)
1334 print("### LAYER UPDATE:" ..
1335 layer_operation_name(oper) ..
1336 " mask: " .. tostring(mask))
1341 if oper == 3 then -- visible
1342 local command = 0x10008 -- change_layer
1343 local msg = m:JSON({
1346 arg = m:JSON({layer = layer.id,
1347 visible = layer.visible
1351 print("### <== sending "..command_name(command)..
1357 sc:send_message(homescreen, msg)
1360 print("### nothing to do")
1365 output_update = function(self, oper, out, mask)
1366 local idx = out.index
1367 local defidx = self.output_order[idx+1]
1369 print("### OUTPUT UPDATE:" .. oper ..
1370 " mask: "..tostring(mask))
1376 local outdef = self.outputs[defidx+1]
1377 if (oper == 1) then -- create
1379 self:output_request(m:JSON({index = idx,
1384 elseif (oper == 5) then -- done
1385 local ads = outdef.areas
1386 local on = outdef.name
1388 for name,ad in pairs(ads) do
1389 local can = wmgr:canonical_name(on.."."..name)
1390 local a = m:JSON({name = name,
1391 output = out.index})
1392 for fld,val in pairs(ad) do
1393 a[fld] = self:geometry(out.width,
1398 resmgr:area_create(area[can], outdef.zone)
1406 imgr = input_manager {
1407 inputs = {{ name = "G27 Racing Wheel",
1409 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1410 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1411 [4] = {appid="org.tizen.ico.app-soundsample" },
1412 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1416 manager_update = function(self, oper)
1418 print("### <== INPUT MANAGER UPDATE:" ..
1419 input_manager_operation_name(oper))
1423 input_update = function(self, oper, inp, mask)
1425 print("### INPUT UPDATE:" ..
1426 input_operation_name(oper) ..
1427 " mask: " .. tostring(mask))
1433 code_update = function(self, oper, code, mask)
1435 print("### CODE UPDATE: mask: " .. tostring(mask))
1440 local msg = m:JSON({ command = 1,
1441 appid = "org.tizen.ico.homescreen",
1442 arg = m:JSON({ device = code.device,
1450 print("### <== sending " ..
1451 command_name(msg.command) ..
1457 sc:send_message(homescreen, msg)
1461 sc = m:get_system_controller()
1466 -- special screen resource sets
1467 -- TODO: just rewrite screen resource handling to use regular resource API
1469 special_screen_sets = {}
1472 um = m:UserManager()
1478 -- these shoud be before wmgr:connect() is called
1480 print("====== creating applications ======")
1484 area = "Center.Full",
1485 privileges = { screen = "none", audio = "none" },
1486 resource_class = "player",
1492 area = "Center.Full",
1493 privileges = { screen = "system", audio = "none" },
1494 resource_class = "implicit",
1495 screen_priority = 30
1499 appid = "org.tizen.ico.homescreen",
1500 area = "Center.Full",
1501 windows = { {'ico_hs_controlbarwindow', 'Center.Control'} },
1502 privileges = { screen = "system", audio = "system" },
1503 resource_class = "player",
1504 screen_priority = 20
1508 appid = "org.tizen.ico.statusbar",
1509 area = "Center.Status",
1510 privileges = { screen = "system", audio = "none" },
1511 resource_class = "player",
1512 screen_priority = 20
1516 appid = "org.tizen.ico.onscreen",
1517 area = "Center.Full",
1518 privileges = { screen = "system", audio = "system" },
1519 resource_class = "player",
1520 screen_priority = 20
1524 appid = "org.tizen.ico.login",
1525 area = "Center.Full",
1526 privileges = { screen = "system", audio = "system" },
1527 resource_class = "player",
1528 screen_priority = 20
1532 appid = "org.tizen.ico.camera_left",
1533 area = "Center.SysApp.Left",
1534 privileges = { screen = "system", audio = "none" },
1535 requisites = { screen = "blinker_left", audio = "none" },
1536 resource_class = "player",
1537 screen_priority = 30
1541 appid = "org.tizen.ico.camera_right",
1542 area = "Center.SysApp.Right",
1543 privileges = { screen = "system", audio = "none" },
1544 requisites = { screen = "blinker_right", audio = "none" },
1545 resource_class = "player",
1546 screen_priority = 30
1550 appid = "net.zmap.navi",
1551 area = "Center.Full",
1552 privileges = { screen = "none", audio = "none" },
1553 resource_class = "navigator",
1554 screen_priority = 30
1558 appid = "GV3ySIINq7.GhostCluster",
1559 area = "Center.Full",
1560 privileges = { screen = "none", audio = "none" },
1561 resource_class = "system",
1562 screen_priority = 30
1566 sc.client_handler = function (self, cid, msg)
1567 local command = msg.command
1568 local appid = msg.appid
1570 print('### ==> client handler:')
1576 -- known commands: 1 for SEND_APPID, synthetic command 0xFFFF for
1579 if command == 0xFFFF then
1581 print('client ' .. cid .. ' disconnected')
1583 if msg.appid == homescreen then
1585 for i,v in pairs(special_screen_sets) do
1586 resclnt:resource_set_destroy("screen", i)
1587 special_screen_sets[i] = nil
1593 -- handle the connection to weston
1596 if appid == "org.tizen.ico.homescreen" then
1597 print('Setting homescreen='..appid)
1599 if command and command == 1 then
1600 send_driving_mode_to(homescreen)
1601 send_night_mode_to(homescreen)
1603 elseif appid == "org.tizen.ico.onscreen" then
1605 if command and command == 1 then
1606 send_driving_mode_to(onscreen)
1607 send_night_mode_to(onscreen)
1611 if not connected and appid == "org.tizen.ico.homescreen" then
1612 print('Trying to connect to weston...')
1613 connected = wmgr:connect()
1618 sc.generic_handler = function (self, cid, msg)
1620 print('### ==> generic handler:')
1627 sc.window_handler = function (self, cid, msg)
1629 print('### ==> received ' ..
1630 command_name(msg.command) .. ' message')
1632 print(tostring(msg))
1636 local a = animation({})
1638 if msg.command == 0x10003 then -- ico SHOW command
1639 local raise_mask = 0x01000000
1640 local lower_mask = 0x02000000
1641 local nores_mask = 0x40000000
1642 local time_mask = 0x00ffffff
1646 if msg.arg.anim_time then
1647 local t = msg.arg.anim_time
1648 time = m:AND(t, time_mask)
1649 nores = not m:AND(t, nores_mask)
1650 if m:AND(t, raise_mask) then
1652 elseif m:AND(t, lower_mask) then
1656 if msg.arg.anim_name then
1657 a.show = { msg.arg.anim_name, time }
1658 print('time: ' .. tostring(a.show[2]))
1662 local p = wmgr:application(msg.appid)
1663 local s = p.privileges.screen
1664 if s == "system" then
1666 if not msg.arg.raise then
1672 print('### ==> SHOW')
1673 print(tostring(msg.arg))
1676 wmgr:window_request(msg.arg, a, 0)
1678 local surface = msg.arg.surface
1679 resclnt:resource_set_acquire("screen", surface)
1680 resmgr:window_raise(msg.appid, surface, 1)
1682 elseif msg.command == 0x10004 then -- ico HIDE command
1683 local raise_mask = 0x01000000
1684 local lower_mask = 0x02000000
1685 local nores_mask = 0x40000000
1686 local time_mask = 0x00ffffff
1690 if msg.arg.anim_time then
1691 local t = msg.arg.anim_time
1692 time = m:AND(t, time_mask)
1693 nores = not m:AND(t, nores_mask)
1695 if msg.arg.anim_name then
1696 a.hide = { msg.arg.anim_name, time }
1697 print('hide animation time: ' .. tostring(a.hide[2]))
1701 local p = wmgr:application(msg.appid)
1702 local s = p.privileges.screen
1703 if s == "system" then
1709 print('### ==> HIDE REQUEST')
1710 print(tostring(msg.arg))
1713 wmgr:window_request(msg.arg, a, 0)
1715 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1717 elseif msg.command == 0x10005 then -- ico MOVE
1719 print('### ==> MOVE REQUEST')
1720 print(tostring(msg.arg))
1722 if msg.arg.zone then
1723 msg.arg.area = msg.arg.zone
1725 wmgr:window_request(msg.arg, a, 0)
1726 -- TODO: handle if area changed
1727 elseif msg.command == 0x10007 then -- ico CHANGE_ACTIVE
1728 if not msg.arg.active then
1729 msg.arg.active = 3 -- pointer + keyboard
1732 print('### ==> CHANGE_ACTIVE REQUEST')
1733 print(tostring(msg.arg))
1735 wmgr:window_request(msg.arg, a, 0)
1736 elseif msg.command == 0x10008 then -- ico CHANGE_LAYER
1738 print('### ==> CHANGE_LAYER REQUEST')
1739 print(tostring(msg.arg))
1742 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1743 print("do not change layer for other than cursor or touch")
1747 wmgr:window_request(msg.arg, a, 0)
1748 elseif msg.command == 0x10020 then -- ico MAP_THUMB
1749 local framerate = msg.arg.framerate
1750 local animname = msg.arg.anim_name
1752 a.map = { animname, 1 }
1753 if not framerate or framerate < 0 then
1758 print('### ==> MAP_THUMB REQUEST')
1760 print('framerate: '..framerate)
1762 wmgr:window_request(msg.arg, a, framerate)
1764 elseif msg.command == 0x10021 then -- ico UNMAP_THUMB
1767 print('### ==> UNMAP_THUMB REQUEST')
1770 wmgr:window_request(msg.arg, a, 0)
1772 elseif msg.command == 0x10013 then -- ico MAP_BUFFER command
1773 local shmname = msg.arg.anim_name
1774 local bufsize = msg.arg.width
1775 local bufnum = msg.arg.height
1776 if shmname and bufsize and bufnum then
1778 print('### ==> MAP_BUFFER REQUEST')
1779 print("shmaname='" .. shmname ..
1780 "' bufsize='" .. bufsize ..
1781 " bufnum=" .. bufnum)
1783 wmgr:buffer_request(shmname, bufsize, bufnum)
1786 elseif msg.command == 0x10030 then -- ico SHOW_LAYER command
1789 print('### ==> SHOW_LAYER REQUEST')
1792 wmgr:layer_request(msg.arg)
1793 elseif msg.command == 0x10031 then -- ico HIDE_LAYER command
1796 print('### ==> HIDE_LAYER REQUEST')
1799 wmgr:layer_request(msg.arg)
1803 sc.input_handler = function (self, cid, msg)
1805 print('### ==> input handler: ' .. command_name(msg.command))
1810 if msg.command == 0x20001 then -- add_input
1811 msg.arg.appid = msg.appid
1813 print('### ==> ADD_INPUT REQUEST')
1814 print(tostring(msg.arg))
1816 imgr:input_request(msg.arg)
1817 elseif msg.command == 0x20002 then -- del_input
1820 print('### ==> DEL_INPUT REQUEST')
1821 print(tostring(msg.arg))
1823 imgr:input_request(msg.arg)
1824 -- elseif msg.command == 0x20003 then -- send_input
1828 sc.user_handler = function (self, cid, msg)
1830 print('### ==> user handler: ' .. command_name(msg.command))
1837 print("User Manager not initialized")
1841 if msg.command == 0x30001 then -- change_user
1842 print("command CHANGE_USER")
1844 print("invalid message")
1848 username = msg.arg.user
1849 passwd = msg.arg.pass
1851 if not username then
1859 success = um:changeUser(username, passwd)
1866 if sc:send_message(msg.appid, reply) then
1867 print('*** sent authentication failed message')
1869 print('*** failed to send authentication failed message')
1873 elseif msg.command == 0x30002 then -- get_userlist
1874 print("command GET_USERLIST")
1875 if not msg.appid then
1876 print("invalid message")
1880 users, currentUser = um:getUserList()
1883 print("failed to get user list")
1889 for i,v in pairs(users) do
1893 if not currentUser then
1898 print("current user: " .. currentUser)
1900 for i,v in pairs(users) do
1911 user_login = currentUser
1916 print("### <== GetUserList reply: " .. tostring(reply))
1919 if sc:send_message(msg.appid, reply) then
1920 print('*** reply OK')
1922 print('*** reply FAILED')
1925 elseif msg.command == 0x30003 then -- get_lastinfo
1926 print("command GET_LASTINFO")
1927 if not msg.appid then
1928 print("invalid message")
1932 lastInfo = um:getLastInfo(msg.appid)
1934 if not lastInfo then
1935 print("failed to get last info for app" .. msg.appid)
1947 if sc:send_message(msg.appid, reply) then
1948 print('*** reply OK')
1950 print('*** reply FAILED')
1953 elseif msg.command == 0x30004 then -- set_lastinfo
1954 print("command SET_LASTINFO")
1955 if not msg.arg or not msg.appid then
1956 print("invalid message")
1960 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1964 sc.resource_handler = function (self, cid, msg)
1966 print('### ==> resource handler: ' .. command_name(msg.command))
1972 createResourceSet = function (ctl, client, msg)
1973 cb = function(rset, data)
1974 print("> resource callback")
1976 -- type is either basic (0) or interrupt (1)
1978 if msg.res.type then
1979 requestType = msg.res.type
1982 if rset.acquired then
1983 cmd = 0x00040001 -- acquire
1985 cmd = 0x00040002 -- release
1989 appid = data.client,
1996 if rset.resources.audio_playback then
2005 if rset.resources.display then
2006 reply.res.window = {
2013 if rset.resources.input then
2019 print("sending message to client: " .. data.client)
2021 if sc:send_message(data.client, reply) then
2022 print('*** reply OK')
2024 print('*** reply FAILED')
2028 rset = m:ResourceSet({
2029 application_class = "player",
2030 zone = "driver", -- msg.zone ("full")
2039 if msg.res.sound then
2041 resource_name = "audio_playback"
2043 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
2044 rset.resources.audio_playback.attributes.appid = msg.appid
2045 print("sound name: " .. msg.res.sound.name)
2046 print("sound zone:" .. msg.res.sound.zone)
2047 print("sound adjust: " .. tostring(msg.res.sound.adjust))
2048 if msg.res.sound.id then
2049 print("sound id: " .. msg.res.sound.id)
2053 if msg.res.input then
2055 resource_name = "input"
2057 rset.resources.input.attributes.pid = tostring(msg.pid)
2058 rset.resources.input.attributes.appid = msg.appid
2059 print("input name: " .. msg.res.sound.name)
2060 print("input event:" .. tostring(msg.res.input.event))
2063 if msg.res.window then
2065 resource_name = "display"
2067 rset.resources.display.attributes.pid = tostring(msg.pid)
2068 rset.resources.display.attributes.appid = msg.appid
2069 print("display name: " .. msg.res.display.name)
2070 print("display zone:" .. msg.res.display.zone)
2071 if msg.res.display.id then
2072 print("display id: " .. msg.res.display.id)
2079 -- parse the message
2081 -- fields common to all messages:
2086 if msg.command == 0x40011 then -- create_res
2087 print("command CREATE_RES")
2089 if not sets.cid then
2090 sets.cid = createResourceSet(self, cid, msg)
2093 elseif msg.command == 0x40012 then -- destroy_res
2094 print("command DESTROY_RES")
2100 sets.cid = nil -- garbage collecting
2102 elseif msg.command == 0x40001 then -- acquire_res
2103 print("command ACQUIRE_RES")
2105 if not sets.cid then
2106 sets.cid = createResourceSet(self, cid, msg)
2111 elseif msg.command == 0x40002 then -- release_res
2112 print("command RELEASE_RES")
2118 elseif msg.command == 0x40003 then -- deprive_res
2119 print("command DEPRIVE_RES")
2121 elseif msg.command == 0x40004 then -- waiting_res
2122 print("command WAITING_RES")
2124 elseif msg.command == 0x40005 then -- revert_res
2125 print("command REVERT_RES")
2129 sc.inputdev_handler = function (self, cid, msg)
2131 print('*** inputdev handler: ' .. command_name(msg.command))
2138 sc.notify_handler = function (self, cid, msg)
2140 print('### notify handler: ' .. command_name(msg.command))
2148 function send_driving_mode_to(client)
2149 if client == "" then
2153 local driving_mode = mdb.select.select_driving_mode.single_value
2155 if not driving_mode then driving_mode = 0 end
2157 local reply = m:JSON({ command = 0x60001,
2158 arg = m:JSON({ stateid = 1,
2159 state = driving_mode
2164 print("### <== sending " .. command_name(reply.command) .. " message")
2170 sc:send_message(client, reply)
2173 function send_night_mode_to(client)
2174 if client == "" then
2178 local night_mode = mdb.select.select_night_mode.single_value
2180 if not night_mode then night_mode = 0 end
2182 local reply = m:JSON({ command = 0x60001,
2183 arg = m:JSON({ stateid = 2,
2189 print("### <== sending " .. command_name(reply.command) .. " message")
2195 sc:send_message(client, reply)
2198 -- we should have 'audio_playback' defined by now
2199 m:try_load_plugin('telephony')