draw_state create_draw_state(boost::property_tree::ptree const& props) { return{ nullptr, props.get("use_alpha_blending", false), read_property(props, "alpha_blending_src_function", get_map_from_alpha_blending_function_names_to_gl_values()), read_property(props, "alpha_blending_dst_function", get_map_from_alpha_blending_function_names_to_gl_values()) }; }
bool property_get(const std::string &key, std::string &value_out) { const prop_info *pi = libc_system_property_find(key.c_str()); if (!pi) { return false; } std::string name; read_property(pi, name, value_out); return true; }
bool property_get_all(std::unordered_map<std::string, std::string> &map) { return libc_system_property_foreach( [](const prop_info *pi, void *cookie) { auto *map_ = static_cast<std::unordered_map<std::string, std::string> *>(cookie); std::string name; std::string value; read_property(pi, name, value); (*map_)[name] = value; }, &map); }
draw_state_data::draw_state_data(async::finalise_load_on_destroy_ptr const finaliser) : m_use_alpha_blending(false) , m_alpha_blending_src_function(GL_SRC_ALPHA) , m_alpha_blending_dst_function(GL_ONE_MINUS_CONSTANT_ALPHA) , m_cull_face_mode(GL_BACK) { TMPROF_BLOCK(); boost::filesystem::path const pathname = finaliser->get_key().get_unique_id(); if (!boost::filesystem::exists(pathname)) throw std::runtime_error(msgstream() << "The passed file '" << pathname << "' does not exist."); boost::property_tree::ptree draw_state_ptree; boost::property_tree::read_info(pathname.string(), draw_state_ptree); m_use_alpha_blending = draw_state_ptree.get("use_alpha_blending", false); m_alpha_blending_src_function = read_property(draw_state_ptree, "alpha_blending_src_function", get_map_from_alpha_blending_function_names_to_gl_values()); m_alpha_blending_dst_function = read_property(draw_state_ptree, "alpha_blending_dst_function", get_map_from_alpha_blending_function_names_to_gl_values()); m_cull_face_mode = read_property(draw_state_ptree, "cull_face_mode", get_map_from_cull_mode_names_to_gl_values()); }
bool property_list(PropertyListCb prop_fn, void *cookie) { struct PropListCtx { PropertyListCb prop_fn; void *cookie; }; PropListCtx ctx{ prop_fn, cookie }; return libc_system_property_foreach( [](const prop_info *pi, void *cookie_) { auto *ctx_ = static_cast<PropListCtx *>(cookie_); std::string name; std::string value; read_property(pi, name, value); ctx_->prop_fn(name, value, ctx_->cookie); }, &ctx); }
/* Set properties on the view based on settings from the specified theme file. */ grub_err_t grub_gfxmenu_view_load_theme (grub_gfxmenu_view_t view, const char *theme_path) { grub_file_t file; struct parsebuf p; p.view = view; p.theme_dir = grub_get_dirname (theme_path); file = grub_file_open (theme_path, GRUB_FILE_TYPE_THEME); if (! file) { grub_free (p.theme_dir); return grub_errno; } p.len = grub_file_size (file); p.buf = grub_malloc (p.len); p.pos = 0; p.line_num = 1; p.col_num = 1; p.filename = theme_path; if (! p.buf) { grub_file_close (file); grub_free (p.theme_dir); return grub_errno; } if (grub_file_read (file, p.buf, p.len) != p.len) { grub_free (p.buf); grub_file_close (file); grub_free (p.theme_dir); return grub_errno; } if (view->canvas) view->canvas->component.ops->destroy (view->canvas); view->canvas = grub_gui_canvas_new (); if (!view->canvas) goto fail; ((grub_gui_component_t) view->canvas) ->ops->set_bounds ((grub_gui_component_t) view->canvas, &view->screen); while (has_more (&p)) { /* Skip comments (lines beginning with #). */ if (peek_char (&p) == '#') { advance_to_next_line (&p); continue; } /* Find the first non-whitespace character. */ skip_whitespace (&p); /* Handle the content. */ if (peek_char (&p) == '+') { /* Skip the '+'. */ read_char (&p); read_object (&p, view->canvas); } else { read_property (&p); } if (grub_errno != GRUB_ERR_NONE) goto fail; } /* Set the new theme path. */ grub_free (view->theme_path); view->theme_path = grub_strdup (theme_path); goto cleanup; fail: if (view->canvas) { view->canvas->component.ops->destroy (view->canvas); view->canvas = 0; } cleanup: grub_free (p.buf); grub_file_close (file); grub_free (p.theme_dir); return grub_errno; }
/*----------------------------------------------------------------------------- FUNCTION: phDal4Nfc_uart_read PURPOSE: Reads nNbBytesToRead bytes and writes them in pBuffer. Returns the number of bytes really read or -1 in case of error. -----------------------------------------------------------------------------*/ int phDal4Nfc_uart_read(uint8_t * pBuffer, int nNbBytesToRead) { int ret; int numRead = 0; struct timeval tv; struct timeval *ptv; struct timespec timeout; fd_set rfds; DAL_ASSERT_STR(gComPortContext.nOpened == 1, "read called but not opened!"); DAL_DEBUG("_uart_read() called to read %d bytes", nNbBytesToRead); read_property(); // Read timeout: // FW mode: 10s timeout // 1 byte read: steady-state LLC length read, allowed to block forever // >1 byte read: LLC payload, 100ms timeout (before pn544 re-transmit) if (nNbBytesToRead > 1 && !libnfc_firmware_mode) { clock_gettime(CLOCK_MONOTONIC, &timeout); timeout.tv_nsec += 100000000; if (timeout.tv_nsec > 1000000000) { timeout.tv_sec++; timeout.tv_nsec -= 1000000000; } ptv = &tv; } else if (libnfc_firmware_mode) { clock_gettime(CLOCK_MONOTONIC, &timeout); timeout.tv_sec += 10; ptv = &tv; } else { ptv = NULL; } while (numRead < nNbBytesToRead) { FD_ZERO(&rfds); FD_SET(gComPortContext.nHandle, &rfds); if (ptv) { tv = timeval_remaining(timeout); ptv = &tv; } ret = select(gComPortContext.nHandle + 1, &rfds, NULL, NULL, ptv); if (ret < 0) { DAL_DEBUG("select() errno=%d", errno); if (errno == EINTR || errno == EAGAIN) { continue; } return -1; } else if (ret == 0) { ALOGW("timeout!"); break; // return partial response } ret = read(gComPortContext.nHandle, pBuffer + numRead, nNbBytesToRead - numRead); if (ret > 0) { ret = apply_errors(pBuffer + numRead, ret); DAL_DEBUG("read %d bytes", ret); numRead += ret; } else if (ret == 0) { DAL_PRINT("_uart_read() EOF"); return 0; } else { DAL_DEBUG("_uart_read() errno=%d", errno); if (errno == EINTR || errno == EAGAIN) { continue; } return -1; } } return numRead; }
/*----------------------------------------------------------------------------- FUNCTION: phDal4Nfc_uart_read PURPOSE: Reads nNbBytesToRead bytes and writes them in pBuffer. Returns the number of bytes really read or -1 in case of error. -----------------------------------------------------------------------------*/ int phDal4Nfc_uart_read(uint8_t * pBuffer, int nNbBytesToRead) { int ret; int numRead = 0; struct timeval tv; struct timeval *ptv; struct timespec timeout; fd_set rfds; #ifdef SWISSKNIFEVERSION struct timespec time,time2; clock_gettime(CLOCK_MONOTONIC, &time); #endif DAL_ASSERT_STR(gComPortContext.nOpened == 1, "read called but not opened!"); DAL_DEBUG("_uart_read() called to read %d bytes", nNbBytesToRead); read_property(); // Read timeout: // FW mode: 10s timeout // 1 byte read: steady-state LLC length read, allowed to block forever // >1 byte read: LLC payload, 100ms timeout (before pn544 re-transmit) if (nNbBytesToRead > 1 && !libnfc_firmware_mode) { clock_gettime(CLOCK_MONOTONIC, &timeout); timeout.tv_nsec += 100000000; if (timeout.tv_nsec > 1000000000) { timeout.tv_sec++; timeout.tv_nsec -= 1000000000; } ptv = &tv; } else if (libnfc_firmware_mode) { clock_gettime(CLOCK_MONOTONIC, &timeout); timeout.tv_sec += 10; ptv = &tv; } else { ptv = NULL; } while (numRead < nNbBytesToRead) { FD_ZERO(&rfds); FD_SET(gComPortContext.nHandle, &rfds); if (ptv) { tv = timeval_remaining(timeout); ptv = &tv; } ret = select(gComPortContext.nHandle + 1, &rfds, NULL, NULL, ptv); if (ret < 0) { DAL_DEBUG("select() errno=%d", errno); if (errno == EINTR || errno == EAGAIN) { continue; } return -1; } else if (ret == 0) { ALOGW("timeout!"); break; // return partial response } ret = read(gComPortContext.nHandle, pBuffer + numRead, nNbBytesToRead - numRead); if (ret > 0) { // ret = apply_errors(pBuffer + numRead, ret); DAL_DEBUG("read %d bytes", ret); numRead += ret; } else if (ret == 0) { DAL_PRINT("_uart_read() EOF"); return 0; } else { DAL_DEBUG("_uart_read() errno=%d", errno); if (errno == EINTR || errno == EAGAIN) { continue; } return -1; } } #ifdef SWISSKNIFEVERSION clock_gettime(CLOCK_MONOTONIC, &time2); #ifdef LOGSWISSKNIFE SwissKnife_Log(pBuffer,nNbBytesToRead,"Receiving message:"); #endif if(rapidBitExchange && receivedMessages < 32) { if(nNbBytesToRead == 1) { if(pBuffer[0] == 0x03) { msg3[receivedMessages] = (time2.tv_sec*1000000000)+time2.tv_nsec; } else if (pBuffer[0] == 0x07) { msgsize[receivedMessages] = (time2.tv_sec*1000000000)+time2.tv_nsec; } } else if(nNbBytesToRead == 7) { data[receivedMessages] = (time2.tv_sec*1000000000)+time2.tv_nsec; } } #endif return numRead; }