title: Print out response of Dbus Method Call in C
body: <p>The problem I am having is <strong>specifically printing out the response of a dbus method call in C</strong> using the low level API. I am new to C's libdbus, but have done some work in python-dbus.</p>
  
  <ul>
  <li>I know how to write dbus methods and method calls in python as well as the CLI</li>
  <li>I can find code on the internet to invoke dbus methods, but they don't return or print out the response</li>
  <li>I have been looking at the libdbus doxygen api, but cannot determine how to pull out the response.</li>
  </ul>
  
  <p>The way I have my code set up, a python dbus daemon runs with methods I want to call. Some of them return a string. I want a C program to connect to the session bus, call the method, print out the reply and exit. </p>
  
  <p>This is what I have currently:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;dbus/dbus.h&gt;
  
  static void send_dbus_message (DBusConnection *connection, const char *msg)
  {
  DBusMessage *message;
  //initialize the message
  message = dbus_message_new_signal ("/org/example/foo/bar",
                                      "org.example.foo.bar",
                                      msg);
  
  //send the message
  dbus_connection_send (connection, message, NULL);
  //deallocate the message
  dbus_message_unref (message);
  }
  
  int main (int argc, char **argv)
  {
  DBusConnection *connection;
  DBusError error;
  
  //init error message
  dbus_error_init (&amp;error);
  connection = dbus_bus_get (DBUS_BUS_SESSION, &amp;error);
  if (!connection)
  {
      printf ("Connection to D-BUS daemon failed: %s", error.message);
  
      //deallocate error message
      dbus_error_free (&amp;error);
      return 1;
  }
  
  send_dbus_message (connection, "HelloWorld");
  return 0;
  }
  </code></pre>
  
  <p>Can be synchronous or asynchronous. </p>