1 with_system_controller = true
6 -- try loading the various logging plugins
7 m:try_load_plugin('systemd')
8 m:try_load_plugin('dlog')
10 -- load the console plugin
11 m:try_load_plugin('console')
13 m:try_load_plugin('console.disabled', 'webconsole', {
14 address = 'wsck:127.0.0.1:3000/murphy',
15 httpdir = '/usr/share/murphy/webconsole' });
17 -- load the dbus plugin
18 if m:plugin_exists('dbus') then
22 -- load the native resource plugin
23 if m:plugin_exists('resource-native') then
24 m:load_plugin('resource-native')
25 m:info("native resource plugin loaded")
27 m:info("No native resource plugin found...")
30 -- load the dbus resource plugin
31 m:try_load_plugin('resource-dbus', {
33 dbus_service = "org.Murphy",
35 default_zone = "driver",
36 default_class = "implicit"
39 -- load the domain control plugin
40 if m:plugin_exists('domain-control') then
41 m:load_plugin('domain-control')
43 m:info("No domain-control plugin found...")
46 -- load the AMB plugin
47 if m:plugin_exists('amb') then
50 m:info("No amb plugin found...")
53 -- load the ASM resource plugin
54 if m:plugin_exists('resource-asm') then
55 m:load_plugin('resource-asm', {
57 share_mmplayer = "player:AVP,mandatory,exclusive,strict",
58 ignored_argv0 = "WebProcess"
61 m:info("No audio session manager plugin found...")
64 if m:plugin_exists('ivi-resource-manager') then
65 m:load_plugin('ivi-resource-manager')
66 with_system_controller = false
69 -- define application classes
116 application_class { name="event" , priority=4 , modal=false, share=true , order="fifo" }
117 application_class { name="game" , priority=3 , modal=false, share=false, order="lifo" }
118 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
119 --#application_class { name="basic" , priority=2 , modal=false, share=false, order="lifo" }
120 application_class { name="player" , priority=1 , modal=false, share=true , order="lifo" }
121 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
123 -- define zone attributes
125 type = {mdb.string, "common", "rw"},
126 location = {mdb.string, "anywhere", "rw"}
134 location = "front-left"
142 location = "front-right"
150 location = "back-left"
158 location = "back-right"
166 location = "back-left"
171 -- define resource classes
172 if not m:plugin_exists('ivi-resource-manager') then
174 name = "audio_playback",
177 role = { mdb.string, "music", "rw" },
178 pid = { mdb.string, "<unknown>", "rw" },
179 policy = { mdb.string, "relaxed", "rw" }
185 name = "audio_recording",
188 role = { mdb.string, "music" , "rw" },
189 pid = { mdb.string, "<unknown>", "rw" },
190 policy = { mdb.string, "relaxed" , "rw" }
195 name = "video_playback",
200 name = "video_recording",
204 if not m:plugin_exists('ivi-resource-manager') then
205 resource.method.veto = {
206 function(zone, rset, grant, owners)
207 rset_priority = application_class[rset.application_class].priority
209 owner_id = owners.audio_playback.resource_set
212 if (rset_priority >= 50 and owner_id ~= rset_id) then
213 print("*** resource-set "..rset_id.." - veto")
222 -- test for creating selections
224 name = "audio_owner",
225 table = "audio_playback_owner",
226 columns = {"application_class"},
227 condition = "zone_name = 'driver'"
231 name = "vehicle_speed",
232 table = "amb_vehicle_speed",
234 condition = "key = 'VehicleSpeed'"
238 name = "speed2volume",
239 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
240 outputs = { mdb.table { name = "speedvol",
241 index = {"zone", "device"},
242 columns = {{"zone", mdb.string, 16},
243 {"device", mdb.string, 16},
244 {"value", mdb.floating}},
249 update = function(self)
250 speed = self.inputs.speed.single_value
252 volume = (speed - 144.0) / 7.0
256 diff = volume - self.oldvolume
257 if (diff*diff > self.inputs.param) then
258 print("*** element "..self.name.." update "..volume)
259 self.oldvolume = volume
260 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
265 -- Night mode processing chain
268 name = "exterior_brightness",
269 table = "amb_exterior_brightness",
270 columns = { "value" },
271 condition = "key = 'ExteriorBrightness'"
276 inputs = { brightness = mdb.select.exterior_brightness },
280 name = "amb_nightmode",
284 { "id", mdb.unsigned },
285 { "night_mode", mdb.unsigned }
289 update = function(self)
290 -- This is a trivial function to calculate night mode. Later, we will
291 -- need a better threshold value and hysteresis to prevent oscillation.
293 brightness = self.inputs.brightness.single_value
295 if not brightness then
299 print("*** element "..self.name.." update brightness: "..brightness)
301 if brightness > 300 then
307 print("*** resulting mode: ".. mode)
309 if not (mode == self.oldmode) then
310 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
318 name = "select_night_mode",
319 table = "amb_nightmode",
320 columns = { "night_mode" },
326 inputs = { owner = mdb.select.select_night_mode },
327 property = "NightMode",
329 initiate = builtin.method.amb_initiate,
330 update = builtin.method.amb_update
334 -- Driving mode processing chain
338 name = "drivingmode",
339 inputs = { speed = mdb.select.vehicle_speed },
343 name = "amb_drivingmode",
347 { "id", mdb.unsigned },
348 { "driving_mode", mdb.unsigned }
352 update = function(self)
354 speed = self.inputs.speed.single_value
366 if not (mode == self.oldmode) then
367 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
375 name = "select_driving_mode",
376 table = "amb_drivingmode",
377 columns = { "driving_mode" },
382 name = "driving_mode",
383 inputs = { owner = mdb.select.select_driving_mode },
384 property = "DrivingMode",
386 initiate = builtin.method.amb_initiate,
387 update = builtin.method.amb_update
390 -- turn signals (left, right)
394 table = "amb_turn_signal",
395 columns = { "value" },
396 condition = "key = 'TurnSignal'"
399 -- regulation (on), use "select_driving_mode"
401 -- shift position (parking, reverse, other)
404 name = "gear_position",
405 table = "amb_gear_position",
406 columns = { "value" },
407 condition = "key = 'GearPosition'"
410 -- cameras (back, front, left, right)
413 name = "camera_state",
414 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
418 name = "target_camera_state",
422 { "id", mdb.unsigned },
423 { "front_camera", mdb.unsigned },
424 { "back_camera", mdb.unsigned },
425 { "right_camera", mdb.unsigned },
426 { "left_camera", mdb.unsigned }
430 update = function(self)
437 if self.inputs.gear == 128 then
439 elseif self.inputs.winker == 1 then
441 elseif self.inputs.winker == 2 then
445 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
450 -- load the telephony plugin
451 m:try_load_plugin('telephony')
454 -- system controller test setup
456 if not with_system_controller or not m:plugin_exists('system-controller') then
460 m:load_plugin('system-controller')
462 window_manager_operation_names = {
467 function window_manager_operation_name(oper)
468 local name = window_manager_operation_names[oper]
469 if name then return name end
470 return "<unknown " .. tostring(oper) .. ">"
473 window_operation_names = {
482 function window_operation_name(oper)
483 local name = window_operation_names[oper]
484 if name then return name end
485 return "<unknown " .. tostring(oper) .. ">"
488 layer_operation_names = {
494 function layer_operation_name(oper)
495 local name = layer_operation_names[oper]
496 if name then return name end
497 return "<unknown " .. tostring(oper) .. ">"
501 [0x00001] = "send_appid",
502 [0x10001] = "create",
503 [0x10002] = "destroy",
507 [0x10006] = "change_active",
508 [0x10007] = "change_layer",
509 [0x10008] = "change_attr",
511 [0x10011] = "map_thumb",
512 [0x10012] = "unmap_thumb",
513 [0x10020] = "show layer",
514 [0x10021] = "hide_layer",
515 [0x10022] = "change_layer_attr",
516 [0x20001] = "add_input",
517 [0x20002] = "del_input",
518 [0x20003] = "send_input",
519 [0x40001] = "acquire_res",
520 [0x40002] = "release_res",
521 [0x40003] = "deprive_res",
522 [0x40004] = "waiting_res",
523 [0x40005] = "revert_res",
524 [0x40011] = "create_res",
525 [0x40012] = "destroy_res",
526 [0x50001] = "set_region",
527 [0x50002] = "unset_region",
528 [0x60001] = "change_state"
531 function command_name(command)
532 local name = command_names[command]
533 if name then return name end
534 return "<unknown " .. tostring(command) .. ">"
543 resmgr = resource_manager {
544 screen_event_handler = function(self, ev)
545 local event = ev.event
546 local surface = ev.surface
548 if event == "grant" then
550 print("*** make visible surface "..surface)
552 local a = animation({})
553 local r = m:JSON({surface = surface,
556 wmgr:window_request(r,a,0)
557 elseif event == "revoke" then
559 print("*** hide surface "..surface)
561 local a = animation({})
562 local r = m:JSON({surface = ev.surface,
564 wmgr:window_request(r,a,0)
567 print("*** resource event: "..tostring(ev))
573 resclnt = resource_client {}
575 wmgr = window_manager {
576 geometry = function(self, w,h, v)
577 if type(v) == "function" then
583 application = function(self, appid)
585 local app = application_lookup(appid)
587 app = application_lookup("default")
591 return { privileges = {screen="none", audio="none"} }
594 outputs = { { name = "Center",
601 width = function(w,h) return w end,
608 width = function(w,h) return w end,
609 height = function(w,h) return h-64-128 end
615 width = function(w,h) return w end,
616 height = function(w,h) return (h-64-128)/2 end
621 pos_y = function(w,h) return (h-64-128)/2+64 end,
622 width = function(w,h) return w end,
623 height = function(w,h) return (h-64-128)/2 end
629 width = function(w,h) return w/2 end,
630 height = function(w,h) return (h-64-128)/2 end
634 pos_x = function(w,h) return w/2 end,
636 width = function(w,h) return w/2 end,
637 height = function(w,h) return (h-64-128)/2 end
642 pos_y = function(w,h) return (h-64-128/2)+64 end,
643 width = function(w,h) return w/2 end,
644 height = function(w,h) return (h-64-128)/2 end
648 pos_x = function(w,h) return w/2 end,
649 pos_y = function(w,h) return (h-64-128/2)+64 end,
650 width = function(w,h) return w/2 end,
651 height = function(w,h) return (h-64-128)/2 end
657 width = function(w,h) return w end,
658 height = function(w,h) return h-64-128 end
664 width = function(w,h) return w/2-181 end,
665 height = function(w,h) return h-64-128 end
669 pos_x = function(w,h) return w/2+181 end,
671 width = function(w,h) return w/2-181 end,
672 height = function(w,h) return h-64-128 end
682 layers = { { 0, "Background" , 1 },
683 { 1, "Application" , 2 },
684 { 2, "Softkeyboard" , 4 },
685 { 3, "HomeScreen" , 2 },
686 { 4, "ControlBar" , 2 },
687 { 5, "InterruptApp" , 2 },
688 { 6, "OnScreen" , 2 },
689 { 101, "Input" , 3 },
690 { 102, "Cursor" , 5 },
691 { 103, "Startup" , 6 },
692 { 0x1000, "Background" , 1 },
693 { 0x2000, "Normal" , 2 },
694 { 0x3000, "Fullscreen" , 2 },
695 { 0x4000, "InputPanel" , 3 },
696 { 0xA000, "Touch" , 4 },
697 { 0xB000, "Cursor" , 5 },
698 { 0xC000, "Startup" , 6 }
702 manager_update = function(self, oper)
704 print("### <== WINDOW MANAGER UPDATE:" ..
705 window_manager_operation_name(oper))
708 local umask = window_mask { raise = true,
711 local rmask = window_mask { active = true }
713 passthrough_update = umask:tointeger(),
714 passthrough_request = rmask:tointeger()
716 self:manager_request(req)
720 window_update = function(self, oper, win, mask)
722 print("### <== WINDOW UPDATE oper:" ..
723 window_operation_name(oper) ..
724 " mask: " .. tostring(mask))
730 local arg = m:JSON({ surface = win.surface,
735 if oper == 1 then -- create
736 local layertype = win.layertype
737 if layertype and input_layer[layertype] then
739 print("ignoring input panel creation")
744 elseif oper == 2 then -- destroy
746 elseif oper == 3 then -- namechange
748 elseif oper == 4 or oper == 5 then --visible or configure
752 arg.layer = win.layer
753 arg.pos_x = win.pos_x
754 arg.pos_y = win.pos_y
755 arg.width = win.width
756 arg.height = win.height
757 arg.raise = win.raise
758 arg.visible = win.visible
759 arg.active = win.active
760 elseif oper == 6 then -- active
762 arg.active = win.active
765 print("### nothing to do")
770 local msg = m:JSON({ command = command,
776 print("### <== sending " ..
777 command_name(msg.command) ..
778 " window message to '" .. win.name .. "'")
783 sc:send_message(sysctlid, msg)
785 if oper == 1 then -- create
786 local i = input_layer[win.layertype]
787 local p = self:application(win.appid)
788 local s = p.privileges.screen
790 if s == "system" then
791 local a = animation({})
792 local r = m:JSON({surface = win.surface,
795 self:window_request(r,a,0)
799 print("do not make resource for " ..
803 resclnt:resource_set_create("screen",
809 elseif oper == 2 then -- destroy
810 resclnt:resource_set_destroy("screen", win.surface)
811 elseif oper == 6 then -- active
813 local i = input_layer[win.layertype]
814 local p = self:application(win.appid)
815 local s = p.privileges.screen
816 local surface = win.surface
817 if not i and s ~= "system" then
818 resclnt:resource_set_acquire("screen",surface)
819 resmgr:window_raise(win.appid, surface, 1)
825 layer_update = function(self, oper, layer, mask)
827 print("### LAYER UPDATE:" ..
828 layer_operation_name(oper) ..
829 " mask: " .. tostring(mask))
834 if oper == 3 then -- visible
835 local command = 0x10022
839 arg = m:JSON({layer = layer.id,
840 visible = layer.visible
844 print("### <== sending "..command_name(command)..
850 sc:send_message(sysctlid, msg)
853 print("### nothing to do")
858 output_update = function(self, oper, out, mask)
859 local idx = out.index
861 print("### OUTPUT UPDATE:" .. oper ..
862 " mask: "..tostring(mask))
865 local outdef = self.outputs[idx+1]
866 if (oper == 1) then -- create
868 self:output_request(m:JSON({index = idx,
873 elseif (oper == 5) then -- done
874 local ads = outdef.areas
875 local on = outdef.name
877 for name,ad in pairs(ads) do
878 local can = wmgr:canonical_name(on.."."..name)
879 local a = m:JSON({name = name,
881 for fld,val in pairs(ad) do
882 a[fld] = self:geometry(out.width,
887 resmgr:area_create(area[can], outdef.zone)
895 sc = m:get_system_controller()
903 -- these shoud be before wmgr:connect() is called
905 print("====== creating applications ======")
909 area = "Center.Full",
910 privileges = { screen = "none", audio = "none" },
911 resource_class = "player",
917 area = "Center.Full",
918 privileges = { screen = "system", audio = "none" },
919 resource_class = "implicit",
924 appid = "org.tizen.ico.homescreen",
925 area = "Center.Full",
926 privileges = { screen = "system", audio = "system" },
927 resource_class = "player",
932 appid = "org.tizen.ico.statusbar",
933 area = "Center.Status",
934 privileges = { screen = "system", audio = "none" },
935 resource_class = "player",
941 sc.client_handler = function (self, cid, msg)
942 local command = msg.command
944 print('### ==> client handler:')
949 if not connected then
950 print('Setting sysctlid='..msg.appid)
952 print('Trying to connect to wayland...')
953 connected = wmgr:connect()
955 if connected and command then
956 if command == 1 then -- send_appid
957 local reply = m:JSON({ command = 0x60001,
958 arg = m:JSON({ stateid = 1,
962 print("### <== sending " ..
963 command_name(command) .. " message")
968 sc:send_message(sysctlid, reply)
970 reply = m:JSON({ command = 0x60001,
971 arg = m:JSON({ stateid = 2,
975 print("### <== sending " ..
976 command_name(command) .. " message")
981 sc:send_message(sysctlid, reply)
986 sc.generic_handler = function (self, cid, msg)
988 print('### ==> generic handler:')
995 sc.window_handler = function (self, cid, msg)
997 print('### ==> received ' ..
998 command_name(msg.command) .. ' message')
1000 print(tostring(msg))
1004 local a = animation({})
1006 if msg.command == 0x10003 then -- ico SHOW command
1007 local raise_mask = 0x01000000
1008 local lower_mask = 0x02000000
1009 local nores_mask = 0x40000000
1010 local time_mask = 0x00ffffff
1014 if msg.arg.anim_time then
1015 local t = msg.arg.anim_time
1016 time = m:AND(t, time_mask)
1017 nores = m:AND(t, nores_mask)
1018 if m:AND(t, raise_mask) then
1020 elseif m:AND(t, lower_mask) then
1024 if msg.arg.anim_name then
1025 a.show = { msg.arg.anim_name, time }
1026 print('time: ' .. tostring(a.show[2]))
1030 local p = wmgr:application(msg.appid)
1031 local s = p.privileges.screen
1032 if s == "system" then
1037 print('### ==> SHOW')
1038 print(tostring(msg.arg))
1041 wmgr:window_request(msg.arg, a, 0)
1043 local surface = msg.arg.surface
1044 resclnt:resource_set_acquire("screen", surface)
1045 resmgr:window_raise(msg.appid, surface, 1)
1047 elseif msg.command == 0x10004 then -- ico HIDE command
1048 local raise_mask = 0x01000000
1049 local lower_mask = 0x02000000
1050 local nores_mask = 0x40000000
1051 local time_mask = 0x00ffffff
1055 if msg.arg.anim_time then
1056 local t = msg.arg.anim_time
1057 time = m:AND(t, time_mask)
1058 nores = m:AND(t, nores_mask)
1060 if msg.arg.anim_name then
1061 a.hide = { msg.arg.anim_name, time }
1062 print('hide animation time: ' .. tostring(a.hide[2]))
1066 local p = wmgr:application(msg.appid)
1067 local s = p.privileges.screen
1068 if s == "system" then
1073 print('### ==> HIDE REQUEST')
1074 print(tostring(msg.arg))
1077 wmgr:window_request(msg.arg, a, 0)
1079 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1081 elseif msg.command == 0x10005 then -- ico MOVE
1083 print('### ==> MOVE REQUEST')
1084 print(tostring(msg.arg))
1086 wmgr:window_request(msg.arg, a, 0)
1087 -- TODO: handle if area changed
1088 elseif msg.command == 0x10006 then -- ico ACTIVE
1089 if not msg.arg.active then
1090 msg.arg.active = 3 -- pointer + keyboard
1093 print('### ==> ACTIVE REQUEST')
1094 print(tostring(msg.arg))
1096 wmgr:window_request(msg.arg, a, 0)
1097 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1099 print('### ==> CHANGE_LAYER REQUEST')
1100 print(tostring(msg.arg))
1103 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1104 print("do not change layer for other than cursor or touch")
1108 wmgr:window_request(msg.arg, a, 0)
1109 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1110 local framerate = msg.arg.framerate
1111 if not framerate or framerate < 0 then
1116 print('### ==> MAP_THUMB REQUEST')
1118 print('framerate: '..framerate)
1120 wmgr:window_request(msg.arg, a, framerate)
1121 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1124 print('### ==> UNMAP_THUMB REQUEST')
1127 wmgr:window_request(msg.arg, a, 0)
1128 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1131 print('### ==> SHOW_LAYER REQUEST')
1134 wmgr:layer_request(msg.arg)
1135 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1138 print('### ==> HIDE_LAYER REQUEST')
1141 wmgr:layer_request(msg.arg)
1145 sc.input_handler = function (self, cid, msg)
1147 print('### ==> input handler: ' .. command_name(msg.comand))
1154 sc.user_handler = function (self, cid, msg)
1156 print('### ==> user handler: ' .. command_name(msg.command))
1163 sc.resource_handler = function (self, cid, msg)
1165 print('### ==> resource handler: ' .. command_name(msg.command))
1171 createResourceSet = function (ctl, client, msg)
1172 cb = function(rset, data)
1173 print("> resource callback")
1175 -- type is either basic (0) or interrupt (1)
1177 if msg.res.type then
1178 requestType = msg.res.type
1181 if rset.acquired then
1182 cmd = 0x00040001 -- acquire
1184 cmd = 0x00040002 -- release
1188 appid = data.client,
1195 if rset.resources.audio_playback then
1204 if rset.resources.display then
1205 reply.res.window = {
1212 if rset.resources.input then
1218 print("sending message to client: " .. data.client)
1220 if sc:send_message(data.client, reply) then
1221 print('*** reply OK')
1223 print('*** reply FAILED')
1227 rset = m:ResourceSet({
1228 application_class = "player",
1229 zone = "driver", -- msg.zone ("full")
1238 if msg.res.sound then
1240 resource_name = "audio_playback"
1242 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1243 rset.resources.audio_playback.attributes.appid = msg.appid
1244 print("sound name: " .. msg.res.sound.name)
1245 print("sound zone:" .. msg.res.sound.zone)
1246 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1247 if msg.res.sound.id then
1248 print("sound id: " .. msg.res.sound.id)
1252 if msg.res.input then
1254 resource_name = "input"
1256 rset.resources.input.attributes.pid = tostring(msg.pid)
1257 rset.resources.input.attributes.appid = msg.appid
1258 print("input name: " .. msg.res.sound.name)
1259 print("input event:" .. tostring(msg.res.input.event))
1262 if msg.res.window then
1264 resource_name = "display"
1266 rset.resources.display.attributes.pid = tostring(msg.pid)
1267 rset.resources.display.attributes.appid = msg.appid
1268 print("display name: " .. msg.res.display.name)
1269 print("display zone:" .. msg.res.display.zone)
1270 if msg.res.display.id then
1271 print("display id: " .. msg.res.display.id)
1278 -- parse the message
1280 -- fields common to all messages:
1285 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1286 print("command CREATE")
1288 if not sets.cid then
1289 sets.cid = createResourceSet(self, cid, msg)
1292 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1293 print("command DESTROY")
1299 sets.cid = nil -- garbage collecting
1301 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1302 print("command ACQUIRE")
1304 if not sets.cid then
1305 sets.cid = createResourceSet(self, cid, msg)
1310 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1311 print("command RELEASE")
1317 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1318 print("command DEPRIVE")
1320 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1321 print("command WAITING")
1323 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1324 print("command REVERT")
1328 sc.inputdev_handler = function (self, cid, msg)
1330 print('*** inputdev handler: ' .. command_name(msg.command))