Active Topics

 


Reply
Thread Tools
hopbeat's Avatar
Posts: 516 | Thanked: 643 times | Joined on Oct 2009 @ Denmark/Poland
#1
Hello,

I'm a noob in D-bus handling, so please, be patient.

I'm trying to do as simple thing, namely to write a C program that would invoke a remote method and would handle the response.
I would like to implement this call (provided by @qwerty12):

Code:
Nokia-N900-42-11:~# dbus-send --system --print-reply --type=method_call --dest='com.nokia.phone.net' /com/nokia/phone/net Phone.Net.get_registration_status
method return sender=:1.17 -> dest=:1.539 reply_serial=2
   byte 0
   uint16 1002
   uint32 799685
   uint32 20
   uint32 238
   byte 0
   byte 3
   int32 0
When trying to use

Code:
msg = dbus_message_new_method_call("com.nokia.phone.net", 
                                      "/com/nokia/phone/net",
                                      "Phone.Net", 
                                      "get_registration_status");
I don't get any result (or I cannot handle it). Can someone point me in the right direction? It should be straightforward, but I cannot figure this out.

Thanks!

[edit] This is the function I'm using:

Code:
void query(char* param)
{
   DBusMessage* msg;
   DBusMessageIter args;
   DBusConnection* conn;
   DBusError err;
   DBusPendingCall* pending;
   int ret;
   char stat;
   dbus_uint16_t level;

   printf("Calling remote method with %s\n", param);

   // initialiset the errors
   dbus_error_init(&err);

   // connect to the system bus and check for errors
   conn = dbus_bus_get(DBUS_BUS_SESSION, &err);
   if (dbus_error_is_set(&err)) {
      fprintf(stderr, "Connection Error (%s)\n", err.message);
      dbus_error_free(&err);
   }
   if (NULL == conn) {
      exit(1);
   }

   // request our name on the bus
   ret = dbus_bus_request_name(conn, "test.method.caller", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
   if (dbus_error_is_set(&err)) {
      fprintf(stderr, "Name Error (%s)\n", err.message);
      dbus_error_free(&err);
   }
   if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
      exit(1);
   }



   msg = dbus_message_new_method_call("com.nokia.phone.net", // target for the method call
                                      "/com/nokia/phone/net", // object to call on
                                      "Phone.Net", // interface to call on
                                      "get_registration_status"); // method name
   if (NULL == msg) {
      fprintf(stderr, "Message Null\n");
      exit(1);
// send message and get a handle for a reply
   if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
      fprintf(stderr, "Out Of Memory!\n");
      exit(1);
   }
   if (NULL == pending) {
      fprintf(stderr, "Pending Call Null\n");
      exit(1);
   }
   dbus_connection_flush(conn);

   printf("Request Sent\n");

   // free message
   dbus_message_unref(msg);

   // block until we recieve a reply
   dbus_pending_call_block(pending);

   // get the reply message
   msg = dbus_pending_call_steal_reply(pending);
   if (NULL == msg) {
      fprintf(stderr, "Reply Null\n");
      exit(1);
   }
   // free the pending message handle
   dbus_pending_call_unref(pending);

   // read the parameters
   if (!dbus_message_iter_init(msg, &args))
      fprintf(stderr, "Message has no arguments!\n");
 //  else if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&args))
   //   fprintf(stderr, "Argument is not boolean!\n");
   else
      dbus_message_iter_get_basic(&args, &stat);

   if (!dbus_message_iter_next(&args))
      fprintf(stderr, "Message has too few arguments!\n");
   else if (DBUS_TYPE_UINT16 != dbus_message_iter_get_arg_type(&args))
      fprintf(stderr, "Argument is not int!\n");
   else
      dbus_message_iter_get_basic(&args, &level);





   printf("Got Reply: %d, %d\n", stat, level);

   // free reply
   dbus_message_unref(msg);
}
The reply I get:
Code:
Nokia-N900-42-11:/home/user# ./dbus.out query
Calling remote method with no param
Request Sent
Message has too few arguments!
Got Reply: 12, 0
[edit2] I have changed the bus to the system one, but it doesn't solve anything...
__________________
Hi! I'm a Maemo Greeter!
Witaj na talk.maemo.org!

Useful links for newcomers:
Użyteczne linki:
Nowi użyktownicy mówią cześć | New members say hello , Tu zaczynają nowi użytkownicy | New users start here, Podforum społeczności | Community subforum, Wiki dla początkujących | Beginners' wiki page, Maemo5 101, Często zadawane pytania | Frequently Asked Questions (FAQ), Google

