int main(int argc, char const *argv[]) { glyr_init(); atexit(glyr_cleanup); if(argc > 1) { GlyrDatabase *db = glyr_db_init(argv[1]); if(db != NULL) { if(argv[2] != NULL && strcmp(argv[2], "delete") == 0) { do_delete = true; } glyr_db_foreach(db, foreach_callback, db); } else { g_message("Could not open DB at %s", argv[1]); } } else { g_message("Usage: %s /path/to/db/directory [delete]", argv[0]); } return EXIT_SUCCESS; }
int main(void) { g_thread_init(NULL); glyr_init(); atexit(glyr_cleanup); /* Create a new async queue */ FinishedNotify notify; notify.queue = g_async_queue_new(); notify.counter = 0; /* Initialize a new thread */ GError * err = NULL; GThread * apollo = g_thread_create(apollo_orbiter,¬ify,TRUE,&err); if(apollo != NULL) { /* Push a few jobs */ GlyrQuery one,two,three; build_queries(&one,&two,&three); g_async_queue_push(notify.queue,&one ); g_async_queue_push(notify.queue,&two ); g_async_queue_push(notify.queue,&three); #define ABORT_IMMEDIATELY FALSE #if ABORT_IMMEDIATELY /* Test if it really aborts immediately, if not it crashes :-) */ g_async_queue_push(notify.queue,(gpointer)0x2); #endif /* Terminate by pushing a special value */ g_async_queue_push(notify.queue,THREAD_TERMINATOR); #if ABORT_IMMEDIATELY /* Sort the THREAD_TERMINATOR before anything else. */ g_async_queue_sort(notify.queue,sort_async_queue_jobs,NULL); #endif /* Wait till he finished */ g_thread_join(apollo); } else { g_printerr("Could not create thread: %s\n",err->message); g_error_free(err); } g_async_queue_unref(notify.queue); return EXIT_SUCCESS; }
int main (void) { /* Init this thing, the only two methods not being threadsafe */ glyr_init(); /* Also clear ressources on exit */ atexit (glyr_cleanup); /* This struct is used to store all settings you do via glyr_opt_* */ GlyrQuery q; /* We also should set it to standard values */ glyr_query_init (&q); /* We want lyrics, well, I want. */ glyr_opt_type (&q,GLYR_GET_LYRICS); /* Set random artist/title - you could also omit the album line */ glyr_opt_artist (&q, (char*) "Die Ärzte"); glyr_opt_album (&q, (char*) "Die Bestie in Menschengestalt"); glyr_opt_title (&q, (char*) "FaFaFa"); /* If any error occured it will be saved here, or GLYRE_OK */ /* You could have also passed a NULL pointer to glyr_get() if you're not interested in this */ GLYR_ERROR err; /* Now get the job done! The 3rd */ GlyrMemCache * head = glyr_get (&q,&err,NULL); /* The results are stored in the GlyrMemCache struct - you are most likely only interested in the fields data, size and type*/ if (head != NULL) { /* head contains also a pointer to the next element, you can use it therefore as linkedlist */ // puts(head->data); glyr_cache_print (head); /* We have to free it again also, you can pass ANY pointer of the list, it works in both directions */ glyr_free_list (head); } /* glyr_query_init may allocate memory - free it. */ glyr_query_destroy (&q); return err; }
int main(int argc, const char *argv[]) { /* We need to init first*/ glyr_init(); atexit(glyr_cleanup); GlyrFetcherInfo * info = glyr_info_get(); if(info != NULL) { /* Iterate over all getters */ for(GlyrFetcherInfo * elem0 = info; elem0; elem0 = elem0->next) { /* Iterate over all providers */ g_print(" %s => %d\n",elem0->name,elem0->type); for(GlyrSourceInfo * elem1 = elem0->head; elem1; elem1 = elem1->next) { g_print(" # %s [%c]\n",elem1->name,elem1->key); g_print(" - Quality: %d\n",elem1->quality); g_print(" - Speed: %d\n",elem1->speed); g_print(" - Type: %d\n",elem1->type); } /* Test which fields are required for a certain getter */ g_print(" + Requires: (%s%s%s)\n", elem0->reqs & GLYR_REQUIRES_ARTIST ? "Artist " : "", elem0->reqs & GLYR_REQUIRES_ALBUM ? "Album " : "", elem0->reqs & GLYR_REQUIRES_TITLE ? "Title" : "" ); /* And which are optional? */ g_print(" + Optional: (%s%s%s)\n", elem0->reqs & GLYR_OPTIONAL_ARTIST ? "Artist " : "", elem0->reqs & GLYR_OPTIONAL_ALBUM ? "Album " : "", elem0->reqs & GLYR_OPTIONAL_TITLE ? "Title" : "" ); g_print("\n///////////////////////////////\n"); } } glyr_info_free(info); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { /* You need to call this before anything happens */ glyr_init(); atexit(glyr_cleanup); /* Initialize a new query (this may allocate memory) */ GlyrQuery q; glyr_query_init(&q); /* Say we want a Songtext */ GLYR_GET_TYPE type = GLYR_GET_LYRICS; glyr_opt_type(&q, type); /* Set at least the required fields to your needs * * For lyrics those are 'artist' and 'title', ('album') * * is strictly optional and may be used by a few plugins */ glyr_opt_artist(&q, (char *) "Die Apokalyptischen Reiter"); glyr_opt_album(&q, (char *) "Riders on the Storm"); glyr_opt_title(&q, (char *) "Friede sei mit dir"); /* Execute a func when getting one item */ int this_be_my_counter = 0; glyr_opt_dlcallback(&q, funny_callback, &this_be_my_counter); /* For the start: Enable verbosity */ glyr_opt_verbosity(&q, 2); /* Download 5 (or less) items */ glyr_opt_number(&q, 5); /* Just search, without downloading items */ glyr_opt_download(&q, 0); /* Call the most important command: GET! * This returned a list of (GlyrMemCache *)s * Each containing ONE item. (i.e. a songtext) */ GLYR_ERROR err; GlyrMemCache *it = glyr_get(&q, &err, NULL); if(err != GLYRE_OK) { fprintf(stderr, "E:%s\n", glyr_strerror(err)); } /* Now iterate through it... */ if(it != NULL) { GlyrMemCache *start = it; int counter = 0; while(it != NULL) { /* This has the same effect as in the callback, * Just that it's executed just once after all DL is done. * Commented out, as this would print it twice * */ print_item(it, counter); /* Every cache has a link to the next and prev one (or NULL respectively) */ it = it->next; ++counter; } /* The contents of it are dynamically allocated. */ /* So better free them if you're not keen on memoryleaks */ glyr_free_list(start); } /* Destroy query (reset to default values and free dyn memory) */ /* You could start right off to use this query in another glyr_get */ glyr_query_destroy(&q); return EXIT_SUCCESS; }