static void playlist_update_cb (void * data, void * unused) { if (! database) update_database (); else { int list = get_playlist (TRUE, TRUE); int at, count; if (list < 0 || aud_playlist_updated_range (list, & at, & count) >= PLAYLIST_UPDATE_METADATA) update_database (); } }
// Purpose: iterate though all single receivers and find balanced system for // each, the most urgent receivers are serviced first // Input: Accepts three lists, each list being the rows of corresponding tables // Output: A list of balanced systems, each taking the form: // s_receicer <- (p_donor | p_receiver)* <- s_donor // where s_receiver is a single receiver, s_donor is single donor // p_receiver is paired receiver, paired with the paired donor on other side of "|" // "*" means there can be any number of [D/R Pairs], (regular expression notation) void Database::build_system() { // blank balanced system to be filled by algorithm Balanced_Sys bal_sys; // sort the s_receievers and pairs by how many weeks the receiver has to live (increasing) single_receivers.sort(); d_r_pairs.sort(); // iterate through all receivers, making a system for each list<Receiver>::iterator r_iter = single_receivers.begin(); unsigned long original_length = single_receivers.size(); for (int i = 0; i < original_length; i++) { // clear out the old balnaced system to make way for the new one bal_sys = Balanced_Sys(); // get the next receiver in list bal_sys.single_receiver = *r_iter; r_iter++; // find system for receiver bal_sys.find_match(d_r_pairs, single_donors); if (bal_sys.balanced) { // if a balanced system was found, add it to the list // and remove patients from patient lists balanced_systems.push_back(bal_sys); update_database(bal_sys); } } return; }
static void refresh_cb (GtkButton * button, GtkWidget * chooser) { char * path = gtk_file_chooser_get_filename ((GtkFileChooser *) chooser); begin_add (path); g_free (path); update_database (); }
void Database::connect() { if( p->db.isOpen() ) return; p->db.open(); reinit_buffer(); update_database(); }
static bool_t search_init (void) { find_playlist (); search_terms = index_new (); items = index_new (); selection = g_array_new (FALSE, FALSE, 1); update_database (); hook_associate ("playlist add complete", add_complete_cb, NULL); hook_associate ("playlist scan complete", scan_complete_cb, NULL); hook_associate ("playlist update", playlist_update_cb, NULL); return TRUE; }
static void add_complete_cb (void * unused, void * unused2) { if (adding) { int list = get_playlist (TRUE, FALSE); if (list >= 0 && ! aud_playlist_add_in_progress (list)) { adding = FALSE; destroy_added_table (); aud_playlist_sort_by_scheme (list, PLAYLIST_SORT_PATH); } } if (! database && ! aud_playlist_update_pending ()) update_database (); }
int add_parts_to_database() { int loop_counter,new_part_place; for(loop_counter=0;loop_counter<ARRAY_SIZE;loop_counter++) { if(list[loop_counter].part_number == 0) { new_part_place = loop_counter; break; } } printf("Please enter the part name \r\n"); fgets(list[new_part_place].part_name,50,stdin); printf("Please enter a part section for %s \r\n",list[new_part_place].part_name); fgets(list[new_part_place].part_section,50,stdin); printf("Please enter the part number\r\n"); while( scanf("%d",&list[new_part_place].part_number) != 1) { fflush(stdin); } printf("Please enter the part price\r\n"); while( scanf("%f",&list[new_part_place].part_price) != 1) { fflush(stdin); } printf("Please enter the part rating\r\n"); while( scanf("%lf",&list[new_part_place].part_rating) != 1) { fflush(stdin); } update_database(); wait_for_user(); menu(); return 0; }
void bases::rescale() { CALLSTACKITEM_N(_CL("bases"), _CL("rescale")); bases_info->rescaled++; RDebug::Print(_L("Rescaling")); cell_list_node *n=first_cell; bool seen_top=false; total_t/=1024.0; while (n) { n->t/=1024.0; n->rescaled=bases_info->rescaled; if (n->prev) n->cum_t=n->prev->cum_t+n->t; else n->cum_t=n->t; if (!seen_top) { n->is_base=true; update_database(n, current==n); } if (n->cum_t > proportion*total_t) seen_top=true; n=n->next; } scale/=1024.0; }
int sort_database() { int loop_counter; for(loop_counter=0;loop_counter<ARRAY_SIZE-1;loop_counter++) { if(list[loop_counter].part_name[0] > list[loop_counter+1].part_name[0]) { struct database temporary_struct; temporary_struct = list[loop_counter]; list[loop_counter] = list[loop_counter+1]; list[loop_counter+1] = temporary_struct; } } update_database(); printf("\r\n Database Sorted and Updated \r\n"); menu(); }
int remove_parts_from_database() { int remove_part; printf("Please enter the part number or a negative number to exit\r\n"); while( scanf("%d",&remove_part) != 1) { fflush(stdin); } if(remove_part >= 0) { int loop_counter; for(loop_counter=0;loop_counter<ARRAY_SIZE;loop_counter++) { if(list[loop_counter].part_number == remove_part) { strcpy(list[loop_counter].part_name , "" ); strcpy(list[loop_counter].part_section , ""); list[loop_counter].part_number = 0 ; list[loop_counter].part_price = 0.0 ; list[loop_counter].part_rating = 0.0 ; } } update_database(); menu(); } else { menu(); } return 0; }
void bases::NewSensorEventL(const TTupleName& aTuple, const TDesC& , const CBBSensorEvent& aEvent) { CALLSTACKITEM_N(_CL("bases"), _CL("NewSensorEventL")); #ifdef __WINS__ //User::Leave(KErrGeneral); //return; #endif const TBBCellId* cell=bb_cast<TBBCellId>(aEvent.iData()); if (aEvent.iPriority()!=CBBSensorEvent::VALUE || !cell) return; if (!testing) now=aEvent.iStamp(); bool missing_data=false; if ( cell->iLocationAreaCode()==0 ) { if (started) { if (aTuple==KNoTuple) { now_at_location(cell, -1, false, false, aEvent.iStamp()); } return; } missing_data=true; } TInt id=cell->iMappedId(); current_cell_value=*cell; cell_list_node *n=0; n=get_single(id); while (n && n->merged_to != n->id) { id=n->merged_to; n=get_single(id); } if (started && current) { // see if we have a gap between stop and start if (current->id!=id) { // different cell, allow 10 minute difference TTimeIntervalMinutes d(10); if (previous_time+d < now && !missed_data ) { current->f++; update_database(current, false); current=0; } } else { // same cell, allow 30 minute difference TTimeIntervalMinutes d(30); if (previous_time+d < now) { current->f++; update_database(current, false); current=0; } } if (!current) iCandidates->reset(); } started=false; bool same_loc=true; if (current) { if (current->id != id) { current->f++; same_loc=false; iGraph->AddEdge(current->id, id); } #ifdef __S60V3__ TInt64 diff=now.Int64()-previous_time.Int64(); double unaged_spent=I64REAL(diff)/(1024.0*1024.0); #else double unaged_spent=(now.Int64()-previous_time.Int64()).GetTReal()/(1024.0*1024.0); #endif if (unaged_spent<0.0) unaged_spent=0.0; double spent=scale*unaged_spent; current->unaged_t+=unaged_spent; MergeEvent(current, unaged_spent, !same_loc); previous_time=now; move_into_place(current, spent); update_database(current, same_loc); } else { previous_time=now; same_loc=false; } if (missing_data ) { now_at_location(cell, -1, false, false, aEvent.iStamp()); started=true; missed_data=true; return; } else { missed_data=false; } if (!n) { n=new (ELeave) cell_list_node(id, now); CC_TRAPD(err, cell_hash->AddDataL(id, n)); if (err!=KErrNone) { delete n; User::Leave(1); } n->prev=last_cell; if (last_cell) { last_cell->next=n; n->pos=last_cell->pos+1; } last_cell=n; } if (!first_cell) { first_cell=n; n->pos=0; } while (n && n->merged_to != n->id) { id=n->merged_to; n=(cell_list_node*)cell_hash->GetData(id); } current=n; n->last_seen=now; update_database(n, true); if (now.DayNoInYear()!=previous_day.DayNoInYear()) { scale*=(1.0/aging); if (scale>1024.0) { rescale(); } previous_day=now; bases_info->t=scale; update_database(bases_info, false); } if (!testing) { now_at_location(cell, id, n->is_base, !same_loc, aEvent.iStamp()); } }
/** * Process a package file and store updates in the database */ static void process_packages(char *filename, char *product, bool security) { char *uri, line[BUF_LEN], *pos, *package = NULL, *version = NULL; pacman_state_t pacman_state; enumerator_t *e; database_t *db; int pid; FILE *file; stats_t stats; bool success; /* initialize statistics */ memset(&stats, 0x00, sizeof(stats_t)); /* Set release date to current time */ stats.release = time(NULL); /* opening package file */ printf("loading\"%s\"\n", filename); file = fopen(filename, "r"); if (!file) { fprintf(stderr, "could not open \"%s\"\n", filename); exit(EXIT_FAILURE); } /* connect package database */ uri = lib->settings->get_str(lib->settings, "pacman.database", NULL); if (!uri) { fprintf(stderr, "database URI pacman.database not set\n"); fclose(file); exit(EXIT_FAILURE); } db = lib->db->create(lib->db, uri); if (!db) { fprintf(stderr, "could not connect to database '%s'\n", uri); fclose(file); exit(EXIT_FAILURE); } /* check if product is already in database */ e = db->query(db, "SELECT id FROM products WHERE name = ?", DB_TEXT, product, DB_INT); if (e) { if (e->enumerate(e, &pid)) { stats.product = pid; } e->destroy(e); } if (!stats.product) { if (db->execute(db, &pid, "INSERT INTO products (name) VALUES (?)", DB_TEXT, product) != 1) { fprintf(stderr, "could not store product '%s' to database\n", product); fclose(file); db->destroy(db); exit(EXIT_FAILURE); } stats.product = pid; } pacman_state = PACMAN_STATE_BEGIN_PACKAGE; while (fgets(line, sizeof(line), file)) { /* set read pointer to beginning of line */ pos = line; switch (pacman_state) { case PACMAN_STATE_BEGIN_PACKAGE: pos = strstr(pos, "Package: "); if (!pos) { continue; } pos += 9; package = pos; pos = strchr(pos, '\n'); if (pos) { package = strndup(package, pos - package); pacman_state = PACMAN_STATE_VERSION; } break; case PACMAN_STATE_VERSION: pos = strstr(pos, "Version: "); if (!pos) { continue; } pos += 9; version = pos; pos = strchr(pos, '\n'); if (pos) { version = strndup(version, pos - version); pacman_state = PACMAN_STATE_END_PACKAGE; } break; case PACMAN_STATE_END_PACKAGE: if (*pos != '\n') { continue; } success = update_database(db, package, version, security, &stats); free(package); free(version); if (!success) { fclose(file); db->destroy(db); exit(EXIT_FAILURE); } pacman_state = PACMAN_STATE_BEGIN_PACKAGE; } } fclose(file); db->destroy(db); printf("processed %d packages, %d new packages, %d new versions, " "%d updated versions, %d deleted versions\n", stats.packages, stats.new_packages, stats.new_versions, stats.updated_versions, stats.deleted_versions); }
void bases::MergeCells( CList< TInt >& Candidates) { CALLSTACKITEM_N(_CL("bases"), _CL("MergeCells")); RDebug::Print(_L("Merging Cells...")); double max_time=0.0; CList< TInt >::Node *n=Candidates.iFirst; cell_list_node *merge_to=0, *cand_n=0; while (n) { cand_n=(cell_list_node*)cell_hash->GetData(n->Item); if (cand_n->t > max_time) { max_time=cand_n->t; merge_to=cand_n; } n=n->Next; } if (op) { op->write_time(now); op->write_to_output(_L("merging: ")); } TBuf<30> id; n=Candidates.iFirst; double added_time=0.0; auto_ptr< CList<TInt> > cells_in_merge_to( iMerged->GetCells(merge_to->id) ); while (n) { cand_n=(cell_list_node*)cell_hash->GetData(n->Item); if (cand_n != merge_to ) { auto_ptr< CList<TInt> > cells_in_merge_from( iMerged->GetCells(cand_n->id) ); if (op) { id.Format(_L("%d "), n->Item); op->write_to_output(id); } cand_n->merged_to=merge_to->id; added_time+=cand_n->t; merge_to->unaged_t+=cand_n->unaged_t; merge_to->f+=cand_n->f; CList<TInt>::Node *to_i, *from_i; for (from_i=cells_in_merge_from->iFirst; from_i; from_i=from_i->Next) { for (to_i=cells_in_merge_to->iFirst; to_i; to_i=to_i->Next) { merge_to->f-=iGraph->GetCount(from_i->Item, to_i->Item); merge_to->f-=iGraph->GetCount(to_i->Item, from_i->Item); } iMerged->Add(from_i->Item, merge_to->id); } cand_n->t=0; // FIXME: isn't correct if several to-be-merged // are adjacent in the list cand_n->cum_t=cand_n->prev->cum_t; // TODO: what should be done with the count? update_database(cand_n, false); } n=n->Next; } if (op) { id.Format(_L(" into %d\n"), merge_to->id); op->write_to_output(id); } total_t-=added_time; move_into_place(merge_to, added_time); update_database(merge_to, merge_to==current); }
static void process_message(const word describer, const char * const body, const size_t index) { char message_type[8]; char times[16]; time_t timestamp; char from[16], to[16], descr[16], wasf[16], wast[16]; jsmn_find_extract_token(body, tokens, index, "msg_type", message_type, sizeof(message_type)); _log(DEBUG, "Message name = \"%s\".", message_type); jsmn_find_extract_token(body, tokens, index, "time", times, sizeof(times)); times[10] = '\0'; timestamp = atol(times); time_t now = time(NULL); last_td_processed[describer] = now; if(((status_last_td_actual[describer] + 8) < timestamp) || ((status_last_td_processed + 8) < now)) { status_last_td_actual[describer] = timestamp; status_last_td_processed = now; char query[256]; sprintf(query, "update status SET last_td_processed = %ld", now); db_query(query); sprintf(query, "update td_status set last_timestamp = %ld WHERE d = '%s'", timestamp, describers[describer]); db_query(query); } if(!strcasecmp(message_type, "CA")) { jsmn_find_extract_token(body, tokens, index, "from", from, sizeof(from)); jsmn_find_extract_token(body, tokens, index, "to", to, sizeof(to)); jsmn_find_extract_token(body, tokens, index, "descr", descr, sizeof(descr)); strcpy(wasf, query_berth(describer, from)); strcpy(wast, query_berth(describer, to)); _log(DEBUG, "%s CA: Berth step (%s) Description \"%s\" from berth \"%s\" to berth \"%s\"", describers[describer], time_text(timestamp, true), descr, from, to); log_detail(timestamp, "%s CA: %s from %s to %s", describers[describer], descr, from, to); if(strcmp(wasf, descr) || strcmp(wast, "")) { _log(DEBUG, "Message %s CA: Step \"%s\" from \"%s\" to \"%s\" found \"%s\" in \"%s\" and \"%s\" in \"%s\".", describers[describer], descr, from, to, wasf, from, wast, to); } update_database(Berth, describer, from, ""); update_database(Berth, describer, to, descr); stats[CA]++; } else if(!strcasecmp(message_type, "CB")) { jsmn_find_extract_token(body, tokens, index, "from", from, sizeof(from)); jsmn_find_extract_token(body, tokens, index, "descr", descr, sizeof(descr)); strcpy(wasf, query_berth(describer, from)); _log(DEBUG, "%s CB: Berth cancel (%s) Description \"%s\" from berth \"%s\"", describers[describer], time_text(timestamp, true), descr, from); log_detail(timestamp, "%s CB: %s from %s", describers[describer], descr, from); if(strcmp(wasf, descr)) { _log(DEBUG, "Message %s CB: Cancel \"%s\" from \"%s\" found \"%s\" in \"%s\".", describers[describer], descr, from, wasf, from); } update_database(Berth, describer, from, ""); stats[CB]++; } else if(!strcasecmp(message_type, "CC")) { jsmn_find_extract_token(body, tokens, index, "to", to, sizeof(to)); jsmn_find_extract_token(body, tokens, index, "descr", descr, sizeof(descr)); _log(DEBUG, "%s CC: Berth interpose (%s) Description \"%s\" to berth \"%s\"", describers[describer], time_text(timestamp, true), descr, to); log_detail(timestamp, "%s CC: %s to %s", describers[describer], descr, to); update_database(Berth, describer, to, descr); stats[CC]++; } else if(!strcasecmp(message_type, "CT")) { // Heartbeat char report_time[16]; jsmn_find_extract_token(body, tokens, index, "report_time", report_time, sizeof(report_time)); _log(DEBUG, "%s CT: Heartbeat (%s) Report time = %s", describers[describer], time_text(timestamp, true), report_time); stats[CT]++; } else if(!strcasecmp(message_type, "SF")) { char address[16], data[32]; jsmn_find_extract_token(body, tokens, index, "address", address, sizeof(address)); jsmn_find_extract_token(body, tokens, index, "data", data, sizeof(data)); _log(DEBUG, "%s SF: Signalling update (%s) Address \"%s\", data \"%s\"", describers[describer], time_text(timestamp, true), address, data); word a = strtoul(address, NULL, 16); dword d = strtoul(data, NULL, 16); signalling_update("SF", describer, timestamp, a, d); stats[SF]++; } else if(!strcasecmp(message_type, "SG")) { char address[16], data[32]; jsmn_find_extract_token(body, tokens, index, "address", address, sizeof(address)); jsmn_find_extract_token(body, tokens, index, "data", data, sizeof(data)); _log(DEBUG, "%s SG: Signalling refresh (%s) Address \"%s\", data \"%s\"", describers[describer], time_text(timestamp, true), address, data); word a = strtoul(address, NULL, 16); dword d = strtoul(data, NULL, 16); _log(DEBUG, "a = %04x, d = %08x", a, d); signalling_update("SG", describer, timestamp, a , 0xff & (d >> 24)); signalling_update("SG", describer, timestamp, a + 1 , 0xff & (d >> 16)); signalling_update("SG", describer, timestamp, a + 2 , 0xff & (d >> 8 )); signalling_update("SG", describer, timestamp, a + 3 , 0xff & (d )); stats[SG]++; }
int main(int argc, char *argv[]) { int retval = EXIT_FAILURE; int long_opt_index = 0, display_info = 0, display_public_cert = 0, update_db = 0, quiet = 0; char c = 0; char *pcap_filter = NULL, *pcap_file = NULL, *pcap_interface = NULL, *update_db_outfile = NULL; struct keymaster certinfo = { 0 }; struct option long_options[] = { { "fingerprint", required_argument, NULL, 'f' }, { "pem", required_argument, NULL, 'p' }, { "host", required_argument, NULL, 'r' }, { "pcap", required_argument, NULL, 'c' }, { "interface", required_argument, NULL, 'i' }, { "search", required_argument, NULL, 's' }, { "filter", required_argument, NULL, 'l' }, { "keypair", no_argument, NULL, 'k' }, { "info", no_argument, NULL, 'v' }, { "quiet", no_argument, NULL, 'q' }, { "update", optional_argument, NULL, 'u' }, { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } }; char *short_options = "f:p:r:c:i:s:l:u::kvqh"; if(argc < MIN_ARGS) { usage(argv[0]); goto end; } while((c = getopt_long(argc,argv,short_options, long_options, &long_opt_index)) != -1) { switch(c) { case 'c': if(optarg) pcap_file = strdup(optarg); break; case 'f': if(optarg) certinfo.fingerprint = strdup(optarg); break; case 'p': if(optarg) certinfo.fingerprint = fingerprint_pem_file(optarg); break; case 'r': if(optarg) certinfo.fingerprint = fingerprint_host(optarg); break; case 'i': if(optarg) pcap_interface = strdup(optarg); break; case 'l': if(optarg) pcap_filter = strdup(optarg); break; case 's': if(optarg) print_search_results(optarg); break; case 'u': update_db = 1; if(optarg) update_db_outfile = strdup(optarg); else update_db_outfile = strdup(DB_NAME); break; case 'k': display_public_cert = 1; break; case 'v': display_info = 1; break; case 'q': quiet = 1; break; default: usage(argv[0]); goto end; } } /* Update the certificate database */ if(update_db) { fprintf(stderr, "Updating %s from %s...", update_db_outfile, DB_UPDATE_URL); if(!update_database(DB_UPDATE_URL, update_db_outfile)) { fprintf(stderr, "update failed!\n"); goto end; } else { fprintf(stderr, "done.\n"); goto success; } } /* If no filter was specified, use the default */ if(pcap_filter == NULL) { pcap_filter = strdup(DEFAULT_FILTER); } /* Do raw traffic capture if specified */ if(pcap_file != NULL) { certinfo.fingerprint = sniff(pcap_file, pcap_filter, PFILE); } else if(pcap_interface != NULL) { certinfo.fingerprint = sniff(pcap_interface, pcap_filter, IFACE); } /* Make sure we have a fingerprint */ if(!certinfo.fingerprint) { fprintf(stderr, "No suitable certificate fingerprint provided!\n"); goto end; } /* Try to lookup the private key that corresponds to this certificate */ if(!lookup_key(&certinfo) || certinfo.key == NULL) { fprintf(stderr, "ERROR: Failed to locate a matching private certificate for fingerprint: %s\n", certinfo.fingerprint); goto end; } /* Display private key */ if(!quiet) { printf("%s\n", certinfo.key); } /* Display public key */ if(display_public_cert) { printf("%s\n", certinfo.certificate); } /* Show all certificate info for this cert */ if(display_info) { print_all_cert_info(&certinfo); } success: retval = EXIT_SUCCESS; end: free_key(&certinfo); if(update_db_outfile) free(update_db_outfile); if(pcap_file) free(pcap_file); if(pcap_interface) free(pcap_interface); if(pcap_filter) free(pcap_filter); return retval; }
int main(int argc, char **argv) { int c; int exe_inst; char *db_path = NULL; char *input_path = NULL; char *out_file = NULL; unsigned int vid = 0; char *ptr; char *file_path = NULL; struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"db", required_argument, 0, 'd'}, {"binary", required_argument, 0, 'b'}, {"text", required_argument, 0, 't'}, {"compare", no_argument, 0, 'p'}, {"cluster", no_argument, 0, 'r'}, {"neighbor", required_argument, 0, 'n'}, {"vinfo", required_argument, 0, 'q'}, {"jaccard", required_argument, 0, 'j'}, {"size", required_argument, 0, 's'}, {"window", required_argument, 0, 'w'}, {"debug", no_argument, 0, 'z'}, {"output", required_argument, 0, 'o'}, {0,0,0,0} }; int option_index = 0; if (argc == 1) { usage(); return -1; } umask(0002); // Set file access right exe_inst = -1; opterr = 0; while ((c = getopt_long(argc, argv, "hd:b:t:prn:q:j:s:w:zo:", long_options, &option_index)) != -1) switch (c) { case 'd': db_path = strdup(optarg); break; case 'b': input_path = strdup(optarg); exe_inst = EXE_ADD_BIN; break; case 't': input_path = strdup(optarg); exe_inst = EXE_ADD_TXT; break; case 'p': exe_inst = EXE_COMPARE; break; case 'r': exe_inst = EXE_CLUSTER; break; case 'n': input_path = strdup(optarg); exe_inst = EXE_NEIGHBOR; break; case 'q': vid = atoi(optarg); exe_inst = EXE_GETVINFO; break; case 'j': threshold = atof(optarg); break; case 's': shredsize = atoi(optarg); break; case 'w': windowsize = atoi(optarg); break; case 'z': debug_flag = 1; break; case 'o': out_file = strdup(optarg); file_path = strdup(out_file); ptr = strrchr(file_path, '/'); if(ptr != NULL) { *ptr = '\0'; if(access(file_path, F_OK)) mkdir(file_path, S_IRWXU|S_IXGRP|S_IRGRP|S_IROTH|S_IXOTH); free(file_path); } if((freopen(out_file, "w", stdout)) == NULL) { bs_errmsg("[!] %s fopen()\n", out_file); exit(EXIT_FAILURE); } break; case '?': if (optopt=='j' || optopt=='s' || optopt=='w') bs_errmsg("[!] missing argument value for -%c option\n", optopt); else if (optopt=='d' || optopt=='b' || optopt=='t' || optopt=='o' || optopt=='n') bs_errmsg("[!] missing file name for -%c option\n", optopt); else if (optopt=='q') bs_errmsg("[!] missing index number for --get option\n"); else bs_errmsg("[!] unknown option\n"); return -1; case 'h': default: usage(); return -1; } if(optind < argc){ usage(); return -1; } switch (exe_inst) { case EXE_ADD_BIN: case EXE_ADD_TXT: if(input_path == NULL){ bs_errmsg("[!] input path missing\n"); return -1; } if(db_path == NULL) db_path = strdup(DB_PATH); update_database(db_path, input_path, exe_inst); break; case EXE_COMPARE: if(db_path == NULL) db_path = strdup(DB_PATH); compare_database(db_path); break; case EXE_CLUSTER: if(db_path == NULL) db_path = strdup(DB_PATH); cluster_database(db_path); break; case EXE_GETVINFO: if(db_path == NULL) db_path = strdup(DB_PATH); if(vid == 0){ bs_errmsg("[!] index number cannot be zero\n"); return -1; } get_vinfo(db_path, vid); break; case EXE_NEIGHBOR: if(input_path == NULL) { bs_errmsg("[!] input path missing\n"); return -1; } if(db_path == NULL) db_path = strdup(DB_PATH); neighbor(db_path, input_path); break; default: return -1; } if(db_path) free(db_path); if(input_path) free(input_path); if(out_file) fclose(stdout); return 0; }
static void scan_complete_cb (void * unused, void * unused2) { if (! database && ! aud_playlist_update_pending ()) update_database (); }
void bases::move_into_place(cell_list_node* n, double t) { CALLSTACKITEM_N(_CL("bases"), _CL("move_into_place")); // Invariant: // the top proportion*total_t nodes have up to date cum_t // // no other nodes can move up to that group than the // one we're moving, so updating nodes under it, if // they are within the group is enough to keep the invariant // // so even though we update cum_t for all nodes on the // way when moving the node, not all of them are // necessarily correct if (!n) { post_error(_L("int error: n is NULL"), KErrGeneral); return; } total_t+=t; cell_list_node* update=n->next; n->t+=t; if (n->pos<=up_to_date_cum_pos) { if (n->pos==up_to_date_cum_pos) up_to_date_cum_pos=n->pos+1; if (n->next) n->next->cum_t=n->cum_t+n->next->t+t; } while (n->prev && n->prev->t < n->t) { cell_list_node* tmp; tmp=n->prev; if (n->next) n->next->prev=tmp; else last_cell=tmp; tmp->next=n->next; n->next=tmp; n->prev=tmp->prev; tmp->prev=n; if (n->prev) { n->prev->next=n; n->cum_t=n->prev->cum_t+n->t; n->pos=n->prev->pos+1; if (n->prev->pos==up_to_date_cum_pos) { up_to_date_cum_pos+=2; update=n->next; } } else { n->cum_t=n->t; n->pos=0; } n->next->cum_t=n->cum_t+n->next->t; // (1) n->next->pos=n->pos+1; } if (!n->prev) { first_cell=n; n->cum_t=n->t; // if n was first, cum_t hasn't been updated yet n->pos=0; } else { n->cum_t=n->prev->cum_t+n->t; // if n wasn't moved, cum_t hasn't been updated yet } if (update && update->pos <= up_to_date_cum_pos) { while (update && (update->cum_t)<proportion*total_t) { // the first one has been updated by (1) or (2) up_to_date_cum_pos=update->pos; update=update->next; if (!update || !update->prev) { post_error(_L("int error, update->prev is NULL"), KErrGeneral); } else if (update) update->cum_t=update->prev->cum_t+update->t; } if (update) { if (! update->prev ) { post_error(_L("int error, update->prev is NULL"), KErrGeneral); } else { update->cum_t=update->prev->cum_t+update->t; up_to_date_cum_pos=update->pos; } } } if (!learning_done ) { TTimeIntervalDays learning_period(2); if (! (first_time+learning_period > previous_time) ) { learning_done=true; cell_list_node* b=first_cell; while (b && b->cum_t<proportion*total_t) { add_as_base(b); update_database(b, false); b=b->next; } if (b) { add_as_base(b); update_database(b, false); } } } else { if ( ( ( ( (n->cum_t)<(proportion*total_t) ) && n->pos<=up_to_date_cum_pos) || (!(n->prev)) || (n->prev && ( (n->prev->cum_t)<(proportion*total_t) ) && n->prev->pos<=up_to_date_cum_pos) ) && !n->is_base) add_as_base(n); } }
void bases::read_from_database(bool aConvertOnly, CCellMap* aCellMap) { CALLSTACKITEM_N(_CL("bases"), _CL("read_from_database")); TInt dbver=0; Settings().GetSettingL(SETTING_BASEDB_VERSION, dbver); if (!aConvertOnly) { clear(); User::LeaveIfError(table.SetIndex(idx_id)); bases_info=get_single(0); TInt rescalings=0; if (bases_info) { first_time=bases_info->last_seen; scale=bases_info->t; rescalings=bases_info->rescaled; } User::LeaveIfError(table.SetIndex(idx_t)); TBool rows_left=table.LastL(); cell_list_node* previous=0; int pos=0; total_t=0.0; double t; while (rows_left) { table.GetL(); TInt id; id=table.ColUint32(colno_id); t=table.ColReal(colno_t); /* * This doesn't quite work. We should still * update the total with the smaller items as well. * And to do that they should be scaled here, and * maybe rewritten to the db, which might take a lot of time. * So leave it for now - MR 20041215 if (t < limit ) { // not reading very small items will allow // us lower memory consumption with little // accuracy loss in the base decision. They'll // still be read by get_single() as necessary rows_left=table.PreviousL(); continue; } */ cell_list_node *n=new (ELeave) cell_list_node(id, table.ColTime(colno_last_seen)); n->t=t; n->f=table.ColUint32(colno_f); n->in_db=true; n->rescaled=table.ColUint32(colno_rescaled); if (table.ColUint32(colno_isbase)==1) { n->is_base=true; } else { n->is_base=false; } if (n->id==0) { // bases info, got it already delete n; } else { // actual cell if (table.ColUint32(colno_iscurrent)==1) { current=n; previous_time=n->last_seen; previous_day=previous_time; } if (dbver<3) { n->merged_to=n->id; n->unaged_t=0.0; n->f=0; } else { n->merged_to=table.ColUint32(colno_merged_to); if (n->merged_to == 0) n->merged_to=n->id; n->unaged_t=table.ColReal(colno_unaged_t); } if (n->t < 0.0) { n->t=0.0; } if (n->unaged_t < 0.0) { n->unaged_t=0.0; } if (previous) { previous->next=n; n->cum_t=previous->cum_t+n->t; } else { first_cell=n; n->cum_t=n->t; } n->prev=previous; previous=n; n->pos=pos++; total_t+=n->t; cell_hash->AddDataL(n->id, n); } rows_left=table.PreviousL(); } Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER); User::LeaveIfError(table.SetIndex(idx_id)); bool needed_rescaling=false; db.Begin(); RDebug::Print(_L("scaling db...")); cell_list_node *n=first_cell; while (n) { TInt i=1; if (n->rescaled < bases_info->rescaled && n->t>0) { TReal scale; TReal pow=bases_info->rescaled-n->rescaled; Math::Pow(scale, 1024.0, pow); n->t/=scale; n->rescaled=bases_info->rescaled; update_database(n, false); needed_rescaling=true; if (i % 50 == 0) { db.Commit(); db.Compact(); } } i++; n=n->next; } db.Commit(); db.Compact(); RDebug::Print(_L("scaling db done.")); last_cell=previous; if (needed_rescaling) { RDebug::Print(_L("sorting...")); sort(); RDebug::Print(_L("done sorting.")); previous=last_cell; } if (previous) { previous->next=0; up_to_date_cum_pos=previous->pos; last_cell=previous; } else { total_t=0; up_to_date_cum_pos=0; } } else { table.SetNoIndex(); TBool rows_left=table.FirstL(); while (rows_left) { table.GetL(); TInt id; id=table.ColUint32(colno_id); if (dbver<2 && id>0) { aCellMap->SetId(table.ColDes(colno_cellid), id); } rows_left=table.NextL(); } } }
void bases::InnerConstructL(bool aConvertOnly, CCellMap* aCellMap) { CALLSTACKITEM_N(_CL("bases"), _CL("ConstructL")); iConvertOnly=aConvertOnly; if (!aConvertOnly) { Mlogger::ConstructL(AppContextAccess()); Mlog_base_impl::ConstructL(); iBBSubSessionNotif->AddNotificationL(KCellIdTuple, ETrue); iEvent.iData.SetValue(&iLocation); iEvent.iData.SetOwnsValue(EFalse); cell_hash=CGenericIntMap::NewL(); // initial values learning_done=false; first_time=GetTime(); previous_time=previous_day=first_time; scale=1.0; } TInt dbver=0; MoveIntoDataDirL(AppContext(), database_file); TFileName database_filename_install, database_filename; database_filename_install.Format(_L("%S%S"), &AppDir(), &database_file_install); database_filename.Format(_L("%S%S"), &DataDir(), &database_file); if (BaflUtils::FileExists(Fs(), database_filename_install)) { User::LeaveIfError(BaflUtils::CopyFile(Fs(), database_filename_install, database_filename)); User::LeaveIfError(BaflUtils::DeleteFile(Fs(), database_filename_install)); Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER); learning_done=true; } dbver=LATEST_DBVER; Settings().GetSettingL(SETTING_BASEDB_VERSION, dbver); auto_ptr<CDbColSet> cols(CDbColSet::NewL()); TInt colno=1; cols->AddL(TDbCol(col_id, EDbColUint32)); colno_id=colno++; cols->AddL(TDbCol(col_t, EDbColReal64) ); colno_t=colno++; cols->AddL(TDbCol(col_f, EDbColUint32) ); colno_f=colno++; cols->AddL(TDbCol(col_isbase, EDbColBit) ); colno_isbase=colno++; cols->AddL(TDbCol(col_last_seen, EDbColDateTime) ); colno_last_seen=colno++; cols->AddL(TDbCol(col_iscurrent, EDbColBit) ); colno_iscurrent=colno++; TInt store_exists; CC_TRAP(store_exists, store = CPermanentFileStore::OpenL(Fs(), database_filename, EFileRead|EFileWrite)); if (store_exists!=KErrNone) { dbver=LATEST_DBVER; Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER); } if (dbver<2) { cols->AddL(TDbCol(col_cellid, EDbColText)); colno_cellid=colno++; } cols->AddL(TDbCol(col_merged_to, EDbColUint32)); colno_merged_to=colno++; cols->AddL(TDbCol(col_unaged_t, EDbColReal64) ); colno_unaged_t=colno++; cols->AddL(TDbCol(col_rescaled, EDbColUint32) ); colno_rescaled=colno++; if (store_exists==KErrNone) { db.OpenL(store, store->Root()); User::LeaveIfError(db.Recover()); db_open=true; RDebug::Print(_L("converting database...")); User::LeaveIfError(db.AlterTable(table_cells, *cols)); RDebug::Print(_L("converting database done.")); User::LeaveIfError(table.Open(db, table_cells)); table_open=true; // read cells in order read_from_database(aConvertOnly, aCellMap); } else { if (aConvertOnly) return; // construct database store = CPermanentFileStore::ReplaceL(Fs(), database_filename, EFileRead|EFileWrite); store->SetTypeL(store->Layout()); TStreamId id=db.CreateL(store); db_open=true; store->SetRootL(id); store->CommitL(); User::LeaveIfError(db.CreateTable(table_cells, *cols)); auto_ptr<CDbKey> idx_key(CDbKey::NewL()); idx_key->AddL(TDbKeyCol(col_id)); idx_key->MakeUnique(); User::LeaveIfError(db.CreateIndex(idx_id, table_cells, *idx_key)); idx_key->Clear(); idx_key->AddL(TDbKeyCol(col_t)); User::LeaveIfError(db.CreateIndex(idx_t, table_cells, *idx_key)); User::LeaveIfError(table.Open(db, table_cells)); table_open=true; User::LeaveIfError(table.SetIndex(idx_id)); Settings().WriteSettingL(SETTING_BASEDB_VERSION, LATEST_DBVER); } if (aConvertOnly) return; if (! bases_info) { bases_info=new (ELeave) cell_list_node(0, first_time); bases_info->id=0; bases_info->t=scale; bases_info->merged_to=0; bases_info->last_seen=first_time; update_database(bases_info, false); } iGraph=CDirectedGraph::NewL(db, _L("GRAPH")); iMerged=CMerged::NewL(db, _L("MERGE")); iCandidates=CList<TCandidate>::NewL(); iTimer=CTimeOut::NewL(*this); iTimer->Wait(CELL_REFRESH); }