blob: fa6bb60ccdf5403a4e24f12239707fbbb6a6241a [file] [log] [blame]
Brad Bishop732c6db2015-10-19 14:49:21 -04001#!/usr/bin/env python
2
Brad Bishopb3385602016-03-04 15:32:01 -05003# Contributors Listed Below - COPYRIGHT 2016
Brad Bishop732c6db2015-10-19 14:49:21 -04004# [+] International Business Machines Corp.
5#
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
16# implied. See the License for the specific language governing
17# permissions and limitations under the License.
18
Brad Bishop732c6db2015-10-19 14:49:21 -040019import dbus
20import dbus.service
Brad Bishopae0c0af2015-11-09 18:41:28 -050021import dbus.exceptions
Brad Bishop732c6db2015-10-19 14:49:21 -040022import dbus.mainloop.glib
23import gobject
Brad Bishopfb1f58e2016-03-04 15:19:13 -050024from obmc.dbuslib.introspection import IntrospectionParser
25import obmc.utils.pathtree
26import obmc.utils.misc
27import obmc.mapper
Brad Bishopfed968e2016-03-18 10:47:26 -040028import obmc.dbuslib.bindings
Brad Bishopd9fc21c2016-03-18 12:24:42 -040029import obmc.dbuslib.enums
Brad Bishop732c6db2015-10-19 14:49:21 -040030
Brad Bishop4b849412016-02-04 15:40:26 -050031
Brad Bishopae0c0af2015-11-09 18:41:28 -050032class MapperNotFoundException(dbus.exceptions.DBusException):
Brad Bishopfb1f58e2016-03-04 15:19:13 -050033 _dbus_error_name = obmc.mapper.MAPPER_NOT_FOUND
Brad Bishop4b849412016-02-04 15:40:26 -050034
35 def __init__(self, path):
36 super(MapperNotFoundException, self).__init__(
Brad Bishop9cff26b2016-03-18 11:16:47 -040037 "path or object not found: %s" % path)
Brad Bishop4b849412016-02-04 15:40:26 -050038
Brad Bishopae0c0af2015-11-09 18:41:28 -050039
Brad Bishopd9fc21c2016-03-18 12:24:42 -040040class Association(dbus.service.Object):
41 def __init__(self, bus, path, endpoints):
42 super(Association, self).__init__(bus, path)
43 self.endpoints = endpoints
44
45 def __getattr__(self, name):
46 if name == 'properties':
47 return {
48 obmc.dbuslib.enums.OBMC_ASSOC_IFACE: {
49 'endpoints': self.endpoints}}
50 return super(Association, self).__getattr__(name)
51
52 def emit_signal(self, old):
53 if old != self.endpoints:
54 self.PropertiesChanged(
55 obmc.dbuslib.enums.OBMC_ASSOC_IFACE,
56 {'endpoints': self.endpoints}, ['endpoints'])
57
58 def append(self, endpoints):
59 old = self.endpoints
60 self.endpoints = list(set(endpoints).union(self.endpoints))
61 self.emit_signal(old)
62
63 def remove(self, endpoints):
64 old = self.endpoints
65 self.endpoints = list(set(self.endpoints).difference(endpoints))
66 self.emit_signal(old)
67
68 @dbus.service.method(dbus.PROPERTIES_IFACE, 'ss', 'as')
69 def Get(self, interface_name, property_name):
70 if property_name != 'endpoints':
71 raise dbus.exceptions.DBusException(name=DBUS_UNKNOWN_PROPERTY)
72 return self.GetAll(interface_name)[property_name]
73
74 @dbus.service.method(dbus.PROPERTIES_IFACE, 's', 'a{sas}')
75 def GetAll(self, interface_name):
76 if interface_name != obmc.dbuslib.enums.OBMC_ASSOC_IFACE:
77 raise dbus.exceptions.DBusException(DBUS_UNKNOWN_INTERFACE)
78 return {'endpoints': self.endpoints}
79
80 @dbus.service.signal(
81 dbus.PROPERTIES_IFACE, signature='sa{sas}as')
82 def PropertiesChanged(
83 self, interface_name, changed_properties, invalidated_properties):
84 pass
85
86
87class Manager(obmc.dbuslib.bindings.DbusObjectManager):
88 def __init__(self, bus, path):
89 obmc.dbuslib.bindings.DbusObjectManager.__init__(self)
90 dbus.service.Object.__init__(self, bus.dbus, path)
91
92
Brad Bishop732c6db2015-10-19 14:49:21 -040093class ObjectMapper(dbus.service.Object):
Brad Bishop4b849412016-02-04 15:40:26 -050094 def __init__(self, bus, path,
Brad Bishopfb1f58e2016-03-04 15:19:13 -050095 name_match=obmc.utils.misc.org_dot_openbmc_match,
96 intf_match=obmc.utils.misc.org_dot_openbmc_match):
Brad Bishop4b849412016-02-04 15:40:26 -050097 super(ObjectMapper, self).__init__(bus.dbus, path)
Brad Bishopfb1f58e2016-03-04 15:19:13 -050098 self.cache = obmc.utils.pathtree.PathTree()
Brad Bishop4b849412016-02-04 15:40:26 -050099 self.bus = bus
100 self.name_match = name_match
101 self.intf_match = intf_match
Brad Bishopfb1f58e2016-03-04 15:19:13 -0500102 self.tag_match = obmc.utils.misc.ListMatch(['children', 'interface'])
Brad Bishop4b849412016-02-04 15:40:26 -0500103 self.service = None
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400104 self.index = {}
105 self.manager = Manager(bus, obmc.dbuslib.bindings.OBJ_PREFIX)
106 self.unique = bus.dbus.get_unique_name()
Brad Bishop732c6db2015-10-19 14:49:21 -0400107
Brad Bishop4b849412016-02-04 15:40:26 -0500108 gobject.idle_add(self.discover)
109 self.bus.dbus.add_signal_receiver(
110 self.bus_handler,
111 dbus_interface=
112 dbus.BUS_DAEMON_IFACE,
113 signal_name='NameOwnerChanged')
114 self.bus.dbus.add_signal_receiver(
115 self.interfaces_added_handler,
116 dbus_interface=
117 dbus.BUS_DAEMON_IFACE + '.ObjectManager',
118 signal_name='InterfacesAdded',
Brad Bishopc568e022016-03-23 14:50:05 -0400119 sender_keyword='sender',
120 path_keyword='sender_path')
Brad Bishop4b849412016-02-04 15:40:26 -0500121 self.bus.dbus.add_signal_receiver(
122 self.interfaces_removed_handler,
123 dbus_interface=dbus.BUS_DAEMON_IFACE + '.ObjectManager',
124 signal_name='InterfacesRemoved',
Brad Bishopc568e022016-03-23 14:50:05 -0400125 sender_keyword='sender',
126 path_keyword='sender_path')
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400127 self.bus.dbus.add_signal_receiver(
128 self.properties_changed_handler,
129 dbus_interface=dbus.PROPERTIES_IFACE,
130 signal_name='PropertiesChanged',
131 path_keyword='path',
132 sender_keyword='sender')
Brad Bishop732c6db2015-10-19 14:49:21 -0400133
Brad Bishop9cff26b2016-03-18 11:16:47 -0400134 def bus_match(self, owner):
135 # Ignore my own signals
136 return owner != obmc.mapper.MAPPER_NAME and \
137 self.name_match(owner)
Brad Bishop65b7ceb2015-11-04 23:05:56 -0500138
Brad Bishop4b849412016-02-04 15:40:26 -0500139 def discovery_pending(self):
140 return not bool(self.service)
Brad Bishopcb7aa602015-11-03 10:40:17 -0500141
Brad Bishopc568e022016-03-23 14:50:05 -0400142 def add_new_objmgr(self, path, owner):
143 # We don't get a signal for the ObjectManager
144 # interface itself, so if we see a signal from
145 # make sure its in our cache, and add it if not.
146 cache_entry = self.cache.get(path, {})
147 cache_entry = cache_entry if cache_entry is not None else {}
148 old = self.interfaces_get(cache_entry, owner)
149 new = list(set(old).union([dbus.BUS_DAEMON_IFACE + '.ObjectManager']))
150 self.update_interfaces(path, owner, old, new)
151
Brad Bishop4b849412016-02-04 15:40:26 -0500152 def interfaces_added_handler(self, path, iprops, **kw):
Brad Bishopfed968e2016-03-18 10:47:26 -0400153 path = str(path)
154 owner = str(kw['sender'])
Brad Bishopc568e022016-03-23 14:50:05 -0400155 self.add_new_objmgr(str(kw['sender_path']), owner)
Brad Bishopfed968e2016-03-18 10:47:26 -0400156 interfaces = self.get_signal_interfaces(owner, iprops.iterkeys())
157 cache_entry = self.cache.get(path, {})
158 old = self.interfaces_get(cache_entry, owner)
159 new = list(set(interfaces).union(old))
160 self.update_interfaces(path, owner, old, new)
Brad Bishop732c6db2015-10-19 14:49:21 -0400161
Brad Bishop4b849412016-02-04 15:40:26 -0500162 def interfaces_removed_handler(self, path, interfaces, **kw):
Brad Bishopfed968e2016-03-18 10:47:26 -0400163 path = str(path)
164 owner = str(kw['sender'])
Brad Bishopc568e022016-03-23 14:50:05 -0400165 self.add_new_objmgr(str(kw['sender_path']), owner)
Brad Bishopfed968e2016-03-18 10:47:26 -0400166 interfaces = self.get_signal_interfaces(owner, interfaces)
167 cache_entry = self.cache.get(path, {})
168 old = self.interfaces_get(cache_entry, owner)
169 new = list(set(old).difference(interfaces))
170 self.update_interfaces(path, owner, old, new)
Brad Bishop732c6db2015-10-19 14:49:21 -0400171
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400172 def properties_changed_handler(self, interface, new, old, **kw):
173 owner = str(kw['sender'])
174 path = str(kw['path'])
175 interfaces = self.get_signal_interfaces(owner, [interface])
176 if not self.is_association(interfaces):
177 return
178 associations = new.get('associations', None)
179 if associations is None:
180 return
181
182 associations = [
183 (str(x), str(y), str(z)) for x, y, z in associations]
184 self.update_associations(
185 path, owner,
186 self.index_get_associations(path, [owner]),
187 associations)
188
Brad Bishop9cff26b2016-03-18 11:16:47 -0400189 def process_new_owner(self, owner):
Brad Bishop4b849412016-02-04 15:40:26 -0500190 # unique name
Brad Bishop9cff26b2016-03-18 11:16:47 -0400191 return self.discover([IntrospectionParser(owner,
Brad Bishop4b849412016-02-04 15:40:26 -0500192 self.bus.dbus,
193 self.tag_match,
194 self.intf_match)])
Brad Bishop732c6db2015-10-19 14:49:21 -0400195
Brad Bishop9cff26b2016-03-18 11:16:47 -0400196 def process_old_owner(self, owner):
Brad Bishopfed968e2016-03-18 10:47:26 -0400197 for path, item in self.cache.dataitems():
Brad Bishop9cff26b2016-03-18 11:16:47 -0400198 old = self.interfaces_get(item, owner)
Brad Bishopfed968e2016-03-18 10:47:26 -0400199 # remove all interfaces for this service
200 self.update_interfaces(
Brad Bishop9cff26b2016-03-18 11:16:47 -0400201 path, owner, old=old, new=[])
Brad Bishop732c6db2015-10-19 14:49:21 -0400202
Brad Bishopfed968e2016-03-18 10:47:26 -0400203 def bus_handler(self, owner, old, new):
204 valid = False
205 if not obmc.dbuslib.bindings.is_unique(owner):
206 valid = self.valid_signal(owner)
Brad Bishop732c6db2015-10-19 14:49:21 -0400207
Brad Bishopfed968e2016-03-18 10:47:26 -0400208 if valid and new:
Brad Bishop4b849412016-02-04 15:40:26 -0500209 self.process_new_owner(new)
Brad Bishopfed968e2016-03-18 10:47:26 -0400210 if valid and old:
Brad Bishop4b849412016-02-04 15:40:26 -0500211 self.process_old_owner(old)
Brad Bishop732c6db2015-10-19 14:49:21 -0400212
Brad Bishopfed968e2016-03-18 10:47:26 -0400213 def update_interfaces(self, path, owner, old, new):
214 cache_entry = self.cache.setdefault(path, {})
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400215 created = [] if self.has_interfaces(cache_entry) else [path]
Brad Bishopfed968e2016-03-18 10:47:26 -0400216 added = list(set(new).difference(old))
217 removed = list(set(old).difference(new))
218 self.interfaces_append(cache_entry, owner, added)
219 self.interfaces_remove(cache_entry, owner, removed, path)
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400220 destroyed = [] if self.has_interfaces(cache_entry) else [path]
221
222 # react to anything that requires association updates
223 new_assoc = []
224 old_assoc = []
225 if self.is_association(added):
226 new_assoc = self.dbus_get_associations(path, owner)
227 if self.is_association(removed):
228 old_assoc = self.index_get_associations(path, [owner])
229 self.update_associations(
230 path, owner, old_assoc, new_assoc, created, destroyed)
Brad Bishop86398d22015-10-28 21:58:31 -0400231
Brad Bishop4b849412016-02-04 15:40:26 -0500232 def add_items(self, owner, bus_items):
Brad Bishopfed968e2016-03-18 10:47:26 -0400233 for path, items in bus_items.iteritems():
234 # convert dbus types to native.
235 interfaces = [str(i) for i in items.get('interfaces', [])]
236 self.update_interfaces(path, str(owner), old=[], new=interfaces)
Brad Bishop86398d22015-10-28 21:58:31 -0400237
Brad Bishop9cff26b2016-03-18 11:16:47 -0400238 def discover(self, owners=[]):
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400239 def match(iface):
240 return iface == dbus.BUS_DAEMON_IFACE + '.ObjectManager' or \
241 self.intf_match(iface)
Brad Bishop4b849412016-02-04 15:40:26 -0500242 if not owners:
Brad Bishop9cff26b2016-03-18 11:16:47 -0400243 owners = [
244 IntrospectionParser(
245 x, self.bus.dbus,
246 self.tag_match,
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400247 match)
Brad Bishop9cff26b2016-03-18 11:16:47 -0400248 for x in self.bus.get_owner_names(self.bus_match)]
Brad Bishop4b849412016-02-04 15:40:26 -0500249 for o in owners:
250 self.add_items(o.name, o.introspect())
Brad Bishop732c6db2015-10-19 14:49:21 -0400251
Brad Bishop4b849412016-02-04 15:40:26 -0500252 if self.discovery_pending():
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400253 # add my object mananger instance
254 self.add_items(
255 self.unique,
256 {obmc.dbuslib.bindings.OBJ_PREFIX:
257 {'interfaces':
258 [dbus.BUS_DAEMON_IFACE + '.ObjectManager']}})
259
Brad Bishop4b849412016-02-04 15:40:26 -0500260 print "ObjectMapper discovery complete..."
261 self.service = dbus.service.BusName(
Brad Bishopfb1f58e2016-03-04 15:19:13 -0500262 obmc.mapper.MAPPER_NAME, self.bus.dbus)
Brad Bishop732c6db2015-10-19 14:49:21 -0400263
Brad Bishopfed968e2016-03-18 10:47:26 -0400264 def valid_signal(self, owner):
265 if obmc.dbuslib.bindings.is_unique(owner):
266 owner = self.bus.get_owned_name(self.bus_match, owner)
267
268 return owner is not None and not self.discovery_pending() and \
269 self.bus_match(owner)
270
271 def get_signal_interfaces(self, owner, interfaces):
272 filtered = []
273 if self.valid_signal(owner):
274 filtered = [str(x) for x in interfaces if self.intf_match(x)]
275
276 return filtered
277
278 @staticmethod
279 def interfaces_get(item, owner, default=[]):
280 return item.get(owner, default)
281
282 @staticmethod
283 def interfaces_append(item, owner, append):
284 interfaces = item.setdefault(owner, [])
285 item[owner] = list(set(append).union(interfaces))
286
287 def interfaces_remove(self, item, owner, remove, path):
288 interfaces = item.get(owner, [])
289 item[owner] = list(set(interfaces).difference(remove))
290
291 if not item[owner]:
292 # remove the owner if there aren't any interfaces left
293 del item[owner]
294
295 if item:
296 # other owners remain
297 return
298
299 if self.cache.get_children(path):
300 # there are still references to this path
301 # from objects further down the tree.
302 # mark it for removal if that changes
303 self.cache.demote(path)
304 else:
305 # delete the entire path if everything is gone
306 del self.cache[path]
307
Brad Bishopfb1f58e2016-03-04 15:19:13 -0500308 @dbus.service.method(obmc.mapper.MAPPER_IFACE, 's', 'a{sas}')
Brad Bishop4b849412016-02-04 15:40:26 -0500309 def GetObject(self, path):
310 o = self.cache.get(path)
311 if not o:
312 raise MapperNotFoundException(path)
313 return o
Brad Bishop732c6db2015-10-19 14:49:21 -0400314
Brad Bishopfb1f58e2016-03-04 15:19:13 -0500315 @dbus.service.method(obmc.mapper.MAPPER_IFACE, 'si', 'as')
Brad Bishop4b849412016-02-04 15:40:26 -0500316 def GetSubTreePaths(self, path, depth):
317 try:
318 return self.cache.iterkeys(path, depth)
319 except KeyError:
320 raise MapperNotFoundException(path)
Brad Bishop732c6db2015-10-19 14:49:21 -0400321
Brad Bishopfb1f58e2016-03-04 15:19:13 -0500322 @dbus.service.method(obmc.mapper.MAPPER_IFACE, 'si', 'a{sa{sas}}')
Brad Bishop4b849412016-02-04 15:40:26 -0500323 def GetSubTree(self, path, depth):
324 try:
325 return {x: y for x, y in self.cache.dataitems(path, depth)}
326 except KeyError:
327 raise MapperNotFoundException(path)
328
Brad Bishopd9fc21c2016-03-18 12:24:42 -0400329 @staticmethod
330 def has_interfaces(item):
331 for owner in item.iterkeys():
332 if ObjectMapper.interfaces_get(item, owner):
333 return True
334 return False
335
336 @staticmethod
337 def is_association(interfaces):
338 return obmc.dbuslib.enums.OBMC_ASSOCIATIONS_IFACE in interfaces
339
340 def index_get(self, index, path, owners):
341 items = []
342 item = self.index.get(index, {})
343 item = item.get(path, {})
344 for o in owners:
345 items.extend(item.get(o, []))
346 return items
347
348 def index_append(self, index, path, owner, assoc):
349 item = self.index.setdefault(index, {})
350 item = item.setdefault(path, {})
351 item = item.setdefault(owner, [])
352 item.append(assoc)
353
354 def index_remove(self, index, path, owner, assoc):
355 index = self.index.get(index, {})
356 owners = index.get(path, {})
357 items = owners.get(owner, [])
358 if assoc in items:
359 items.remove(assoc)
360 if not items:
361 del owners[owner]
362 if not owners:
363 del index[path]
364
365 def dbus_get_associations(self, path, owner):
366 obj = self.bus.dbus.get_object(owner, path, introspect=False)
367 iface = dbus.Interface(obj, dbus.PROPERTIES_IFACE)
368 return [(str(f), str(r), str(e)) for f, r, e in iface.Get(
369 obmc.dbuslib.enums.OBMC_ASSOCIATIONS_IFACE,
370 'associations')]
371
372 def index_get_associations(self, path, owners=[], direction='forward'):
373 forward = 'forward' if direction == 'forward' else 'reverse'
374 reverse = 'reverse' if direction == 'forward' else 'forward'
375
376 associations = []
377 if not owners:
378 index = self.index.get(forward, {})
379 owners = index.get(path, {}).keys()
380
381 # f: forward
382 # r: reverse
383 for rassoc in self.index_get(forward, path, owners):
384 elements = rassoc.split('/')
385 rtype = ''.join(elements[-1:])
386 fendpoint = '/'.join(elements[:-1])
387 for fassoc in self.index_get(reverse, fendpoint, owners):
388 elements = fassoc.split('/')
389 ftype = ''.join(elements[-1:])
390 rendpoint = '/'.join(elements[:-1])
391 if rendpoint != path:
392 continue
393 associations.append((ftype, rtype, fendpoint))
394
395 return associations
396
397 def update_association(self, path, removed, added):
398 iface = obmc.dbuslib.enums.OBMC_ASSOC_IFACE
399 create = [] if self.manager.get(path, False) else [iface]
400
401 if added and create:
402 self.manager.add(
403 path, Association(self.bus.dbus, path, added))
404 elif added:
405 self.manager.get(path).append(added)
406
407 obj = self.manager.get(path, None)
408 if obj and removed:
409 obj.remove(removed)
410
411 if obj and not obj.endpoints:
412 self.manager.remove(path)
413
414 delete = [] if self.manager.get(path, False) else [iface]
415
416 if create != delete:
417 self.update_interfaces(
418 path, self.unique, delete, create)
419
420 def update_associations(
421 self, path, owner, old, new, created=[], destroyed=[]):
422 added = list(set(new).difference(old))
423 removed = list(set(old).difference(new))
424 for forward, reverse, endpoint in added:
425 # update the index
426 forward_path = str(path + '/' + forward)
427 reverse_path = str(endpoint + '/' + reverse)
428 self.index_append(
429 'forward', path, owner, reverse_path)
430 self.index_append(
431 'reverse', endpoint, owner, forward_path)
432
433 # create the association if the endpoint exists
434 if self.cache.get(endpoint, None) is None:
435 continue
436
437 self.update_association(forward_path, [], [endpoint])
438 self.update_association(reverse_path, [], [path])
439
440 for forward, reverse, endpoint in removed:
441 # update the index
442 forward_path = str(path + '/' + forward)
443 reverse_path = str(endpoint + '/' + reverse)
444 self.index_remove(
445 'forward', path, owner, reverse_path)
446 self.index_remove(
447 'reverse', endpoint, owner, forward_path)
448
449 # destroy the association if it exists
450 self.update_association(forward_path, [endpoint], [])
451 self.update_association(reverse_path, [path], [])
452
453 # If the associations interface endpoint comes
454 # or goes create or destroy the appropriate
455 # associations
456 for path in created:
457 for forward, reverse, endpoint in \
458 self.index_get_associations(path, direction='reverse'):
459 forward_path = str(path + '/' + forward)
460 reverse_path = str(endpoint + '/' + reverse)
461 self.update_association(forward_path, [], [endpoint])
462 self.update_association(reverse_path, [], [path])
463
464 for path in destroyed:
465 for forward, reverse, endpoint in \
466 self.index_get_associations(path, direction='reverse'):
467 forward_path = str(path + '/' + forward)
468 reverse_path = str(endpoint + '/' + reverse)
469 self.update_association(forward_path, [endpoint], [])
470 self.update_association(reverse_path, [path], [])
471
472 @dbus.service.method(obmc.mapper.MAPPER_IFACE, 's', 'a{sa{sas}}')
473 def GetAncestors(self, path):
474 elements = filter(bool, path.split('/'))
475 paths = []
476 objs = {}
477 while elements:
478 elements.pop()
479 paths.append('/' + '/'.join(elements))
480 if path != '/':
481 paths.append('/')
482
483 for path in paths:
484 obj = self.cache.get(path, None)
485 if obj is None:
486 continue
487 objs[path] = obj
488
489 return objs
490
Brad Bishop732c6db2015-10-19 14:49:21 -0400491
Brad Bishop732c6db2015-10-19 14:49:21 -0400492class BusWrapper:
Brad Bishop4b849412016-02-04 15:40:26 -0500493 def __init__(self, bus):
494 self.dbus = bus
Brad Bishop732c6db2015-10-19 14:49:21 -0400495
Brad Bishop4b849412016-02-04 15:40:26 -0500496 def get_owned_name(self, match, bus):
497 for x in self.get_service_names(match):
498 if self.dbus.get_name_owner(x) == bus:
499 return x
Brad Bishop5ffc2a32015-11-25 08:46:01 -0500500
Brad Bishop4b849412016-02-04 15:40:26 -0500501 def get_service_names(self, match):
502 # these are well known names
503 return [x for x in self.dbus.list_names()
504 if match(x)]
Brad Bishop732c6db2015-10-19 14:49:21 -0400505
Brad Bishop4b849412016-02-04 15:40:26 -0500506 def get_owner_names(self, match):
507 # these are unique connection names
508 return list(set(
509 [self.dbus.get_name_owner(x)
510 for x in self.get_service_names(match)]))
Brad Bishop732c6db2015-10-19 14:49:21 -0400511
Brad Bishop732c6db2015-10-19 14:49:21 -0400512if __name__ == '__main__':
Brad Bishop4b849412016-02-04 15:40:26 -0500513 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
514 bus = dbus.SystemBus()
Brad Bishopfb1f58e2016-03-04 15:19:13 -0500515 o = ObjectMapper(BusWrapper(bus), obmc.mapper.MAPPER_PATH)
Brad Bishop4b849412016-02-04 15:40:26 -0500516 loop = gobject.MainLoop()
Brad Bishop732c6db2015-10-19 14:49:21 -0400517
Brad Bishop4b849412016-02-04 15:40:26 -0500518 loop.run()