int main(int argc, const char** argv) { // To track progress: // naip-sample naip.xml | tee log.txt // tail -f log.txt if(argc != 2) { LOGE("usage: %s <naip.xml>", argv[0]); return EXIT_FAILURE; } glist = a3d_list_new(); if(glist == NULL) { return EXIT_FAILURE; } if(naip_readXml(argv[1]) == 0) { goto fail_xml; } naip_sampleStart(); naip_deleteList(); // success return EXIT_SUCCESS; // failure fail_xml: naip_deleteList(); return EXIT_FAILURE; }
a3d_listbox_t* a3d_listbox_new(a3d_screen_t* screen, int wsize, int orientation, int anchor, int wrapx, int wrapy, int stretch_mode, float stretch_factor, int style_border, int style_line, a3d_vec4f_t* color_fill, a3d_vec4f_t* color_line, a3d_widget_reflow_fn reflow_fn, a3d_widget_refresh_fn refresh_fn) { // reflow_fn, refresh_fn may be NULL assert(screen); assert(color_fill); assert(color_line); LOGD("debug wsize=%i, orientation=%i, anchor=%i, wrapx=%i, wrapy=%i", wsize, orientation, anchor, wrapx, wrapy); LOGD("debug stretch_mode=%i, stretch_factor=%f, style_border=%i, style_line=%i", stretch_mode, stretch_factor, style_border, style_line); LOGD("debug color_fill: r=%f, g=%f, b=%f, a=%f", color_fill->r, color_fill->g, color_fill->b, color_fill->a); LOGD("debug color_line: r=%f, g=%f, b=%f, a=%f", color_line->r, color_line->g, color_line->b, color_line->a); if(wsize == 0) { wsize = sizeof(a3d_listbox_t); } // optionally overide refresh_fn if(refresh_fn == NULL) { refresh_fn = a3d_listbox_refresh; } a3d_listbox_t* self = (a3d_listbox_t*) a3d_widget_new(screen, wsize, anchor, wrapx, wrapy, stretch_mode, stretch_factor, style_border, style_line, color_line, color_fill, reflow_fn, a3d_listbox_size, a3d_listbox_click, a3d_listbox_layout, a3d_listbox_drag, a3d_listbox_draw, a3d_listbox_fade, refresh_fn); if(self == NULL) { return NULL; } a3d_widget_soundFx((a3d_widget_t*) self, 0); self->list = a3d_list_new(); if(self->list == NULL) { goto fail_list; } a3d_list_notify(self->list, (void*) self, a3d_listbox_notify, a3d_listbox_notify, a3d_listbox_notify); self->orientation = orientation; // success return self; // failure fail_list: a3d_widget_delete((a3d_widget_t**) &self); return NULL; }
a3d_workq_t* a3d_workq_new(void* owner, int thread_count, a3d_workqrun_fn run_fn, a3d_workqpurge_fn purge_fn) { // owner may be NULL assert(run_fn); assert(purge_fn); LOGD("debug"); a3d_workq_t* self = (a3d_workq_t*) malloc(sizeof(a3d_workq_t)); if(!self) { LOGE("malloc failed"); return NULL; } self->state = A3D_WORKQ_RUNNING; self->owner = owner; self->purge_id = 0; self->thread_count = thread_count; self->next_tid = 0; self->run_fn = run_fn; self->purge_fn = purge_fn; // PTHREAD_MUTEX_DEFAULT is not re-entrant if(pthread_mutex_init(&self->mutex, NULL) != 0) { LOGE("pthread_mutex_init failed"); goto fail_mutex_init; } if(pthread_cond_init(&self->cond_pending, NULL) != 0) { LOGE("pthread_cond_init failed"); goto fail_cond_pending; } if(pthread_cond_init(&self->cond_complete, NULL) != 0) { LOGE("pthread_cond_init failed"); goto fail_cond_complete; } self->queue_pending = a3d_list_new(); if(self->queue_pending == NULL) { goto fail_queue_pending; } self->queue_complete = a3d_list_new(); if(self->queue_complete == NULL) { goto fail_queue_complete; } self->queue_active = a3d_list_new(); if(self->queue_active == NULL) { goto fail_queue_active; } // alloc threads int sz = thread_count*sizeof(pthread_t); self->threads = (pthread_t*) malloc(sz); if(self->threads == NULL) { LOGE("malloc failed"); goto fail_threads; } // create threads pthread_mutex_lock(&self->mutex); int i; for(i = 0; i < thread_count; ++i) { if(pthread_create(&(self->threads[i]), NULL, a3d_workq_thread, (void*) self) != 0) { LOGE("pthread_create failed"); goto fail_pthread_create; } } pthread_mutex_unlock(&self->mutex); // success return self; // fail fail_pthread_create: self->state = A3D_WORKQ_STOP; pthread_mutex_unlock(&self->mutex); int j; for(j = 0; j < i; ++j) { pthread_join(self->threads[j], NULL); } free(self->threads); fail_threads: a3d_list_delete(&self->queue_active); fail_queue_active: a3d_list_delete(&self->queue_complete); fail_queue_complete: a3d_list_delete(&self->queue_pending); fail_queue_pending: pthread_cond_destroy(&self->cond_complete); fail_cond_complete: pthread_cond_destroy(&self->cond_pending); fail_cond_pending: pthread_mutex_destroy(&self->mutex); fail_mutex_init: free(self); return NULL; }
a3d_layer_t* a3d_layer_new(a3d_screen_t* screen, int wsize, int anchor, int wrapx, int wrapy, int stretch_mode, float stretch_factor, int style_border, int style_line, a3d_vec4f_t* color_fill, a3d_vec4f_t* color_line, int mode) { assert(screen); assert(color_fill); assert(color_line); LOGD("debug wsize=%i, anchor=%i, wrapx=%i, wrapy=%i", wsize, anchor, wrapx, wrapy); LOGD("debug stretch_mode=%i, stretch_factor=%f, style_border=%i, style_line=%i", stretch_mode, stretch_factor, style_border, style_line); LOGD("debug color_fill: r=%f, g=%f, b=%f, a=%f", color_fill->r, color_fill->g, color_fill->b, color_fill->a); LOGD("debug color_line: r=%f, g=%f, b=%f, a=%f", color_line->r, color_line->g, color_line->b, color_line->a); if(wsize == 0) { wsize = sizeof(a3d_layer_t); } a3d_layer_t* self = (a3d_layer_t*) a3d_widget_new(screen, wsize, anchor, wrapx, wrapy, stretch_mode, stretch_factor, style_border, style_line, color_line, color_fill, NULL, a3d_layer_size, a3d_layer_click, a3d_layer_layout, a3d_layer_drag, a3d_layer_draw, a3d_layer_fade, a3d_layer_refresh); if(self == NULL) { return NULL; } a3d_widget_soundFx((a3d_widget_t*) self, 0); self->list = a3d_list_new(); if(self->list == NULL) { goto fail_list; } self->mode = mode; a3d_list_notify(self->list, (void*) self, a3d_layer_notify, a3d_layer_notify, a3d_layer_notify); // success return self; // failure fail_list: a3d_widget_delete((a3d_widget_t**) &self); return NULL; }
a3d_textbox_t* a3d_textbox_new(a3d_screen_t* screen, int wsize, int orientation, int anchor, int wrapx, int wrapy, int stretch_mode, float stretch_factor, int style_border, int style_line, a3d_vec4f_t* color_fill, a3d_vec4f_t* color_line, int text_anchor, int text_wrapx, int text_style_border, int text_style_line, int text_style_text, a3d_vec4f_t* text_color_fill, a3d_vec4f_t* text_color_line, a3d_vec4f_t* text_color_text, int text_max_len) { assert(screen); assert(color_fill); assert(color_line); assert(text_color_fill); assert(text_color_line); assert(text_color_text); LOGD("debug wsize=%i, orientation=%i, anchor=%i, wrapx=%i, wrapy=%i", wsize, orientation, anchor, wrapx, wrapy); LOGD("debug stretch_mode=%i, stretch_factor=%f, style_border=%i, style_line=%i", stretch_mode, stretch_factor, style_border, style_line); LOGD("debug color_fill: r=%f, g=%f, b=%f, a=%f", color_fill->r, color_fill->g, color_fill->b, color_fill->a); LOGD("debug color_line: r=%f, g=%f, b=%f, a=%f", color_line->r, color_line->g, color_line->b, color_line->a); LOGD("text_anchor=%i, text_style_border=%i, text_style_line=%i, text_style_text=%i", text_anchor, text_style_border, text_style_line, text_style_text); LOGD("debug color_fill: r=%f, g=%f, b=%f, a=%f", color_fill->r, color_fill->g, color_fill->b, color_fill->a); LOGD("debug color_line: r=%f, g=%f, b=%f, a=%f", color_line->r, color_line->g, color_line->b, color_line->a); LOGD("debug color_text: r=%f, g=%f, b=%f, a=%f", color_text->r, color_text->g, color_text->b, color_text->a); LOGD("debug text_max_len=%i", text_max_len); if(wsize == 0) { wsize = sizeof(a3d_textbox_t); } a3d_widget_reflow_fn reflow_fn = a3d_textbox_reflow; if(wrapx == A3D_WIDGET_WRAP_SHRINK) { reflow_fn = NULL; } a3d_textbox_t* self; self = (a3d_textbox_t*) a3d_listbox_new(screen, wsize, orientation, anchor, wrapx, wrapy, stretch_mode, stretch_factor, style_border, style_line, color_fill, color_line, reflow_fn, NULL); if(self == NULL) { return NULL; } self->strings = a3d_list_new(); if(self->strings == NULL) { goto fail_strings; } self->dirty = 1; self->last_w = 0.0f; self->last_h = 0.0f; self->anchor = text_anchor; self->text_wrapx = text_wrapx; self->style_border = text_style_border; self->style_line = text_style_line; self->style_text = text_style_text; self->max_len = text_max_len; a3d_vec4f_copy(text_color_fill, &self->color_fill); a3d_vec4f_copy(text_color_line, &self->color_line); a3d_vec4f_copy(text_color_text, &self->color_text); // success return self; // failure fail_strings: a3d_listbox_delete((a3d_listbox_t**) &self); return NULL; }
int a3d_multimap_add(a3d_multimap_t* self, const void* val, const char* key) { assert(self); assert(val); assert(key); a3d_listitem_t* item; // check if the list already exists a3d_hashmapIter_t iter; a3d_list_t* list; list = (a3d_list_t*) a3d_hashmap_find(self->hash, &iter, key); if(list && self->compare) { item = a3d_list_insertSorted(list, self->compare, val); if(item == NULL) { return 0; } return 1; } else if(list) { item = a3d_list_append(list, NULL, val); if(item == NULL) { return 0; } return 1; } // create a new list and add to hash list = a3d_list_new(); if(list == NULL) { return 0; } item = a3d_list_append(list, NULL, val); if(item == NULL) { goto fail_append; } if(a3d_hashmap_add(self->hash, (const void*) list, key) == 0) { goto fail_add; } // success return 1; // failure fail_add: a3d_list_remove(list, &item); fail_append: a3d_list_delete(&list); return 0; }