diff options
| author | 2008-10-30 19:58:49 +0100 | |
|---|---|---|
| committer | 2008-10-30 20:00:55 +0100 | |
| commit | e46784e5cfe7dbf760d9ab3c0a31c95305a86808 (patch) | |
| tree | 3369724dd04d741fe5751a8157b799382183f42d /src/afccheck.c | |
| parent | 41778c3dcd0bf0ede8f526d9045a023a9188d455 (diff) | |
| download | libimobiledevice-e46784e5cfe7dbf760d9ab3c0a31c95305a86808.tar.gz libimobiledevice-e46784e5cfe7dbf760d9ab3c0a31c95305a86808.tar.bz2 | |
move dev specific tools to dev/ subdir.
update autoconf files accordingly
Diffstat (limited to 'src/afccheck.c')
| -rw-r--r-- | src/afccheck.c | 136 |
1 files changed, 0 insertions, 136 deletions
diff --git a/src/afccheck.c b/src/afccheck.c deleted file mode 100644 index e772d99..0000000 --- a/src/afccheck.c +++ /dev/null | |||
| @@ -1,136 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * afccheck.c | ||
| 3 | * creates threads and check communication through AFC is done rigth | ||
| 4 | * | ||
| 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | #include <glib.h> | ||
| 25 | |||
| 26 | #include "usbmux.h" | ||
| 27 | #include "iphone.h" | ||
| 28 | #include <libiphone/libiphone.h> | ||
| 29 | |||
| 30 | #define BUFFER_SIZE 20000 | ||
| 31 | #define NB_THREADS 10 | ||
| 32 | |||
| 33 | int debug = 0; | ||
| 34 | |||
| 35 | typedef struct { | ||
| 36 | iphone_afc_client_t afc; | ||
| 37 | int id; | ||
| 38 | } param; | ||
| 39 | |||
| 40 | |||
| 41 | void check_afc(gpointer data) | ||
| 42 | { | ||
| 43 | //prepare a buffer | ||
| 44 | int buffersize = BUFFER_SIZE * sizeof(int); | ||
| 45 | int *buf = (int *) malloc(buffersize); | ||
| 46 | int *buf2 = (int *) malloc(buffersize); | ||
| 47 | int bytes = 0; | ||
| 48 | //fill buffer | ||
| 49 | int i = 0; | ||
| 50 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 51 | buf[i] = ((param *) data)->id * i; | ||
| 52 | } | ||
| 53 | |||
| 54 | //now writes buffer on iphone | ||
| 55 | iphone_afc_file_t file = NULL; | ||
| 56 | char path[50]; | ||
| 57 | sprintf(path, "/Buf%i", ((param *) data)->id); | ||
| 58 | iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_WRITE, &file); | ||
| 59 | iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); | ||
| 60 | iphone_afc_close_file(((param *) data)->afc, file); | ||
| 61 | file = NULL; | ||
| 62 | if (bytes != buffersize) | ||
| 63 | printf("Write operation failed\n"); | ||
| 64 | |||
| 65 | //now read it | ||
| 66 | bytes = 0; | ||
| 67 | iphone_afc_open_file(((param *) data)->afc, path, IPHONE_AFC_FILE_READ, &file); | ||
| 68 | iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); | ||
| 69 | iphone_afc_close_file(((param *) data)->afc, file); | ||
| 70 | if (bytes != buffersize) | ||
| 71 | printf("Read operation failed\n"); | ||
| 72 | |||
| 73 | //compare buffers | ||
| 74 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 75 | if (buf[i] != buf2[i]) { | ||
| 76 | printf("Buffers are differents, stream corrupted\n"); | ||
| 77 | break; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | //cleanup | ||
| 82 | iphone_afc_delete_file(((param *) data)->afc, path); | ||
| 83 | g_thread_exit(0); | ||
| 84 | } | ||
| 85 | |||
| 86 | int main(int argc, char *argv[]) | ||
| 87 | { | ||
| 88 | iphone_lckd_client_t control = NULL; | ||
| 89 | iphone_device_t phone = NULL; | ||
| 90 | GError *err; | ||
| 91 | int port = 0; | ||
| 92 | iphone_afc_client_t afc = NULL; | ||
| 93 | |||
| 94 | if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { | ||
| 95 | printf("No iPhone found, is it plugged in?\n"); | ||
| 96 | return 1; | ||
| 97 | } | ||
| 98 | |||
| 99 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 100 | iphone_free_device(phone); | ||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | |||
| 104 | if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) { | ||
| 105 | iphone_lckd_free_client(control); | ||
| 106 | iphone_free_device(phone); | ||
| 107 | fprintf(stderr, "Something went wrong when starting AFC."); | ||
| 108 | return 1; | ||
| 109 | } | ||
| 110 | |||
| 111 | iphone_afc_new_client(phone, 3432, port, &afc); | ||
| 112 | |||
| 113 | //makes sure thread environment is available | ||
| 114 | if (!g_thread_supported()) | ||
| 115 | g_thread_init(NULL); | ||
| 116 | |||
| 117 | GThread *threads[NB_THREADS]; | ||
| 118 | param data[NB_THREADS]; | ||
| 119 | |||
| 120 | int i = 0; | ||
| 121 | for (i = 0; i < NB_THREADS; i++) { | ||
| 122 | data[i].afc = afc; | ||
| 123 | data[i].id = i + 1; | ||
| 124 | threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err); | ||
| 125 | } | ||
| 126 | |||
| 127 | for (i = 0; i < NB_THREADS; i++) { | ||
| 128 | g_thread_join(threads[i]); | ||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | iphone_lckd_free_client(control); | ||
| 133 | iphone_free_device(phone); | ||
| 134 | |||
| 135 | return 0; | ||
| 136 | } | ||
