/** * Initialize a scope * * @return initialized scope */ scopes_tree scopes_tree_init (scopes_tree parent) /**< parent scope */ { scopes_tree tree = (scopes_tree) jsp_mm_alloc (sizeof (scopes_tree_int)); memset (tree, 0, sizeof (scopes_tree_int)); tree->t.parent = (tree_header *) parent; tree->t.children = null_list; tree->t.children_num = 0; if (parent != NULL) { if (parent->t.children_num == 0) { parent->t.children = linked_list_init (sizeof (scopes_tree)); } linked_list_set_element (parent->t.children, parent->t.children_num, &tree); void *added = linked_list_element (parent->t.children, parent->t.children_num); JERRY_ASSERT (*(scopes_tree *) added == tree); parent->t.children_num++; } tree->instrs_count = 0; tree->strict_mode = false; tree->ref_eval = false; tree->ref_arguments = false; tree->instrs = linked_list_init (sizeof (op_meta)); tree->var_decls_cout = 0; tree->var_decls = linked_list_init (sizeof (op_meta)); return tree; } /* scopes_tree_init */
int netbench_master_run(int rank, int clientsnb, options_t opts) { int tmp; struct linked_list *results; struct linked_list *process; results = linked_list_init(); process = linked_list_init(); tmp = 0; while (tmp < clientsnb) { if (tmp == rank) { tmp++; continue; } linked_list_add(process,linked_list_proc_value_init( netbench_comm_proc_recv(tmp) )); tmp++; } netbench_algo_run_master(NETBENCH_ALGO_MATRIX,results,clientsnb); netbench_printer_print(process, results, clientsnb,opts); linked_list_free(results); linked_list_free(process); return 0; }
static void osprd_setup(osprd_info_t *d) { /* Initialize the wait queue. */ init_waitqueue_head(&d->blockq); osp_spin_lock_init(&d->mutex); d->ticket_head = d->ticket_tail = 0; /* Add code here if you add fields to osprd_info_t. */ linked_list_init(&d->read_locking_pids); linked_list_init(&d->invalid_tickets); d->write_locking_pid = 0; d->passwd_hash = 0; }
AgpsStateMachine::AgpsStateMachine(servicerType servType, void *cb_func, AGpsExtType type, bool enforceSingleSubscriber) : mStatePtr(new AgpsReleasedState(this)),mType(type), mAPN(NULL), mAPNLen(0), mBearer(AGPS_APN_BEARER_INVALID), mEnforceSingleSubscriber(enforceSingleSubscriber), mServicer(Servicer :: getServicer(servType, (void *)cb_func)) { linked_list_init(&mSubscribers); // setting up mReleasedState mStatePtr->mPendingState = new AgpsPendingState(this); mStatePtr->mAcquiredState = new AgpsAcquiredState(this); mStatePtr->mReleasingState = new AgpsReleasingState(this); // setting up mAcquiredState mStatePtr->mAcquiredState->mReleasedState = mStatePtr; mStatePtr->mAcquiredState->mPendingState = mStatePtr->mPendingState; mStatePtr->mAcquiredState->mReleasingState = mStatePtr->mReleasingState; // setting up mPendingState mStatePtr->mPendingState->mAcquiredState = mStatePtr->mAcquiredState; mStatePtr->mPendingState->mReleasedState = mStatePtr; mStatePtr->mPendingState->mReleasingState = mStatePtr->mReleasingState; // setting up mReleasingState mStatePtr->mReleasingState->mReleasedState = mStatePtr; mStatePtr->mReleasingState->mPendingState = mStatePtr->mPendingState; mStatePtr->mReleasingState->mAcquiredState = mStatePtr->mAcquiredState; }
void lrucache_init(LRUCache *lru, MallocFactory *mf, int max_size, lru_free_f *lru_free, CmpFunc cmp_func) { linked_list_init(&lru->ll, mf); lru->max_size = max_size; lru->lru_free = lru_free; lru->cmp_func = cmp_func; }
void hash_map_put(hash_map *map, void *key, void *value) { linked_list *list = map->table[map->hash_func(key, map->capacity)]; if (!list) { list = (linked_list *) safe_malloc(sizeof(linked_list)); linked_list_init(list, (linked_list_destructor) safe_free); map->table[map->hash_func(key, map->capacity)] = list; } linked_list_node *head = linked_list_head(list); while (head) { hash_map_pair *pair = (hash_map_pair *) head->data; // if key already exists, update the value if (map->comparator(pair->key, key) == 0) { pair->value = value; return; } head = head->next; } // or else insert new one hash_map_pair *pair = (hash_map_pair *) safe_malloc(sizeof(hash_map_pair)); pair->key = key; pair->value = value; linked_list_prepend(list, pair); linked_list_append(map->keys, key); map->size++; }
MmapBehavior::MmapBehavior() : filename(NULL), aligned_mapping_size(0), aligned_mapping_copies(0) { linked_list_init(&precious_ranges, standard_malloc_factory_init()); }
AgpsStateMachine::AgpsStateMachine(void (*servicer)(AGpsStatus* status), AGpsType type, bool enforceSingleSubscriber) : mServicer(servicer), mType(type), mStatePtr(new AgpsReleasedState(this)), mAPN(NULL), mAPNLen(0), mEnforceSingleSubscriber(enforceSingleSubscriber) { linked_list_init(&mSubscribers); // setting up mReleasedState mStatePtr->mPendingState = new AgpsPendingState(this); mStatePtr->mAcquiredState = new AgpsAcquiredState(this); mStatePtr->mReleasingState = new AgpsReleasingState(this); // setting up mAcquiredState mStatePtr->mAcquiredState->mReleasedState = mStatePtr; mStatePtr->mAcquiredState->mPendingState = mStatePtr->mPendingState; mStatePtr->mAcquiredState->mReleasingState = mStatePtr->mReleasingState; // setting up mPendingState mStatePtr->mPendingState->mAcquiredState = mStatePtr->mAcquiredState; mStatePtr->mPendingState->mReleasedState = mStatePtr; mStatePtr->mPendingState->mReleasingState = mStatePtr->mReleasingState; // setting up mReleasingState mStatePtr->mReleasingState->mReleasedState = mStatePtr; mStatePtr->mReleasingState->mPendingState = mStatePtr->mPendingState; mStatePtr->mReleasingState->mAcquiredState = mStatePtr->mAcquiredState; }
struct linked_list * netbench_list_result_recv(struct linked_list *results, int rank) { struct linked_list *ret; struct netbench_result *res; unsigned int size; if (results) ret = results; else ret = linked_list_init(); size = netbench_comm_list_recv(rank); if (!size) return ret; while (size--) { res = netbench_result_recv(rank); linked_list_add(ret,linked_list_res_value_init(res)); } return ret; }
object_t *object_create(scenario_t *scenario) { object_t *obj = (object_t*) malloc(sizeof(object_t)); obj->scenario = scenario; linked_list_init(&obj->components); scenario_add_object(scenario, obj); return obj; }
scenario_t *scenario_create(zephyrjc_t *zjc) { scenario_t *s = (scenario_t*) malloc(sizeof(scenario_t)); s->graphics = &zjc->core.graphics; s->core = &zjc->core; linked_list_init(&s->objects); event_dispatcher_init(&s->ed); return s; }
void corefile_init(CoreFile *c, MallocFactory *mf) { c->mf = mf; lite_memset(&c->corenote_zoog, 0, sizeof(c->corenote_zoog)); c->corenote_zoog.note.nhdr.n_namesz = 5; c->corenote_zoog.note.nhdr.n_descsz = sizeof(c->corenote_zoog)-sizeof(NoteHeader); c->corenote_zoog.note.nhdr.n_type = 0x20092009; // nonsense value c->corenote_zoog.note.name[0] = 'Z'; c->corenote_zoog.note.name[1] = 'O'; c->corenote_zoog.note.name[2] = 'O'; c->corenote_zoog.note.name[3] = 'G'; c->corenote_zoog.note.name[4] = '\0'; c->corenote_zoog.bootblock_addr = 0x0; linked_list_init(&c->threads, mf); linked_list_init(&c->segments, mf); }
static bool ieee80211_psm_atim_list_contains_DA(struct ar9170* ar, U8* da) { int i; /* Extract the ATIM queue for the considered AR9170 device. */ ar9170_tx_queue* atim_queue = ar->tx_pending_atims; if (atim_queue == NULL) { /* The list should normally be initialized, so we signal a warning. */ #if IBSS_PSM_DEBUG printf("WARNING: PSM; ATIM queue is null. Should not occur.\n"); #endif ar->tx_pending_atims = linked_list_init(ar->tx_pending_atims); return false; } if (linked_list_is_empty(ar->tx_pending_atims)) { /* If the list is empty, we can immediately return. */ #if IBSS_PSM_DEBUG_DEEP printf("DEBUG: PSM; The ATIM list is empty.\n"); #endif return false; } /* The ATIM list is non-empty at this point. */ /* Walk through the list of ATIM frames. If an ATIM has already * been created for the requested DA, we do not need to create * a new one. */ for (i=0; i<linked_list_get_len(ar->tx_pending_atims); i++) { /* Extract packet */ struct sk_buff* atim_packet = linked_list_get_element_at(atim_queue, i); if (atim_packet == NULL || atim_packet->data == NULL) { printf("WARNING: Got null ATIM from the list.\n"); return false; } /* Extract data from packet */ struct ieee80211_hdr* atim_header = (struct ieee80211_hdr*)(atim_packet->data); /* Extract DA address */ U8* atim_da = atim_header->addr1; if (ether_addr_equal(atim_da, da)) { #if IBSS_PSM_DEBUG_DEEP printf("DEBUG: PSM; ATIM for current DA is already pending.\n"); #endif return true; } } /* The DA was not found among the ones of the pending ATIMS. Signal "false", * so the ATIM is constructed. */ return false; }
TieredPriorityQueue_t *tiered_priority_queue_create() { TieredPriorityQueue_t *queue = (TieredPriorityQueue_t*)malloc(sizeof(TieredPriorityQueue_t)); if (!queue) return queue; for (int i = 0; i < TIERED_PRIORITY_QUEUE_LEVELS; i++) { linked_list_init(&queue->lists[i]); } pthread_mutex_init(&queue->mutex, NULL); return queue; }
wiced_result_t bt_packet_pool_init( bt_packet_pool_t* pool, uint32_t packet_count, uint32_t header_size, uint32_t data_size ) { uint32_t packet_size = header_size + data_size + sizeof(bt_packet_t) - 1; uint32_t buffer_size = packet_count * packet_size; uint8_t* packet_ptr = NULL; void* buffer = NULL; wiced_result_t result; uint32_t a; memset( pool, 0, sizeof( *pool ) ); buffer = (void*)malloc_named( "bt_packet_pool", buffer_size ); if ( buffer == NULL ) { return WICED_BT_OUT_OF_HEAP_SPACE; } result = linked_list_init( &pool->pool_list ); if ( result != WICED_BT_SUCCESS ) { return result; } pool->pool_id = PACKET_POOL_ID; pool->max_packet_count = packet_count; pool->header_size = header_size; pool->data_size = data_size; pool->pool_buffer = buffer; packet_ptr = buffer; for ( a = 0; a < packet_count; a++ ) { bt_packet_t* packet = (bt_packet_t*)packet_ptr; result = linked_list_insert_node_at_front( &pool->pool_list, &packet->node ); if ( result == WICED_BT_SUCCESS ) { packet->node.data = (void*)packet; packet->pool = pool; packet->packet_id = PACKET_ID; } else { return result; } packet_ptr += packet_size; } return wiced_rtos_init_mutex( &pool->mutex ); }
component_t *tileengine_create(object_t *obj) { component_t *c = component_create(COMPONENT_TILEENGINE, obj, sizeof(tileengine_t)); tileengine_t *te = (tileengine_t*) c; te->current_tilemap = NULL; te->source.x = 0; te->source.y = 0; te->source.w = 128; te->source.h = 128; linked_list_init(&te->tilemaps); register_event_callback(&c->obj->scenario->ed, EV_RENDER, c, &tileengine_render); return c; }
void crt_process(){ int sender_id; MSG_BUF * new_msg; linked_list_init(crt_buffer); while(1) { new_msg = receive_message(&sender_id); if(new_msg->mtype == MSG_CRT_DISPLAY) { uart0_put_string((unsigned char*)new_msg->mtext); uart0_put_string("\n\r"); } } }
struct linked_list_value *linked_list_add(struct linked_list *l,struct linked_list_value *val) { if (l->value) { struct linked_list *ptr; ptr = l; while (l->next) l = l->next; l->next = linked_list_init(); l = l->next; } l->value = val; return val; }
int tpool_create(thread_pool_t * pool, int n_threads) { pool->threads = malloc(sizeof(pthread_t) * n_threads); pool->pool_size = n_threads; if (pthread_mutex_init(&pool->pj_mutex, NULL) != 0) return -1; if (pthread_cond_init(&pool->pj_cond, NULL) != 0) return -1; if (pthread_mutex_init(&pool->cj_mutex, NULL) != 0) return -1; if (pthread_cond_init(&pool->cj_cond, NULL) != 0) return -1; pool->pending_jobs = linked_list_init(NULL); pool->completed_jobs = linked_list_init(NULL); pool->shutdown = FALSE; pthread_mutex_lock(&pool->pj_mutex); int i; for (i = 0; i < n_threads; i++) { if (pthread_create(&pool->threads[i], NULL, tpool_worker, pool) != 0) { return -1; } } pthread_mutex_unlock(&pool->pj_mutex); return 0; }
/*=========================================================================== FUNCTION: msg_q_init ===========================================================================*/ msq_q_err_type msg_q_init(void** msg_q_data) { if( msg_q_data == NULL ) { LOC_LOGE("%s: Invalid msg_q_data parameter!\n", __FUNCTION__); return eMSG_Q_INVALID_PARAMETER; } msg_q* tmp_msg_q; tmp_msg_q = (msg_q*)calloc(1, sizeof(msg_q)); if( tmp_msg_q == NULL ) { LOC_LOGE("%s: Unable to allocate space for message queue!\n", __FUNCTION__); return eMSG_Q_FAILURE_GENERAL; } if( linked_list_init(&tmp_msg_q->msg_list) != 0 ) { LOC_LOGE("%s: Unable to initialize storage list!\n", __FUNCTION__); free(tmp_msg_q); return eMSG_Q_FAILURE_GENERAL; } if( pthread_mutex_init(&tmp_msg_q->list_mutex, NULL) != 0 ) { LOC_LOGE("%s: Unable to initialize list mutex!\n", __FUNCTION__); linked_list_destroy(&tmp_msg_q->msg_list); free(tmp_msg_q); return eMSG_Q_FAILURE_GENERAL; } if( pthread_cond_init(&tmp_msg_q->list_cond, NULL) != 0 ) { LOC_LOGE("%s: Unable to initialize msg q cond var!\n", __FUNCTION__); linked_list_destroy(&tmp_msg_q->msg_list); pthread_mutex_destroy(&tmp_msg_q->list_mutex); free(tmp_msg_q); return eMSG_Q_FAILURE_GENERAL; } tmp_msg_q->unblocked = 0; *msg_q_data = tmp_msg_q; return eMSG_Q_SUCCESS; }
void hash_map_init(hash_map *map, size_t capacity, hash_map_comparator comparator, hash_map_hash_func hash_func) { map->capacity = capacity; map->size = 0; map->table = (linked_list **) safe_malloc(sizeof(linked_list *) * map->capacity); memset(map->table, 0, sizeof(linked_list *) * map->capacity); if (comparator) { map->comparator = comparator; } else { map->comparator = hash_map_default_comparator; } if (hash_func) { map->hash_func = hash_func; } else { map->hash_func = hash_map_default_hash_func; } map->keys = (linked_list *) safe_malloc(sizeof(linked_list)); // No free_data func here because keys will be free'd by linked_list_free for **table linked_list_init(map->keys, NULL); }
void ieee80211_psm_add_awake_node(struct ar9170* ar, U8* sa) { U8* awake_node = (U8*)smalloc(ETH_ALEN); if (!awake_node) { printf("ERROR: No memory for allocation of SA for awake list.\n"); return; } memcpy(awake_node, sa, ETH_ALEN); if (ar->ps_mgr.wake_neighbors_list == NULL) { printf("WARNING: Neighbors' List is Null. Should not occur.\n"); ar->ps_mgr.wake_neighbors_list = linked_list_init(ar->ps_mgr.wake_neighbors_list); } /* We do not need to protect this list from interrupts, as no interrupt access it. */ int position = linked_list_add_tail(ar->ps_mgr.wake_neighbors_list, awake_node, AR9170_PSM_MAX_AWAKE_NODES_LIST_LEN, true); if (position < 0) { printf("WARNING: IBSS; Awake not could not be added to the intended list.\n"); } #if IBSS_PSM_DEBUG_DEEP printf("DEBUG: PSM; Node is added to the list in position: %d.\n", position); #endif }
void linked_list_set_element (linked_list list, size_t element_num, void *element) { ASSERT_LIST (list); linked_list_header *header = (linked_list_header *) list; size_t block_size = linked_list_block_size (header->element_size); uint8_t *raw = (uint8_t *) (header + 1); if (block_size < header->element_size * (element_num + 1)) { if (header->next == null_list) { header->next = (linked_list_header *) linked_list_init (header->element_size); } linked_list_set_element ((linked_list) header->next, element_num - (block_size / header->element_size), element); return; } if (element == NULL) { return; } memcpy (raw + element_num * header->element_size, element, header->element_size); }
void args_init(ZArgs *args, int argc, char **argv, MallocFactory *mf) { args->log = NULL; args->zar = NULL; args->include_elf_syms = false; args->verbose = false; args->dep_file = NULL; linked_list_init(&args->overlay_list, mf); argc-=1; argv+=1; while (argc>0) { CONSUME_STRING("--log", args->log); CONSUME_STRING("--zar", args->zar); CONSUME_BOOL("--include-elf-syms", args->include_elf_syms); CONSUME_BOOL("--verbose", args->verbose); CONSUME_STRING("--dep-file", args->dep_file); CONSUME_BYFUNC("--overlay", list_append, &args->overlay_list); UNKNOWN_ARG(); } check(args->log != NULL, "--log <input-log-filename> required"); check(args->zar != NULL, "--zar <output-zar-filename> required"); }
/* * Initialize the address mapping for multi-hop PSM. * The function parses the source routing info, which * is hard-coded in the program flash and resolves the * next-hop MAC address for the [fixed] end-node MAC * address. */ bool ieee80211_mh_psm_init_address_map() { if (mh_psm_addr_map != NULL) { #if IBSS_MH_PSM_DEBUG printf("WARNING: List is already initialized.\n"); #endif return true; } /* Initialize the linked list. */ mh_psm_addr_map = linked_list_init(mh_psm_addr_map); if (mh_psm_addr_map == NULL) { printf("ERROR: MH_PSM Address Map could not be initialized.\n"); return false; } /* TODO: If we want to use MH-PSM we must implement this function, * e.g. with duplicate address detection. For compatibility we just * return false here. */ return false; }
void action_paste_contents(linked_list* items, list_item* selected) { if(!clipboard_has_contents()) { prompt_display("Failure", "Clipboard empty.", COLOR_TEXT, false, NULL, NULL, NULL); return; } paste_files_data* data = (paste_files_data*) calloc(1, sizeof(paste_files_data)); if(data == NULL) { error_display(NULL, NULL, "Failed to allocate paste files data."); return; } data->items = items; data->target = (file_info*) selected->data; data->pasteInfo.data = data; data->pasteInfo.op = DATAOP_COPY; data->pasteInfo.copyBufferSize = 256 * 1024; data->pasteInfo.copyEmpty = true; data->pasteInfo.isSrcDirectory = action_paste_files_is_src_directory; data->pasteInfo.makeDstDirectory = action_paste_files_make_dst_directory; data->pasteInfo.openSrc = action_paste_files_open_src; data->pasteInfo.closeSrc = action_paste_files_close_src; data->pasteInfo.getSrcSize = action_paste_files_get_src_size; data->pasteInfo.readSrc = action_paste_files_read_src; data->pasteInfo.openDst = action_paste_files_open_dst; data->pasteInfo.closeDst = action_paste_files_close_dst; data->pasteInfo.writeDst = action_paste_files_write_dst; data->pasteInfo.suspendCopy = action_paste_files_suspend_copy; data->pasteInfo.restoreCopy = action_paste_files_restore_copy; data->pasteInfo.suspend = action_paste_files_suspend; data->pasteInfo.restore = action_paste_files_restore; data->pasteInfo.error = action_paste_files_error; data->pasteInfo.finished = true; linked_list_init(&data->contents); populate_files_data popData; memset(&popData, 0, sizeof(popData)); popData.items = &data->contents; popData.archive = clipboard_get_archive(); strncpy(popData.path, clipboard_get_path(), FILE_PATH_MAX); popData.recursive = true; popData.includeBase = !clipboard_is_contents_only() || !util_is_dir(clipboard_get_archive(), clipboard_get_path()); popData.filter = NULL; popData.filterData = NULL; Result listRes = task_populate_files(&popData); if(R_FAILED(listRes)) { error_display_res(NULL, NULL, listRes, "Failed to initiate clipboard content list population."); action_paste_files_free_data(data); return; } while(!popData.finished) { svcSleepThread(1000000); } if(R_FAILED(popData.result)) { error_display_res(NULL, NULL, popData.result, "Failed to populate clipboard content list."); action_paste_files_free_data(data); return; } data->pasteInfo.total = linked_list_size(&data->contents); data->pasteInfo.processed = data->pasteInfo.total; prompt_display("Confirmation", "Paste clipboard contents to the current directory?", COLOR_TEXT, true, data, action_paste_files_draw_top, action_paste_files_onresponse); }
/* * This function is called outside the interrupt context, * mainly because it might take a long time to create all * the required ATIM frames. */ void ieee80211_psm_create_atim_pkts(struct ar9170* ar) { #if IBSS_PSM_DEBUG_DEEP printf("DEBUG: IBSS PSM; Create ATIMS.\n"); #endif /* Extract the transmission queue for the AR910 device. */ ar9170_tx_queue* tx_queue = ar->tx_pending_pkts; /* Signal a warning if the queue is NULL, as it should * have been initialized when the AR9170 interface is * added. */ if (tx_queue == NULL) { printf("WARNING: PSM; Null list of pending frames. Should not occur.\n"); ar->tx_pending_pkts = linked_list_init(ar->tx_pending_pkts); return; } /* If the list of pending packets is empty, we do not need * to proceed with creating more ATIM frames. Additionally, * we might want to erase any pending frames as well - TODO */ if (linked_list_is_empty(tx_queue)) { #if IBSS_PSM_DEBUG_DEEP printf("DEBUG: PSM: Empty list. No ATIM packets created.\n"); #endif return; } /* The ATIM packet creation depends on the implemented * power-save mode at the Station so the execution will * branch accordingly. */ if (ibss_info->ps_mode == IBSS_MH_PSM) { /* Walk through the list of pending data packets For * each A3, construct an ATIM frame and place it in * the pending ATIM queue. */ int i; for (i=0; i<linked_list_get_len(tx_queue); i++) { /* Extract packet from the list */ struct sk_buff* packet = linked_list_get_element_at(tx_queue, i); /* Check */ if (packet == NULL || packet->data == NULL) { printf("WARNING: List returned null packet.\n"); continue; } /* Extract data from packet [socket] buffer */ struct ieee80211_hdr_3addr* pkt_header = (struct ieee80211_hdr_3addr*)packet->data; /* Extract DA address */ U8* da = pkt_header->addr1; /* Extract the A3 address. */ U8* a3 = pkt_header->addr3; /* If an ATIM for this A3 has not been added to the pending list, * the packet needs to be created. */ if (!ieee80211_mh_psm_atim_list_contains_A3(ar,a3)) { /* Handle control to the IEEE80211 module, that will * create and push the ATIM to the ATIM queue */ #if IBSS_MH_PSM_DEBUG_DEEP printf("DEBUG: PSM; Creating ATIM packet for a final destination.\n"); #endif ieee80211_create_atim_pkt(ar, da, a3); } } } else if (ibss_info->ps_mode == IBSS_STD_PSM) { /* Walk through the list of packets that are pending. * For each DA, construct an ATIM frame and place it * in the pending ATIM queue. */ int i; for (i=0; i<linked_list_get_len(tx_queue); i++) { /* Extract packet from the list. */ struct sk_buff* packet = linked_list_get_element_at(tx_queue, i); #if IBSS_PSM_DEBUG_DEEP int j; printf("IBSS: [%u]",packet->len); for (j=0; j<packet->len; j++) printf("%02x ", (packet->data)[j]); printf(" \n"); #endif /* Extract data from packet [socket] buffer */ struct ieee80211_hdr* pkt_header = (struct ieee80211_hdr*)(packet->data); /* Extract DA address */ U8* da = pkt_header->addr1; /* If an ATIM for this DA has not been added to the pending list, * the packet needs to be created. */ if (!ieee80211_psm_atim_list_contains_DA(ar,da)) { /* Handle control to the IEEE80211 module, that will * create and push the ATIM to the ATIM queue */ ieee80211_create_atim_pkt(ar, da, NULL); } else { /* No need to create an ATIM, because such an ATIM * is already there. This is the case when multiple * packets for the same DA arrive in the same beacon * interval. */ #if IBSS_MH_PSM_DEBUG_DEEP printf("ATIM for this DA Contained.\n"); #endif } } } else { /* Signal an error, as the function is supposed to generate ATIMS for a * Station that is not in PS mode. */ printf("WARNING: Device is not in PS mode. Why do we need to create ATIMS?\n"); return; } }
static void task_populate_titledb_thread(void* arg) { populate_titledb_data* data = (populate_titledb_data*) arg; Result res = 0; linked_list titles; linked_list_init(&titles); json_t* root = NULL; if(R_SUCCEEDED(res = http_download_json("https://api.titledb.com/v1/entry?nested=true" "&only=id&only=name&only=author&only=headline&only=category" "&only=cia.id&only=cia.mtime&only=cia.version&only=cia.size&only=cia.titleid" "&only=tdsx.id&only=tdsx.mtime&only=tdsx.version&only=tdsx.size&only=tdsx.smdh.id", &root, 1024 * 1024))) { if(json_is_array(root)) { for(u32 i = 0; i < json_array_size(root) && R_SUCCEEDED(res); i++) { svcWaitSynchronization(task_get_pause_event(), U64_MAX); if(task_is_quit_all() || svcWaitSynchronization(data->cancelEvent, 0) == 0) { break; } json_t* entry = json_array_get(root, i); if(json_is_object(entry)) { list_item* item = (list_item*) calloc(1, sizeof(list_item)); if(item != NULL) { titledb_info* titledbInfo = (titledb_info*) calloc(1, sizeof(titledb_info)); if(titledbInfo != NULL) { titledbInfo->id = (u32) json_object_get_integer(entry, "id", 0); string_copy(titledbInfo->category, json_object_get_string(entry, "category", "Unknown"), sizeof(titledbInfo->category)); string_copy(titledbInfo->meta.shortDescription, json_object_get_string(entry, "name", ""), sizeof(titledbInfo->meta.shortDescription)); string_copy(titledbInfo->meta.publisher, json_object_get_string(entry, "author", ""), sizeof(titledbInfo->meta.publisher)); json_t* headline = json_object_get(entry, "headline"); if(json_is_string(headline)) { const char* val = json_string_value(headline); if(json_string_length(headline) > sizeof(titledbInfo->headline) - 1) { snprintf(titledbInfo->headline, sizeof(titledbInfo->headline), "%.508s...", val); } else { string_copy(titledbInfo->headline, val, sizeof(titledbInfo->headline)); } } else { titledbInfo->headline[0] = '\0'; } json_t* cias = json_object_get(entry, "cia"); if(json_is_array(cias)) { for(u32 j = 0; j < json_array_size(cias); j++) { json_t* cia = json_array_get(cias, j); if(json_is_object(cia)) { const char* mtime = json_object_get_string(cia, "mtime", "Unknown"); if(!titledbInfo->cia.exists || task_populate_titledb_compare_dates(mtime, titledbInfo->cia.mtime, sizeof(titledbInfo->cia.mtime)) >= 0) { titledbInfo->cia.exists = true; titledbInfo->cia.id = (u32) json_object_get_integer(cia, "id", 0); string_copy(titledbInfo->cia.mtime, mtime, sizeof(titledbInfo->cia.mtime)); string_copy(titledbInfo->cia.version, json_object_get_string(cia, "version", "Unknown"), sizeof(titledbInfo->cia.version)); titledbInfo->cia.size = (u32) json_object_get_integer(cia, "size", 0); titledbInfo->cia.titleId = strtoull(json_object_get_string(cia, "titleid", "0"), NULL, 16); } } } } json_t* tdsxs = json_object_get(entry, "tdsx"); if(json_is_array(tdsxs)) { for(u32 j = 0; j < json_array_size(tdsxs); j++) { json_t* tdsx = json_array_get(tdsxs, j); if(json_is_object(tdsx)) { const char* mtime = json_object_get_string(tdsx, "mtime", "Unknown"); if(!titledbInfo->tdsx.exists || task_populate_titledb_compare_dates(mtime, titledbInfo->tdsx.mtime, sizeof(titledbInfo->tdsx.mtime)) >= 0) { titledbInfo->tdsx.exists = true; titledbInfo->tdsx.id = (u32) json_object_get_integer(tdsx, "id", 0); string_copy(titledbInfo->tdsx.mtime, mtime, sizeof(titledbInfo->tdsx.mtime)); string_copy(titledbInfo->tdsx.version, json_object_get_string(tdsx, "version", "Unknown"), sizeof(titledbInfo->tdsx.version)); titledbInfo->tdsx.size = (u32) json_object_get_integer(tdsx, "size", 0); json_t* smdh = json_object_get(tdsx, "smdh"); if(json_is_object(smdh)) { titledbInfo->tdsx.smdh.exists = true; titledbInfo->tdsx.smdh.id = (u32) json_object_get_integer(smdh, "id", 0); } } } } } char* latestTime = "Unknown"; if(titledbInfo->cia.exists && titledbInfo->tdsx.exists) { if(task_populate_titledb_compare_dates(titledbInfo->cia.mtime, titledbInfo->tdsx.mtime, sizeof(titledbInfo->cia.mtime)) >= 0) { latestTime = titledbInfo->cia.mtime; } else { latestTime = titledbInfo->tdsx.mtime; } } else if(titledbInfo->cia.exists) { latestTime = titledbInfo->cia.mtime; } else if(titledbInfo->tdsx.exists) { latestTime = titledbInfo->tdsx.mtime; } string_copy(titledbInfo->mtime, latestTime, sizeof(titledbInfo->mtime)); if((titledbInfo->cia.exists || titledbInfo->tdsx.exists) && (data->filter == NULL || data->filter(data->userData, titledbInfo))) { string_copy(item->name, titledbInfo->meta.shortDescription, LIST_ITEM_NAME_MAX); item->data = titledbInfo; task_populate_titledb_update_status(item); linked_list_add_sorted(&titles, item, data->userData, data->compare); } else { free(titledbInfo); free(item); } } else { free(item); res = R_APP_OUT_OF_MEMORY; } } else { res = R_APP_OUT_OF_MEMORY; } } } linked_list_iter iter; linked_list_iterate(&titles, &iter); while(linked_list_iter_has_next(&iter)) { list_item* item = linked_list_iter_next(&iter); if(R_SUCCEEDED(res)) { linked_list_add(data->items, item); } else { task_free_titledb(item); linked_list_iter_remove(&iter); } } } else { res = R_APP_BAD_DATA; } json_decref(root); } data->itemsListed = true; if(R_SUCCEEDED(res)) { linked_list_iter iter; linked_list_iterate(&titles, &iter); while(linked_list_iter_has_next(&iter)) { svcWaitSynchronization(task_get_pause_event(), U64_MAX); Handle events[2] = {data->resumeEvent, data->cancelEvent}; s32 index = 0; svcWaitSynchronizationN(&index, events, 2, false, U64_MAX); if(task_is_quit_all() || svcWaitSynchronization(data->cancelEvent, 0) == 0) { break; } list_item* item = (list_item*) linked_list_iter_next(&iter); titledb_info* titledbInfo = (titledb_info*) item->data; char url[128]; if(titledbInfo->cia.exists) { snprintf(url, sizeof(url), "https://3ds.titledb.com/v1/cia/%lu/icon_l.bin", titledbInfo->cia.id); } else if(titledbInfo->tdsx.exists && titledbInfo->tdsx.smdh.exists) { snprintf(url, sizeof(url), "https://3ds.titledb.com/v1/smdh/%lu/icon_l.bin", titledbInfo->tdsx.smdh.id); } else { continue; } u8 icon[0x1200]; u32 iconSize = 0; if(R_SUCCEEDED(http_download(url, &iconSize, &icon, sizeof(icon))) && iconSize == sizeof(icon)) { titledbInfo->meta.texture = screen_allocate_free_texture(); screen_load_texture_tiled(titledbInfo->meta.texture, icon, sizeof(icon), 48, 48, GPU_RGB565, false); } } } linked_list_destroy(&titles); svcCloseHandle(data->resumeEvent); svcCloseHandle(data->cancelEvent); data->result = res; data->finished = true; }
linked_list * get_key_list(rb_tree * tree, uint32_t cutoff){ linked_list *ll = linked_list_init(); get_keys(tree, tree->root, 1, cutoff, ll); return ll; }
ChunkTable::ChunkTable(MallocFactory *mf) { total_size = 0; chunk_index = 0; linked_list_init(&chunks, mf); }