Jeżeli mogę w czymś pomóc, pytaj!
If I can help with anything else, just ask!

Bored? Follow me

Last edited by hopbeat; 2009-11-21 at 21:23.
 
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#2
I'm a GLib whore, so I'ma use the DBus-GLib bindings:

http://slexy.org/view/s2HUwWewVX

Compile with: "gcc -Wall cellid_example.c -o cellid_example `pkg-config --cflags --libs glib-2.0 dbus-glib-1`"

This produces the following output:

~ $ /sdk/cellid_example
Cell ID obtained via requesting for it: 8503
~ $ dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_registration_status
method return sender=:1.16 -> dest=:1.631 reply_serial=2
<cut>
uint32 8503
</cut>
You will have noticed that I have a define - LISTEN_FOR_CHANGES. If you wish to listen to the Cell ID being changed, you can do this:

* Save http://slexy.org/view/s2WhO33Yr3 as marshal.list
* Run: "glib-genmarshal --prefix=marshal marshal.list --header > marshal.h && glib-genmarshal --prefix=marshal marshal.list --body > marshal.c"
* Compile with: "gcc -Wall cellid_example.c -o cellid_example `pkg-config --cflags --libs glib-2.0 dbus-glib-1` -DLISTEN_FOR_CHANGES marshal.c marshal.h"

This produces the following output:
~ $ /sdk/cellid_example
Cell ID obtained via requesting for it: 8503
<Going Offline>
<Coming Online>
Cell ID obtained from notification of its change: 8503
Cell ID obtained from notification of its change: 8503
Cell ID obtained from notification of its change: 8503
Cell ID obtained from notification of its change: 8503
<Ctrl-C>
~ $ dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.net /com/nokia/phone/net Phone.Net.get_registration_status
method return sender=:1.16 -> dest=:1.704 reply_serial=2
<cut>
uint32 8503
</cut>
 

The Following 11 Users Say Thank You to qwerty12 For This Useful Post:
hopbeat's Avatar
Posts: 516 | Thanked: 643 times | Joined on Oct 2009 @ Denmark/Poland
#3
Thanks, you're amazing

I have managed to make it kinda-working in low level, I will post the code for future reference when/if I'm done with it.
__________________
Hi! I'm a Maemo Greeter!
Witaj na talk.maemo.org!

Useful links for newcomers:
Użyteczne linki:
Nowi użyktownicy mówią cześć | New members say hello , Tu zaczynają nowi użytkownicy | New users start here, Podforum społeczności | Community subforum, Wiki dla początkujących | Beginners' wiki page, Maemo5 101, Często zadawane pytania | Frequently Asked Questions (FAQ), Google

Jeżeli mogę w czymś pomóc, pytaj!
If I can help with anything else, just ask!

Bored? Follow me
 

The Following User Says Thank You to hopbeat For This Useful Post:
hopbeat's Avatar
Posts: 516 | Thanked: 643 times | Joined on Oct 2009 @ Denmark/Poland
#4
This is a working low-level example of the dbus-method call (without arguments):

http://slexy.org/view/s2rHWulgQW

not as elegant as the one by @qwerty12, but it works fairly well.
__________________
Hi! I'm a Maemo Greeter!
Witaj na talk.maemo.org!

Useful links for newcomers:
Użyteczne linki:
Nowi użyktownicy mówią cześć | New members say hello , Tu zaczynają nowi użytkownicy | New users start here, Podforum społeczności | Community subforum, Wiki dla początkujących | Beginners' wiki page, Maemo5 101, Często zadawane pytania | Frequently Asked Questions (FAQ), Google

Jeżeli mogę w czymś pomóc, pytaj!
If I can help with anything else, just ask!

Bored? Follow me
 

