@@ -278,32 +278,40 @@ func (p *Properties) Introspection(iface string) []introspect.Property {
278
278
279
279
// set sets the given property and emits PropertyChanged if appropriate. p.mut
280
280
// must already be locked.
281
- func (p * Properties ) set (iface , property string , v interface {}) error {
282
- prop := p.m [iface ][property ]
283
- err := dbus .Store ([]interface {}{v }, prop .Value )
281
+ func (p * Properties ) set (iface string , properties []string , v ... interface {}) error {
282
+ var props []interface {}
283
+ for _ , property := range properties {
284
+ props = append (props , p.m [iface ][property ].Value )
285
+ }
286
+ err := dbus .Store (v , props ... )
284
287
if err != nil {
285
288
return err
286
289
}
287
- return p .emitChange (iface , property )
290
+ return p .emitChange (iface , properties ... )
288
291
}
289
292
290
- func (p * Properties ) emitChange (iface , property string ) error {
291
- prop := p.m [iface ][property ]
292
- switch prop .Emit {
293
- case EmitFalse :
294
- return nil // do nothing
295
- case EmitInvalidates :
296
- return p .conn .Emit (p .path , "org.freedesktop.DBus.Properties.PropertiesChanged" ,
297
- iface , map [string ]dbus.Variant {}, []string {property })
298
- case EmitTrue :
299
- return p .conn .Emit (p .path , "org.freedesktop.DBus.Properties.PropertiesChanged" ,
300
- iface , map [string ]dbus.Variant {property : dbus .MakeVariant (prop .Value )},
301
- []string {})
302
- case EmitConst :
303
- return nil
304
- default :
305
- panic ("invalid value for EmitType" )
293
+ func (p * Properties ) emitChange (iface string , properties ... string ) error {
294
+ changes := make (map [string ]dbus.Variant )
295
+ invalidates := []string {}
296
+
297
+ for _ , property := range properties {
298
+ prop := p.m [iface ][property ]
299
+ switch prop .Emit {
300
+ case EmitFalse :
301
+ return nil // do nothing
302
+ case EmitInvalidates :
303
+ invalidates = append (invalidates , property )
304
+ case EmitTrue :
305
+ changes [property ] = dbus .MakeVariant (prop .Value )
306
+ case EmitConst :
307
+ return nil
308
+ default :
309
+ panic ("invalid value for EmitType" )
310
+ }
306
311
}
312
+
313
+ return p .conn .Emit (p .path , "org.freedesktop.DBus.Properties.PropertiesChanged" ,
314
+ iface , changes , invalidates )
307
315
}
308
316
309
317
// Set implements org.freedesktop.Properties.Set.
@@ -330,7 +338,7 @@ func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error
330
338
return err
331
339
}
332
340
}
333
- if err := p .set (iface , property , newv .Value ()); err != nil {
341
+ if err := p .set (iface , [] string { property } , newv .Value ()); err != nil {
334
342
return dbus .MakeFailedError (err )
335
343
}
336
344
return nil
@@ -341,7 +349,25 @@ func (p *Properties) Set(iface, property string, newv dbus.Variant) *dbus.Error
341
349
func (p * Properties ) SetMust (iface , property string , v interface {}) {
342
350
p .mut .Lock ()
343
351
defer p .mut .Unlock () // unlock in case of panic
344
- err := p .set (iface , property , v )
352
+ err := p .set (iface , []string {property }, v )
353
+ if err != nil {
354
+ panic (err )
355
+ }
356
+ }
357
+
358
+ // SetMustMany sets the values of the given property value map and panics if any interface or
359
+ // property name are invalid.
360
+ func (p * Properties ) SetMustMany (iface string , newValues map [string ]interface {}) {
361
+ p .mut .Lock ()
362
+ defer p .mut .Unlock ()
363
+
364
+ properties := make ([]string , 0 , len (newValues ))
365
+ values := make ([]interface {}, 0 , len (newValues ))
366
+ for key , val := range newValues {
367
+ properties = append (properties , key )
368
+ values = append (values , val )
369
+ }
370
+ err := p .set (iface , properties , values ... )
345
371
if err != nil {
346
372
panic (err )
347
373
}
0 commit comments