1 with_system_controller = true
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 -- load the AMB plugin
48 if m:plugin_exists('amb') then
49 m:try_load_plugin('amb')
51 if builtin.method.amb_initiate and
52 builtin.method.amb_update
57 m:info("No amb plugin found...")
60 -- load the ASM resource plugin
61 if m:plugin_exists('resource-asm') then
62 m:try_load_plugin('resource-asm', {
64 share_mmplayer = "player:AVP,mandatory,exclusive,strict",
65 ignored_argv0 = "WebProcess"
68 m:info("No audio session manager plugin found...")
71 if m:plugin_exists('ivi-resource-manager') then
72 m:load_plugin('ivi-resource-manager')
73 with_system_controller = false
76 -- define application classes
123 application_class { name="event" , priority=4 , modal=false, share=true , order="fifo" }
124 application_class { name="game" , priority=3 , modal=false, share=false, order="lifo" }
125 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
126 --#application_class { name="basic" , priority=2 , modal=false, share=false, order="lifo" }
127 application_class { name="player" , priority=1 , modal=false, share=true , order="lifo" }
128 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
130 -- define zone attributes
132 type = {mdb.string, "common", "rw"},
133 location = {mdb.string, "anywhere", "rw"}
141 location = "front-left"
149 location = "front-right"
157 location = "back-left"
165 location = "back-right"
173 location = "back-left"
178 -- define resource classes
179 if not m:plugin_exists('ivi-resource-manager') then
181 name = "audio_playback",
184 role = { mdb.string, "music", "rw" },
185 pid = { mdb.string, "<unknown>", "rw" },
186 policy = { mdb.string, "relaxed", "rw" }
192 name = "audio_recording",
195 role = { mdb.string, "music" , "rw" },
196 pid = { mdb.string, "<unknown>", "rw" },
197 policy = { mdb.string, "relaxed" , "rw" }
202 name = "video_playback",
207 name = "video_recording",
211 if not m:plugin_exists('ivi-resource-manager') and
212 not with_system_controller
214 resource.method.veto = {
215 function(zone, rset, grant, owners, req_set)
221 -- test for creating selections
223 name = "audio_owner",
224 table = "audio_playback_owner",
225 columns = {"application_class"},
226 condition = "zone_name = 'driver'"
230 name = "vehicle_speed",
231 table = "amb_vehicle_speed",
233 condition = "key = 'VehicleSpeed'"
237 name = "speed2volume",
238 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
239 outputs = { mdb.table { name = "speedvol",
240 index = {"zone", "device"},
241 columns = {{"zone", mdb.string, 16},
242 {"device", mdb.string, 16},
243 {"value", mdb.floating}},
248 update = function(self)
249 speed = self.inputs.speed.single_value
251 volume = (speed - 144.0) / 7.0
255 diff = volume - self.oldvolume
256 if (diff*diff > self.inputs.param) then
257 print("*** element "..self.name.." update "..volume)
258 self.oldvolume = volume
259 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
264 -- Night mode processing chain
267 name = "exterior_brightness",
268 table = "amb_exterior_brightness",
269 columns = { "value" },
270 condition = "key = 'ExteriorBrightness'"
275 inputs = { brightness = mdb.select.exterior_brightness },
279 name = "amb_nightmode",
283 { "id", mdb.unsigned },
284 { "night_mode", mdb.unsigned }
288 update = function(self)
289 -- This is a trivial function to calculate night mode. Later, we will
290 -- need a better threshold value and hysteresis to prevent oscillation.
292 brightness = self.inputs.brightness.single_value
294 if not brightness then
298 print("*** element "..self.name.." update brightness: "..brightness)
300 if brightness > 300 then
306 print("*** resulting mode: ".. mode)
308 if not (mode == self.oldmode) then
309 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
317 name = "select_night_mode",
318 table = "amb_nightmode",
319 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
335 -- Driving mode processing chain
339 name = "drivingmode",
340 inputs = { speed = mdb.select.vehicle_speed },
344 name = "amb_drivingmode",
348 { "id", mdb.unsigned },
349 { "driving_mode", mdb.unsigned }
353 update = function(self)
355 speed = self.inputs.speed.single_value
367 if not (mode == self.oldmode) then
368 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
376 name = "select_driving_mode",
377 table = "amb_drivingmode",
378 columns = { "driving_mode" },
384 name = "driving_mode",
385 inputs = { owner = mdb.select.select_driving_mode },
386 property = "DrivingMode",
388 initiate = builtin.method.amb_initiate,
389 update = builtin.method.amb_update
393 -- turn signals (left, right)
397 table = "amb_turn_signal",
398 columns = { "value" },
399 condition = "key = 'TurnSignal'"
402 -- regulation (on), use "select_driving_mode"
404 -- shift position (parking, reverse, other)
407 name = "gear_position",
408 table = "amb_gear_position",
409 columns = { "value" },
410 condition = "key = 'GearPosition'"
413 -- cameras (back, front, left, right)
416 name = "camera_state",
417 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
421 name = "target_camera_state",
425 { "id", mdb.unsigned },
426 { "front_camera", mdb.unsigned },
427 { "back_camera", mdb.unsigned },
428 { "right_camera", mdb.unsigned },
429 { "left_camera", mdb.unsigned }
433 update = function(self)
440 if self.inputs.gear == 128 then
442 elseif self.inputs.winker == 1 then
444 elseif self.inputs.winker == 2 then
448 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
453 -- load the telephony plugin
454 m:try_load_plugin('telephony')
457 -- system controller test setup
459 if not with_system_controller or not m:plugin_exists('system-controller') then
463 m:load_plugin('system-controller')
465 window_manager_operation_names = {
470 function window_manager_operation_name(oper)
471 local name = window_manager_operation_names[oper]
472 if name then return name end
473 return "<unknown " .. tostring(oper) .. ">"
476 window_operation_names = {
485 function window_operation_name(oper)
486 local name = window_operation_names[oper]
487 if name then return name end
488 return "<unknown " .. tostring(oper) .. ">"
491 layer_operation_names = {
497 function layer_operation_name(oper)
498 local name = layer_operation_names[oper]
499 if name then return name end
500 return "<unknown " .. tostring(oper) .. ">"
504 [0x00001] = "send_appid",
505 [0x10001] = "create",
506 [0x10002] = "destroy",
510 [0x10006] = "change_active",
511 [0x10007] = "change_layer",
512 [0x10008] = "change_attr",
514 [0x10011] = "map_thumb",
515 [0x10012] = "unmap_thumb",
516 [0x10020] = "show layer",
517 [0x10021] = "hide_layer",
518 [0x10022] = "change_layer_attr",
519 [0x20001] = "add_input",
520 [0x20002] = "del_input",
521 [0x20003] = "send_input",
522 [0x40001] = "acquire_res",
523 [0x40002] = "release_res",
524 [0x40003] = "deprive_res",
525 [0x40004] = "waiting_res",
526 [0x40005] = "revert_res",
527 [0x40011] = "create_res",
528 [0x40012] = "destroy_res",
529 [0x50001] = "set_region",
530 [0x50002] = "unset_region",
531 [0x60001] = "change_state"
534 function command_name(command)
535 local name = command_names[command]
536 if name then return name end
537 return "<unknown " .. tostring(command) .. ">"
546 resmgr = resource_manager {
547 screen_event_handler = function(self, ev)
548 local event = ev.event
549 local surface = ev.surface
551 if event == "grant" then
553 print("*** make visible surface "..surface)
555 local a = animation({})
556 local r = m:JSON({surface = surface,
559 wmgr:window_request(r,a,0)
560 elseif event == "revoke" then
562 print("*** hide surface "..surface)
564 local a = animation({})
565 local r = m:JSON({surface = ev.surface,
567 wmgr:window_request(r,a,0)
570 print("*** resource event: "..tostring(ev))
576 resclnt = resource_client {}
578 wmgr = window_manager {
579 geometry = function(self, w,h, v)
580 if type(v) == "function" then
586 application = function(self, appid)
588 local app = application_lookup(appid)
590 app = application_lookup("default")
594 return { privileges = {screen="none", audio="none"} }
597 outputs = { { name = "Center",
604 width = function(w,h) return w end,
611 width = function(w,h) return w end,
612 height = function(w,h) return h-64-128 end
618 width = function(w,h) return w end,
619 height = function(w,h) return (h-64-128)/2 end
624 pos_y = function(w,h) return (h-64-128)/2+64 end,
625 width = function(w,h) return w end,
626 height = function(w,h) return (h-64-128)/2 end
632 width = function(w,h) return w/2 end,
633 height = function(w,h) return (h-64-128)/2 end
637 pos_x = function(w,h) return w/2 end,
639 width = function(w,h) return w/2 end,
640 height = function(w,h) return (h-64-128)/2 end
645 pos_y = function(w,h) return (h-64-128/2)+64 end,
646 width = function(w,h) return w/2 end,
647 height = function(w,h) return (h-64-128)/2 end
651 pos_x = function(w,h) return w/2 end,
652 pos_y = function(w,h) return (h-64-128/2)+64 end,
653 width = function(w,h) return w/2 end,
654 height = function(w,h) return (h-64-128)/2 end
660 width = function(w,h) return w end,
661 height = function(w,h) return h-64-128 end
667 width = function(w,h) return w/2-181 end,
668 height = function(w,h) return h-64-128 end
672 pos_x = function(w,h) return w/2+181 end,
674 width = function(w,h) return w/2-181 end,
675 height = function(w,h) return h-64-128 end
685 layers = { { 0, "Background" , 1 },
686 { 1, "Application" , 2 },
687 { 2, "Softkeyboard" , 4 },
688 { 3, "HomeScreen" , 2 },
689 { 4, "ControlBar" , 2 },
690 { 5, "InterruptApp" , 2 },
691 { 6, "OnScreen" , 2 },
692 { 101, "Input" , 3 },
693 { 102, "Cursor" , 5 },
694 { 103, "Startup" , 6 },
695 { 0x1000, "Background" , 1 },
696 { 0x2000, "Normal" , 2 },
697 { 0x3000, "Fullscreen" , 2 },
698 { 0x4000, "InputPanel" , 3 },
699 { 0xA000, "Touch" , 4 },
700 { 0xB000, "Cursor" , 5 },
701 { 0xC000, "Startup" , 6 }
705 manager_update = function(self, oper)
707 print("### <== WINDOW MANAGER UPDATE:" ..
708 window_manager_operation_name(oper))
711 local umask = window_mask { raise = true,
714 local rmask = window_mask { active = true }
716 passthrough_update = umask:tointeger(),
717 passthrough_request = rmask:tointeger()
719 self:manager_request(req)
723 window_update = function(self, oper, win, mask)
725 print("### <== WINDOW UPDATE oper:" ..
726 window_operation_name(oper) ..
727 " mask: " .. tostring(mask))
733 local arg = m:JSON({ surface = win.surface,
738 if oper == 1 then -- create
739 local layertype = win.layertype
740 if layertype and input_layer[layertype] then
742 print("ignoring input panel creation")
747 elseif oper == 2 then -- destroy
749 elseif oper == 3 then -- namechange
751 elseif oper == 4 or oper == 5 then --visible or configure
755 arg.layer = win.layer
756 arg.pos_x = win.pos_x
757 arg.pos_y = win.pos_y
758 arg.width = win.width
759 arg.height = win.height
760 arg.raise = win.raise
761 arg.visible = win.visible
762 arg.active = win.active
763 elseif oper == 6 then -- active
765 arg.active = win.active
768 print("### nothing to do")
773 local msg = m:JSON({ command = command,
779 print("### <== sending " ..
780 command_name(msg.command) ..
781 " window message to '" .. win.name .. "'")
786 sc:send_message(sysctlid, msg)
788 if oper == 1 then -- create
789 local i = input_layer[win.layertype]
790 local p = self:application(win.appid)
791 local s = p.privileges.screen
793 if s == "system" then
794 local a = animation({})
795 local r = m:JSON({surface = win.surface,
798 self:window_request(r,a,0)
802 print("do not make resource for " ..
806 resclnt:resource_set_create("screen",
812 elseif oper == 2 then -- destroy
813 resclnt:resource_set_destroy("screen", win.surface)
814 elseif oper == 6 then -- active
816 local i = input_layer[win.layertype]
817 local p = self:application(win.appid)
818 local s = p.privileges.screen
819 local surface = win.surface
820 if not i and s ~= "system" then
821 resclnt:resource_set_acquire("screen",surface)
822 resmgr:window_raise(win.appid, surface, 1)
828 layer_update = function(self, oper, layer, mask)
830 print("### LAYER UPDATE:" ..
831 layer_operation_name(oper) ..
832 " mask: " .. tostring(mask))
837 if oper == 3 then -- visible
838 local command = 0x10022
842 arg = m:JSON({layer = layer.id,
843 visible = layer.visible
847 print("### <== sending "..command_name(command)..
853 sc:send_message(sysctlid, msg)
856 print("### nothing to do")
861 output_update = function(self, oper, out, mask)
862 local idx = out.index
864 print("### OUTPUT UPDATE:" .. oper ..
865 " mask: "..tostring(mask))
868 local outdef = self.outputs[idx+1]
869 if (oper == 1) then -- create
871 self:output_request(m:JSON({index = idx,
876 elseif (oper == 5) then -- done
877 local ads = outdef.areas
878 local on = outdef.name
880 for name,ad in pairs(ads) do
881 local can = wmgr:canonical_name(on.."."..name)
882 local a = m:JSON({name = name,
884 for fld,val in pairs(ad) do
885 a[fld] = self:geometry(out.width,
890 resmgr:area_create(area[can], outdef.zone)
898 sc = m:get_system_controller()
906 -- these shoud be before wmgr:connect() is called
908 print("====== creating applications ======")
912 area = "Center.Full",
913 privileges = { screen = "none", audio = "none" },
914 resource_class = "player",
920 area = "Center.Full",
921 privileges = { screen = "system", audio = "none" },
922 resource_class = "implicit",
927 appid = "org.tizen.ico.homescreen",
928 area = "Center.Full",
929 privileges = { screen = "system", audio = "system" },
930 resource_class = "player",
935 appid = "org.tizen.ico.statusbar",
936 area = "Center.Status",
937 privileges = { screen = "system", audio = "none" },
938 resource_class = "player",
944 sc.client_handler = function (self, cid, msg)
945 local command = msg.command
947 print('### ==> client handler:')
952 if not connected then
953 print('Setting sysctlid='..msg.appid)
955 print('Trying to connect to wayland...')
956 connected = wmgr:connect()
958 if connected and command then
959 if command == 1 then -- send_appid
960 local reply = m:JSON({ command = 0x60001,
961 arg = m:JSON({ stateid = 1,
965 print("### <== sending " ..
966 command_name(command) .. " message")
971 sc:send_message(sysctlid, reply)
973 reply = m:JSON({ command = 0x60001,
974 arg = m:JSON({ stateid = 2,
978 print("### <== sending " ..
979 command_name(command) .. " message")
984 sc:send_message(sysctlid, reply)
989 sc.generic_handler = function (self, cid, msg)
991 print('### ==> generic handler:')
998 sc.window_handler = function (self, cid, msg)
1000 print('### ==> received ' ..
1001 command_name(msg.command) .. ' message')
1003 print(tostring(msg))
1007 local a = animation({})
1009 if msg.command == 0x10003 then -- ico SHOW command
1010 local raise_mask = 0x01000000
1011 local lower_mask = 0x02000000
1012 local nores_mask = 0x40000000
1013 local time_mask = 0x00ffffff
1017 if msg.arg.anim_time then
1018 local t = msg.arg.anim_time
1019 time = m:AND(t, time_mask)
1020 nores = m:AND(t, nores_mask)
1021 if m:AND(t, raise_mask) then
1023 elseif m:AND(t, lower_mask) then
1027 if msg.arg.anim_name then
1028 a.show = { msg.arg.anim_name, time }
1029 print('time: ' .. tostring(a.show[2]))
1033 local p = wmgr:application(msg.appid)
1034 local s = p.privileges.screen
1035 if s == "system" then
1040 print('### ==> SHOW')
1041 print(tostring(msg.arg))
1044 wmgr:window_request(msg.arg, a, 0)
1046 local surface = msg.arg.surface
1047 resclnt:resource_set_acquire("screen", surface)
1048 resmgr:window_raise(msg.appid, surface, 1)
1050 elseif msg.command == 0x10004 then -- ico HIDE command
1051 local raise_mask = 0x01000000
1052 local lower_mask = 0x02000000
1053 local nores_mask = 0x40000000
1054 local time_mask = 0x00ffffff
1058 if msg.arg.anim_time then
1059 local t = msg.arg.anim_time
1060 time = m:AND(t, time_mask)
1061 nores = m:AND(t, nores_mask)
1063 if msg.arg.anim_name then
1064 a.hide = { msg.arg.anim_name, time }
1065 print('hide animation time: ' .. tostring(a.hide[2]))
1069 local p = wmgr:application(msg.appid)
1070 local s = p.privileges.screen
1071 if s == "system" then
1076 print('### ==> HIDE REQUEST')
1077 print(tostring(msg.arg))
1080 wmgr:window_request(msg.arg, a, 0)
1082 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1084 elseif msg.command == 0x10005 then -- ico MOVE
1086 print('### ==> MOVE REQUEST')
1087 print(tostring(msg.arg))
1089 wmgr:window_request(msg.arg, a, 0)
1090 -- TODO: handle if area changed
1091 elseif msg.command == 0x10006 then -- ico ACTIVE
1092 if not msg.arg.active then
1093 msg.arg.active = 3 -- pointer + keyboard
1096 print('### ==> ACTIVE REQUEST')
1097 print(tostring(msg.arg))
1099 wmgr:window_request(msg.arg, a, 0)
1100 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1102 print('### ==> CHANGE_LAYER REQUEST')
1103 print(tostring(msg.arg))
1106 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1107 print("do not change layer for other than cursor or touch")
1111 wmgr:window_request(msg.arg, a, 0)
1112 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1113 local framerate = msg.arg.framerate
1114 if not framerate or framerate < 0 then
1119 print('### ==> MAP_THUMB REQUEST')
1121 print('framerate: '..framerate)
1123 wmgr:window_request(msg.arg, a, framerate)
1124 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1127 print('### ==> UNMAP_THUMB REQUEST')
1130 wmgr:window_request(msg.arg, a, 0)
1131 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1134 print('### ==> SHOW_LAYER REQUEST')
1137 wmgr:layer_request(msg.arg)
1138 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1141 print('### ==> HIDE_LAYER REQUEST')
1144 wmgr:layer_request(msg.arg)
1148 sc.input_handler = function (self, cid, msg)
1150 print('### ==> input handler: ' .. command_name(msg.comand))
1157 sc.user_handler = function (self, cid, msg)
1159 print('### ==> user handler: ' .. command_name(msg.command))
1166 sc.resource_handler = function (self, cid, msg)
1168 print('### ==> resource handler: ' .. command_name(msg.command))
1174 createResourceSet = function (ctl, client, msg)
1175 cb = function(rset, data)
1176 print("> resource callback")
1178 -- type is either basic (0) or interrupt (1)
1180 if msg.res.type then
1181 requestType = msg.res.type
1184 if rset.acquired then
1185 cmd = 0x00040001 -- acquire
1187 cmd = 0x00040002 -- release
1191 appid = data.client,
1198 if rset.resources.audio_playback then
1207 if rset.resources.display then
1208 reply.res.window = {
1215 if rset.resources.input then
1221 print("sending message to client: " .. data.client)
1223 if sc:send_message(data.client, reply) then
1224 print('*** reply OK')
1226 print('*** reply FAILED')
1230 rset = m:ResourceSet({
1231 application_class = "player",
1232 zone = "driver", -- msg.zone ("full")
1241 if msg.res.sound then
1243 resource_name = "audio_playback"
1245 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1246 rset.resources.audio_playback.attributes.appid = msg.appid
1247 print("sound name: " .. msg.res.sound.name)
1248 print("sound zone:" .. msg.res.sound.zone)
1249 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1250 if msg.res.sound.id then
1251 print("sound id: " .. msg.res.sound.id)
1255 if msg.res.input then
1257 resource_name = "input"
1259 rset.resources.input.attributes.pid = tostring(msg.pid)
1260 rset.resources.input.attributes.appid = msg.appid
1261 print("input name: " .. msg.res.sound.name)
1262 print("input event:" .. tostring(msg.res.input.event))
1265 if msg.res.window then
1267 resource_name = "display"
1269 rset.resources.display.attributes.pid = tostring(msg.pid)
1270 rset.resources.display.attributes.appid = msg.appid
1271 print("display name: " .. msg.res.display.name)
1272 print("display zone:" .. msg.res.display.zone)
1273 if msg.res.display.id then
1274 print("display id: " .. msg.res.display.id)
1281 -- parse the message
1283 -- fields common to all messages:
1288 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1289 print("command CREATE")
1291 if not sets.cid then
1292 sets.cid = createResourceSet(self, cid, msg)
1295 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1296 print("command DESTROY")
1302 sets.cid = nil -- garbage collecting
1304 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1305 print("command ACQUIRE")
1307 if not sets.cid then
1308 sets.cid = createResourceSet(self, cid, msg)
1313 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1314 print("command RELEASE")
1320 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1321 print("command DEPRIVE")
1323 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1324 print("command WAITING")
1326 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1327 print("command REVERT")
1331 sc.inputdev_handler = function (self, cid, msg)
1333 print('*** inputdev handler: ' .. command_name(msg.command))