Re: org.freedesktop.NetworkManager.Settings.PropertiesChanged deprecated



On Donnerstag, 15. Juli 2021 09:17:00 CEST Andrei Borzenkov wrote:
On Wed, Jul 14, 2021 at 5:52 PM Thomas Haller via networkmanager-list

<networkmanager-list gnome org> wrote:
So, yes, there should be not much to do except replace the interface
name "org.freedesktop.NetworkManager*" with
"org.freedesktop.DBus.Properties".

It is probably oversimplified. Signatures are different, so any code
that handles these signals has to be modified to account for it. Also
NM signal unambiguously identifies a specific interface, while D-Bus
signal can come from any interface object implements, so additional
verification that we are dealing with the expected interface is needed
before properties can be interpreted.

I'm not sure, if I really did it right, but this one seems to work as expected 
(at least as it did before):

!/usr/bin/perl -w

use strict;

use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
use Net::DBus;
use Net::DBus::Dumper;
use Net::DBus::Reactor;

my $oBUS = Net::DBus->system || die $!;
my $nm = "org.freedesktop.NetworkManager";
my $oNMSVC = $oBUS->get_service( $nm ) || die $!;

my $nmobjpath = "/org/freedesktop/NetworkManager";
my $nmif = "org.freedesktop.NetworkManager";
my $oNMIF = $oNMSVC->get_object( $nmobjpath, $nmif ) || die $!;

my $busif = "org.freedesktop.DBus.Properties";
my $oBUSIF = $oNMSVC->get_object( $nmobjpath, $busif );

$oBUSIF->connect_to_signal(
  "PropertiesChanged",
  sub {
    &{ \&dbnm_onNMPropertiesChanged }( $oNMSVC, $oNMIF, @_ );
  }
) || die $!;

my $reactor = Net::DBus::Reactor->main() || die $!;
$reactor->run() || die $!;

sub dbnm_onNMPropertiesChanged {

  my( $oNMSVC, $oNMIF, $props, $propsinval ) = @_;

  print "got `PropertiesChanged` signal for NetworkManager:\n";
  my $sprop = 'ActiveConnections';
  if( ref( $props ) eq 'HASH' ) {
    print "\n- props -\n", Dumper( $props ), "\n--\n";
    if( exists( $props->{ $sprop } ) ) {
      &dbnm_HandleAllActiveConnections(
        "PropertiesChanged (NM)", $props->{ $sprop }, $oNMSVC, $oNMIF
      );
    }
  } elsif( ref( $propsinval ) eq 'HASH' ) {
    print "\n- propsinval -\n", Dumper( $propsinval ), "\n--\n";
    if( exists( $propsinval->{ $sprop } ) ) {
      &dbnm_HandleAllActiveConnections(
        "PropertiesChanged (NM)", $propsinval->{ $sprop }, $oNMSVC, $oNMIF
      );
    }
  } else {
    print "WARNING: Expected some property hash, but got `",
          ref( $props ), "` and `", ref( $propsinval ), "`!\n";
  }

}

Thx to you both!

Bye.
Michael.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]