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') then
212 resource.method.veto = {
213 function(zone, rset, grant, owners)
214 rset_priority = application_class[rset.application_class].priority
216 owner_id = owners.audio_playback.resource_set
219 if (rset_priority >= 50 and owner_id ~= rset_id) then
220 print("*** resource-set "..rset_id.." - veto")
229 -- test for creating selections
231 name = "audio_owner",
232 table = "audio_playback_owner",
233 columns = {"application_class"},
234 condition = "zone_name = 'driver'"
238 name = "vehicle_speed",
239 table = "amb_vehicle_speed",
241 condition = "key = 'VehicleSpeed'"
245 name = "speed2volume",
246 inputs = { speed = mdb.select.vehicle_speed, param = 9 },
247 outputs = { mdb.table { name = "speedvol",
248 index = {"zone", "device"},
249 columns = {{"zone", mdb.string, 16},
250 {"device", mdb.string, 16},
251 {"value", mdb.floating}},
256 update = function(self)
257 speed = self.inputs.speed.single_value
259 volume = (speed - 144.0) / 7.0
263 diff = volume - self.oldvolume
264 if (diff*diff > self.inputs.param) then
265 print("*** element "..self.name.." update "..volume)
266 self.oldvolume = volume
267 mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
272 -- Night mode processing chain
275 name = "exterior_brightness",
276 table = "amb_exterior_brightness",
277 columns = { "value" },
278 condition = "key = 'ExteriorBrightness'"
283 inputs = { brightness = mdb.select.exterior_brightness },
287 name = "amb_nightmode",
291 { "id", mdb.unsigned },
292 { "night_mode", mdb.unsigned }
296 update = function(self)
297 -- This is a trivial function to calculate night mode. Later, we will
298 -- need a better threshold value and hysteresis to prevent oscillation.
300 brightness = self.inputs.brightness.single_value
302 if not brightness then
306 print("*** element "..self.name.." update brightness: "..brightness)
308 if brightness > 300 then
314 print("*** resulting mode: ".. mode)
316 if not (mode == self.oldmode) then
317 mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
325 name = "select_night_mode",
326 table = "amb_nightmode",
327 columns = { "night_mode" },
334 inputs = { owner = mdb.select.select_night_mode },
335 property = "NightMode",
337 initiate = builtin.method.amb_initiate,
338 update = builtin.method.amb_update
343 -- Driving mode processing chain
347 name = "drivingmode",
348 inputs = { speed = mdb.select.vehicle_speed },
352 name = "amb_drivingmode",
356 { "id", mdb.unsigned },
357 { "driving_mode", mdb.unsigned }
361 update = function(self)
363 speed = self.inputs.speed.single_value
375 if not (mode == self.oldmode) then
376 mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
384 name = "select_driving_mode",
385 table = "amb_drivingmode",
386 columns = { "driving_mode" },
392 name = "driving_mode",
393 inputs = { owner = mdb.select.select_driving_mode },
394 property = "DrivingMode",
396 initiate = builtin.method.amb_initiate,
397 update = builtin.method.amb_update
401 -- turn signals (left, right)
405 table = "amb_turn_signal",
406 columns = { "value" },
407 condition = "key = 'TurnSignal'"
410 -- regulation (on), use "select_driving_mode"
412 -- shift position (parking, reverse, other)
415 name = "gear_position",
416 table = "amb_gear_position",
417 columns = { "value" },
418 condition = "key = 'GearPosition'"
421 -- cameras (back, front, left, right)
424 name = "camera_state",
425 inputs = { winker = mdb.select.winker, gear = mdb.select.gear_position },
429 name = "target_camera_state",
433 { "id", mdb.unsigned },
434 { "front_camera", mdb.unsigned },
435 { "back_camera", mdb.unsigned },
436 { "right_camera", mdb.unsigned },
437 { "left_camera", mdb.unsigned }
441 update = function(self)
448 if self.inputs.gear == 128 then
450 elseif self.inputs.winker == 1 then
452 elseif self.inputs.winker == 2 then
456 mdb.table.target_camera_state:replace({ id = 0, front_camera = front_camera, back_camera = back_camera, right_camera = right_camera, left_camera = left_camera })
461 -- load the telephony plugin
462 m:try_load_plugin('telephony')
465 -- system controller test setup
467 if not with_system_controller or not m:plugin_exists('system-controller') then
471 m:load_plugin('system-controller')
473 window_manager_operation_names = {
478 function window_manager_operation_name(oper)
479 local name = window_manager_operation_names[oper]
480 if name then return name end
481 return "<unknown " .. tostring(oper) .. ">"
484 window_operation_names = {
493 function window_operation_name(oper)
494 local name = window_operation_names[oper]
495 if name then return name end
496 return "<unknown " .. tostring(oper) .. ">"
499 layer_operation_names = {
505 function layer_operation_name(oper)
506 local name = layer_operation_names[oper]
507 if name then return name end
508 return "<unknown " .. tostring(oper) .. ">"
512 [0x00001] = "send_appid",
513 [0x10001] = "create",
514 [0x10002] = "destroy",
518 [0x10006] = "change_active",
519 [0x10007] = "change_layer",
520 [0x10008] = "change_attr",
522 [0x10011] = "map_thumb",
523 [0x10012] = "unmap_thumb",
524 [0x10020] = "show layer",
525 [0x10021] = "hide_layer",
526 [0x10022] = "change_layer_attr",
527 [0x20001] = "add_input",
528 [0x20002] = "del_input",
529 [0x20003] = "send_input",
530 [0x40001] = "acquire_res",
531 [0x40002] = "release_res",
532 [0x40003] = "deprive_res",
533 [0x40004] = "waiting_res",
534 [0x40005] = "revert_res",
535 [0x40011] = "create_res",
536 [0x40012] = "destroy_res",
537 [0x50001] = "set_region",
538 [0x50002] = "unset_region",
539 [0x60001] = "change_state"
542 function command_name(command)
543 local name = command_names[command]
544 if name then return name end
545 return "<unknown " .. tostring(command) .. ">"
554 resmgr = resource_manager {
555 screen_event_handler = function(self, ev)
556 local event = ev.event
557 local surface = ev.surface
559 if event == "grant" then
561 print("*** make visible surface "..surface)
563 local a = animation({})
564 local r = m:JSON({surface = surface,
567 wmgr:window_request(r,a,0)
568 elseif event == "revoke" then
570 print("*** hide surface "..surface)
572 local a = animation({})
573 local r = m:JSON({surface = ev.surface,
575 wmgr:window_request(r,a,0)
578 print("*** resource event: "..tostring(ev))
584 resclnt = resource_client {}
586 wmgr = window_manager {
587 geometry = function(self, w,h, v)
588 if type(v) == "function" then
594 application = function(self, appid)
596 local app = application_lookup(appid)
598 app = application_lookup("default")
602 return { privileges = {screen="none", audio="none"} }
605 outputs = { { name = "Center",
612 width = function(w,h) return w end,
619 width = function(w,h) return w end,
620 height = function(w,h) return h-64-128 end
626 width = function(w,h) return w end,
627 height = function(w,h) return (h-64-128)/2 end
632 pos_y = function(w,h) return (h-64-128)/2+64 end,
633 width = function(w,h) return w end,
634 height = function(w,h) return (h-64-128)/2 end
640 width = function(w,h) return w/2 end,
641 height = function(w,h) return (h-64-128)/2 end
645 pos_x = function(w,h) return w/2 end,
647 width = function(w,h) return w/2 end,
648 height = function(w,h) return (h-64-128)/2 end
653 pos_y = function(w,h) return (h-64-128/2)+64 end,
654 width = function(w,h) return w/2 end,
655 height = function(w,h) return (h-64-128)/2 end
659 pos_x = function(w,h) return w/2 end,
660 pos_y = function(w,h) return (h-64-128/2)+64 end,
661 width = function(w,h) return w/2 end,
662 height = function(w,h) return (h-64-128)/2 end
668 width = function(w,h) return w end,
669 height = function(w,h) return h-64-128 end
675 width = function(w,h) return w/2-181 end,
676 height = function(w,h) return h-64-128 end
680 pos_x = function(w,h) return w/2+181 end,
682 width = function(w,h) return w/2-181 end,
683 height = function(w,h) return h-64-128 end
693 layers = { { 0, "Background" , 1 },
694 { 1, "Application" , 2 },
695 { 2, "Softkeyboard" , 4 },
696 { 3, "HomeScreen" , 2 },
697 { 4, "ControlBar" , 2 },
698 { 5, "InterruptApp" , 2 },
699 { 6, "OnScreen" , 2 },
700 { 101, "Input" , 3 },
701 { 102, "Cursor" , 5 },
702 { 103, "Startup" , 6 },
703 { 0x1000, "Background" , 1 },
704 { 0x2000, "Normal" , 2 },
705 { 0x3000, "Fullscreen" , 2 },
706 { 0x4000, "InputPanel" , 3 },
707 { 0xA000, "Touch" , 4 },
708 { 0xB000, "Cursor" , 5 },
709 { 0xC000, "Startup" , 6 }
713 manager_update = function(self, oper)
715 print("### <== WINDOW MANAGER UPDATE:" ..
716 window_manager_operation_name(oper))
719 local umask = window_mask { raise = true,
722 local rmask = window_mask { active = true }
724 passthrough_update = umask:tointeger(),
725 passthrough_request = rmask:tointeger()
727 self:manager_request(req)
731 window_update = function(self, oper, win, mask)
733 print("### <== WINDOW UPDATE oper:" ..
734 window_operation_name(oper) ..
735 " mask: " .. tostring(mask))
741 local arg = m:JSON({ surface = win.surface,
746 if oper == 1 then -- create
747 local layertype = win.layertype
748 if layertype and input_layer[layertype] then
750 print("ignoring input panel creation")
755 elseif oper == 2 then -- destroy
757 elseif oper == 3 then -- namechange
759 elseif oper == 4 or oper == 5 then --visible or configure
763 arg.layer = win.layer
764 arg.pos_x = win.pos_x
765 arg.pos_y = win.pos_y
766 arg.width = win.width
767 arg.height = win.height
768 arg.raise = win.raise
769 arg.visible = win.visible
770 arg.active = win.active
771 elseif oper == 6 then -- active
773 arg.active = win.active
776 print("### nothing to do")
781 local msg = m:JSON({ command = command,
787 print("### <== sending " ..
788 command_name(msg.command) ..
789 " window message to '" .. win.name .. "'")
794 sc:send_message(sysctlid, msg)
796 if oper == 1 then -- create
797 local i = input_layer[win.layertype]
798 local p = self:application(win.appid)
799 local s = p.privileges.screen
801 if s == "system" then
802 local a = animation({})
803 local r = m:JSON({surface = win.surface,
806 self:window_request(r,a,0)
810 print("do not make resource for " ..
814 resclnt:resource_set_create("screen",
820 elseif oper == 2 then -- destroy
821 resclnt:resource_set_destroy("screen", win.surface)
822 elseif oper == 6 then -- active
824 local i = input_layer[win.layertype]
825 local p = self:application(win.appid)
826 local s = p.privileges.screen
827 local surface = win.surface
828 if not i and s ~= "system" then
829 resclnt:resource_set_acquire("screen",surface)
830 resmgr:window_raise(win.appid, surface, 1)
836 layer_update = function(self, oper, layer, mask)
838 print("### LAYER UPDATE:" ..
839 layer_operation_name(oper) ..
840 " mask: " .. tostring(mask))
845 if oper == 3 then -- visible
846 local command = 0x10022
850 arg = m:JSON({layer = layer.id,
851 visible = layer.visible
855 print("### <== sending "..command_name(command)..
861 sc:send_message(sysctlid, msg)
864 print("### nothing to do")
869 output_update = function(self, oper, out, mask)
870 local idx = out.index
872 print("### OUTPUT UPDATE:" .. oper ..
873 " mask: "..tostring(mask))
876 local outdef = self.outputs[idx+1]
877 if (oper == 1) then -- create
879 self:output_request(m:JSON({index = idx,
884 elseif (oper == 5) then -- done
885 local ads = outdef.areas
886 local on = outdef.name
888 for name,ad in pairs(ads) do
889 local can = wmgr:canonical_name(on.."."..name)
890 local a = m:JSON({name = name,
892 for fld,val in pairs(ad) do
893 a[fld] = self:geometry(out.width,
898 resmgr:area_create(area[can], outdef.zone)
906 sc = m:get_system_controller()
914 -- these shoud be before wmgr:connect() is called
916 print("====== creating applications ======")
920 area = "Center.Full",
921 privileges = { screen = "none", audio = "none" },
922 resource_class = "player",
928 area = "Center.Full",
929 privileges = { screen = "system", audio = "none" },
930 resource_class = "implicit",
935 appid = "org.tizen.ico.homescreen",
936 area = "Center.Full",
937 privileges = { screen = "system", audio = "system" },
938 resource_class = "player",
943 appid = "org.tizen.ico.statusbar",
944 area = "Center.Status",
945 privileges = { screen = "system", audio = "none" },
946 resource_class = "player",
952 sc.client_handler = function (self, cid, msg)
953 local command = msg.command
955 print('### ==> client handler:')
960 if not connected then
961 print('Setting sysctlid='..msg.appid)
963 print('Trying to connect to wayland...')
964 connected = wmgr:connect()
966 if connected and command then
967 if command == 1 then -- send_appid
968 local reply = m:JSON({ command = 0x60001,
969 arg = m:JSON({ stateid = 1,
973 print("### <== sending " ..
974 command_name(command) .. " message")
979 sc:send_message(sysctlid, reply)
981 reply = m:JSON({ command = 0x60001,
982 arg = m:JSON({ stateid = 2,
986 print("### <== sending " ..
987 command_name(command) .. " message")
992 sc:send_message(sysctlid, reply)
997 sc.generic_handler = function (self, cid, msg)
999 print('### ==> generic handler:')
1006 sc.window_handler = function (self, cid, msg)
1008 print('### ==> received ' ..
1009 command_name(msg.command) .. ' message')
1011 print(tostring(msg))
1015 local a = animation({})
1017 if msg.command == 0x10003 then -- ico SHOW command
1018 local raise_mask = 0x01000000
1019 local lower_mask = 0x02000000
1020 local nores_mask = 0x40000000
1021 local time_mask = 0x00ffffff
1025 if msg.arg.anim_time then
1026 local t = msg.arg.anim_time
1027 time = m:AND(t, time_mask)
1028 nores = m:AND(t, nores_mask)
1029 if m:AND(t, raise_mask) then
1031 elseif m:AND(t, lower_mask) then
1035 if msg.arg.anim_name then
1036 a.show = { msg.arg.anim_name, time }
1037 print('time: ' .. tostring(a.show[2]))
1041 local p = wmgr:application(msg.appid)
1042 local s = p.privileges.screen
1043 if s == "system" then
1048 print('### ==> SHOW')
1049 print(tostring(msg.arg))
1052 wmgr:window_request(msg.arg, a, 0)
1054 local surface = msg.arg.surface
1055 resclnt:resource_set_acquire("screen", surface)
1056 resmgr:window_raise(msg.appid, surface, 1)
1058 elseif msg.command == 0x10004 then -- ico HIDE command
1059 local raise_mask = 0x01000000
1060 local lower_mask = 0x02000000
1061 local nores_mask = 0x40000000
1062 local time_mask = 0x00ffffff
1066 if msg.arg.anim_time then
1067 local t = msg.arg.anim_time
1068 time = m:AND(t, time_mask)
1069 nores = m:AND(t, nores_mask)
1071 if msg.arg.anim_name then
1072 a.hide = { msg.arg.anim_name, time }
1073 print('hide animation time: ' .. tostring(a.hide[2]))
1077 local p = wmgr:application(msg.appid)
1078 local s = p.privileges.screen
1079 if s == "system" then
1084 print('### ==> HIDE REQUEST')
1085 print(tostring(msg.arg))
1088 wmgr:window_request(msg.arg, a, 0)
1090 resmgr:window_raise(msg.appid, msg.arg.surface, -1)
1092 elseif msg.command == 0x10005 then -- ico MOVE
1094 print('### ==> MOVE REQUEST')
1095 print(tostring(msg.arg))
1097 wmgr:window_request(msg.arg, a, 0)
1098 -- TODO: handle if area changed
1099 elseif msg.command == 0x10006 then -- ico ACTIVE
1100 if not msg.arg.active then
1101 msg.arg.active = 3 -- pointer + keyboard
1104 print('### ==> ACTIVE REQUEST')
1105 print(tostring(msg.arg))
1107 wmgr:window_request(msg.arg, a, 0)
1108 elseif msg.command == 0x10007 then -- ico CHANGE_LAYER
1110 print('### ==> CHANGE_LAYER REQUEST')
1111 print(tostring(msg.arg))
1114 if msg.arg.layer ~= 4 or msg.arg.layer ~= 5 then
1115 print("do not change layer for other than cursor or touch")
1119 wmgr:window_request(msg.arg, a, 0)
1120 elseif msg.command == 0x10011 then -- ico MAP_THUMB
1121 local framerate = msg.arg.framerate
1122 if not framerate or framerate < 0 then
1127 print('### ==> MAP_THUMB REQUEST')
1129 print('framerate: '..framerate)
1131 wmgr:window_request(msg.arg, a, framerate)
1132 elseif msg.command == 0x10012 then -- ico UNMAP_THUMB
1135 print('### ==> UNMAP_THUMB REQUEST')
1138 wmgr:window_request(msg.arg, a, 0)
1139 elseif msg.command == 0x10020 then -- ico SHOW_LAYER command
1142 print('### ==> SHOW_LAYER REQUEST')
1145 wmgr:layer_request(msg.arg)
1146 elseif msg.command == 0x10021 then -- ico HIDE_LAYER command
1149 print('### ==> HIDE_LAYER REQUEST')
1152 wmgr:layer_request(msg.arg)
1156 sc.input_handler = function (self, cid, msg)
1158 print('### ==> input handler: ' .. command_name(msg.comand))
1165 sc.user_handler = function (self, cid, msg)
1167 print('### ==> user handler: ' .. command_name(msg.command))
1174 sc.resource_handler = function (self, cid, msg)
1176 print('### ==> resource handler: ' .. command_name(msg.command))
1182 createResourceSet = function (ctl, client, msg)
1183 cb = function(rset, data)
1184 print("> resource callback")
1186 -- type is either basic (0) or interrupt (1)
1188 if msg.res.type then
1189 requestType = msg.res.type
1192 if rset.acquired then
1193 cmd = 0x00040001 -- acquire
1195 cmd = 0x00040002 -- release
1199 appid = data.client,
1206 if rset.resources.audio_playback then
1215 if rset.resources.display then
1216 reply.res.window = {
1223 if rset.resources.input then
1229 print("sending message to client: " .. data.client)
1231 if sc:send_message(data.client, reply) then
1232 print('*** reply OK')
1234 print('*** reply FAILED')
1238 rset = m:ResourceSet({
1239 application_class = "player",
1240 zone = "driver", -- msg.zone ("full")
1249 if msg.res.sound then
1251 resource_name = "audio_playback"
1253 rset.resources.audio_playback.attributes.pid = tostring(msg.pid)
1254 rset.resources.audio_playback.attributes.appid = msg.appid
1255 print("sound name: " .. msg.res.sound.name)
1256 print("sound zone:" .. msg.res.sound.zone)
1257 print("sound adjust: " .. tostring(msg.res.sound.adjust))
1258 if msg.res.sound.id then
1259 print("sound id: " .. msg.res.sound.id)
1263 if msg.res.input then
1265 resource_name = "input"
1267 rset.resources.input.attributes.pid = tostring(msg.pid)
1268 rset.resources.input.attributes.appid = msg.appid
1269 print("input name: " .. msg.res.sound.name)
1270 print("input event:" .. tostring(msg.res.input.event))
1273 if msg.res.window then
1275 resource_name = "display"
1277 rset.resources.display.attributes.pid = tostring(msg.pid)
1278 rset.resources.display.attributes.appid = msg.appid
1279 print("display name: " .. msg.res.display.name)
1280 print("display zone:" .. msg.res.display.zone)
1281 if msg.res.display.id then
1282 print("display id: " .. msg.res.display.id)
1289 -- parse the message
1291 -- fields common to all messages:
1296 if msg.command == 0x00040011 then -- MSG_CMD_CREATE_RES
1297 print("command CREATE")
1299 if not sets.cid then
1300 sets.cid = createResourceSet(self, cid, msg)
1303 elseif msg.command == 0x00040012 then -- MSG_CMD_DESTORY_RES
1304 print("command DESTROY")
1310 sets.cid = nil -- garbage collecting
1312 elseif msg.command == 0x00040001 then -- MSG_CMD_ACQUIRE_RES
1313 print("command ACQUIRE")
1315 if not sets.cid then
1316 sets.cid = createResourceSet(self, cid, msg)
1321 elseif msg.command == 0x00040002 then -- MSG_CMD_RELEASE_RES
1322 print("command RELEASE")
1328 elseif msg.command == 0x00040003 then -- MSG_CMD_DEPRIVE_RES
1329 print("command DEPRIVE")
1331 elseif msg.command == 0x00040004 then -- MSG_CMD_WAITING_RES
1332 print("command WAITING")
1334 elseif msg.command == 0x00040005 then -- MSG_CMD_REVERT_RES
1335 print("command REVERT")
1339 sc.inputdev_handler = function (self, cid, msg)
1341 print('*** inputdev handler: ' .. command_name(msg.command))