Em Wednesday 21 December 2011, devine-ml...@ddevnet.net escreveu:
>  I have hacked up the change-ipv4-address.cpp example in an attempt to
>  make it so that the program takes an interface name such as "eth0" and
>  changes the IP address instead of a UUID.
>  The problem is:
>  "Error: could not update connection:
>  org.freedesktop.DBus.Error.UnknownMethod Method "Update" with signature
>  "a{sa{sv}}" on interface
>  "org.freedesktop.NetworkManager.Settings.Connection" doesn't exist"

        change-ipv4-address.cpp was created to work with NM 0.9. If you are 
using NM 0.8 it will not work.
 
>  This comes from a piece of code that I did not change and should work
>  the same as the original - unless I have really misunderstood something.
>  Surfing around using the qdbus tool I noticed that I could not get to
>  the Settings methods. I could only get
>  org.freedesktop.NetworkManager.Device.* stuff.
> 
>  qdbus --system org.freedesktop.NetworkManager
>  /org/freedesktop/NetworkManager/Devices/0
>  org.freedesktop.NetworkManager.[no Settings methods here!]

        You should use the Settings path to get the settings for a connection:

qdbus --system org.freedesktop.NetworkManager 
 /org/freedesktop/NetworkManager/Settings/0

        Although that is not very usefull since the most important methods in 
the Settings object uses "custom" objects" which qdbus does not understand.

        You should try QtNetworkManager instead of creating your program from 
scratch:

https://projects.kde.org/projects/kdereview/libnm-qt

        QtNetworkManager make those details transparent. Unfortunately there is 
not small example of how to use it. I use it in Plasma NetworkManagement, but 
Plasma NM is a big program. If you want to try take a look at manager.h and 
connection.h, those probably contain the methods you are looking for.

        OBS: the link above may change to 
https://projects.kde.org/projects/extragear/base/libnm-qt in some weeks.

>  Example code:
>  http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/C/
> qt/change-ipv4-addresses.cpp
> 
> 
>  My code:
>  ===================================
> 
>  #include <QtDBus/QDBusConnection>
>  #include <QtDBus/QDBusInterface>
>  #include <QtDBus/QDBusMetaType>
>  #include <QtDBus/QDBusReply>
>  #include <QtCore/QList>
>  #include <QtCore/QMap>
>  #include <QtCore/QString>
>  #include <QtCore/QDebug>
>  #include <QtNetwork/QHostAddress>
> 
>  #include "arpa/inet.h"
> 
>  #include "NetworkManager.h"
> 
>  typedef QMap<QString, QMap<QString, QVariant> > Connection;
>  Q_DECLARE_METATYPE(Connection)
>  Q_DECLARE_METATYPE(QList<uint>);
>  Q_DECLARE_METATYPE(QList<QList<uint> >);
> 
> 
>  QString ifaceNameToPath(const QString& iface_name){
>          // Set up DBus interface to org.freedesktop.NetworkManager
>          QDBusInterface interface(
>                  NM_DBUS_SERVICE,
>                  NM_DBUS_PATH,
>                  NM_DBUS_INTERFACE,
>                  QDBusConnection::systemBus());
> 
>          // Call GetDevicesByIpIface using iface_name
>          QDBusReply<QDBusObjectPath> path =
>  interface.call("GetDeviceByIpIface", iface_name);
>          qDebug() << path.value().path();
>          // return the path.
>          return path.value().path();
>  }
> 
> 
>  void changeConnection(const QString& ifname)
>  {
>      // Register types with D-Bus
>      qDBusRegisterMetaType<Connection>();
>      qDBusRegisterMetaType<QList<uint> >();
>      qDBusRegisterMetaType<QList<QList<uint> > >();
> 
>      Connection connection;
>      QString conPath;
> 
>      // Find connection by provided UUID
>      conPath = ifaceNameToPath(ifname);
>      qDebug() << "Derp conPath " << conPath << " ifname was " << ifname;
>      if (!conPath.isEmpty()) {
>          QList<QList<uint> > addresses;
>          QList<uint> addr1, addr2;
> 
>          // Add some addresses
>          addr1 << htonl(QHostAddress("192.168.1.105").toIPv4Address());
>          addresses << addr1;
> 
>          // Set method to "Manual" and put addresses to the connection
>  map
>          connection["ipv4"]["method"] = "manual";
>          connection["ipv4"]["addresses"] =
>  QVariant::fromValue(addresses);
> 
>          QDBusInterface interface(
>              NM_DBUS_SERVICE,
>              conPath,
>              NM_DBUS_IFACE_SETTINGS_CONNECTION,
>              QDBusConnection::systemBus());
> 
>          // Call Update() D-Bus method to update connection
>          QDBusReply<void> result = interface.call("Update",
>  QVariant::fromValue(connection));
>          if (result.isValid()) {
>              qDebug() << QString("Connection successfully updated (path
>  %1)").arg(conPath);
>          } else {
>             qDebug() << QString("Error: could not update connection: %1
>  %2").arg(result.error().name()).arg(result.error().message());
>          }
>      } else {
>              qDebug() << QString("Error: connection with name '%1' not
>  found").arg(ifname);
>      }
>  }
> 
>  int main(int argc, char *argv[])
>  {
>      if (argc != 2) {
>          qDebug() << QString("Usage: %1 <UUID>").arg(argv[0]);
>          return -1;
>      }
> 
>      changeConnection(argv[1]);
>  }
> 
>  --Daniel Devine
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list


-- 
Lamarque V. Souza
KDE's Network Management maintainer
http://planetkde.org/pt-br
_______________________________________________
networkmanager-list mailing list
networkmanager-list@gnome.org
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to