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
372 name = "nightmode_homescreen",
373 inputs = { owner = mdb.select.select_night_mode },
374 initiate = function(self)
375 -- data = mdb.select.select_night_mode.single_value
378 update = function(self)
379 send_night_mode_to_home_screen()
383 -- Driving mode processing chain
386 name = "drivingmode",
387 inputs = { speed = mdb.select.vehicle_speed },
391 name = "amb_drivingmode",
395 { "id", mdb.unsigned },
396 { "driving_mode", mdb.unsigned }
400 update = function(self)
402 speed = self.inputs.speed.single_value
414 if not (mode == self.oldmode) then
415 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
423 name = "select_driving_mode",
424 table = "amb_drivingmode",
425 columns = { "driving_mode" },
431 name = "driving_mode",
432 inputs = { DrivingMode = mdb.select.select_driving_mode,
433 amb_state = mdb.select.amb_state },
434 property = "DrivingMode",
436 initiate = builtin.method.amb_initiate,
437 update = builtin.method.amb_update
441 -- turn signals (left, right)
445 table = "amb_turn_signal",
446 columns = { "value" },
447 condition = "key = 'TurnSignal'"
450 -- define three categories
453 name = "undefined_applications",
454 table = "aul_applications",
455 columns = { "appid" },
456 condition = "category = '<undefined>'"
460 name = "basic_applications",
461 table = "aul_applications",
462 columns = { "appid" },
463 condition = "category = 'basic'"
467 name = "entertainment_applications",
468 table = "aul_applications",
469 columns = { "appid" },
470 condition = "category = 'entertainment'"
474 -- filter the object garbage out of the tables
477 for k,v in pairs(t) do
478 if k ~= "userdata" and k ~= "new" then
486 function getApplication(appid)
489 -- find the correct local application definition
491 for k,v in pairs(ft(application)) do
492 if appid == v.appid then
501 function regulateApplications(t, regulation)
502 for k,v in pairs(ft(t)) do
504 -- iterate through the undefined and entertainment apps, see if
505 -- they have been overruled in local config
507 local conf = getApplication(v.appid)
509 if conf and conf.resource_class ~= "player" then
510 -- override, don't disable
511 resmgr:disable_screen_by_appid("*", "*", v.appid, false, false)
513 resmgr:disable_screen_by_appid("*", "*", v.appid, regulation == 1, false)
516 resource.method.recalc("driver")
519 -- regulation (on), use "select_driving_mode"
522 name = "driving_regulation",
523 inputs = { owner = mdb.select.select_driving_mode },
524 initiate = function(self)
525 -- local data = mdb.select.select_driving_mode.single_value
528 update = function(self)
529 local data = mdb.select.select_driving_mode.single_value
532 print("Driving mode updated: " .. tostring(data))
539 -- tell homescreen that driving mode was updated
540 send_driving_mode_to_home_screen()
542 regulateApplications(ft(mdb.select.entertainment_applications), data)
543 regulateApplications(ft(mdb.select.undefined_applications), data)
550 name = "regulated_app_change",
551 inputs = { undef = mdb.select.undefined_applications,
552 entertainment = mdb.select.entertainment_applications },
553 initiate = function(self)
556 update = function(self)
557 local data = mdb.select.select_driving_mode.single_value
564 print("regulated application list was changed")
567 regulateApplications(ft(mdb.select.entertainment_applications), data)
568 regulateApplications(ft(mdb.select.undefined_applications), data)
575 -- shift position (parking, reverse, other)
578 name = "gear_position",
579 table = "amb_gear_position",
580 columns = { "value" },
581 condition = "key = 'GearPosition'"
584 -- cameras (back, front, left, right)
587 name = "camera_state",
588 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
592 name = "target_camera_state",
596 { "id", mdb.unsigned },
597 { "front_camera", mdb.unsigned },
598 { "back_camera", mdb.unsigned },
599 { "right_camera", mdb.unsigned },
600 { "left_camera", mdb.unsigned }
604 update = function(self)
611 if self.inputs.gear == 128 then
613 elseif self.inputs.winker == 1 then
615 elseif self.inputs.winker == 2 then
619 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
624 -- system controller test setup
626 if not with_system_controller then
627 -- ok, we should have 'audio_playback' defined by now
628 m:try_load_plugin('telephony')
632 m:load_plugin('system-controller')
634 window_manager_operation_names = {
639 function window_manager_operation_name(oper)
640 local name = window_manager_operation_names[oper]
641 if name then return name end
642 return "<unknown " .. tostring(oper) .. ">"
645 window_operation_names = {
654 function window_operation_name(oper)
655 local name = window_operation_names[oper]
656 if name then return name end
657 return "<unknown " .. tostring(oper) .. ">"
660 layer_operation_names = {
666 function layer_operation_name(oper)
667 local name = layer_operation_names[oper]
668 if name then return name end
669 return "<unknown " .. tostring(oper) .. ">"
672 input_manager_operation_names = {
678 function input_manager_operation_name(oper)
679 local name = input_manager_operation_names[oper]
680 if name then return name end
681 return "<unknown " .. tostring(oper) .. ">"
684 input_operation_names = {
690 function input_operation_name(oper)
691 local name = input_operation_names[oper]
692 if name then return name end
693 return "<unknown " .. tostring(oper) .. ">"
696 code_operation_names = {
702 function code_operation_name(oper)
703 local name = code_operation_names[oper]
704 if name then return name end
705 return "<unknown " .. tostring(oper) .. ">"
709 [0x00001] = "send_appid",
710 [0x10001] = "create",
711 [0x10002] = "destroy",
715 [0x10006] = "change_active",
716 [0x10007] = "change_layer",
717 [0x10008] = "change_attr",
719 [0x10011] = "map_thumb",
720 [0x10012] = "unmap_thumb",
721 [0x10020] = "show layer",
722 [0x10021] = "hide_layer",
723 [0x10022] = "change_layer_attr",
724 [0x20001] = "add_input",
725 [0x20002] = "del_input",
726 [0x20003] = "send_input",
727 [0x40001] = "acquire_res",
728 [0x40002] = "release_res",
729 [0x40003] = "deprive_res",
730 [0x40004] = "waiting_res",
731 [0x40005] = "revert_res",
732 [0x40011] = "create_res",
733 [0x40012] = "destroy_res",
734 [0x50001] = "set_region",
735 [0x50002] = "unset_region",
736 [0x60001] = "change_state"
739 function command_name(command)
740 local name = command_names[command]
741 if name then return name end
742 return "<unknown " .. tostring(command) .. ">"
751 resmgr = resource_manager {
752 screen_event_handler = function(self, ev)
753 local event = ev.event
754 local surface = ev.surface
756 if event == "init" then
758 print("*** init screen resource allocation -- disable all 'player'")
760 resmgr:disable_audio_by_appid("*", "player", "*", true, false)
761 elseif event == "preallocate" then
763 print("*** preallocate screen resource "..
764 "for '" .. ev.appid .. "' -- enable 'player', if any")
766 resmgr:disable_audio_by_appid("*", "player", ev.appid, false, false)
767 elseif event == "grant" then
769 print("*** make visible surface "..surface)
771 local a = animation({})
772 local r = m:JSON({surface = surface,
775 wmgr:window_request(r,a,0)
776 elseif event == "revoke" then
778 print("*** hide surface "..surface)
780 local a = animation({})
781 local r = m:JSON({surface = ev.surface,
783 wmgr:window_request(r,a,0)
785 elseif event == "create" then
788 print("*** screen resource event: " ..
792 local regulation = mdb.select.select_driving_mode.single_value
794 if regulation == 1 then
796 local blacklisted = false
798 -- applications which have their category set to "entertainment"
799 -- or "undefined" are blacklisted, meaning they should be regulated
801 for i,v in pairs(ft(mdb.select.undefined_applications)) do
802 if v.appid == ev.appid then
804 print(ev.appid .. " was blacklisted (undefined)")
811 if not blacklisted then
812 for i,v in pairs(ft(mdb.select.entertainment_applications)) do
813 if v.appid == ev.appid then
815 print(ev.appid .. " was blacklisted (entertainment)")
823 -- our local application config, which takes precedence
824 local conf = getApplication(ev.appid)
826 -- disable only non-whitelisted applications
827 if not conf or conf.resource_class == "player" then
830 print("disabling screen for " .. ev.appid)
832 resmgr:disable_screen_by_appid("*", "*", ev.appid, true, true)
837 elseif event == "destroy" then
839 print("*** screen resource event: " ..
844 print("*** screen resource event: " ..
849 audio_event_handler = function(self, ev)
850 local event = ev.event
851 local appid = ev.appid
852 local audioid = ev.audioid
854 if event == "grant" then
856 print("*** grant audio to "..appid..
857 " ("..audioid..") in '" ..
860 elseif event == "revoke" then
862 print("*** revoke audio from "..appid..
863 " ("..audioid..") in '" ..
868 print("*** audio resource event: " ..
875 resclnt = resource_client {}
877 wmgr = window_manager {
878 geometry = function(self, w,h, v)
879 if type(v) == "function" then
885 application = function(self, appid)
887 local app = application_lookup(appid)
889 app = application_lookup("default")
893 return { privileges = {screen="none", audio="none"} }
896 output_order = { 1, 0 },
898 outputs = { { name = "Mid",
905 width = function(w,h) return w end,
906 height = function(w,h) return h end
913 height = function(w,h) return h end
917 pos_x = function(w,h) return w-320 end,
920 height = function(w,h) return h end
931 width = function(w,h) return w end,
938 width = function(w,h) return w end,
939 height = function(w,h) return h-64-128 end
945 width = function(w,h) return w end,
946 height = function(w,h) return (h-64-128)/2 end
951 pos_y = function(w,h) return (h-64-128)/2+64 end,
952 width = function(w,h) return w end,
953 height = function(w,h) return (h-64-128)/2 end
959 width = function(w,h) return w/2 end,
960 height = function(w,h) return (h-64-128)/2 end
964 pos_x = function(w,h) return w/2 end,
966 width = function(w,h) return w/2 end,
967 height = function(w,h) return (h-64-128)/2 end
972 pos_y = function(w,h) return (h-64-128/2)+64 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,
979 pos_y = function(w,h) return (h-64-128/2)+64 end,
980 width = function(w,h) return w/2 end,
981 height = function(w,h) return (h-64-128)/2 end
987 width = function(w,h) return w end,
988 height = function(w,h) return h-64-128 end
994 width = function(w,h) return w/2-181 end,
995 height = function(w,h) return h-64-128 end
999 pos_x = function(w,h) return w/2+181 end,
1001 width = function(w,h) return w/2-181 end,
1002 height = function(w,h) return h-64-128 end
1007 pos_y = function(w,h) return h-128 end,
1008 width = function(w,h) return w end,
1014 layers = { { 0, "Background" , 1 },
1015 { 1, "Application" , 2 },
1016 { 2, "Softkeyboard" , 4 },
1017 { 3, "HomeScreen" , 2 },
1018 { 4, "ControlBar" , 2 },
1019 { 5, "InterruptApp" , 2 },
1020 { 6, "OnScreen" , 2 },
1021 { 101, "Input" , 3 },
1022 { 102, "Cursor" , 5 },
1023 { 103, "Startup" , 6 },
1024 { 0x1000, "Background" , 1 },
1025 { 0x2000, "Normal" , 2 },
1026 { 0x3000, "Fullscreen" , 2 },
1027 { 0x4000, "InputPanel" , 3 },
1028 { 0xA000, "Touch" , 4 },
1029 { 0xB000, "Cursor" , 5 },
1030 { 0xC000, "Startup" , 6 }
1034 manager_update = function(self, oper)
1036 print("### <== WINDOW MANAGER UPDATE:" ..
1037 window_manager_operation_name(oper))
1040 local wumask = window_mask { raise = true,
1043 local wrmask = window_mask { active = true }
1044 local lumask = layer_mask { visible = true }
1045 local lrmask = layer_mask { visible = true }
1046 local req = m:JSON({
1047 passthrough_window_update = wumask:tointeger(),
1048 passthrough_window_request = wrmask:tointeger(),
1049 passthrough_layer_update = lumask:tointeger(),
1050 passthrough_layer_request = lrmask:tointeger()
1052 self:manager_request(req)
1056 window_update = function(self, oper, win, mask)
1058 print("### <== WINDOW UPDATE oper:" ..
1059 window_operation_name(oper) ..
1060 " mask: " .. tostring(mask))
1066 local arg = m:JSON({ surface = win.surface,
1071 if oper == 1 then -- create
1072 local layertype = win.layertype
1073 if layertype and input_layer[layertype] then
1075 print("ignoring input panel creation")
1080 elseif oper == 2 then -- destroy
1082 elseif oper == 3 then -- namechange
1084 elseif oper == 4 or oper == 5 then --visible or configure
1088 arg.layer = win.layer
1089 arg.pos_x = win.pos_x
1090 arg.pos_y = win.pos_y
1091 arg.width = win.width
1092 arg.height = win.height
1093 arg.raise = win.raise
1094 arg.visible = win.visible
1095 arg.active = win.active
1096 elseif oper == 6 then -- active
1098 arg.active = win.active
1101 print("### nothing to do")
1106 local msg = m:JSON({ command = command,
1112 print("### <== sending " ..
1113 command_name(msg.command) ..
1114 " window message to '" .. win.name .. "'")
1119 sc:send_message(homescreen, msg)
1121 if oper == 1 then -- create
1122 local i = input_layer[win.layertype]
1123 local p = self:application(win.appid)
1124 local s = p.privileges.screen
1126 if s == "system" then
1127 local a = animation({})
1128 local r = m:JSON({surface = win.surface,
1131 self:window_request(r,a,0)
1135 print("do not make resource for " ..
1139 resclnt:resource_set_create("screen",
1145 elseif oper == 2 then -- destroy
1146 resclnt:resource_set_destroy("screen", win.surface)
1147 elseif oper == 6 then -- active
1149 local i = input_layer[win.layertype]
1150 local p = self:application(win.appid)
1151 local s = p.privileges.screen
1152 local surface = win.surface
1153 if not i and s ~= "system" then
1154 resclnt:resource_set_acquire("screen",surface)
1155 resmgr:window_raise(win.appid, surface, 1)
1161 layer_update = function(self, oper, layer, mask)
1163 print("### LAYER UPDATE:" ..
1164 layer_operation_name(oper) ..
1165 " mask: " .. tostring(mask))
1170 if oper == 3 then -- visible
1171 local command = 0x10022
1172 local msg = m:JSON({
1175 arg = m:JSON({layer = layer.id,
1176 visible = layer.visible
1180 print("### <== sending "..command_name(command)..
1186 sc:send_message(homescreen, msg)
1189 print("### nothing to do")
1194 output_update = function(self, oper, out, mask)
1195 local idx = out.index
1196 local defidx = self.output_order[idx+1]
1198 print("### OUTPUT UPDATE:" .. oper ..
1199 " mask: "..tostring(mask))
1205 local outdef = self.outputs[defidx+1]
1206 if (oper == 1) then -- create
1208 self:output_request(m:JSON({index = idx,
1213 elseif (oper == 5) then -- done
1214 local ads = outdef.areas
1215 local on = outdef.name
1217 for name,ad in pairs(ads) do
1218 local can = wmgr:canonical_name(on.."."..name)
1219 local a = m:JSON({name = name,
1220 output = out.index})
1221 for fld,val in pairs(ad) do
1222 a[fld] = self:geometry(out.width,
1227 resmgr:area_create(area[can], outdef.zone)
1235 imgr = input_manager {
1236 inputs = {{ name = "G27 Racing Wheel",
1238 switch = { [2] = {appid="org.tizen.ico.app-soundsample" },
1239 [3] = {appid="org.tizen.ico.homescreen", keycode=1},
1240 [4] = {appid="org.tizen.ico.app-soundsample" },
1241 [5] = {appid="org.tizen.ico.homescreen", keycode=2}
1245 manager_update = function(self, oper)
1247 print("### <== INPUT MANAGER UPDATE:" ..
1248 input_manager_operation_name(oper))
1252 input_update = function(self, oper, inp, mask)
1254 print("### INPUT UPDATE:" ..
1255 input_operation_name(oper) ..
1256 " mask: " .. tostring(mask))
1262 code_update = function(self, oper, code, mask)
1264 print("### CODE UPDATE: mask: " .. tostring(mask))
1269 local msg = m:JSON({ command = 1,
1270 appid = "org.tizen.ico.homescreen",
1271 arg = m:JSON({ device = code.device,
1279 print("### <== sending " ..
1280 command_name(msg.command) ..
1286 sc:send_message(homescreen, msg)
1290 sc = m:get_system_controller()
1296 um = m:UserManager()
1302 -- these shoud be before wmgr:connect() is called
1304 print("====== creating applications ======")
1308 area = "Center.Full",
1309 privileges = { screen = "none", audio = "none" },
1310 resource_class = "player",
1316 area = "Center.Full",
1317 privileges = { screen = "system", audio = "none" },
1318 resource_class = "implicit",
1319 screen_priority = 30
1323 appid = "org.tizen.ico.homescreen",
1324 area = "Center.Full",
1325 windows = { {'ico_hs_controlbarwindow', 'Center.Control'} },
1326 privileges = { screen = "system", audio = "system" },
1327 resource_class = "player",
1328 screen_priority = 20
1332 appid = "org.tizen.ico.statusbar",
1333 area = "Center.Status",
1334 privileges = { screen = "system", audio = "none" },
1335 resource_class = "player",
1336 screen_priority = 20
1340 appid = "org.tizen.ico.onscreen",
1341 area = "Center.Full",
1342 privileges = { screen = "system", audio = "system" },
1343 resource_class = "player",
1344 screen_priority = 20
1348 appid = "org.tizen.ico.login",
1349 area = "Center.Full",
1350 privileges = { screen = "system", audio = "system" },
1351 resource_class = "player",
1352 screen_priority = 20
1356 appid = "org.tizen.ico.camera_left",
1357 area = "Center.SysApp.Left",
1358 privileges = { screen = "system", audio = "none" },
1359 requisites = { screen = "blinker_left", audio = "none" },
1360 resource_class = "player",
1361 screen_priority = 30
1365 appid = "org.tizen.ico.camera_right",
1366 area = "Center.SysApp.Right",
1367 privileges = { screen = "system", audio = "none" },
1368 requisites = { screen = "blinker_right", audio = "none" },
1369 resource_class = "player",
1370 screen_priority = 30
1374 appid = "net.zmap.navi",
1375 area = "Center.Full",
1376 privileges = { screen = "none", audio = "none" },
1377 resource_class = "navigator",
1378 screen_priority = 30
1382 appid = "GV3ySIINq7.GhostCluster",
1384 privileges = { screen = "none", audio = "none" },
1385 resource_class = "system",
1386 screen_priority = 30
1390 sc.client_handler = function (self, cid, msg)
1391 local command = msg.command
1392 local appid = msg.appid
1394 print('### ==> client handler:')
1400 -- known commands: 1 for SEND_APPID, synthetic command 0xFFFF for
1403 if command == 0xFFFF then
1405 print('client ' .. cid .. ' disconnected')
1407 if msg.appid == homescreen then
1414 -- handle the connection
1416 if not connected and appid then
1417 if appid == "org.tizen.ico.homescreen" then
1418 print('Setting homescreen='..appid)
1420 if command and command == 1 then
1421 send_driving_mode_to_home_screen()
1422 send_night_mode_to_home_screen()
1424 print('Trying to connect to wayland...')
1425 connected = wmgr:connect()
1426 elseif appid == "org.tizen.ico.onscreen" then
1432 sc.generic_handler = function (self, cid, msg)
1434 print('### ==> generic handler:')
1441 sc.window_handler = function (self, cid, msg)
1443 print('### ==> received ' ..
1444 command_name(msg.command) .. ' message')
1446 print(tostring(msg))
1450 local a = animation({})
1452 if msg.command == 0x10003 then -- ico SHOW command
1453 local raise_mask = 0x01000000
1454 local lower_mask = 0x02000000
1455 local nores_mask = 0x40000000
1456 local time_mask = 0x00ffffff
1460 if msg.arg.anim_time then
1461 local t = msg.arg.anim_time
1462 time = m:AND(t, time_mask)
1463 nores = not m:AND(t, nores_mask)
1464 if m:AND(t, raise_mask) then
1466 elseif m:AND(t, lower_mask) then
1470 if msg.arg.anim_name then
1471 a.show = { msg.arg.anim_name, time }
1472 print('time: ' .. tostring(a.show[2]))
1476 local p = wmgr:application(msg.appid)
1477 local s = p.privileges.screen
1478 if s == "system" then
1480 if not msg.arg.raise then
1486 print('### ==> SHOW')
1487 print(tostring(msg.arg))
1490 wmgr:window_request(msg.arg, a, 0)
1492 local surface = msg.arg.surface
1493 resclnt:resource_set_acquire("screen", surface)
1494 resmgr:window_raise(msg.appid, surface, 1)
1496 elseif msg.command == 0x10004 then -- ico HIDE command
1497 local raise_mask = 0x01000000
1498 local lower_mask = 0x02000000
1499 local nores_mask = 0x40000000
1500 local time_mask = 0x00ffffff
1504 if msg.arg.anim_time then
1505 local t = msg.arg.anim_time
1506 time = m:AND(t, time_mask)
1507 nores = not m:AND(t, nores_mask)
1509 if msg.arg.anim_name then
1510 a.hide = { msg.arg.anim_name, time }
1511 print('hide animation time: ' .. tostring(a.hide[2]))
1515 local p = wmgr:application(msg.appid)
1516 local s = p.privileges.screen
1517 if s == "system" then
1523 print('### ==> HIDE REQUEST')
1524 print(tostring(msg.arg))
1527 wmgr:window_request(msg.arg, a, 0)
1529 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1531 elseif msg.command == 0x10005 then -- ico MOVE
1533 print('### ==> MOVE REQUEST')
1534 print(tostring(msg.arg))
1536 if msg.arg.zone then
1537 msg.arg.area = msg.arg.zone
1539 wmgr:window_request(msg.arg, a, 0)
1540 -- TODO: handle if area changed
1541 elseif msg.command == 0x10006 then -- ico ACTIVE
1542 if not msg.arg.active then
1543 msg.arg.active = 3 -- pointer + keyboard
1546 print('### ==> ACTIVE REQUEST')
1547 print(tostring(msg.arg))
1549 wmgr:window_request(msg.arg, a, 0)
1550 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1552 print('### ==> CHANGE_LAYER REQUEST')
1553 print(tostring(msg.arg))
1556 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1557 print("do not change layer for other than cursor or touch")
1561 wmgr:window_request(msg.arg, a, 0)
1562 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1563 local framerate = msg.arg.framerate
1564 if not framerate or framerate < 0 then
1569 print('### ==> MAP_THUMB REQUEST')
1571 print('framerate: '..framerate)
1573 wmgr:window_request(msg.arg, a, framerate)
1574 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1577 print('### ==> UNMAP_THUMB REQUEST')
1580 wmgr:window_request(msg.arg, a, 0)
1581 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1584 print('### ==> SHOW_LAYER REQUEST')
1587 wmgr:layer_request(msg.arg)
1588 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1591 print('### ==> HIDE_LAYER REQUEST')
1594 wmgr:layer_request(msg.arg)
1598 sc.input_handler = function (self, cid, msg)
1600 print('### ==> input handler: ' .. command_name(msg.command))
1605 if msg.command == 0x20001 then -- add_input
1606 msg.arg.appid = msg.appid
1608 print('### ==> ADD_INPUT REQUEST')
1609 print(tostring(msg.arg))
1611 imgr:input_request(msg.arg)
1612 elseif msg.command == 0x20002 then -- del_input
1615 print('### ==> DEL_INPUT REQUEST')
1616 print(tostring(msg.arg))
1618 imgr:input_request(msg.arg)
1619 elseif msg.command == 0x20003 then -- send_input
1623 sc.user_handler = function (self, cid, msg)
1625 print('### ==> user handler: ' .. command_name(msg.command))
1632 print("User Manager not initialized")
1636 if msg.command == 0x00030001 then -- MSG_CMD_CHANGE_USER
1637 print("command CHANGE_USER")
1639 print("invalid message")
1643 username = msg.arg.user
1644 passwd = msg.arg.pass
1646 if not username then
1654 success = um:changeUser(username, passwd)
1661 if sc:send_message(msg.appid, reply) then
1662 print('*** sent authentication failed message')
1664 print('*** failed to send authentication failed message')
1668 elseif msg.command == 0x00030002 then -- MSG_CMD_GET_USERLIST
1669 print("command GET_USERLIST")
1670 if not msg.appid then
1671 print("invalid message")
1675 users, currentUser = um:getUserList()
1678 print("failed to get user list")
1684 for i,v in pairs(users) do
1688 if not currentUser then
1693 print("current user: " .. currentUser)
1695 for i,v in pairs(users) do
1706 user_login = currentUser
1711 print("### <== GetUserList reply: " .. tostring(reply))
1714 if sc:send_message(msg.appid, reply) then
1715 print('*** reply OK')
1717 print('*** reply FAILED')
1720 elseif msg.command == 0x00030003 then -- MSG_CMD_GET_LASTINFO
1721 print("command GET_LASTINFO")
1722 if not msg.appid then
1723 print("invalid message")
1727 lastInfo = um:getLastInfo(msg.appid)
1729 if not lastInfo then
1730 print("failed to get last info for app" .. msg.appid)
1742 if sc:send_message(msg.appid, reply) then
1743 print('*** reply OK')
1745 print('*** reply FAILED')
1748 elseif msg.command == 0x00030004 then -- MSG_CMD_SET_LASTINFO
1749 print("command SET_LASTINFO")
1750 if not msg.arg or not msg.appid then
1751 print("invalid message")
1755 lastInfo = um:setLastInfo(msg.appid, msg.arg.lastinfo)
1759 sc.resource_handler = function (self, cid, msg)
1761 print('### ==> resource handler: ' .. command_name(msg.command))
1767 createResourceSet = function (ctl, client, msg)
1768 cb = function(rset, data)
1769 print("> resource callback")
1771 -- type is either basic (0) or interrupt (1)
1773 if msg.res.type then
1774 requestType = msg.res.type
1777 if rset.acquired then
1778 cmd = 0x00040001 -- acquire
1780 cmd = 0x00040002 -- release
1784 appid = data.client,
1791 if rset.resources.audio_playback then
1800 if rset.resources.display then
1801 reply.res.window = {
1808 if rset.resources.input then
1814 print("sending message to client: " .. data.client)
1816 if sc:send_message(data.client, reply) then
1817 print('*** reply OK')
1819 print('*** reply FAILED')
1823 rset = m:ResourceSet({
1824 application_class = "player",
1825 zone = "driver", -- msg.zone ("full")
1834 if msg.res.sound then
1836 resource_name = "audio_playback"
1838 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1839 rset.resources.audio_playback.attributes.appid = msg.appid
1840 print("sound name: " .. msg.res.sound.name)
1841 print("sound zone:" .. msg.res.sound.zone)
1842 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1843 if msg.res.sound.id then
1844 print("sound id: " .. msg.res.sound.id)
1848 if msg.res.input then
1850 resource_name = "input"
1852 rset.resources.input.attributes.pid = tostring(msg.pid)
1853 rset.resources.input.attributes.appid = msg.appid
1854 print("input name: " .. msg.res.sound.name)
1855 print("input event:" .. tostring(msg.res.input.event))
1858 if msg.res.window then
1860 resource_name = "display"
1862 rset.resources.display.attributes.pid = tostring(msg.pid)
1863 rset.resources.display.attributes.appid = msg.appid
1864 print("display name: " .. msg.res.display.name)
1865 print("display zone:" .. msg.res.display.zone)
1866 if msg.res.display.id then
1867 print("display id: " .. msg.res.display.id)
1874 -- parse the message
1876 -- fields common to all messages:
1881 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1882 print("command CREATE")
1884 if not sets.cid then
1885 sets.cid = createResourceSet(self, cid, msg)
1888 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1889 print("command DESTROY")
1895 sets.cid = nil -- garbage collecting
1897 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1898 print("command ACQUIRE")
1900 if not sets.cid then
1901 sets.cid = createResourceSet(self, cid, msg)
1906 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1907 print("command RELEASE")
1913 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1914 print("command DEPRIVE")
1916 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1917 print("command WAITING")
1919 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1920 print("command REVERT")
1924 sc.inputdev_handler = function (self, cid, msg)
1926 print('*** inputdev handler: ' .. command_name(msg.command))
1934 function send_driving_mode_to_home_screen()
1935 if homescreen == "" then
1939 local driving_mode = mdb.select.select_driving_mode.single_value
1941 if not driving_mode then driving_mode = 0 end
1943 local reply = m:JSON({ command = 0x60001,
1944 arg = m:JSON({ stateid = 1,
1945 state = driving_mode
1950 print("### <== sending " .. command_name(reply.command) .. " message")
1956 sc:send_message(homescreen, reply)
1959 function send_night_mode_to_home_screen()
1960 if homescreen == "" then
1964 local night_mode = mdb.select.select_night_mode.single_value
1966 if not night_mode then night_mode = 0 end
1968 local reply = m:JSON({ command = 0x60001,
1969 arg = m:JSON({ stateid = 2,
1975 print("### <== sending " .. command_name(reply.command) .. " message")
1981 sc:send_message(homescreen, reply)
1984 -- we should have 'audio_playback' defined by now
1985 m:try_load_plugin('telephony')