int main(){ head_list_t *head = createlisthead(), *tail; item_t *items = createitems(1); *(items->p) = 1; *(items->w) = 10; additems(head, 1, items); items = createitems(2); *(items->p) = 2; *(items->p+1) = 3; *(items->w) = 9; *(items->w+1) = 8; node_list_t *node = createlistnode(); node->items = items; node->length = 2; addnode(head, node); tail = createlisthead(); items = createitems(3); *(items->p) = 4; *(items->p+1) = 5; *(items->p+2) = 6; *(items->w) = 7; *(items->w+1) = 6; *(items->w+2) = 5; additems(tail,3,items); addlist(head,tail); printf("list size is %d\n",head->count); print_list(head); tail->next = NULL; puts("free head"); fflush(stdout); free_list(&head); puts("free tail"); fflush(stdout); free_list(&tail); }
// Add a path to list, recursing through (to a maximum of depth subdirectories) static void additems(std::vector<std::string> *items, std::string path, int depth) { if(depth < 0) return; // Try expand this URI char **expanded = reader_expand (path.c_str ()); if (expanded) { char **c_uri = expanded; while (*c_uri) additems (items, *(c_uri++), depth-1); reader_free_expanded (expanded); } else { items->push_back(path); } }
// Thread which performs an insert to playlist void insert_looper(void *data) { std::set<PlaylistInterface *>::const_iterator i; std::set<playlist_interface *>::const_iterator j; PlInsertItems * items = (PlInsertItems *)data; Playlist *playlist = items->playlist; // Stop the list being changed while we add these items playlist->Lock(); // First vetting of the list, and recurse through directories std::vector<std::string> vetted_items; std::vector<std::string>::const_iterator k = items->items.begin(); while(k != items->items.end() && playlist->active) { additems(&(vetted_items), *k++, MAXRECURSEDEPTH); } std::vector<PlayItem> newitems; if(vetted_items.size() > 0) { char cwd[PATH_MAX + 1]; std::vector<std::string>::const_iterator path; if (!getcwd(cwd, PATH_MAX)) { alsaplayer_error("Failed to get current working directory"); cwd[0] = 0; } // Check items for adding to list for(path = vetted_items.begin(); path != vetted_items.end() && playlist->active; path++) { // Check that item is valid if(!playlist->CanPlay(*path)) { //alsaplayer_error("Can't find a player for `%s'\n", path->c_str()); } else { newitems.push_back(PlayItem(*path)); } } } // Check position is valid if(playlist->queue.size() < items->position) { items->position = playlist->queue.size(); } // Add to list playlist->queue.insert(playlist->queue.begin() + items->position, newitems.begin(), newitems.end()); if(playlist->curritem > items->position) playlist->curritem += newitems.size(); if(playlist->curritem == 0) { playlist->curritem = 1; } // Tell the subscribing interfaces about the changes playlist->LockInterfaces(); if(playlist->interfaces.size() > 0) { for(i = playlist->interfaces.begin(); i != playlist->interfaces.end(); i++) { (*i)->CbInsert(newitems, items->position); (*i)->CbSetCurrent(playlist->curritem); } } if (playlist->cinterfaces.size() > 0) { for (j = playlist->cinterfaces.begin(); j != playlist->cinterfaces.end(); j++) { (*j)->cbinsert((*j)->data, newitems, items->position); (*j)->cbsetcurrent((*j)->data, playlist->curritem); } } playlist->UnlockInterfaces(); // Free the list again /* Metadate gathering is disabled for now. It completely * breaks streaming and it was never very efficient. A complete * reimplementation will follow shortly */ if (playlist->active) info_looper(playlist); playlist->Unlock(); delete items; }