/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

  • Committer: Teddy Hogeborn
  • Date: 2014-08-10 14:13:02 UTC
  • Revision ID: teddy@recompile.se-20140810141302-8q1xaaxlh8ho5joz
Emit D-Bus "org.freedesktop.DBus.Properties.PropertiesChanged" signal.

This deprecates the "se.recompile.Mandos.Client.PropertyChanged"
signal.  The new signal also adds support for noticing changes to the
"se.recompile.Mandos.Client.Secret" write-only property.

* mandos (dbus_annotations): Fix usage example in doc string.
  (DBusObjectWithProperties.PropertiesChanged): New; from D-Bus
                                                standard.
  (ClientDBus._interface): Set early instead of later.
  (ClientDBus.notifychangeproperty): Take new "invalidate_only"
                                     parameter, and pass in _interface
                                     as a default keyword argument.
  (ClientDBus.notifychangeproperty/setter): Also emit
                                            PropertiesChanged signal;
                                            emit new value or
                                            invalidation depending on
                                            "invalidate_only".
  (ClientDBus.secret): Apply notifychangeproperty with
                       "invalidate_only=True".
  (ClientDBus._foo): Removed defunct interface annotation.
  (ClientDBus.PropertyChanged): Add annotation; this method is now
                                deprecated.
  (main/MandosDBusService.GetAllClientsWithProperties): Use dictionary
                                                        comprehension.
* DBUS-API (Mandos Client Interface/Signals/PropertyChanged): Removed.
* mandos-monitor: Use standard "PropertiesChanged" signal instead of
                  old signal "PropertyChanged".
  (MandosClientPropertyCache.__init__): Connect to signal
                                        PropertiesChanged instead of
                                        PropertyChanged.
  (MandosClientPropertyCache._property_changed): Removed.
  (MandosClientPropertyCache.property_changed): Renamed to
                                                "properties_changed"
                                                and adapted to new
                                                call signature.
  (MandosClientWidget.properties_changed): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
813
813
    """Decorator to annotate D-Bus methods, signals or properties
814
814
    Usage:
815
815
    
 
816
    @dbus_annotations({"org.freedesktop.DBus.Deprecated": "true",
 
817
                       "org.freedesktop.DBus.Property."
 
818
                       "EmitsChangedSignal": "false"})
816
819
    @dbus_service_property("org.example.Interface", signature="b",
817
820
                           access="r")
818
 
    @dbus_annotations({{"org.freedesktop.DBus.Deprecated": "true",
819
 
                        "org.freedesktop.DBus.Property."
820
 
                        "EmitsChangedSignal": "false"})
821
821
    def Property_dbus_property(self):
822
822
        return dbus.Boolean(False)
823
823
    """
946
946
                                           value.variant_level+1)
947
947
        return dbus.Dictionary(properties, signature="sv")
948
948
    
 
949
    @dbus.service.signal(dbus.PROPERTIES_IFACE, signature="sa{sv}as")
 
950
    def PropertiesChanged(self, interface_name, changed_properties,
 
951
                          invalidated_properties):
 
952
        """Standard D-Bus PropertiesChanged() signal, see D-Bus
 
953
        standard.
 
954
        """
 
955
        pass
 
956
    
949
957
    @dbus.service.method(dbus.INTROSPECTABLE_IFACE,
950
958
                         out_signature="s",
951
959
                         path_keyword='object_path',
1218
1226
    runtime_expansions = (Client.runtime_expansions
1219
1227
                          + ("dbus_object_path",))
1220
1228
    
 
1229
    _interface = "se.recompile.Mandos.Client"
 
1230
    
1221
1231
    # dbus.service.Object doesn't use super(), so we can't either.
1222
1232
    
1223
1233
    def __init__(self, bus = None, *args, **kwargs):
1235
1245
    
1236
1246
    def notifychangeproperty(transform_func,
1237
1247
                             dbus_name, type_func=lambda x: x,
1238
 
                             variant_level=1):
 
1248
                             variant_level=1, invalidate_only=False,
 
1249
                             _interface=_interface):
1239
1250
        """ Modify a variable so that it's a property which announces
1240
1251
        its changes to DBus.
1241
1252
        
1252
1263
                if (not hasattr(self, attrname) or
1253
1264
                    type_func(getattr(self, attrname, None))
1254
1265
                    != type_func(value)):
1255
 
                    dbus_value = transform_func(type_func(value),
1256
 
                                                variant_level
1257
 
                                                =variant_level)
1258
 
                    self.PropertyChanged(dbus.String(dbus_name),
1259
 
                                         dbus_value)
 
1266
                    if invalidate_only:
 
1267
                        self.PropertiesChanged(_interface,
 
1268
                                               dbus.Dictionary(),
 
1269
                                               dbus.Array
 
1270
                                               ((dbus_name,)))
 
1271
                    else:
 
1272
                        dbus_value = transform_func(type_func(value),
 
1273
                                                    variant_level
 
1274
                                                    =variant_level)
 
1275
                        self.PropertyChanged(dbus.String(dbus_name),
 
1276
                                             dbus_value)
 
1277
                        self.PropertiesChanged(_interface,
 
1278
                                               dbus.Dictionary({
 
1279
                                    dbus.String(dbus_name):
 
1280
                                        dbus_value }), dbus.Array())
1260
1281
            setattr(self, attrname, value)
1261
1282
        
1262
1283
        return property(lambda self: getattr(self, attrname), setter)
1300
1321
                                    lambda td: td.total_seconds()
1301
1322
                                    * 1000)
1302
1323
    checker_command = notifychangeproperty(dbus.String, "Checker")
 
1324
    secret = notifychangeproperty(dbus.ByteArray, "Secret",
 
1325
                                  invalidate_only=True)
1303
1326
    
1304
1327
    del notifychangeproperty
1305
1328
    
1352
1375
        self.send_changedstate()
1353
1376
    
1354
1377
    ## D-Bus methods, signals & properties
1355
 
    _interface = "se.recompile.Mandos.Client"
1356
1378
    
1357
1379
    ## Interfaces
1358
1380
    
1359
 
    @dbus_interface_annotations(_interface)
1360
 
    def _foo(self):
1361
 
        return { "org.freedesktop.DBus.Property.EmitsChangedSignal":
1362
 
                     "false"}
1363
 
    
1364
1381
    ## Signals
1365
1382
    
1366
1383
    # CheckerCompleted - signal
1376
1393
        pass
1377
1394
    
1378
1395
    # PropertyChanged - signal
 
1396
    @dbus_annotations({"org.freedesktop.DBus.Deprecated": "true"})
1379
1397
    @dbus.service.signal(_interface, signature="sv")
1380
1398
    def PropertyChanged(self, property, value):
1381
1399
        "D-Bus signal"
2709
2727
            def GetAllClientsWithProperties(self):
2710
2728
                "D-Bus method"
2711
2729
                return dbus.Dictionary(
2712
 
                    ((c.dbus_object_path, c.GetAll(""))
2713
 
                     for c in tcp_server.clients.itervalues()),
 
2730
                    { c.dbus_object_path: c.GetAll("")
 
2731
                      for c in tcp_server.clients.itervalues() },
2714
2732
                    signature="oa{sv}")
2715
2733
            
2716
2734
            @dbus.service.method(_interface, in_signature="o")