#include #include #include #include #ifndef TRUE #define TRUE 0x01 #endif /* Private calls ------------------------------------------------ */ static usage(FILE * stream, char * command) { fprintf(stream, "Usage : %s \n", command); } static void display_error(DBusError *perr, const char * message) { if (dbus_error_is_set(perr) == TRUE) { fprintf(stderr, "%s : %s\n",message, perr->message); dbus_error_free(perr); } else fprintf(stderr, "%s\n", message); } /* The main ---------------------------------------------------- */ int main(int argc, char *argv[]) { DBusConnection *conn; DBusError err; DBusMessage * msg, * reply; DBusMessageIter iter, dict, entry, value; char * address, * file; int ret = 0; unsigned int serial; if (argc != 3) { fprintf(stderr, "Invalid parameters count !\n"); usage(stderr, argv[0]); exit(EXIT_FAILURE); } address = argv[1]; file = argv[2]; dbus_error_init(&err); /* Connect the session bus */ conn = dbus_bus_get(DBUS_BUS_SESSION, &err); if (conn == NULL) { display_error(&err, "Cannot connect session bus"); exit(EXIT_FAILURE); } else printf("Obex puller : session bus connected\n"); /* Create the message to be sent */ msg = dbus_message_new_method_call("org.openobex.client", "/", "org.openobex.Client", "PullBusinessCard"); if ( !msg ) { fprintf(stderr, "Cannot allocate call method PullBusinessCard\n"); dbus_connection_unref(conn); exit(EXIT_FAILURE); } dbus_message_iter_init_append(msg, &iter); /* Add the destination argument */ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); char * key = "Destination"; dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); char sig[2] = { DBUS_TYPE_STRING, '\0' }; dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, sig, &value); dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &address); dbus_message_iter_close_container(&entry, &value); dbus_message_iter_close_container(&dict, &entry); dbus_message_iter_close_container(&iter, &dict); /* Add the file argument */ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &file); printf("Obex puller : message created\n"); /* Send the message */ if ( !dbus_connection_send(conn, msg, &serial) ) { fprintf(stderr, "Cannot send the message (serial=%u)\n", serial); dbus_message_unref(msg); dbus_connection_unref(conn); ret = EXIT_FAILURE; } #if 0 if ((reply = dbus_connection_send_with_reply_and_block(conn, msg, 60000, &err)) == NULL) { display_error(&err, "Cannot send the message !"); ret = EXIT_FAILURE; } #endif else printf("Obex puller : message sent\n"); dbus_message_unref(msg); dbus_connection_flush(conn); /* Disconnect */ dbus_connection_unref(conn); printf("Obex puller : disconnected\n"); return ret; }