The Following 2 Users Say Thank You to hopbeat For This Useful Post:
hopbeat's Avatar
Posts: 516 | Thanked: 643 times | Joined on Oct 2009 @ Denmark/Poland
#5
Now, another problem (I'm a very troubled man, I know )

WLAN scanning: the request for scanning is sent via method call, the result is obtained via a signal.

I have fixed a Python example so now it works with N900:

http://slexy.org/view/s25h3to4Rr

I however have a problem translating it to C.

To get the results of scanning, we first need to request the scan:
Code:
dbus-send --system --dest=com.nokia.wlancond --type=method_call --print-reply /com/nokia/wlancond/request com.nokia.wlancond.request.scan int32:4 array:byte:0 int32:2
And then get the signal from
Code:
com.nokia.wlancond.signal, scan_results
I would really appreciate some help in making this work, hopefully after those interfaces are done with, people will be able to use this as an API.
__________________
Hi! I'm a Maemo Greeter!
Witaj na talk.maemo.org!

Useful links for newcomers:
Użyteczne linki:
Nowi użyktownicy mówią cześć | New members say hello , Tu zaczynają nowi użytkownicy | New users start here, Podforum społeczności | Community subforum, Wiki dla początkujących | Beginners' wiki page, Maemo5 101, Często zadawane pytania | Frequently Asked Questions (FAQ), Google

Jeżeli mogę w czymś pomóc, pytaj!
If I can help with anything else, just ask!

Bored? Follow me

Last edited by hopbeat; 2009-11-24 at 06:01.
 
Posts: 2 | Thanked: 3 times | Joined on Jan 2010
#6
Is there a ref for Dbus methods and signals. What I am looking for specifcally is GSM network parameters. ARFCN, BSIC, MCC,MNC,LAC,CID, C1,C2, RSSI, Neighbor list measurements, cell reselect hist, etc...
I'm not even sure if all of these are available through Dbus but I would appreciate if someone could point me in the right direction.
 
Posts: 10 | Thanked: 5 times | Joined on Jan 2010 @ Tasmania, Australia
#7
Originally Posted by cmbennett View Post
Is there a ref for Dbus methods and signals? [...] I would appreciate if someone could point me in the right direction.
+1 on this. I would've thought there was a list somewhere of at least com.nokia.* dbus methods available. The closest I've found is a user-compiled list on the wiki[1] which is quite helpful but clearly incomplete. Aside from that my google-fu is failing me .

Anyone have any thoughts?

[1] http://wiki.maemo.org/User:Jebba/DBUS
 
Posts: 2 | Thanked: 3 times | Joined on Jan 2010
#8
with dbus-monitor (below) I get updates for signal strength changes and MCC,MNC,LAC,CID when the phone is on line (the signal strength and operator are diplayed and updated on the desktop) but for the other network parameters like ARFCN, TA, C1, C2 and neighbor lists etc. If they are available I imagine you would need to call a specific method.

Code:
signal sender=:1.18 -> dest=(null destination) serial=1582 path=/com/nokia/phone/net; interface=Phone.Net; member=signal_strength_change
   byte 100 # signal strength percentage ?
   byte 74  # signal strength in dbm ?
signal sender=:1.18 -> dest=(null destination) serial=1583 path=/com/nokia/phone/net; interface=Phone.Net; member=cell_info_change
   byte 1       # ?
   uint16 8370  # LAC
   uint32 11101 # CID
   uint32 260	# MNC
   uint32 310	# MCC
   byte 0       # ?
   byte 0       # ?
signal sender=:1.18 -> dest=(null destination) serial=1584 path=/com/nokia/phone/net; interface=Phone.Net; member=registration_status_change
   byte 0
   uint16 8370
   uint32 11101
   uint32 260
   uint32 310
   byte 0
   byte 7
signal sender=:1.18 -> dest=(null destination) serial=1585 path=/com/nokia/phone/net; interface=Phone.Net; member=operator_name_change
   byte 10     # ?
   string "T - Mobile"
   string ""
   uint32 260  # MNC
   uint32 310  # MCC
 

The Following 3 Users Say Thank You to cmbennett For This Useful Post:
Posts: 12 | Thanked: 10 times | Joined on Dec 2010
#9
Originally Posted by cmbennett View Post
with dbus-monitor (below) I get updates for signal strength changes and MCC,MNC,LAC,CID when the phone is on line (the signal strength and operator are diplayed and updated on the desktop) but for the other network parameters like ARFCN, TA, C1, C2 and neighbor lists etc. If they are available I imagine you would need to call a specific method.
I need to launch a script whenever there's a change in Cell Info. Do you know how to do it via dbus signals?

Is it safe to edit /etc/dbus-1/event.d ? is there a dbus-daemon-launch-helper? how does it work?

I've already played with /etc/event.d with relative success. Is it similar to /etc/dbus-1/event.d? where can I find an example of such a config file?

I've read that it's not good to play with dbus, but I should use Telepathy. How does it work? how can I use the command line to control the phone without using dbus methods and signals?

Thank you for your answers.
 
Reply


 
Forum Jump


All times are GMT. The time now is 08:18.