resource: add configurable 'fifo' and 'lifo' ordering to application classes
[profile/ivi/murphy.git] / src / daemon / murphy.lua
1 m = murphy.get()
2
3 -- try loading console plugin
4 m:try_load_plugin('console')
5
6 -- load a test plugin
7 if m:plugin_exists('test') then
8     m:load_plugin('test', {
9                        string2  = 'this is now string2',
10                        boolean2 = true,
11                        int32 = -981,
12                        double = 2.73 })
13 --    m:load_plugin('test', 'test2')
14 --    m:info("Successfully loaded two instances of test...")
15 end
16
17 -- load the dbus plugin if it exists
18 if m:plugin_exists('dbus') then
19     m:load_plugin('dbus')
20 end
21
22 -- load glib plugin, ignoring any errors
23 m:try_load_plugin('glib')
24
25 -- load the native resource plugin
26 if m:plugin_exists('resource-native') then
27     m:load_plugin('resource-native')
28     m:info("native resource plugin loaded")
29 else
30     m:info("No native resource plugin found...")
31 end
32
33 -- load the dbus resource plugin
34 if m:plugin_exists('resource-dbus') then
35     m:try_load_plugin('resource-dbus', {
36         dbus_bus = "system",
37         dbus_service = "org.Murphy",
38         dbus_track = true,
39         default_zone = "driver",
40         default_class = "implicit"
41       })
42     m:info("dbus resource plugin loaded")
43 else
44     m:info("No dbus resource plugin found...")
45 end
46
47
48 -- load the domain control plugin if it exists
49 if m:plugin_exists('domain-control') then
50     m:load_plugin('domain-control')
51 else
52     m:info("No domain-control plugin found...")
53 end
54
55
56 -- define application classes
57 application_class { name="interrupt", priority=99, modal=true , share=false, order="fifo" }
58 application_class { name="navigator", priority=4 , modal=false, share=true , order="fifo" }
59 application_class { name="phone"    , priority=3 , modal=false, share=true , order="lifo" }
60 application_class { name="game"     , priority=2 , modal=false, share=true , order="lifo" }
61 application_class { name="player"   , priority=1 , modal=false, share=true , order="lifo" }
62 application_class { name="implicit" , priority=0 , modal=false, share=true , order="lifo" }
63
64 -- define zone attributes
65 zone.attributes {
66     type = {mdb.string, "common", "rw"},
67     location = {mdb.string, "anywhere", "rw"}
68 }
69
70 -- define zones
71 zone {
72      name = "driver",
73      attributes = {
74          type = "common",
75          location = "front-left"
76      }
77 }
78
79 zone {
80      name = "passanger1",
81      attributes = {
82          type = "private",
83          location = "front-right"
84      }
85 }
86
87 zone {
88      name = "passanger2",
89      attributes = {
90          type = "private",
91          location = "back-left"
92      }
93 }
94
95 zone {
96      name = "passanger3",
97      attributes = {
98          type = "private",
99          location = "back-right"
100      }
101 }
102
103 zone {
104      name = "passanger4",
105      attributes = {
106          type = "private",
107          location = "back-left"
108      }
109 }
110
111
112 -- define resource classes
113 resource.class {
114      name = "audio_playback",
115      shareable = true,
116      attributes = {
117          role = { mdb.string, "music", "rw" },
118          pid = { mdb.string, "<unknown>", "rw" },
119          policy = { mdb.string, "relaxed", "rw" }
120      }
121 }
122
123 resource.class {
124      name = "audio_recording",
125      shareable = false,
126      attributes = {
127          role = { mdb.string, "music", "rw" },
128          pid = { mdb.string, "<unknown>", "rw" },
129          policy = { mdb.string, "relaxed", "rw" }
130      }
131 }
132
133 resource.class {
134      name = "video_playback",
135      shareable = false,
136 }
137
138 resource.class {
139      name = "video_recording",
140      shareable = false
141 }
142
143 -- test for creating selections
144 mdb.select {
145            name = "audio_owner",
146            table = "audio_playback_owner",
147            columns = {"application_class"},
148            condition = "zone_name = 'driver'",
149 }
150
151 element.lua {
152    name    = "speed2volume",
153    inputs  = { owner = mdb.select.audio_owner, param = 5 },
154    outputs = {  mdb.table { name = "speedvol",
155                             index = {"zone", "device"},
156                             columns = {{"zone", mdb.string, 16},
157                                        {"device", mdb.string, 16},
158                                        {"value", mdb.floating}},
159                             create = true
160                            }
161              },
162    update  = function(self)
163                 if (self.inputs.owner.single_value) then
164                    print("*** element "..self.name.." update "..
165                           self.inputs.owner.single_value)
166                 else
167                    print("*** element "..self.name.." update <nil>")
168                 end
169              end
170 }