void get_info(t_uint32 p_subsong, file_info &p_info, abort_callback &p_abort) { int duration = get_song_duration(p_subsong, false); if (duration >= 0) p_info.set_length(duration / 1000.0); const ASAPInfo *info = ASAP_GetInfo(asap); p_info.info_set_int("channels", ASAPInfo_GetChannels(info)); p_info.info_set_int("subsongs", ASAPInfo_GetSongs(info)); meta_set(p_info, "composer", ASAPInfo_GetAuthor(info)); meta_set(p_info, "title", ASAPInfo_GetTitle(info)); meta_set(p_info, "date", ASAPInfo_GetDate(info)); }
// sent direct to mg_connection void send_meta_mc(struct mg_connection *mc, u1_t cmd, u4_t p1, u4_t p2) { meta_t meta; meta_set(&meta, cmd, p1, p2); mg_websocket_write(mc, WS_OPCODE_BINARY, (char*) &meta, 4+2+8); }
// sent on the waterfall port void send_meta(conn_t *c, u1_t cmd, u4_t p1, u4_t p2) { meta_t meta; meta_set(&meta, cmd, p1, p2); assert(c->type == STREAM_WATERFALL); app_to_web(c, (char*) &meta, 4+2+8); }
void _silopit_load(struct silopit *silopit) { int fd, result, all_count = 0; DIR *dd; struct dirent *de; dd = opendir(silopit->basedir); while ((de = readdir(dd))) { if (strstr(de->d_name, ".silopit")) { int fcount = 0, fcrc = 0; struct meta_node mn; struct footer footer; char silopit_file[FILE_PATH_SIZE]; int fsize = sizeof(struct footer); memset(silopit_file, 0, FILE_PATH_SIZE); snprintf(silopit_file, FILE_PATH_SIZE, "%s/%s", silopit->basedir, de->d_name); fd = open(silopit_file, O_RDWR, 0644); lseek(fd, -fsize, SEEK_END); result = read(fd, &footer, sizeof(struct footer)); if (result != sizeof(struct footer)) __PANIC("read footer error"); fcount = from_be32(footer.count); fcrc = from_be32(footer.crc); if (fcrc != F_CRC) { __PANIC("Crc wrong, silo file maybe broken, crc:<%d>,index<%s>", fcrc, silopit_file); close(fd); continue; } if (fcount == 0) { close(fd); continue; } _add_hiraishin(silopit, fd, fcount, from_be32(footer.max_len)); all_count += fcount; mn.count = fcount; memset(mn.end, 0, SILOKATANA_MAX_KEY_SIZE); memcpy(mn.end, footer.key, SILOKATANA_MAX_KEY_SIZE); memset(mn.index_name, 0, FILE_NAME_SIZE); memcpy(mn.index_name, de->d_name, FILE_NAME_SIZE); meta_set(silopit->meta, &mn); close(fd); } } closedir(dd); __DEBUG("Load silopit,all entries count:<%d>", all_count); }
void _sst_load(struct sst *sst) { int fd, result; int all_count = 0; DIR *dd; struct dirent *de;; dd = opendir(sst->basedir); while ((de = readdir(dd))) { if(strstr(de->d_name, ".sst")) { int fcount = 0, fcrc = 0; struct meta_node mn; struct footer footer; char sst_file[FILE_PATH_SIZE]; int fsize = sizeof(struct footer); memset(sst_file, 0, FILE_PATH_SIZE); snprintf(sst_file, FILE_PATH_SIZE, "%s/%s", sst->basedir, de->d_name); fd = open(sst_file, O_RDWR, 0644); lseek(fd, -fsize, SEEK_END); result = read(fd, &footer, sizeof(struct footer)); if(result == -1) abort(); fcount = from_be32(footer.count); fcrc = from_be32(footer.crc); if(fcrc != F_CRC) { __DEBUG(LEVEL_ERROR, "Error: crc wrong, crc:<%d>, index<%s>", fcrc, sst_file); close(fd); continue; } if(fcount == 0) { close(fd); continue; } all_count += fcount; mn.count = fcount; memset(mn.end, 0, NESSDB_MAX_KEY_SIZE); memcpy(mn.end, footer.key, NESSDB_MAX_KEY_SIZE); memset(mn.index_name, 0, FILE_NAME_SIZE); memcpy(mn.index_name, de->d_name, FILE_NAME_SIZE); meta_set(sst->meta, &mn); close(fd); } } closedir(dd); __DEBUG(LEVEL_DEBUG, "load sst, all entries count:<%d>", all_count); }
void file_info::meta_set_ansi(const char * name,const char * value) {//ANSI version meta_set(string_utf8_from_ansi(name),string_utf8_from_ansi(value)); }
void file_info::meta_set_wide(const WCHAR * name,const WCHAR* value) {//widechar version meta_set(string_utf8_from_wide(name),string_utf8_from_wide(value)); }
void *_write_mmap(struct sst *sst, struct skipnode *x, size_t count, int need_new) { int i, j, c_clone; int fd; int sizes; int result; char file[FILE_PATH_SIZE]; struct skipnode *last; struct sst_block *blks; struct footer footer; int fsize = sizeof(struct footer); sizes = count * sizeof(struct sst_block); memset(file, 0, FILE_PATH_SIZE); snprintf(file, FILE_PATH_SIZE, "%s/%s", sst->basedir, sst->name); fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644); lseek(fd, sizes - 1, SEEK_SET); result = write(fd, "", 1); if(result == -1) abort(); blks = mmap(0, sizes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); last = x; c_clone = count; for(i = 0, j = 0; i < c_clone; i++) { if(x->opt == ADD) { memset(blks[j].key, 0, NESSDB_MAX_KEY_SIZE); memcpy(blks[j].key, x->key, NESSDB_MAX_KEY_SIZE); blks[j].offset = to_be64(x->val); j++; } else count --; last = x; x = x->forward[0]; } #ifdef MSYNC if(msync(blks, sizes, , MS_SYNC) == -1) { //__DEBUG } #endif if(munmap(blks, sizes) == -1) { //__DEBUG } footer.count = to_be32(count); footer.crc = to_be32(F_CRC); memset(footer.key, 0, NESSDB_MAX_KEY_SIZE); memcpy(footer.key, last->key, NESSDB_MAX_KEY_SIZE); result = write(fd, &footer, fsize); if(result == -1) abort(); /* Set meta */ struct meta_node mn; mn.count = count; memset(mn.end, 0, NESSDB_MAX_KEY_SIZE); memcpy(mn.end, last->key, NESSDB_MAX_KEY_SIZE); memset(mn.index_name, 0, FILE_NAME_SIZE); memcpy(mn.index_name, sst->name, FILE_NAME_SIZE); if(need_new) meta_set(sst->meta, &mn); else meta_set_byname(sst->meta, &mn); close(fd); return x; }
void *_write_mmap(struct silopit *silopit, struct skipnode *x, size_t count, int need_new) { int i, j, c_clone; int fd; int sizes; int result; char file[FILE_PATH_SIZE]; struct skipnode *last; struct footer footer; struct stats stats; int fsize = sizeof(struct footer); memset(&footer, 0, fsize); _prepare_stats(x, count, &stats); sizes = stats.mmap_size; struct inner_block { char key[stats.max_len]; char offset[8]; }; struct inner_block *blks; memset(file, 0, FILE_PATH_SIZE); snprintf(file, FILE_PATH_SIZE, "%s/%s", silopit->basedir, silopit->name); fd = open(file, O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd == -1) __PANIC("error creating silopit file"); if (lseek(fd, sizes - 1, SEEK_SET) == -1) __PANIC("error lseek silopit"); result = write(fd, "", 1); if (result == -1) __PANIC("error writing empty"); blks = mmap(0, sizes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (blks == MAP_FAILED) { __PANIC("error mapping block when write on process"); } last = x; c_clone = count; for (i = 0, j = 0; i < c_clone; i++) { if (x->opt == ADD) { buffer_putstr(silopit->buf, x->key); buffer_putc(silopit->buf, 0); buffer_putlong(silopit->buf, x->val); j++; } else count--; last = x; x = x->forward[0]; } char *strings = buffer_detach(silopit->buf); memcpy(blks, strings, sizes); #ifdef MSYNC if (msync(blks, sizes, MS_SYNC) == -1) { __ERROR("Error Msync"); } #endif if (munmap(blks, sizes) == -1) { __ERROR("Un-mmapping the file"); } footer.count = to_be32(count); footer.crc = to_be32(F_CRC); footer.size = to_be32(sizes); footer.max_len = to_be32(stats.max_len); memcpy(footer.key, last->key, strlen(last->key)); result = write(fd, &footer, fsize); if (result == -1) __PANIC("writing the footer"); struct meta_node mn; mn.count = count; memset(mn.end, 0, SILOKATANA_MAX_KEY_SIZE); memcpy(mn.end, last->key, SILOKATANA_MAX_KEY_SIZE); memset(mn.index_name, 0, FILE_NAME_SIZE); memcpy(mn.index_name, silopit->name, FILE_NAME_SIZE); if (need_new) meta_set(silopit->meta, &mn); else meta_set_byname(silopit->meta, &mn); close(fd); return x; }