Skip to content

Commit

Permalink
Test functionality with libimobiledevice
Browse files Browse the repository at this point in the history
  • Loading branch information
riktov committed Apr 2, 2016
1 parent d6d72b7 commit eaf376d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ find_package(PkgConfig REQUIRED)

pkg_search_module(glib-2.0 REQUIRED glib-2.0)
pkg_search_module(libgpod-1.0 REQUIRED libgpod-1.0)
pkg_search_module(libimobiledevice-1.0 REQUIRED libimobiledevice-1.0)

#find_package(glib-2.0 REQUIRED glib-2.0)
include_directories(${libgpod-1.0_INCLUDE_DIRS})
include_directories(${libimobiledevice-1.0_INCLUDE_DIRS})

#set(LIBS ${LIBS} ${glib_LIBRARIES})

target_link_libraries(lsipod gpod glib-2.0)
target_link_libraries(lsipod gpod glib-2.0 imobiledevice)

install(TARGETS lsipod DESTINATION bin)
93 changes: 76 additions & 17 deletions lsipod.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ May be useful for copying from iPod to PC without using iTunes.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifdef __linux
#include <mntent.h>
Expand All @@ -20,6 +21,8 @@ May be useful for copying from iPod to PC without using iTunes.
#include <gpod/itdb.h>
//#include <glib-2.0/glib.h>

#include <libimobiledevice/libimobiledevice.h>

#include "lsipod.h"

struct match_table {
Expand All @@ -28,27 +31,32 @@ struct match_table {
char *album ;
} ;

void test() ;
void print_track(gpointer track, gpointer user_data) ;
void print_db_info(Itdb_iTunesDB *db) ;
void print_mounted_ipods() ;
int get_mounted_ipods(char *mounted_ipods[], size_t arr_size) ;
void list_ipod_contents(const char *mnt_point, const struct match_table *matches) ;
int is_rchr(const char *str, char c) ;
void test_imobiledevice() ;

GError *err ;



int main(int argc, char *argv[]) {
/*
if(argc > 2) {
}
}
*/

char *pa ;



test_imobiledevice() ;
exit(0) ;

//struct match_table matches ;

struct match_table matches =
Expand Down Expand Up @@ -265,14 +273,65 @@ void print_track(gpointer data, gpointer user_data) {
free(path) ;
}
}

void test() {
printf("%d\n", is_rchr("Foo/", 'c')) ;
exit(0) ;
}

int is_rchr(const char *str, char c) {
const char *r = strrchr(str, c) ;

return(r == str + strlen(str) - 1) ;
}

int is_rchr(const char *str, char c) {
const char *r = strrchr(str, c) ;

return(r == str + strlen(str) - 1) ;
}

void notify(const idevice_event_t *ev, void *user_data) {
enum idevice_event_type e = ev->event ;
const char * u = ev->udid ;

switch(e) {
case IDEVICE_DEVICE_ADD :
printf("Device added\n") ;
break;
case IDEVICE_DEVICE_REMOVE :
printf("Device removed\n") ;
break;
default :
printf("Unknown idevice_event_type\n") ;
}

printf("Device udid: %s with: %s\n", u, (char *)user_data) ;
}

void test_imobiledevice() {
char **device_udids ;
int count ;

char user_data[] = "Some user data" ;

idevice_event_subscribe(&notify, (void *)user_data) ;

idevice_error_t err = idevice_get_device_list(&device_udids, &count) ;

sleep(3) ;

if(err == IDEVICE_E_SUCCESS) {
printf("Found %d ilibmobile devices.\n", count) ;
for(int i = 0 ; i < count ; i++) {
uint32_t handle ;
idevice_t device ;

idevice_new(&device, device_udids[i]) ;
printf("Just called idevice_new()\n") ;

idevice_get_handle(device, &handle) ;
printf("Just called idevice_get_handle()\n") ;

//printf("%s with handle %d.\n", device_udids[i], handle) ;
idevice_free(device) ;
printf("Just called idevice_free()\n") ;

}
} else {
printf("ilibmobiledevice error\n") ;
}


idevice_device_list_free(device_udids) ;
idevice_event_unsubscribe() ;
}

0 comments on commit eaf376d

Please sign in to comment.