static void WINAPI internet_status_callback(HINTERNET internet, DWORD_PTR context, DWORD internet_status, LPVOID status_info, DWORD status_info_len) { Protocol *protocol = (Protocol*)context; switch(internet_status) { case INTERNET_STATUS_RESOLVING_NAME: TRACE("%p INTERNET_STATUS_RESOLVING_NAME\n", protocol); report_progress(protocol, BINDSTATUS_FINDINGRESOURCE, (LPWSTR)status_info); break; case INTERNET_STATUS_CONNECTING_TO_SERVER: TRACE("%p INTERNET_STATUS_CONNECTING_TO_SERVER\n", protocol); report_progress(protocol, BINDSTATUS_CONNECTING, (LPWSTR)status_info); break; case INTERNET_STATUS_SENDING_REQUEST: TRACE("%p INTERNET_STATUS_SENDING_REQUEST\n", protocol); report_progress(protocol, BINDSTATUS_SENDINGREQUEST, (LPWSTR)status_info); break; case INTERNET_STATUS_REDIRECT: TRACE("%p INTERNET_STATUS_REDIRECT\n", protocol); report_progress(protocol, BINDSTATUS_REDIRECTING, (LPWSTR)status_info); break; case INTERNET_STATUS_REQUEST_COMPLETE: request_complete(protocol, status_info); break; case INTERNET_STATUS_HANDLE_CREATED: TRACE("%p INTERNET_STATUS_HANDLE_CREATED\n", protocol); IInternetProtocol_AddRef(protocol->protocol); break; case INTERNET_STATUS_HANDLE_CLOSING: TRACE("%p INTERNET_STATUS_HANDLE_CLOSING\n", protocol); if(*(HINTERNET *)status_info == protocol->request) { protocol->request = NULL; if(protocol->protocol_sink) { IInternetProtocolSink_Release(protocol->protocol_sink); protocol->protocol_sink = NULL; } if(protocol->bind_info.cbSize) { ReleaseBindInfo(&protocol->bind_info); memset(&protocol->bind_info, 0, sizeof(protocol->bind_info)); } }else if(*(HINTERNET *)status_info == protocol->connection) { protocol->connection = NULL; } IInternetProtocol_Release(protocol->protocol); break; default: WARN("Unhandled Internet status callback %d\n", internet_status); } }
static int checkout_create_the_new( void *cb_data, const git_diff_delta *delta, float progress) { int error = 0; struct checkout_diff_data *data = cb_data; git_checkout_opts *opts = data->checkout_opts; bool do_checkout = false, do_notify = false; GIT_UNUSED(progress); if (delta->status == GIT_DELTA_MODIFIED || delta->status == GIT_DELTA_TYPECHANGE) { if ((opts->checkout_strategy & GIT_CHECKOUT_OVERWRITE_MODIFIED) != 0) do_checkout = true; else if (opts->skipped_notify_cb != NULL) do_notify = !data->create_submodules; } else if (delta->status == GIT_DELTA_DELETED && (opts->checkout_strategy & GIT_CHECKOUT_CREATE_MISSING) != 0) do_checkout = true; if (do_notify) { if (opts->skipped_notify_cb( delta->old_file.path, &delta->old_file.oid, delta->old_file.mode, opts->notify_payload)) { giterr_clear(); error = GIT_EUSER; } } if (do_checkout) { bool is_submodule = S_ISGITLINK(delta->old_file.mode); if (is_submodule) { data->found_submodules = true; } if (!is_submodule && !data->create_submodules) { error = checkout_blob(data, &delta->old_file); data->completed_steps++; report_progress(data, delta->old_file.path); } else if (is_submodule && data->create_submodules) { error = checkout_submodule(data, &delta->old_file); data->completed_steps++; report_progress(data, delta->old_file.path); } } if (error) data->error = error; return error; }
/* * read the AVR device's signature bytes */ int avr_signature(PROGRAMMER * pgm, AVRPART * p) { int rc; report_progress (0,1,"Reading"); rc = avr_read(pgm, p, "signature", 0); if (rc < 0) { logprintf(LOG_ERR, "error reading signature data for part \"%s\", rc=%d", p->desc, rc); return -1; } report_progress (1,1,NULL); return 0; }
static int ft245r_paged_write_gen(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int page_size, int n_bytes) { unsigned long i; int rc; for (i=0; i<n_bytes; i++) { report_progress(i, n_bytes, NULL); rc = avr_write_byte_default(pgm, p, m, i, m->buf[i]); if (rc != 0) { return -2; } if (m->paged) { /* * check to see if it is time to flush the page with a page * write */ if (((i % m->page_size) == m->page_size-1) || (i == n_bytes-1)) { rc = avr_write_page(pgm, p, m, i); if (rc != 0) { return -2; } } } } return i; }
/*============================================ * cgr_callback -- callback for refn traversal * for checking for ghost refns * Created: 2001/01/13, Perry Rapp *==========================================*/ static BOOLEAN cgr_callback (TRAV_REFNS_FUNC_ARGS(key, refn, newset, param)) { /* a refn record which points at record=key */ RECORD rec = key_to_record(key); NODE node = nztop(rec); param = param; /* unused */ if (newset) { finish_and_delete_refnset(); soundexseq = create_indiseq_sval(); } append_indiseq_sval(soundexseq, strsave(key), NULL, strsave(refn) , TRUE, TRUE); /* sure, alloc */ if (!node) { report_error(ERR_ORPHANNAME, _("Orphaned refn: %s"), refn); if (todo.fix_ghosts) enqueue_list(tofix, (VPTR)alloc_namerefn(refn, key, ERR_ORPHANNAME)); } else { } if (noisy) report_progress("Refn: %s", refn); return 1; /* continue traversal */ }
static HRESULT start_downloading(Protocol *protocol) { HRESULT hres; hres = protocol->vtbl->start_downloading(protocol); if(FAILED(hres)) { protocol_close_connection(protocol); report_result(protocol, hres); return hres; } if(protocol->bindf & BINDF_NEEDFILE) { WCHAR cache_file[MAX_PATH]; DWORD buflen = sizeof(cache_file); if(InternetQueryOptionW(protocol->request, INTERNET_OPTION_DATAFILE_NAME, cache_file, &buflen)) { report_progress(protocol, BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_file); }else { FIXME("Could not get cache file\n"); } } protocol->flags |= FLAG_FIRST_CONTINUE_COMPLETE; return S_OK; }
static void on_progress_proc(BindProtocol *This, task_header_t *t) { on_progress_task_t *task = (on_progress_task_t*)t; report_progress(This, task->status_code, task->status_text); heap_free(task->status_text); heap_free(task); }
std::streamsize download_source::read(char* s, std::streamsize n) { dgd_scopef(trace_download); dgd_echo(m_url); dgd_echo(n); if( m_mcurl == NULL ) { initialize(); } std::streamsize total_bytes = 0; std::streamsize bytes_to_read = 0; int handles_changed = 0; curl_multi_perform(m_mcurl, &handles_changed); dgd_echo(handles_changed); do { bytes_to_read = std::min(m_tail-m_head, n - total_bytes); dgd_echo(bytes_to_read); if( bytes_to_read > 0 ) { std::copy(m_head, m_head + bytes_to_read, s + total_bytes); m_head += bytes_to_read; if( m_tail == m_head ) { curl_easy_pause(m_curl, CURLPAUSE_CONT); dgd_logger << "resume curl" << std::endl; } total_bytes += bytes_to_read; dgd_echo(total_bytes); m_total_bytes += bytes_to_read; if(report_progress() != 0) { m_eof = true; dgd_logger << "download aborted" << std::endl; return -1; } } else if( is_eof() ) { return ( total_bytes == 0 ) ? -1 : total_bytes; } else { handles_changed = 0; curl_multi_wait(m_mcurl, NULL, 0, 15000, &handles_changed); if( handles_changed == 0 ) { m_eof = true; dgd_logger << "download timed out" << std::endl; throw download_exception("Download timed out"); } } curl_multi_perform(m_mcurl, &handles_changed); } while( total_bytes < n); return total_bytes; }
void ParameterOptimization::optimize_int_parameter(Parameter<int> ¶meter, const bool fullgrid, const int step){ printf("Altering %s\n", parameter.get_name().c_str()); if(!fullgrid) apply_to_all_parameters(set_to_best<int>, set_to_best<float>); const int min = parameter.get_min(); const int max = parameter.get_max(); float step_size = (float) (max - min) / kResolution; for(int res_step = 0; res_step < kResolution + 1; ++res_step){ const int current_value = (int) (0.5 + min + res_step * step_size); std::cout << " current value is: " << current_value << std::endl << "while: min:" << min << " max: " << max << std::endl << "and res step: " << res_step << " and step_size: " << step_size << std::endl; parameter.set_value(current_value); const ParameterSet handle = get_current_parameter_handle(); if(true || !known(handle)){ //text output ----------- std::cout << "going to test with: " << std::endl << std::endl; printCurrentParameters(); std::cout << ".. now .." << std::endl << std::endl; float result = evaluation_function(); report_progress(); std::cout << "just tested with: " << std::endl; printCurrentParameters(); std::cout << "and that's a fact" << std::endl; printf("result: %.6f\n\n", result); // log results if (result > best) fout << "result is improvement:"; else fout << "results:"; fout << result << endl; printCurrentParametersToFile(); fout << endl; fout.flush(); //text outpus done ---------- TestResult res( handle, result); current_results.push_back(res); if(result > best){ printf("improvement: %f -> %f\n", best, result); best = result; apply_to_all_parameters(&set_current_as_best<int>, &set_current_as_best<float>); } } if(fullgrid) optimize_grid_axis(step + 1); } }
/*============================================ * cgn_callback -- callback for name traversal * for checking for ghost names * Created: 2001/01/01, Perry Rapp *==========================================*/ static BOOLEAN cgn_callback (TRAV_NAMES_FUNC_ARGS(key, name, newset, param)) { /* a name record which points at indi=key */ RECORD indi0 = NULL; NODE indi = NULL; param=param; /* unused */ /* bail out immediately if not INDI */ if (key[0] != 'I') { report_error(ERR_NONINDINAME , _("Non-indi name, key=%s, name=%s") , key, name); return 1; /* continue traversal */ } indi0 = qkey_to_irecord(key); indi = nztop(indi0); if (newset) { finish_and_delete_nameset(); soundexseq = create_indiseq_sval(); } append_indiseq_sval(soundexseq, strsave(key), (STRING)name, strsave(name) , TRUE, TRUE); /* sure, alloc */ if (!indi) { report_error(ERR_ORPHANNAME, _("Orphaned name: %s"), name); if (todo.fix_ghosts) enqueue_list(tofix, (VPTR)alloc_namerefn(name, key, ERR_ORPHANNAME)); } else { NODE node; BOOLEAN found=FALSE; NODE nam, refn, sex, body, famc, fams; split_indi_old(indi, &nam, &refn, &sex, &body, &famc, &fams); for (node = nam; node; node = nsibling(node)) { if (!strcmp(nval(node), name)) found=TRUE; } join_indi(indi, nam, refn, sex, body, famc, fams); if (!found) { report_error(ERR_GHOSTNAME, _("Ghost name: %s -> %s"), name, key); if (todo.fix_ghosts) enqueue_list(tofix, (VPTR)alloc_namerefn(name, key, ERR_GHOSTNAME)); } } if (noisy) report_progress("Name: %s", name); return 1; /* continue traversal */ }
/* * linkAndUpdateFile() * * Creates a hard link between the given relation files. We use * this function to perform a true in-place update. If the on-disk * format of the new cluster is bit-for-bit compatible with the on-disk * format of the old cluster, we can simply link each relation * instead of copying the data from the old cluster to the new cluster. */ const char * linkAndUpdateFile(pageCnvCtx *pageConverter, const char *src, const char *dst) { report_progress(NULL, FILE_COPY, "Link \"%s\" to \"%s\"", src, dst); if (pageConverter != NULL) return "Cannot in-place update this cluster, page-by-page conversion is required"; if (pg_link_file(src, dst) == -1) return getErrorText(); else return NULL; }
static int ft245r_paged_load_gen(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int page_size, int n_bytes) { unsigned char rbyte; unsigned long i; int rc; for (i=0; i<n_bytes; i++) { rc = avr_read_byte_default(pgm, p, m, i, &rbyte); if (rc != 0) { return -2; } m->buf[i] = rbyte; report_progress(i, n_bytes, NULL); } return 0; }
static void progress_calc(disk_t *disk, struct scan_state *state, uint64_t add) { bool do_update; if (add != 0) { state->progress_bytes += add; int progress_part_new = state->progress_bytes * state->progress_full / disk->num_bytes; do_update = progress_part_new != state->progress_part; state->progress_part = progress_part_new; } else { do_update = true; } if (do_update) { report_progress(disk, state->progress_part, state->progress_full); } }
void ParameterOptimization::optimize_float_parameter(Parameter<float> ¶meter, bool fullgrid, const int step){ printf("Altering %s\n", parameter.get_name().c_str()); if(!fullgrid) apply_to_all_parameters(&set_to_best<int>, &set_to_best<float>); const float min = parameter.get_min(); const float max = parameter.get_max(); float step_size = (max - min) / (float)kResolution; for(int res_step = 0; res_step < kResolution + 1; ++res_step){ const float current_value = min + res_step * step_size; parameter.set_value(current_value); const ParameterSet handle = get_current_parameter_handle(); if(true || !known(handle)){ std::cout << "going to test with: " << std::endl << std::endl; printCurrentParameters(); std::cout << ".. now .." << std::endl << std::endl; float result = evaluation_function(); report_progress(); std::cout << "just tested with: " << std::endl; printCurrentParameters(); std::cout << "and that's a fact" << std::endl; printf("result: %.6f\n\n", result); // log results result > best? fout << "result is improvement:" : fout << "results:"; fout << result << endl; printCurrentParametersToFile(); fout << endl; fout.flush(); TestResult res( handle, result); current_results.push_back(res); if(result > best){ printf("improvement: %f -> %f\n", best, result); best = result; //parameter.set_current_as_best(); apply_to_all_parameters(&set_current_as_best<int>, &set_current_as_best<float> ); } } if(fullgrid) optimize_grid_axis(step + 1); } }
/*============================================= * nodes_callback -- callback for node traversal * for checking indis, fams, sours, evens, othes * Created: 2001/01/14, Perry Rapp *===========================================*/ static BOOLEAN nodes_callback(TRAV_RECORDS_FUNC_ARGS(key, rec, param)) { param=param; /* NOTUSED */ if (noisy) report_progress("Node: %s", key); switch (key[0]) { case 'I': return todo.check_indis ? check_indi((CNSTRING)key, (RECORD)rec) : TRUE; case 'F': return todo.check_fams ? check_fam((CNSTRING)key, (RECORD)rec) : TRUE; case 'S': return todo.check_sours ? check_sour((CNSTRING)key, (RECORD)rec) : TRUE; case 'E': return todo.check_evens ? check_even((CNSTRING)key, (RECORD)rec) : TRUE; case 'X': return todo.check_othes ? check_othe((CNSTRING)key, (RECORD)rec) : TRUE; } ASSERT(0); /* traverse_db_key_recs is broken */ return TRUE; }
static HRESULT WINAPI BPInternetProtocolSink_ReportProgress(IInternetProtocolSink *iface, ULONG ulStatusCode, LPCWSTR szStatusText) { BindProtocol *This = PROTSINK_THIS(iface); TRACE("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText)); if(do_direct_notif(This)) { report_progress(This, ulStatusCode, szStatusText); }else { on_progress_task_t *task; task = heap_alloc(sizeof(on_progress_task_t)); task->status_code = ulStatusCode; task->status_text = heap_strdupW(szStatusText); push_task(This, &task->header, on_progress_proc); } return S_OK; }
HRESULT protocol_start(Protocol *protocol, IInternetProtocol *prot, IUri *uri, IInternetProtocolSink *protocol_sink, IInternetBindInfo *bind_info) { DWORD request_flags; HRESULT hres; protocol->protocol = prot; IInternetProtocolSink_AddRef(protocol_sink); protocol->protocol_sink = protocol_sink; memset(&protocol->bind_info, 0, sizeof(protocol->bind_info)); protocol->bind_info.cbSize = sizeof(BINDINFO); hres = IInternetBindInfo_GetBindInfo(bind_info, &protocol->bindf, &protocol->bind_info); if(hres != S_OK) { WARN("GetBindInfo failed: %08x\n", hres); return report_result(protocol, hres); } if(!(protocol->bindf & BINDF_FROMURLMON)) report_progress(protocol, BINDSTATUS_DIRECTBIND, NULL); if(!get_internet_session(bind_info)) return report_result(protocol, INET_E_NO_SESSION); request_flags = INTERNET_FLAG_KEEP_CONNECTION; if(protocol->bindf & BINDF_NOWRITECACHE) request_flags |= INTERNET_FLAG_NO_CACHE_WRITE; if(protocol->bindf & BINDF_NEEDFILE) request_flags |= INTERNET_FLAG_NEED_FILE; hres = protocol->vtbl->open_request(protocol, uri, request_flags, internet_session, bind_info); if(FAILED(hres)) { protocol_close_connection(protocol); return report_result(protocol, hres); } return S_OK; }
/*========================================= * check_typed_missing_data_records -- Check all records * of specified type for orphans *=======================================*/ static void check_typed_missing_data_records (char ntype) { int keynum=0; while (TRUE) { char key[33]; keynum = xref_next(ntype, keynum); if (!keynum) return; sprintf(key, "%c%d", ntype, keynum); if (noisy) report_progress("Check data record presence: %s", key); if (is_record_missing_data_entry(key)) { if (todo.pass == 1) { report_error(ERR_MISSINGREC, _("Missing data record (%s)"), key); } else { if (todo.fix_missing_data_records) { delete_record_missing_data_entry(key); report_fix(ERR_MISSINGREC, _("Fixed missing data record (%s)"), key); } } } } }
static int ft245r_paged_load_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int page_size, int n_bytes) { unsigned long i,j,n; //int rc; int addr,addr_save,buf_pos; int req_count = 0; char buf[FT245R_FRAGMENT_SIZE+1]; addr = 0; for (i=0; i<n_bytes; ) { buf_pos = 0; addr_save = addr; for (j=0; j< FT245R_FRAGMENT_SIZE/8/FT245R_CYCLES/4; j++) { if (i >= n_bytes) break; buf_pos += set_data(buf+buf_pos, (addr & 1)?0x28:0x20 ); buf_pos += set_data(buf+buf_pos, (addr >> 9) & 0xff ); buf_pos += set_data(buf+buf_pos, (addr >> 1) & 0xff ); buf_pos += set_data(buf+buf_pos, 0); addr ++; i++; } if (i >= n_bytes) { buf[buf_pos++] = 0; // sck down } n = j; ft245r_send(pgm, buf, buf_pos); put_request(addr_save, buf_pos, n); req_count++; if (req_count > REQ_OUTSTANDINGS) do_request(pgm, m); report_progress(i, n_bytes, NULL); } while (do_request(pgm, m)) ; return 0; }
static int checkout_remove_the_old( void *cb_data, const git_diff_delta *delta, float progress) { struct checkout_diff_data *data = cb_data; git_checkout_opts *opts = data->checkout_opts; GIT_UNUSED(progress); if ((delta->status == GIT_DELTA_UNTRACKED && (opts->checkout_strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0) || (delta->status == GIT_DELTA_TYPECHANGE && (opts->checkout_strategy & GIT_CHECKOUT_OVERWRITE_MODIFIED) != 0)) { data->error = git_futils_rmdir_r( delta->new_file.path, git_repository_workdir(data->owner), GIT_DIRREMOVAL_FILES_AND_DIRS); data->completed_steps++; report_progress(data, delta->new_file.path); } return data->error; }
static int ft245r_paged_write_flash(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, int page_size, int n_bytes) { unsigned int i,j; int addr,addr_save,buf_pos,do_page_write,req_count; char buf[FT245R_FRAGMENT_SIZE+1+128]; req_count = 0; addr = 0; for (i=0; i<n_bytes; ) { addr_save = addr; buf_pos = 0; do_page_write = 0; for (j=0; j< FT245R_FRAGMENT_SIZE/8/FT245R_CYCLES/4; j++) { buf_pos += set_data(buf+buf_pos, (addr & 1)?0x48:0x40 ); buf_pos += set_data(buf+buf_pos, (addr >> 9) & 0xff ); buf_pos += set_data(buf+buf_pos, (addr >> 1) & 0xff ); buf_pos += set_data(buf+buf_pos, m->buf[i]); addr ++; i++; if ( (m->paged) && (((i % m->page_size) == 0) || (i == n_bytes))) { do_page_write = 1; break; } } #if defined(USE_INLINE_WRITE_PAGE) if (do_page_write) { int addr_wk = addr_save - (addr_save % m->page_size); /* If this device has a "load extended address" command, issue it. */ if (m->op[AVR_OP_LOAD_EXT_ADDR]) { unsigned char cmd[4]; OPCODE *lext = m->op[AVR_OP_LOAD_EXT_ADDR]; memset(cmd, 0, 4); avr_set_bits(lext, cmd); avr_set_addr(lext, cmd, addr_wk/2); buf_pos += set_data(buf+buf_pos, cmd[0]); buf_pos += set_data(buf+buf_pos, cmd[1]); buf_pos += set_data(buf+buf_pos, cmd[2]); buf_pos += set_data(buf+buf_pos, cmd[3]); } buf_pos += set_data(buf+buf_pos, 0x4C); /* Issue Page Write */ buf_pos += set_data(buf+buf_pos,(addr_wk >> 9) & 0xff); buf_pos += set_data(buf+buf_pos,(addr_wk >> 1) & 0xff); buf_pos += set_data(buf+buf_pos, 0); } #endif if (i >= n_bytes) { buf[buf_pos++] = 0; // sck down } ft245r_send(pgm, buf, buf_pos); put_request(addr_save, buf_pos, 0); //ft245r_sync(pgm); #if 0 fprintf(stderr, "send addr 0x%04x bufsize %d [%02x %02x] page_write %d\n", addr_save,buf_pos, extract_data_out(buf , (0*4 + 3) ), extract_data_out(buf , (1*4 + 3) ), do_page_write); #endif req_count++; if (req_count > REQ_OUTSTANDINGS) do_request(pgm, m); if (do_page_write) { #if defined(USE_INLINE_WRITE_PAGE) while (do_request(pgm, m)) ; usleep(m->max_write_delay); #else int addr_wk = addr_save - (addr_save % m->page_size); int rc; while (do_request(pgm, m)) ; rc = avr_write_page(pgm, p, m, addr_wk); if (rc != 0) { return -2; } #endif req_count = 0; } report_progress(i, n_bytes, NULL); } while (do_request(pgm, m)) ; return i; }
int do_op(PROGRAMMER * pgm, struct avrpart * p, AVRUPD * upd, int nowrite, int verify) { struct avrpart * v; AVRMEM * mem = NULL; int size, vsize; int rc; /* NEW */ if(strcmp(upd->memtype, "flash") == 0) { mem = p->flashmem; } else if(strcmp(upd->memtype, "lfuse") == 0) { mem = p->lfusemem; } else if(strcmp(upd->memtype, "hfuse") == 0) { mem = p->hfusemem; } if (mem == NULL) { logprintf(LOG_ERR, "\"%s\" memory type not defined for part \"%s\"", upd->memtype, p->desc); return -1; } if (upd->op == DEVICE_READ) { /* * read out the specified device memory and write it to a file */ report_progress(0,1,"Reading"); rc = avr_read(pgm, p, upd->memtype, 0); if (rc < 0) { logprintf(LOG_ERR, "failed to read all of %s memory, rc=%d", mem->desc, rc); return -1; } report_progress(1,1,NULL); size = rc; logprintf(LOG_INFO, "writing output file \"%s\"", strcmp(upd->filename, "-")==0 ? "<stdout>" : upd->filename); rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size); if (rc < 0) { logprintf(LOG_ERR, "write to file '%s' failed", upd->filename); return -1; } } else if (upd->op == DEVICE_WRITE) { /* * write the selected device memory using data from a file; first * read the data from the specified file */ logprintf(LOG_INFO, "reading input file \"%s\"", strcmp(upd->filename, "-")==0 ? "<stdin>" : upd->filename); rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); if (rc < 0) { logprintf(LOG_INFO, "write to file '%s' failed", upd->filename); return -1; } size = rc; /* * write the buffer contents to the selected memory type */ logprintf(LOG_INFO, "writing %s (%d bytes)", mem->desc, size); if (!nowrite) { report_progress(0,1,"Writing"); rc = avr_write(pgm, p, upd->memtype, size); report_progress(1,1,NULL); } else { /* * test mode, don't actually write to the chip, output the buffer * to stdout in intel hex instead */ rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, upd->memtype, size); } if (rc < 0) { logprintf(LOG_ERR, "failed to write %s memory, rc=%d", mem->desc, rc); return -1; } vsize = rc; logprintf(LOG_INFO, "%d bytes of %s written", vsize, mem->desc); } else if (upd->op == DEVICE_VERIFY) { /* * verify that the in memory file (p->mem[AVR_M_FLASH|AVR_M_EEPROM]) * is the same as what is on the chip */ v = avr_dup_part(p); logprintf(LOG_INFO, "verifying %s memory against %s:", mem->desc, upd->filename); logprintf(LOG_INFO, "load data %s data from input file %s:", mem->desc, upd->filename); rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); if (rc < 0) { logprintf(LOG_ERR, "read from file '%s' failed", upd->filename); return -1; } size = rc; logprintf(LOG_INFO, "input file %s contains %d bytes", upd->filename, size); report_progress (0,1,"Reading"); rc = avr_read(pgm, v, upd->memtype, size); if (rc < 0) { logprintf(LOG_ERR, "failed to read all of %s memory, rc=%d", mem->desc, rc); return -1; } report_progress (1,1,NULL); logprintf(LOG_INFO, "verifying ..."); rc = avr_verify(p, v, upd->memtype, size); if (rc < 0) { logprintf(LOG_ERR, "verification error; content mismatch"); return -1; } logprintf(LOG_INFO, "%d bytes of %s verified", rc, mem->desc); FREE(v->sigmem->buf); FREE(v->sigmem); FREE(v->flashmem->buf); FREE(v->flashmem); FREE(v->hfusemem->buf); FREE(v->hfusemem); FREE(v->lfusemem->buf); FREE(v->lfusemem); FREE(v); } else { logprintf(LOG_ERR, "invalid update operation (%d) requested", upd->op); return -1; } return 0; }
int do_op(PROGRAMMER * pgm, struct avrpart * p, UPDATE * upd, enum updateflags flags) { struct avrpart * v; AVRMEM * mem; int size, vsize; int rc; mem = avr_locate_mem(p, upd->memtype); if (mem == NULL) { fprintf(stderr, "\"%s\" memory type not defined for part \"%s\"\n", upd->memtype, p->desc); return -1; } if (upd->op == DEVICE_READ) { /* * read out the specified device memory and write it to a file */ if (quell_progress < 2) { fprintf(stderr, "%s: reading %s memory:\n", progname, mem->desc); } report_progress(0,1,"Reading"); rc = avr_read(pgm, p, upd->memtype, 0); if (rc < 0) { fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", progname, mem->desc, rc); return -1; } report_progress(1,1,NULL); size = rc; if (quell_progress < 2) { fprintf(stderr, "%s: writing output file \"%s\"\n", progname, strcmp(upd->filename, "-")==0 ? "<stdout>" : upd->filename); } rc = fileio(FIO_WRITE, upd->filename, upd->format, p, upd->memtype, size); if (rc < 0) { fprintf(stderr, "%s: write to file '%s' failed\n", progname, upd->filename); return -1; } } else if (upd->op == DEVICE_WRITE) { /* * write the selected device memory using data from a file; first * read the data from the specified file */ if (quell_progress < 2) { fprintf(stderr, "%s: reading input file \"%s\"\n", progname, strcmp(upd->filename, "-")==0 ? "<stdin>" : upd->filename); } rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); if (rc < 0) { fprintf(stderr, "%s: read from file '%s' failed\n", progname, upd->filename); return -1; } size = rc; /* * write the buffer contents to the selected memory type */ if (quell_progress < 2) { fprintf(stderr, "%s: writing %s (%d bytes):\n", progname, mem->desc, size); } if (!(flags & UF_NOWRITE)) { report_progress(0,1,"Writing"); rc = avr_write(pgm, p, upd->memtype, size, (flags & UF_AUTO_ERASE) != 0); report_progress(1,1,NULL); } else { /* * test mode, don't actually write to the chip, output the buffer * to stdout in intel hex instead */ rc = fileio(FIO_WRITE, "-", FMT_IHEX, p, upd->memtype, size); } if (rc < 0) { fprintf(stderr, "%s: failed to write %s memory, rc=%d\n", progname, mem->desc, rc); return -1; } vsize = rc; if (quell_progress < 2) { fprintf(stderr, "%s: %d bytes of %s written\n", progname, vsize, mem->desc); } } else if (upd->op == DEVICE_VERIFY) { /* * verify that the in memory file (p->mem[AVR_M_FLASH|AVR_M_EEPROM]) * is the same as what is on the chip */ pgm->vfy_led(pgm, ON); if (quell_progress < 2) { fprintf(stderr, "%s: verifying %s memory against %s:\n", progname, mem->desc, upd->filename); fprintf(stderr, "%s: load data %s data from input file %s:\n", progname, mem->desc, upd->filename); } rc = fileio(FIO_READ, upd->filename, upd->format, p, upd->memtype, -1); if (rc < 0) { fprintf(stderr, "%s: read from file '%s' failed\n", progname, upd->filename); return -1; } v = avr_dup_part(p); size = rc; if (quell_progress < 2) { fprintf(stderr, "%s: input file %s contains %d bytes\n", progname, upd->filename, size); fprintf(stderr, "%s: reading on-chip %s data:\n", progname, mem->desc); } report_progress (0,1,"Reading"); rc = avr_read(pgm, p, upd->memtype, v); if (rc < 0) { fprintf(stderr, "%s: failed to read all of %s memory, rc=%d\n", progname, mem->desc, rc); pgm->err_led(pgm, ON); return -1; } report_progress (1,1,NULL); if (quell_progress < 2) { fprintf(stderr, "%s: verifying ...\n", progname); } rc = avr_verify(p, v, upd->memtype, size); if (rc < 0) { fprintf(stderr, "%s: verification error; content mismatch\n", progname); pgm->err_led(pgm, ON); return -1; } if (quell_progress < 2) { fprintf(stderr, "%s: %d bytes of %s verified\n", progname, rc, mem->desc); } pgm->vfy_led(pgm, OFF); } else { fprintf(stderr, "%s: invalid update operation (%d) requested\n", progname, upd->op); return -1; } return 0; }
boolean_t test_report_progress(void) { boolean_t retval = B_FALSE; boolean_t handler_ret = B_FALSE; char *loggername = "mylogger"; const char *host = "localhost"; int port = 2333; logger_t *pLogger = NULL; nvlist_t *handler_args = NULL; printf("Test: test_report_progress\n"); pLogger = (logger_t *)test_setup(); if (pLogger == NULL) { printf("Failed to get a Logger\n"); return (retval); } if (nvlist_alloc(&handler_args, NVATTRS, 0) != 0) { printf("Cannot allocate space for handler args\n"); goto cleanup; } if (handler_args == NULL) { printf("nvlist_alloc failed.\n"); goto cleanup; } /* Create a list of arguments for a ProgressHandler */ if ((nvlist_add_string(handler_args, HANDLER, PROGRESS_HANDLER) != 0) || (nvlist_add_string(handler_args, HOST, host) != 0) || (nvlist_add_int32(handler_args, PORT, port) != 0)) { nvlist_free(handler_args); printf("Cannot create handler args\n"); goto cleanup; } handler_ret = add_handler(pLogger, handler_args, LOGGING_PROGRESS_HDLR); nvlist_free(handler_args); if (!handler_ret) { printf("Adding progress handler failed cannot continue\n"); goto cleanup; } else { retval = report_progress(pLogger, 0, "Test: 0 done"); if (!retval) { printf("test_report_progress: Fail 0\n"); goto cleanup; } retval = report_progress(pLogger, 20, "Test 20 done"); if (!retval) { printf("test_report_progress: Fail 20\n"); goto cleanup; } retval = report_progress(pLogger, 40, "Test: 40 done"); if (!retval) { printf("test_report_progress: Fail 40\n"); goto cleanup; } retval = report_progress(pLogger, 60, "Test: 60 done"); if (!retval) { printf("test_report_progress: Fail 60\n"); goto cleanup; } retval = report_progress(pLogger, 80, "Test:80 done"); if (!retval) { printf("test_report_progress: Fail 80\n"); goto cleanup; } retval = report_progress(pLogger, 100, "Test:100 done"); if (!retval) { printf("test_log_message: Fail 100\n"); goto cleanup; } } printf("test_report_progress: Pass\n"); cleanup: Py_XDECREF(pLogger); return (retval); }
/* * copyAndUpdateFile() * * Copies a relation file from src to dst. If pageConverter is non-NULL, this function * uses that pageConverter to do a page-by-page conversion. */ const char * copyAndUpdateFile(pageCnvCtx *pageConverter, const char *src, const char *dst, bool force) { report_progress(NULL, FILE_COPY, "Copy \"%s\" to \"%s\"", src, dst); if (pageConverter == NULL) { #ifndef WIN32 if (copy_file(src, dst, force) == -1) #else if (CopyFile(src, dst, !force) == 0) #endif return getErrorText(); else return NULL; } else { /* * We have a pageConverter object - that implies that the * PageLayoutVersion differs between the two clusters so we have to * perform a page-by-page conversion. * * If the pageConverter can convert the entire file at once, invoke * that plugin function, otherwise, read each page in the relation * file and call the convertPage plugin function. */ #ifdef PAGE_CONVERSION if (pageConverter->convertFile) return pageConverter->convertFile(pageConverter->pluginData, dst, src); else #endif { int src_fd; int dstfd; char buf[BLCKSZ]; ssize_t bytesRead; const char *msg = NULL; if ((src_fd = open(src, O_RDONLY, 0)) < 0) return "could not open source file"; if ((dstfd = open(dst, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) < 0) { close(src_fd); return "could not create destination file"; } while ((bytesRead = read(src_fd, buf, BLCKSZ)) == BLCKSZ) { #ifdef PAGE_CONVERSION if ((msg = pageConverter->convertPage(pageConverter->pluginData, buf, buf)) != NULL) break; #endif if (write(dstfd, buf, BLCKSZ) != BLCKSZ) { msg = "could not write new page to destination"; break; } } close(src_fd); close(dstfd); if (msg) return msg; else if (bytesRead != 0) return "found partial page in source file"; else return NULL; } } }
int git_checkout_index( git_repository *repo, git_checkout_opts *opts) { git_diff_list *diff = NULL; git_diff_options diff_opts = {0}; git_checkout_opts checkout_opts; struct checkout_diff_data data; git_buf workdir = GIT_BUF_INIT; int error; assert(repo); if ((error = git_repository__ensure_not_bare(repo, "checkout")) < 0) return error; diff_opts.flags = GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_INCLUDE_TYPECHANGE | GIT_DIFF_SKIP_BINARY_CHECK; if (opts && opts->paths.count > 0) diff_opts.pathspec = opts->paths; if ((error = git_diff_workdir_to_index(repo, &diff_opts, &diff)) < 0) goto cleanup; if ((error = git_buf_puts(&workdir, git_repository_workdir(repo))) < 0) goto cleanup; normalize_options(&checkout_opts, opts); memset(&data, 0, sizeof(data)); data.path = &workdir; data.workdir_len = git_buf_len(&workdir); data.checkout_opts = &checkout_opts; data.owner = repo; data.total_steps = (size_t)git_diff_num_deltas(diff); if ((error = retrieve_symlink_capabilities(repo, &data.can_symlink)) < 0) goto cleanup; /* Checkout is best performed with three passes through the diff. * * 1. First do removes, because we iterate in alphabetical order, thus * a new untracked directory will end up sorted *after* a blob that * should be checked out with the same name. * 2. Then checkout all blobs. * 3. Then checkout all submodules in case a new .gitmodules blob was * checked out during pass #2. */ report_progress(&data, NULL); if (!(error = git_diff_foreach( diff, &data, checkout_remove_the_old, NULL, NULL)) && !(error = git_diff_foreach( diff, &data, checkout_create_the_new, NULL, NULL)) && data.found_submodules) { data.create_submodules = true; error = git_diff_foreach( diff, &data, checkout_create_the_new, NULL, NULL); } cleanup: if (error == GIT_EUSER) error = (data.error != 0) ? data.error : -1; git_diff_list_free(diff); git_buf_free(&workdir); return error; }
/* * Read the entirety of the specified memory type into the * corresponding buffer of the avrpart pointed to by 'p'. If size = * 0, read the entire contents, otherwise, read 'size' bytes. * * Return the number of bytes read, or < 0 if an error occurs. */ int avr_read(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size) { unsigned char rbyte; unsigned long i; unsigned char * buf; AVRMEM * mem = NULL; int rc; /* NEW */ if(strcmp(memtype, "signature") == 0) { mem = p->sigmem; } else if(strcmp(memtype, "flash") == 0) { mem = p->flashmem; } else if(strcmp(memtype, "lfuse") == 0) { mem = p->lfusemem; } else if(strcmp(memtype, "hfuse") == 0) { mem = p->hfusemem; } // mem = avr_locate_mem(p, memtype); if (mem == NULL) { logprintf(LOG_ERR, "No \"%s\" memory for part %s", memtype, p->desc); return -1; } buf = mem->buf; if (size == 0) { size = mem->size; } /* * start with all 0xff */ memset(buf, 0xff, size); if (pgm->paged_load != NULL && mem->page_size != 0) { /* * the programmer supports a paged mode read, perhaps more * efficiently than we can read it directly, so use its routine * instead */ rc = pgm->paged_load(pgm, p, mem, mem->page_size, size); if (rc >= 0) { if (strcasecmp(mem->desc, "flash") == 0) return avr_mem_hiaddr(mem); else return rc; } } if (strcmp(mem->desc, "signature") == 0) { if (pgm->read_sig_bytes) { return pgm->read_sig_bytes(pgm, p, mem); } } for (i=0; i<size; i++) { rc = pgm->read_byte(pgm, p, mem, i, &rbyte); if (rc != 0) { logprintf(LOG_ERR, "avr_read(): error reading address 0x%04lx", i); if (rc == -1) logprintf(LOG_ERR, "read operation not supported for memory \"%s\"", memtype); return -2; } buf[i] = rbyte; report_progress(i, size, NULL); } if (strcasecmp(mem->desc, "flash") == 0) return avr_mem_hiaddr(mem); else return i; }
HRESULT protocol_continue(Protocol *protocol, PROTOCOLDATA *data) { HRESULT hres; if (!data) { WARN("Expected pProtocolData to be non-NULL\n"); return S_OK; } if(!protocol->request) { WARN("Expected request to be non-NULL\n"); return S_OK; } if(!protocol->protocol_sink) { WARN("Expected IInternetProtocolSink pointer to be non-NULL\n"); return S_OK; } if(protocol->flags & FLAG_ERROR) { protocol->flags &= ~FLAG_ERROR; protocol->vtbl->on_error(protocol, (DWORD)data->pData); return S_OK; } if(protocol->post_stream) return write_post_stream(protocol); if(data->pData == (LPVOID)BINDSTATUS_DOWNLOADINGDATA) { hres = protocol->vtbl->start_downloading(protocol); if(FAILED(hres)) { protocol_close_connection(protocol); report_result(protocol, hres); return S_OK; } if(protocol->bindf & BINDF_NEEDFILE) { WCHAR cache_file[MAX_PATH]; DWORD buflen = sizeof(cache_file); if(InternetQueryOptionW(protocol->request, INTERNET_OPTION_DATAFILE_NAME, cache_file, &buflen)) { report_progress(protocol, BINDSTATUS_CACHEFILENAMEAVAILABLE, cache_file); }else { FIXME("Could not get cache file\n"); } } protocol->flags |= FLAG_FIRST_CONTINUE_COMPLETE; } if(data->pData >= (LPVOID)BINDSTATUS_DOWNLOADINGDATA) { BOOL res; /* InternetQueryDataAvailable may immediately fork and perform its asynchronous * read, so clear the flag _before_ calling so it does not incorrectly get cleared * after the status callback is called */ protocol->flags &= ~FLAG_REQUEST_COMPLETE; res = InternetQueryDataAvailable(protocol->request, &protocol->available_bytes, 0, 0); if(res) { protocol->flags |= FLAG_REQUEST_COMPLETE; report_data(protocol); }else if(GetLastError() != ERROR_IO_PENDING) { protocol->flags |= FLAG_REQUEST_COMPLETE; WARN("InternetQueryDataAvailable failed: %d\n", GetLastError()); report_result(protocol, INET_E_DATA_NOT_AVAILABLE); } } return S_OK; }
/* * Write the whole memory region of the specified memory from the * corresponding buffer of the avrpart pointed to by 'p'. Write up to * 'size' bytes from the buffer. Data is only written if the new data * value is different from the existing data value. Data beyond * 'size' bytes is not affected. * * Return the number of bytes written, or -1 if an error occurs. */ int avr_write(PROGRAMMER * pgm, AVRPART * p, char * memtype, int size) { int rc; int wsize; long i; unsigned char data; int werror; AVRMEM * m = NULL; /* NEW */ if(strcmp(memtype, "flash") == 0) { m = p->flashmem; } else if(strcmp(memtype, "lfuse") == 0) { m = p->lfusemem; } else if(strcmp(memtype, "hfuse") == 0) { m = p->hfusemem; } if (m == NULL) { logprintf(LOG_ERR, "No \"%s\" memory for part %s", memtype, p->desc); return -1; } werror = 0; wsize = m->size; if (size < wsize) { wsize = size; } else if (size > wsize) { logprintf(LOG_ERR, "%d bytes requested, but memory region is only %d bytes", size, wsize); logprintf(LOG_ERR, "Only %d bytes will actually be written", wsize); } if (pgm->paged_write != NULL && m->page_size != 0) { /* * the programmer supports a paged mode write, perhaps more * efficiently than we can read it directly, so use its routine * instead */ if ((i = pgm->paged_write(pgm, p, m, m->page_size, size)) >= 0) return i; } if (pgm->write_setup) { pgm->write_setup(pgm, p, m); } for (i=0; i<wsize; i++) { data = m->buf[i]; report_progress(i, wsize, NULL); rc = avr_write_byte(pgm, p, m, i, data); if (rc) { logprintf(LOG_ERR, "***failed"); werror = 1; } if (m->paged) { /* * check to see if it is time to flush the page with a page * write */ if (((i % m->page_size) == m->page_size-1) || (i == wsize-1)) { rc = avr_write_page(pgm, p, m, i); if (rc) { logprintf(LOG_ERR, " *** page %ld (addresses 0x%04lx - 0x%04lx) failed to write", i % m->page_size, i - m->page_size + 1, i); werror = 1; } } } } return i; }
int terrain_filter( float *data, // input/output: array of data to process (row-major order) double detail, // input: "detail" exponent to be applied int nrows, // input: number of rows in data array int ncols, // input: number of columns in data array double xdim, // input: spacing between pixel columns (in degrees or meters) double ydim, // input: spacing between pixel rows (in degrees or meters) enum Terrain_Coord_Type coord_type, // input: coordinate type for xdim & ydim (degrees or meters) double center_lat, // input: latitude in degrees at center of data array // (ignored if coord_type == TERRAIN_METERS) const struct Terrain_Progress_Callback *progress // optional callback functor for status; NULL for none // enum Terrain_Reg registration // feature not yet implemented ) // Computes operator (-Laplacian)^(detail/2) applied to data array. // Returns 0 on success, nonzero if an error occurred (see enum Terrain_Filter_Errors). // Mean of data array is always (approximately) zero on output. // On input, vertical units (data array values) should be in meters. { enum Terrain_Reg registration = TERRAIN_REG_CELL; int num_threads = 1; // number of threads used to parallelize the three DCT loops // approximate relative amount of time spent in each step // (actual times vary with data array size, memory size, and DCT algorithms chosen): const float step_times[6] = { 0.5, 2.0/num_threads, 1.0, 4.0/num_threads, 1.0, 2.0/num_threads }; const int total_steps = sizeof( step_times ) / sizeof( *step_times ); struct Terrain_Progress_Info progress_info = init_progress( progress, step_times, total_steps ); struct Transpose_Progress_Callback sub_progress = { relay_progress, &progress_info }; const double steepness = 2.0; int error; int type_fwd, type_bwd; int i, j; float *ptr; float data_min, data_max; double normalizer; double xres, yres; double xscale, yscale; double xsize, ysize; struct Terrain_Operator_Info info; // Determine pixel dimensions: if (coord_type == TERRAIN_DEGREES) { geographic_scale( center_lat, &xsize, &ysize ); // convert degrees to meters (approximately) xres = xdim * xsize; yres = ydim * ysize; } else { xres = xdim; yres = ydim; } xscale = fabs( 1.0 / xres ); yscale = fabs( 1.0 / yres ); switch (registration) { case TERRAIN_REG_GRID: type_fwd = 1; type_bwd = 1; break; case TERRAIN_REG_CELL: type_fwd = 2; type_bwd = 3; break; default: return TERRAIN_FILTER_INVALID_PARAM; } if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } data_min = data[0]; data_max = data[0]; for (i=0, ptr=data; i<nrows; ++i, ptr+=ncols) { //float *ptr = data + (LONG)i * (LONG)ncols; for (j=0; j<ncols; ++j) { if (ptr[j] < data_min) { data_min = ptr[j]; } else if (ptr[j] > data_max) { data_max = ptr[j]; } } } normalizer = pow( 2.0 / (data_max - data_min), 1.0 - detail ); normalizer *= pow( steepness, -detail ); for (i=0, ptr=data; i<nrows; ++i, ptr+=ncols) { //float *ptr = data + (LONG)i * (LONG)ncols; for (j=0; j<ncols; ++j) { ptr[j] *= normalizer; } } error = setup_operator( detail, ncols, nrows, xscale, yscale, registration, &info ); if (error) { return error; } set_progress( &progress_info, 1 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } // CONCURRENCY NOTE: The iterations of the loop below will be // independent and can be executed in parallel, if each thread has // its own dct_plan with separate calls to setup_dcts() and cleanup_dcts(). { struct Dct_Plan dct_plan = setup_dcts( type_fwd, ncols ); if (!dct_plan.dct_buffer) { return TERRAIN_FILTER_MALLOC_ERROR; } for (i=0; i<nrows-1; i+=2) { float *ptr = data + (LONG)i * (LONG)ncols; two_dcts( ptr, ncols, &dct_plan ); if (progress && update_progress( &progress_info, i+2, nrows )) { return TERRAIN_FILTER_CANCELED; } } if (nrows & 1) { float *ptr = data + (LONG)(nrows - 1) * (LONG)ncols; single_dct( ptr, ncols, &dct_plan ); } cleanup_dcts( &dct_plan ); } set_progress( &progress_info, 2 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } error = transpose_inplace( data, nrows, ncols, progress ? &sub_progress : NULL ); if (error) { if (error > 0) { return TERRAIN_FILTER_MALLOC_ERROR; } else { return TERRAIN_FILTER_CANCELED; } } set_progress( &progress_info, 3 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } // CONCURRENCY NOTE: The iterations of the loop below will be // independent and can be executed in parallel, if each thread has // its own fwd_plan and bwd_plan with separate calls to setup_dcts() // and cleanup_dcts(). { struct Dct_Plan fwd_plan = setup_dcts( type_fwd, nrows ); struct Dct_Plan bwd_plan = setup_dcts( type_bwd, nrows ); if (!fwd_plan.dct_buffer || !bwd_plan.dct_buffer) { return TERRAIN_FILTER_MALLOC_ERROR; } for (i=0; i<ncols-1; i+=2) { float *ptr = data + (LONG)i * (LONG)nrows; two_dcts( ptr, nrows, &fwd_plan ); apply_operator( data, i, nrows, info ); apply_operator( data, i+1, nrows, info ); two_dcts( ptr, nrows, &bwd_plan ); if (progress && update_progress( &progress_info, i+2, ncols )) { return TERRAIN_FILTER_CANCELED; } } if (ncols & 1) { float *ptr = data + (LONG)(ncols - 1) * (LONG)nrows; single_dct( ptr, nrows, &fwd_plan ); apply_operator( data, ncols-1, nrows, info ); single_dct( ptr, nrows, &bwd_plan ); } cleanup_dcts( &bwd_plan ); cleanup_dcts( &fwd_plan ); } if (flt_isnan( data[0] )) { return TERRAIN_FILTER_NULL_VALUES; } set_progress( &progress_info, 4 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } error = transpose_inplace( data, ncols, nrows, progress ? &sub_progress : NULL ); if (error) { if (error > 0) { return TERRAIN_FILTER_MALLOC_ERROR; } else { return TERRAIN_FILTER_CANCELED; } } set_progress( &progress_info, 5 ); if (progress && report_progress( &progress_info )) { return TERRAIN_FILTER_CANCELED; } // CONCURRENCY NOTE: The iterations of the loop below will be // independent and can be executed in parallel, if each thread has // its own dct_plan with separate calls to setup_dcts() and cleanup_dcts(). { struct Dct_Plan dct_plan = setup_dcts( type_bwd, ncols ); if (!dct_plan.dct_buffer) { return TERRAIN_FILTER_MALLOC_ERROR; } for (i=0; i<nrows-1; i+=2) { float *ptr = data + (LONG)i * (LONG)ncols; two_dcts( ptr, ncols, &dct_plan ); if (progress && update_progress( &progress_info, i+2, nrows )) { return TERRAIN_FILTER_CANCELED; } } if (nrows & 1) { float *ptr = data + (LONG)(nrows - 1) * (LONG)ncols; single_dct( ptr, ncols, &dct_plan ); } cleanup_dcts( &dct_plan ); } cleanup_operator( info ); set_progress( &progress_info, 6 ); if (progress) { // report final progress; ignore any cancel request at this point report_progress( &progress_info ); } return TERRAIN_FILTER_SUCCESS; }