#include #include #include #include DBusConnection* conn = NULL; //Helper function to setup connection void vsetupconnection(); //Send method call, Returns NULL on failure, else pointer to reply DBusMessage* sendMethodCall(const char* objectpath, \ const char* busname, \ const char* interfacename, \ const char* methodname); #define TEST_BUS_NAME "fi.w1.wpa_supplicant1" #define TEST_OBJ_PATH "/fi/w1/wpa_supplicant1/Interfaces/5" #define TEST_INTERFACE_NAME "fi.w1.wpa_supplicant1.Interface" #define TEST_METHOD_NAME "SignalPoll" int main (int argc, char **argv) { int i; vsetupconnection(); for(i = 0; i < 500000; i++) { DBusMessage* reply = sendMethodCall(TEST_OBJ_PATH, TEST_BUS_NAME, TEST_INTERFACE_NAME, TEST_METHOD_NAME); if(reply != NULL) { printf("%d got result\n",i); dbus_message_unref(reply);//unref reply } else printf("%d null replay\n",i); } //dbus_connection_close(conn); return 0; } void vsetupconnection() { DBusError err; // initialise the errors dbus_error_init(&err); // connect to session bus conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); if (dbus_error_is_set(&err)) { printf("Connection Error (%s)\n", err.message); dbus_error_free(&err); } if (NULL == conn) { exit(1); } else { printf("Connected to system bus\n"); } } DBusMessage* sendMethodCall(const char* objectpath, const char* busname, const char* interfacename, const char* methodname) { assert(objectpath != NULL); assert(busname != NULL); assert(interfacename != NULL); assert(methodname != NULL); assert(conn != NULL); DBusMessage* methodcall = dbus_message_new_method_call(busname,objectpath, interfacename, methodname); if (methodcall == NULL) { printf("Cannot allocate DBus message!\n"); } //Now do a sync call DBusPendingCall* pending; DBusMessage* reply; if (!dbus_connection_send_with_reply(conn, methodcall, &pending, -1))//Send and expect reply using pending call object { printf("failed to send message!\n"); } dbus_connection_flush(conn); dbus_message_unref(methodcall); methodcall = NULL; dbus_pending_call_block(pending);//Now block on the pending call reply = dbus_pending_call_steal_reply(pending);//Get the reply message from the queue dbus_pending_call_unref(pending);//Free pending call handle assert(reply != NULL); if(dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { printf("Error : %s",dbus_message_get_error_name(reply)); dbus_message_unref(reply); reply = NULL; } return reply; }