RE: Confusing about DBus API specification
On Thu, 2010-04-29 at 21:33 -0700, Nguyen Canh Toan wrote: Dear Dan, I do understand these fundamental concepts. Thank for your useful tutorial anyway. I think my problem is I do not understand object as well as interface hierarchy exposed by NetworkManager DBus service. According to API spec here (http://projects.gnome.org/NetworkManager/developers/spec-07.html#org.freede sktop.NetworkManager) and (http://live.gnome.org/NetworkManager/SystemSetting). I understand it as below: 1. Service DBus named org.freedesktop.NetworkManagerSystemSetting and org.freedesktop.NetworkManagerUserSetting is one which I need to connect to inorder to get connection configuration. Right, these are the service names/bus names that you need to talk to. 2. Get org.freedesktop.NetworkManagerSettings interface of service proxy Correct; *both* services implement this common interface, since they provide essentially the same information. This way you only write the code once, and you can talk to both services easily. 3. Invoke ListConnection() on returned interface. I think you mean ListConnections(), but yes. It seems that your API spec isn't very clear so newcomers, like me, get confused when doing with this. Yeah, I think what would be helpful is a general overview in the spec or such about how the pieces fit together, possibly with a diagram and some code examples. I've done a bit of that and I'm about to post something to my blog, which we can then rework into some documentation. There are various pages around that explain things, but mostly general overviews and concepts and not really with code examples. Here's one I whipped up yesterday: http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/python/list-connections.py There's a lot of improvement possible here, especially with examples. Please instruct me how to get used particularly this service. Or please make your spec more clearly. I shall try. Contributions and constructive criticism welcome, like you've done above by pointing out that it's not clear how to talk to the settings services. Dan ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Confusing about DBus API specification
2010/4/29 Nguyen Canh Toan toan...@viettel.com.vn Hi all, After reading DBus API http://projects.gnome.org/NetworkManager/developers/spec-07.html#org.freedesktop.NetworkManager I try to list all connection setting by below interface specification * * *org.freedesktop.NetworkManagerSettings* The NetworkManagerSettings interface is provided by the service which provides connections to NetworkManager. Methods: ListConnections ( ) → ao List the connections stored by this Settings object. Returns connections - ao List of connections. Signals: NewConnection ( o: connection ) Emitted when a new connection has been configured. Parameters connection - o Object path of the new connection. Interface has no properties. *Without success. *DBus service say: Traceback (most recent call last): File ./python_dbus_client, line 21, in module connections = manager.ListConnections() File /var/lib/python-support/python2.6/dbus/proxies.py, line 140, in __call__ **keywords) File /var/lib/python-support/python2.6/dbus/connection.py, line 622, in call_blocking message, timeout) *dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method ListConnections with signature on interface org.freedesktop.NetworkManager doesn't exist* That's because ListConnections is a method of the org.freedesktop.NetworkManagerSettings interface ;) Try executing your method as: connections = manager.ListConnections(dbus_interface= org.freedesktop.NetworkManagerSettings) Best regards, -- Pablo Martí // http://minimoesfuerzo.org python -c print '706d617267616d40676d61696c2e636f6d'.decode('hex') ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
RE: Confusing about DBus API specification
Thank Pablo for quickly reply, I think I am misunderstanding something. I have rewritten my script as your advice but I still error. Here is my short script: #!/usr/bin/env python import dbus bus = dbus.SystemBus() proxy = bus.get_object(org.freedesktop.NetworkManager, /org/freedesktop/NetworkManager) proxy_prop = dbus.Interface(proxy, org.freedesktop.DBus.Properties) manager = dbus.Interface(proxy, org.freedesktop.NetworkManager) settings = dbus.Interface(proxy, org.freedesktop.NetworkManagerSettings) #active connection connections = proxy_prop.Get(org.freedesktop.NetworkManager, ActiveConnections) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessHardwareEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, State) for con in connections: print %s % con con_obj = bus.get_object(org.freedesktop.NetworkManager, con) print list connection connections = manager.ListConnections(dbus_interface=org.freedesktop.NetworkManagerSettin gs) for con in connections: print %s % con It till say: toa...@vt_ttpm_rd_toannc5:~/Desktop$ ./python_dbus_client 1 1 3 /org/freedesktop/NetworkManager/ActiveConnection/1 list connection Traceback (most recent call last): File ./python_dbus_client, line 21, in module connections = manager.ListConnections(dbus_interface=org.freedesktop.NetworkManagerSettin gs) File /var/lib/python-support/python2.6/dbus/proxies.py, line 140, in __call__ **keywords) File /var/lib/python-support/python2.6/dbus/connection.py, line 622, in call_blocking message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method ListConnections with signature on interface org.freedesktop.NetworkManagerSettings doesn't exist Please help. _ From: Pablo Martí Gamboa [mailto:pma...@warp.es] Sent: Tuesday, April 27, 2010 11:41 PM To: Nguyen Canh Toan Cc: networkmanager-list@gnome.org Subject: Re: Confusing about DBus API specification 2010/4/29 Nguyen Canh Toan toan...@viettel.com.vn Hi all, After reading DBus API http://projects.gnome.org/NetworkManager/developers/spec-07.html#org.freedes ktop.NetworkManager I try to list all connection setting by below interface specification org.freedesktop.NetworkManagerSettings The NetworkManagerSettings interface is provided by the service which provides connections to NetworkManager. Methods: ListConnections ( ) → ao List the connections stored by this Settings object. Returns connections - ao List of connections. Signals: NewConnection ( o: connection ) Emitted when a new connection has been configured. Parameters connection - o Object path of the new connection. Interface has no properties. Without success. DBus service say: Traceback (most recent call last): File ./python_dbus_client, line 21, in module connections = manager.ListConnections() File /var/lib/python-support/python2.6/dbus/proxies.py, line 140, in __call__ **keywords) File /var/lib/python-support/python2.6/dbus/connection.py, line 622, in call_blocking message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method ListConnections with signature on interface org.freedesktop.NetworkManager doesn't exist That's because ListConnections is a method of the org.freedesktop.NetworkManagerSettings interface ;) Try executing your method as: connections = manager.ListConnections(dbus_interface=org.freedesktop.NetworkManagerSettin gs) Best regards, -- Pablo Martí // http://minimoesfuerzo.org python -c print '706d617267616d40676d61696c2e636f6d'.decode('hex') ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
Re: Confusing about DBus API specification
ListConnections() method is not provided by /org/freedesktop/NetworkManager service, rather /org/freedesktop/NetworkManagerSystemSettings and org.freedesktop.NetworkManagerUserSettings. See inline comments to adapt your script. On Thursday 29 of April 2010 11:05:13 Nguyen Canh Toan wrote: Thank Pablo for quickly reply, I think I am misunderstanding something. I have rewritten my script as your advice but I still error. Here is my short script: #!/usr/bin/env python import dbus bus = dbus.SystemBus() proxy = bus.get_object(org.freedesktop.NetworkManager, /org/freedesktop/NetworkManager) add here proxy1 = bus.get_object(org.freedesktop.NetworkManagerUserSettings, /org/freedesktop/NetworkManagerSettings) for listing user connections or proxy1 = bus.get_object(org.freedesktop.NetworkManagerSystemSettings, /org/freedesktop/NetworkManagerSettings) for listing system-wide connections. proxy_prop = dbus.Interface(proxy, org.freedesktop.DBus.Properties) manager = dbus.Interface(proxy, org.freedesktop.NetworkManager) settings = dbus.Interface(proxy, org.freedesktop.NetworkManagerSettings) You need to use proxy1 here instead of proxy. settings = dbus.Interface(proxy1, org.freedesktop.NetworkManagerSettings) #active connection connections = proxy_prop.Get(org.freedesktop.NetworkManager, ActiveConnections) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessHardwareEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, State) for con in connections: print %s % con con_obj = bus.get_object(org.freedesktop.NetworkManager, con) print list connection connections = manager.ListConnections(dbus_interface=org.freedesktop.NetworkManagerSetti n gs) this line should look like this: connections = settings.ListConnections() i.e. using settings interface and no arguments to ListConnections() for con in connections: print %s % con Jirka ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
RE: Confusing about DBus API specification
Dear Jirka, It's weird. After adjusting my script, it's still error: [Here is new script:] #!/usr/bin/env python import dbus bus = dbus.SystemBus() proxy = bus.get_object(org.freedesktop.NetworkManager, /org/freedesktop/NetworkManager) proxy_prop = dbus.Interface(proxy, org.freedesktop.DBus.Properties) manager = dbus.Interface(proxy, org.freedesktop.NetworkManager) #proxy_user_setting = bus.get_object(org.freedesktop.NetworkManagerUserSettings, /org/freedesktop/NetworkManagerUserSettings) proxy_sys_setting = bus.get_object(org.freedesktop.NetworkManagerSystemSettings, /org/freedesktop/NetworkManagerSystemSettings) settings = dbus.Interface(proxy_sys_setting, org.freedesktop.NetworkManagerSettings) print = active connection connections = proxy_prop.Get(org.freedesktop.NetworkManager, ActiveConnections) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessHardwareEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, State) for con in connections: print %s % con con_obj = bus.get_object(org.freedesktop.NetworkManager, con) print == list connection connections = settings.ListConnections() for con in connections: print %s % con [Here is log:] toa...@vt_ttpm_rd_toannc5:~/Desktop$ ./python_dbus_client = active connection 1 1 3 == list connection Traceback (most recent call last): File ./python_dbus_client, line 25, in module connections = settings.ListConnections() File /var/lib/python-support/python2.6/dbus/proxies.py, line 68, in __call__ return self._proxy_method(*args, **keywords) File /var/lib/python-support/python2.6/dbus/proxies.py, line 140, in __call__ **keywords) File /var/lib/python-support/python2.6/dbus/connection.py, line 622, in call_blocking message, timeout) dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Method ListConnections with signature on interface org.freedesktop.NetworkManagerSettings doesn't exist Please help. -Original Message- From: Jirka Klimes [mailto:jkli...@redhat.com] Sent: Wednesday, April 28, 2010 1:18 AM To: networkmanager-list@gnome.org Cc: Nguyen Canh Toan; 'Pablo Martí Gamboa' Subject: Re: Confusing about DBus API specification ListConnections() method is not provided by /org/freedesktop/NetworkManager service, rather /org/freedesktop/NetworkManagerSystemSettings and org.freedesktop.NetworkManagerUserSettings. See inline comments to adapt your script. On Thursday 29 of April 2010 11:05:13 Nguyen Canh Toan wrote: Thank Pablo for quickly reply, I think I am misunderstanding something. I have rewritten my script as your advice but I still error. Here is my short script: #!/usr/bin/env python import dbus bus = dbus.SystemBus() proxy = bus.get_object(org.freedesktop.NetworkManager, /org/freedesktop/NetworkManager) add here proxy1 = bus.get_object(org.freedesktop.NetworkManagerUserSettings, /org/freedesktop/NetworkManagerSettings) for listing user connections or proxy1 = bus.get_object(org.freedesktop.NetworkManagerSystemSettings, /org/freedesktop/NetworkManagerSettings) for listing system-wide connections. proxy_prop = dbus.Interface(proxy, org.freedesktop.DBus.Properties) manager = dbus.Interface(proxy, org.freedesktop.NetworkManager) settings = dbus.Interface(proxy, org.freedesktop.NetworkManagerSettings) You need to use proxy1 here instead of proxy. settings = dbus.Interface(proxy1, org.freedesktop.NetworkManagerSettings) #active connection connections = proxy_prop.Get(org.freedesktop.NetworkManager, ActiveConnections) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessHardwareEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, WirelessEnabled) print %d % proxy_prop.Get(org.freedesktop.NetworkManager, State) for con in connections: print %s % con con_obj = bus.get_object(org.freedesktop.NetworkManager, con) print list connection connections = manager.ListConnections(dbus_interface=org.freedesktop.NetworkManagerSetti n gs) this line should look like this: connections = settings.ListConnections() i.e. using settings interface and no arguments to ListConnections() for con in connections: print %s % con Jirka ___ networkmanager-list mailing list networkmanager-list@gnome.org http://mail.gnome.org/mailman/listinfo/networkmanager-list
RE: Confusing about DBus API specification
On Thu, 2010-04-29 at 06:08 -0700, Nguyen Canh Toan wrote: Dear Jirka, It's weird. After adjusting my script, it's still error: D-Bus is simply an IPC mechanism, but it layers a few concepts on top of pure message-passing, as explained below. It did take me some time to understand how the D-Bus object model really works, so don't worry about it you don't completely understand how it all works yet. 1) 'service': a program that responds to requests from clients. Each service is identified by a bus name which clients use to find the service and send requests to it. The bus name usually looks like org.foobar.Baz. A program can claim more than one bus name; NM claims org.freedesktop.NetworkManager and org.freedesktop.NetworkManagerSystemSettings, each is a unique serivce which provides different functionality to clients. 2) 'object': a method of organizing distinct entities, much like programming languages have objects. Each object is uniquely identified by an object path (basically a pointer) that looks like /org/foobar/Baz/235235. Each request sent to the service must be directed to a specific object. Many services have a base object with a well-known path that you use to bootstrap your communication with the service. 3) 'interface': each request belongs to an interface, which is simply a way of logically separating different functionality. The same way that object-oriented languages like Java or C++ or GLib define an interface; a specific API that different objects can implement, but the caller doesn't need to know what type the object is, just the interface. Interface names often look like D-Bus service names, but have no relation to them. 4) 'method call': a request for an operation or information that a client sends to the service; method calls are defined by an Interface and are sent to objects. Say you have a binary called mcdonaldsd that provides a D-Bus service called org.fastfood.McDonalds. Clients that want to talk to this service use org.fastfood.McDonalds to direct requests to mcdonaldsd. mcdonaldsd provides a base object called /org/fastfood/McDonalds. This object implements the org.fastfood.McDonalds interface, which defines the method calls: - GetItems(void) - ao - Order(ao) - b GetItems returns an array of object-paths representing all the things on the menu that you can order. So if you call it you'll get something like this returned: [ '/org/fastfood/McDonalds/Item/0', '/org/fastfood/McDonalds/Item/1' ] Each of these returned object paths is a pointer to an object; mcdonaldsd probably even implements these as objects internally using Java or C++ or GObject or whatever. These objects are probably completely different (one may be a burger, one may be a drink) but they all implement a common interface org.fastfood.McDonalds.Item. The org.fastfood.McDonalds.Item interface has the following method calls: - GetName - GetType (either TYPE_BURGER, TYPE_DRINK, or TYPE_FRIES) - GetPrice - Consume So even if you don't know what /org/fastfood/McDonalds/Item/0 is, you still can get a lot of information about it, enough to decide whether you want to order it or not. Assume that item 0 is a BigMac and item 1 is Coke. These are clearly different objects, but each still has a name, a calorie count, a price, and can be consumed. Next, since each item is different (even though they all implement the common org.fastfood.McDonalds.Item interface) each item type will implement other interfaces that define functionality specific to that type of item. So item 0 (BigMac) implements the org.fastfood.McDonalds.Item.Burger interface which has the following methods: - Unwrap - AddMustard - RemovePickle (nobody likes those stupid limp pickles anyway) And item 1 (Coke) implements the org.fastfood.McDonalds.Item.Drink interface which has the following methods: - PutLidOn - InsertStraw - RemoveStraw Remember, since both objects *also* implement the base org.fastfood.McDonalds.Item interface, you can use the Consume() method to consume both items. But clearly, you don't want to include the InsertStraw() method on the generic org.fastfood.McDonalds.Item interface, because all items implement that interface, and it would be pretty funny if you tried to call InsertStraw() on the BigMac object. People would stare. So interfaces are about logically separating method calls that have specific functionality, and thus any object that wants that functionality can implement that interface, instead of having every object type duplicate all the calls of that interface. So, with pseudocode: # Get local proxy for the remove mcdonaldsd service bus = get_service(org.fastfood.McDonalds) mcds = bus.get_object(org.fastfood.McDonalds, /org/fastfood/McDonalds) burger_path = None drink_path = None # Lets read all the menu items menu_items = mcds.GetItems() for object_path in menu_items: item = bus.get_object(org.fastfood.McDonalds.Item, object_path) print Item: %s price
RE: Confusing about DBus API specification
Dear Dan, I do understand these fundamental concepts. Thank for your useful tutorial anyway. I think my problem is I do not understand object as well as interface hierarchy exposed by NetworkManager DBus service. According to API spec here (http://projects.gnome.org/NetworkManager/developers/spec-07.html#org.freede sktop.NetworkManager) and (http://live.gnome.org/NetworkManager/SystemSetting). I understand it as below: 1. Service DBus named org.freedesktop.NetworkManagerSystemSetting and org.freedesktop.NetworkManagerUserSetting is one which I need to connect to inorder to get connection configuration. 2. Get org.freedesktop.NetworkManagerSettings interface of service proxy 3. Invoke ListConnection() on returned interface. It seems that your API spec isn't very clear so newcomers, like me, get confused when doing with this. Please instruct me how to get used particularly this service. Or please make your spec more clearly. Thank for your time consideration. Toan Nguyen -Original Message- From: Dan Williams [mailto:d...@redhat.com] Sent: Wednesday, April 28, 2010 11:52 AM To: Nguyen Canh Toan Cc: jkli...@redhat.com; networkmanager-list@gnome.org Subject: RE: Confusing about DBus API speciDan Williams [d...@redhat.com]fication On Thu, 2010-04-29 at 06:08 -0700, Nguyen Canh Toan wrote: Dear Jirka, It's weird. After adjusting my script, it's still error: D-Bus is simply an IPC mechanism, but it layers a few concepts on top of pure message-passing, as explained below. It did take me some time to understand how the D-Bus object model really works, so don't worry about it you don't completely understand how it all works yet. 1) 'service': a program that responds to requests from clients. Each service is identified by a bus name which clients use to find the service and send requests to it. The bus name usually looks like org.foobar.Baz. A program can claim more than one bus name; NM claims org.freedesktop.NetworkManager and org.freedesktop.NetworkManagerSystemSettings, each is a unique serivce which provides different functionality to clients. 2) 'object': a method of organizing distinct entities, much like programming languages have objects. Each object is uniquely identified by an object path (basically a pointer) that looks like /org/foobar/Baz/235235. Each request sent to the service must be directed to a specific object. Many services have a base object with a well-known path that you use to bootstrap your communication with the service. 3) 'interface': each request belongs to an interface, which is simply a way of logically separating different functionality. The same way that object-oriented languages like Java or C++ or GLib define an interface; a specific API that different objects can implement, but the caller doesn't need to know what type the object is, just the interface. Interface names often look like D-Bus service names, but have no relation to them. 4) 'method call': a request for an operation or information that a client sends to the service; method calls are defined by an Interface and are sent to objects. Say you have a binary called mcdonaldsd that provides a D-Bus service called org.fastfood.McDonalds. Clients that want to talk to this service use org.fastfood.McDonalds to direct requests to mcdonaldsd. mcdonaldsd provides a base object called /org/fastfood/McDonalds. This object implements the org.fastfood.McDonalds interface, which defines the method calls: - GetItems(void) - ao - Order(ao) - b GetItems returns an array of object-paths representing all the things on the menu that you can order. So if you call it you'll get something like this returned: [ '/org/fastfood/McDonalds/Item/0', '/org/fastfood/McDonalds/Item/1' ] Each of these returned object paths is a pointer to an object; mcdonaldsd probably even implements these as objects internally using Java or C++ or GObject or whatever. These objects are probably completely different (one may be a burger, one may be a drink) but they all implement a common interface org.fastfood.McDonalds.Item. The org.fastfood.McDonalds.Item interface has the following method calls: - GetName - GetType (either TYPE_BURGER, TYPE_DRINK, or TYPE_FRIES) - GetPrice - Consume So even if you don't know what /org/fastfood/McDonalds/Item/0 is, you still can get a lot of information about it, enough to decide whether you want to order it or not. Assume that item 0 is a BigMac and item 1 is Coke. These are clearly different objects, but each still has a name, a calorie count, a price, and can be consumed. Next, since each item is different (even though they all implement the common org.fastfood.McDonalds.Item interface) each item type will implement other interfaces that define functionality specific to that type of item. So item 0 (BigMac) implements the org.fastfood.McDonalds.Item.Burger interface which has the following methods: - Unwrap - AddMustard - RemovePickle (nobody likes those