packaging: ignore WebProcess for appid tagging.
[profile/ivi/murphy.git] / packaging.in / murphy.lua
1 m = murphy.get()
2
3 -- try loading the various logging plugins
4 m:try_load_plugin('systemd')
5 m:try_load_plugin('dlog')
6
7 -- load the console plugin
8 m:try_load_plugin('console')
9
10 m:try_load_plugin('console.disabled', 'webconsole', {
11                   address = 'wsck:127.0.0.1:3000/murphy',
12                   httpdir = '/usr/share/murphy/webconsole' });
13
14 -- load the dbus plugin
15 if m:plugin_exists('dbus') then
16     m:load_plugin('dbus')
17 end
18
19 -- load the native resource plugin
20 if m:plugin_exists('resource-native') then
21     m:load_plugin('resource-native')
22     m:info("native resource plugin loaded")
23 else
24     m:info("No native resource plugin found...")
25 end
26
27 -- load the dbus resource plugin
28 m:try_load_plugin('resource-dbus', {
29     dbus_bus = "system",
30     dbus_service = "org.Murphy",
31     dbus_track = true,
32     default_zone = "driver",
33     default_class = "implicit"
34 })
35
36 -- load the domain control plugin
37 if m:plugin_exists('domain-control') then
38     m:load_plugin('domain-control')
39 else
40     m:info("No domain-control plugin found...")
41 end
42
43 -- load the AMB plugin
44 if m:plugin_exists('amb') then
45     m:load_plugin('amb')
46 else
47     m:info("No amb plugin found...")
48 end
49
50 -- load the ASM resource plugin
51 if m:plugin_exists('resource-asm') then
52     m:load_plugin('resource-asm', {
53         zone = "driver",
54         share_mmplayer = "player:AVP,mandatory,exclusive,relaxed",
55         ignored_argv0 = "WebProcess"
56     })
57 else
58     m:info("No audio session manager plugin found...")
59 end
60
61 if m:plugin_exists('ivi-resource-manager') then
62     m:load_plugin('ivi-resource-manager')
63 end
64
65 -- define application classes
66 application_class {
67     name     = "interrupt",
68     priority = 99,
69     modal    = true ,
70     share    = false,
71     order    = "fifo"
72 }
73
74 application_class {
75     name     = "emergency",
76     priority = 80,
77     modal    = false,
78     share    = false,
79     order    = "fifo"
80 }
81 application_class {
82     name     = "alert",
83     priority = 51,
84     modal    = false,
85     share    = false,
86     order    = "fifo"
87 }
88
89 application_class {
90     name     = "navigator",
91     priority = 50,
92     modal    = false,
93     share    = true,
94     order    = "fifo"
95 }
96
97 application_class {
98     name     = "phone",
99     priority = 6 ,
100     modal    = false,
101     share    = true ,
102     order    = "lifo"
103 }
104 application_class {
105     name     = "camera",
106     priority = 5,
107     modal    = false,
108     share    = false,
109     order    = "lifo"
110 }
111
112 application_class { name="event"    , priority=4 , modal=false, share=true , order="fifo" }
113 application_class { name="game"     , priority=3 , modal=false, share=false, order="lifo" }
114 --# doesn't need to be created here, ivi-resource-manager creates it if loaded
115 --#application_class { name="basic"    , priority=2 , modal=false, share=false, order="lifo" }
116 application_class { name="player"   , priority=1 , modal=false, share=true , order="lifo" }
117 application_class { name="implicit" , priority=0 , modal=false, share=false, order="lifo" }
118
119 -- define zone attributes
120 zone.attributes {
121     type = {mdb.string, "common", "rw"},
122     location = {mdb.string, "anywhere", "rw"}
123 }
124
125 -- define zones
126 zone {
127      name = "driver",
128      attributes = {
129          type = "common",
130          location = "front-left"
131      }
132 }
133
134 zone {
135      name = "passanger1",
136      attributes = {
137          type = "private",
138          location = "front-right"
139      }
140 }
141
142 zone {
143      name = "passanger2",
144      attributes = {
145          type = "private",
146          location = "back-left"
147      }
148 }
149
150 zone {
151      name = "passanger3",
152      attributes = {
153          type = "private",
154          location = "back-right"
155      }
156 }
157
158 zone {
159      name = "passanger4",
160      attributes = {
161          type = "private",
162          location = "back-left"
163      }
164 }
165
166
167 -- define resource classes
168 if not m:plugin_exists('ivi-resource-manager') then
169    resource.class {
170         name = "audio_playback",
171         shareable = true,
172         attributes = {
173             role = { mdb.string, "music", "rw" },
174             pid = { mdb.string, "<unknown>", "rw" },
175             policy = { mdb.string, "relaxed", "rw" }
176         }
177    }
178 end
179
180 resource.class {
181      name = "audio_recording",
182      shareable = true,
183      attributes = {
184          role   = { mdb.string, "music"    , "rw" },
185          pid    = { mdb.string, "<unknown>", "rw" },
186          policy = { mdb.string, "relaxed"  , "rw" }
187      }
188 }
189
190 resource.class {
191      name = "video_playback",
192      shareable = false,
193 }
194
195 resource.class {
196      name = "video_recording",
197      shareable = false
198 }
199
200 if not m:plugin_exists('ivi-resource-manager') then
201 resource.method.veto = {
202     function(zone, rset, grant, owners)
203         rset_priority = application_class[rset.application_class].priority
204
205         owner_id = owners.audio_playback.resource_set
206         rset_id = rset.id
207
208         if (rset_priority >= 50 and owner_id ~= rset_id) then
209             print("*** resource-set "..rset_id.." - veto")
210             return false
211         end
212
213         return true
214     end
215 }
216 end
217
218 -- test for creating selections
219 mdb.select {
220            name = "audio_owner",
221            table = "audio_playback_owner",
222            columns = {"application_class"},
223            condition = "zone_name = 'driver'"
224 }
225
226 mdb.select {
227            name = "vehicle_speed",
228            table = "amb_vehicle_speed",
229            columns = {"value"},
230            condition = "key = 'VehicleSpeed'"
231 }
232
233 element.lua {
234    name    = "speed2volume",
235    inputs  = { speed = mdb.select.vehicle_speed, param = 9 },
236    outputs = {  mdb.table { name = "speedvol",
237                             index = {"zone", "device"},
238                             columns = {{"zone", mdb.string, 16},
239                                        {"device", mdb.string, 16},
240                                        {"value", mdb.floating}},
241                             create = true
242                            }
243              },
244    oldvolume = 0.0,
245    update  = function(self)
246                 speed = self.inputs.speed.single_value
247                 if (speed) then
248                     volume = (speed - 144.0) / 7.0
249                 else
250                     volume = 0.0
251                 end
252                 diff = volume - self.oldvolume
253                 if (diff*diff > self.inputs.param) then
254                     print("*** element "..self.name.." update "..volume)
255                     self.oldvolume = volume
256                     mdb.table.speedvol:replace({zone = "driver", device = "speakers", value = volume})
257                 end
258              end
259 }
260
261 -- Night mode processing chain
262
263 mdb.select {
264     name = "exterior_brightness",
265     table = "amb_exterior_brightness",
266     columns = { "value" },
267     condition = "key = 'ExteriorBrightness'"
268 }
269
270 mdb.table {
271     name = "amb_nightmode",
272     index = { "id" },
273     create = true,
274     columns = {
275         { "id", mdb.unsigned },
276         { "night_mode", mdb.unsigned }
277     }
278 }
279
280 element.lua {
281     name    = "nightmode",
282     inputs  = { brightness = mdb.select.exterior_brightness },
283     oldmode = -1;
284     outputs = {
285     mdb.table {
286         name = "mandatory_placeholder_to_prevent_spurious_updates",
287             create = true,
288             columns = { { "id", mdb.unsigned } }
289         }
290     },
291     update = function(self)
292         -- This is a trivial function to calculate night mode. Later, we will
293         -- need a better threshold value and hysteresis to prevent oscillation.
294
295         brightness = self.inputs.brightness.single_value
296
297         if not brightness then
298             return
299         end
300
301         print("*** element "..self.name.." update brightness: "..brightness)
302
303         if brightness > 300 then
304             mode = 0
305         else
306             mode = 1
307         end
308
309         print("*** resulting mode: ".. mode)
310
311         if not (mode == self.oldmode) then
312             mdb.table.amb_nightmode:replace({ id = 0, night_mode = mode })
313         end
314
315         self.oldmode = mode
316     end
317 }
318
319 mdb.select {
320     name = "select_night_mode",
321     table = "amb_nightmode",
322     columns = { "night_mode" },
323     condition = "id = 0"
324 }
325
326 sink.lua {
327     name = "night_mode",
328     inputs = { owner = mdb.select.select_night_mode },
329     property = "NightMode",
330     type = "b",
331     initiate = builtin.method.amb_initiate,
332     update = builtin.method.amb_update
333 }
334
335
336 -- Driving mode processing chain
337
338 mdb.table {
339     name = "amb_drivingmode",
340     index = { "id" },
341     create = true,
342     columns = {
343         { "id", mdb.unsigned },
344         { "driving_mode", mdb.unsigned }
345     }
346 }
347
348 element.lua {
349     name    = "drivingmode",
350     inputs  = { speed = mdb.select.vehicle_speed },
351     oldmode = -1;
352     outputs = {
353     mdb.table {
354         name = "another_mandatory_placeholder_to_prevent_spurious_updates",
355             create = true,
356             columns = { { "id", mdb.unsigned } }
357         }
358     },
359     update = function(self)
360
361         speed = self.inputs.speed.single_value
362
363         if not speed then
364             return
365         end
366
367         if speed == 0 then
368             mode = 0
369         else
370             mode = 1
371         end
372
373         if not (mode == self.oldmode) then
374             mdb.table.amb_drivingmode:replace({ id = 0, driving_mode = mode })
375         end
376
377         self.oldmode = mode
378     end
379 }
380
381 mdb.select {
382     name = "select_driving_mode",
383     table = "amb_drivingmode",
384     columns = { "driving_mode" },
385     condition = "id = 0"
386 }
387
388 sink.lua {
389     name = "driving_mode",
390     inputs = { owner = mdb.select.select_driving_mode },
391     property = "DrivingMode",
392     type = "u",
393     initiate = builtin.method.amb_initiate,
394     update = builtin.method.amb_update
395 }
396
397 -- load the telephony plugin
398 m:try_load_plugin('telephony')