static twin_bool_t twin_fbdev_init_fb(twin_fbdev_t *tf) { int i; /* We always open /dev/fb0 for now. Might want fixing */ tf->fb_fd = open("/dev/fb0", O_RDWR); if (tf->fb_fd < 0) { SERROR("can't open /dev/fb0"); return 0; } /* Get initial fbdev configuration */ if (ioctl(tf->fb_fd, FBIOGET_VSCREENINFO, &tf->fb_var) < 0) { SERROR("can't get framebuffer config"); return 0; } DEBUG("initial screen size: %dx%d\n", tf->fb_var.xres, tf->fb_var.yres); tf->fb_base = MAP_FAILED; for (i = 0; i < 256; i++) { unsigned short c = (i << 8) | i; tf->cmap[0][i] = tf->cmap[1][i] = tf->cmap[2][i] = c; } return 1; }
void TransPanel::onClickBtnSerialPortOpen() { QComboBox* spCombox = ui.comboBox_serialport ; int currentIdx = spCombox->currentIndex() ; int portNum =spCombox->itemData(currentIdx).toInt(); LOG("选择串口:%d\r\n" ,portNum ); if(serialPort_==NULL) { serialPort_ = new SerialPort(portNum ,DEFAULT_SERIALPORT_BAUD); if(serialPort_ == NULL) return ; serialPort_->set_recv_data_callback(boost::bind(&TransPanel::recvSerialPortDataCB ,this,_1));//数据回调 serialPort_->set_recv_error_callback(boost::bind(&TransPanel::recvSerialPortErrorCB ,this,_1)); //错误回调 bool openSuccess = serialPort_->open() ; //打开串口 if(!openSuccess) { std::string error_msg = serialPort_->get_last_error_message() ; char errorMessage[512] ; sprintf_s(errorMessage,512 , "COM%d 打开失败,错误原因:%s" ,portNum , error_msg.c_str() ); LOG(errorMessage); SERROR(errorMessage); ui.pushButton_com_open->setText("打开串口"); delete serialPort_ ; serialPort_ =NULL ; } else { char message[512] ; sprintf_s(message , 512 ,"COM%d 打开成功!" , portNum); LOG(message); SINFO(message); ui.pushButton_com_open->setText("关闭串口"); spCombox->setEnabled(false); } } else { serialPort_->close() ; delete serialPort_ ; serialPort_ = NULL ; char message[512] ; sprintf_s(message , 512 ,"COM%d 已经关闭!" , portNum); LOG(message); SINFO(message); ui.pushButton_com_open->setText("打开串口"); spCombox->setEnabled(true); } }
static twin_bool_t twin_fbdev_setup_vt(twin_fbdev_t *tf, int switch_sig) { struct vt_mode vtm; struct termios tio; if (ioctl(tf->vt_fd, VT_GETMODE, &vtm) < 0) { SERROR("can't get VT mode"); return 0; } vtm.mode = VT_PROCESS; vtm.relsig = switch_sig; vtm.acqsig = switch_sig; signal(switch_sig, twin_fbdev_vtswitch); tf->vt_swsig = switch_sig; if (ioctl(tf->vt_fd, VT_SETMODE, &vtm) < 0) { SERROR("can't set VT mode"); signal(switch_sig, SIG_IGN); return 0; } tcgetattr(tf->vt_fd, &tf->old_tio); ioctl(tf->vt_fd, KDGKBMODE, &tf->old_kbmode); ioctl(tf->vt_fd, KDSKBMODE, K_MEDIUMRAW); tio = tf->old_tio; tio.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP); tio.c_oflag = 0; tio.c_cflag = CREAD | CS8; tio.c_lflag = 0; tio.c_cc[VTIME]=0; tio.c_cc[VMIN]=1; cfsetispeed(&tio, 9600); cfsetospeed(&tio, 9600); tcsetattr(tf->vt_fd, TCSANOW, &tio); ioctl(tf->vt_fd, KDSETMODE, KD_GRAPHICS); return 1; }
void TransPanel::sendCMD(std::string cmd) { if(serialPort_ == NULL) return ; std::size_t c = serialPort_->write(cmd); if(c) cmdSendInfo(cmd); else { SERROR("命令发送失败!"); } }
/* thread_create() may block forever if it cannot create a thread or * allocate memory. This is preferable to returning a NULL which Solaris * style callers likely never check for... since it can't fail. */ kthread_t * __thread_create(caddr_t stk, size_t stksize, thread_func_t func, const char *name, void *args, size_t len, proc_t *pp, int state, pri_t pri) { thread_priv_t *tp; struct task_struct *tsk; char *p; SENTRY; /* Option pp is simply ignored */ /* Variable stack size unsupported */ ASSERT(stk == NULL); tp = kmem_alloc(sizeof(thread_priv_t), KM_SLEEP); if (tp == NULL) SRETURN(NULL); tp->tp_magic = TP_MAGIC; tp->tp_name_size = strlen(name) + 1; tp->tp_name = kmem_alloc(tp->tp_name_size, KM_SLEEP); if (tp->tp_name == NULL) { kmem_free(tp, sizeof(thread_priv_t)); SRETURN(NULL); } strncpy(tp->tp_name, name, tp->tp_name_size); /* Strip trailing "_thread" from passed name which will be the func * name since the exposed API has no parameter for passing a name. */ p = strstr(tp->tp_name, "_thread"); if (p) p[0] = '\0'; tp->tp_func = func; tp->tp_args = args; tp->tp_len = len; tp->tp_state = state; tp->tp_pri = pri; tsk = kthread_create(thread_generic_wrapper, (void *)tp, "%s", tp->tp_name); if (IS_ERR(tsk)) { SERROR("Failed to create thread: %ld\n", PTR_ERR(tsk)); SRETURN(NULL); } wake_up_process(tsk); SRETURN((kthread_t *)tsk); }
void TransPanel::recvSerialPortErrorCB(boost::system::error_code ec) { if(ec.value() != 995) { LOG( "%d - %s" , ec.value() , ec.message().c_str()); QString com_error; com_error.sprintf("串口读取错误:%s" ,ec.message().c_str() ); SERROR(com_error); } }
void CHistogram2D::apply () throw() { BENCHSTART; FBEGIN; bModuleReady = false; if ( getInput() ) call<Length<imageTL>::value - 1>(); else { alog << LWARN << SERROR("Input type is no 2D or 3D integer image!") << endl; return; } FEND; BENCHSTOP; }
void CNoiseEstimator::apply() throw() { FBEGIN; BENCHSTART; bModuleReady = false; if ( getInput() ) call<Length<imageTL>::value - 1>(); else { alog << LWARN << SERROR("Input type is no 2D or 3D image!") << endl; return; } FEND; BENCHSTOP; }
void vcmn_err(int ce, const char *fmt, va_list ap) { char msg[MAXMSGLEN]; if (ce == CE_PANIC) vpanic(fmt, ap); if (ce != CE_NOTE) { vsnprintf(msg, MAXMSGLEN - 1, fmt, ap); if (fmt[0] == '!') SDEBUG(SD_INFO, "%s%s%s", ce_prefix[ce], msg, ce_suffix[ce]); else SERROR("%s%s%s", ce_prefix[ce], msg, ce_suffix[ce]); } } /* vcmn_err() */
// parse control file --------------------------------------------------------- // PRIVATE void ParseCtrlFile( dword flags ) { int i; char* remptr; char line[ LINE_LENGTH_MAX ]; if ( flags & PARSE_TEXTURES ) NumLoadedTextures = 0; if ( flags & PARSE_OBJECTS ) NumLoadedObjects = 0; if ( flags & PARSE_BITMAPS ) NumLoadedBitmaps = 0; if ( flags & PARSE_CHARSETS ) NumLoadedCharsets = 0; if ( flags & PARSE_SAMPLES ) NumLoadedSamples = 0; if ( flags & PARSE_SONGS ) NumLoadedSongs = 0; if ( flags & PARSE_PALETTES ) NumLoadedPalettes = 0; FILE *fp = SYS_fopen( ctrl_file_name, "r" ); if ( fp == NULL ) { SERROR( "Controlfile error" ); } if ( display_info ) { MSGPUT( "Parsing control file..." ); } // parse sections --------------------------------------------- int linecount = 0; while ( SYS_fgets( line, LINE_LENGTH_MAX, fp ) != NULL ) { if ( ( ( linecount++ & 0x0f ) == 0 ) && display_info ) MSGPUT( "." ); char *scanptr = strtok( line, "/, \t\n\r" ); if ( scanptr == NULL ) continue; else if ( *scanptr == ';' ) continue; else if ( strnicmp( scanptr, "<end", 4 ) == 0 ) break; else if ( *scanptr == '#' ) { if ( stricmp( scanptr, _palette_str ) == 0 ) section = _palette; else if ( stricmp( scanptr, _textures_str ) == 0 ) section = _textures; else if ( stricmp( scanptr, _objects_str ) == 0 ) section = _objects; else if ( stricmp( scanptr, _bitmaps_str ) == 0 ) section = _bitmaps; else if ( stricmp( scanptr, _charsets_str ) == 0 ) section = _charsets; else if ( stricmp( scanptr, _samples_str ) == 0 ) section = _samples; else if ( stricmp( scanptr, _songs_str ) == 0 ) section = _songs; else if ( stricmp( scanptr, _comment_str ) == 0 ) section = _comment; else { SYS_fclose( fp ); PERROR( "Control file-parser: " "[undefined section name]: %s.", scanptr ); } } else switch ( section ) { // texturing data ----------------------------------- case _textures : if ( flags & PARSE_TEXTURES ) { int txwidth, txheight; if ( *scanptr != '\"' ) { txwidth = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); txheight = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); while ( *scanptr++ != '\0' ) {} while ( ( *scanptr == ' ' ) || ( *scanptr == '\t' ) ) scanptr++; } else { txwidth = -1; // fill in later from txheight = -1; // texture file-header remptr = scanptr; while ( *remptr++ != '\0' ) {} if ( *remptr == '\0' ) ParseError( section ); *--remptr = ' '; } if ( ( scanptr = strtok( scanptr, "\"" ) ) == NULL ) ParseError( section ); SETTABENTRY_NAME( TextureInfo, NumLoadedTextures ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); SETTABENTRY_FILENAME( TextureInfo, NumLoadedTextures ); TextureInfo[ NumLoadedTextures ].width = txwidth; TextureInfo[ NumLoadedTextures ].height = txheight; if ( ++NumLoadedTextures >= MAX_TEXTURES ) PANIC( "too many textures." ); } break; // object data files -------------------------------- case _objects : if ( flags & PARSE_OBJECTS ) { int objnum = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); while ( *scanptr++ != '\0' ) {} while ( ( *scanptr == ' ' ) || ( *scanptr == '\t' ) ) scanptr++; if ( ( scanptr = strtok( scanptr, "\"" ) ) == NULL ) ParseError( section ); SETTABENTRY_NAME( ObjectInfo, NumLoadedObjects ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); int objtype = -1; for ( i = 0; i < NUM_DISTINCT_OBJTYPES; i++ ) { if ( stricmp( scanptr, objtype_name[ i ] ) == 0 ) { objtype = i; break; } } if ( ( objtype < 0 ) || ( objtype >= NUM_DISTINCT_OBJTYPES ) ) ParseError( section ); ObjectInfo[ NumLoadedObjects ].type = objtype_id[ objtype ]; if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); SETTABENTRY_FILENAME( ObjectInfo, NumLoadedObjects ); ObjectInfo[ NumLoadedObjects ].lodinfo = NULL; if ( ++NumLoadedObjects >= MAX_DISTINCT_OBJCLASSES ) PANIC( "too many object classes." ); } break; // bitmap files ------------------------------------- case _bitmaps : if ( flags & PARSE_BITMAPS ) { int bitmapnum = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, "x,/ \t\n\r" ) ) == NULL ) ParseError( section ); if ( isdigit( *scanptr ) ) { BitmapInfo[ NumLoadedBitmaps ].width = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, "x,/ \t\n\r" ) ) == NULL ) ParseError( section ); BitmapInfo[ NumLoadedBitmaps ].height = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); } else { BitmapInfo[ NumLoadedBitmaps ].width = -1; // fill in later from BitmapInfo[ NumLoadedBitmaps ].height = -1; // bitmapfile header } SETTABENTRY_FILENAME( BitmapInfo, NumLoadedBitmaps ); BitmapInfo[ NumLoadedBitmaps ].bitmappointer = NULL; if ( ++NumLoadedBitmaps >= MAX_BITMAPS ) PANIC( "too many bitmaps." ); } break; // charset data ------------------------------------- case _charsets : if ( flags & PARSE_CHARSETS ) { int charsetnum = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); if ( isdigit( *scanptr ) ) { CharsetInfo[ NumLoadedCharsets ].srcwidth = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, "x,/ \t\n\r" ) ) == NULL ) ParseError( section ); CharsetInfo[ NumLoadedCharsets ].width = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, "x,/ \t\n\r" ) ) == NULL ) ParseError( section ); CharsetInfo[ NumLoadedCharsets ].height = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); } else { CharsetInfo[ NumLoadedCharsets ].srcwidth = -1; // fill in later CharsetInfo[ NumLoadedCharsets ].width = -1; // from font-info CharsetInfo[ NumLoadedCharsets ].height = -1; // file } SETTABENTRY_FILENAME( CharsetInfo, NumLoadedCharsets ); CharsetInfo[ NumLoadedCharsets ].charsetpointer = NULL; CharsetInfo[ NumLoadedCharsets ].fonttexture = NULL; if ( ++NumLoadedCharsets >= MAX_CHARSETS ) PANIC( "too many charsets." ); } break; // sample data -------------------------------------- case _samples: if ( flags & PARSE_SAMPLES ) { int samplenum = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); // defaults SampleInfo[ NumLoadedSamples ].samplepointer = NULL; SampleInfo[ NumLoadedSamples ].flags = 0; SampleInfo[ NumLoadedSamples ].stereolevel = 0; SampleInfo[ NumLoadedSamples ].volume = AUD_MAX_VOLUME; SampleInfo[ NumLoadedSamples ].samplefreq = 0; SampleInfo[ NumLoadedSamples ].stdfreq = 44100.0f; while ( *scanptr++ != '\0' ) {} if ( isdigit( *scanptr ) ) { if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); float stdfreq = strtod( scanptr, &remptr ); if ( *remptr != '\0' ) ParseError( section ); SampleInfo[ NumLoadedSamples ].stdfreq = stdfreq; while ( *scanptr++ != '\0' ) {} } while ( ( *scanptr == ' ' ) || ( *scanptr == '\t' ) ) scanptr++; if ( ( scanptr = strtok( scanptr, "\"" ) ) == NULL ) ParseError( section ); SETTABENTRY_NAME( SampleInfo, NumLoadedSamples ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); SETTABENTRY_FILENAME( SampleInfo, NumLoadedSamples ); if ( ++NumLoadedSamples >= MAX_SAMPLES ) PANIC( "too many samples." ); } break; // song data ---------------------------------------- case _songs: if ( flags & PARSE_SONGS ) { int songnum = strtol( scanptr, &remptr, 10 ); if ( *remptr != '\0' ) ParseError( section ); while ( *scanptr++ != '\0' ) {} while ( ( *scanptr == ' ' ) || ( *scanptr == '\t' ) ) scanptr++; if ( ( scanptr = strtok( scanptr, "\"" ) ) == NULL ) ParseError( section ); SETTABENTRY_NAME( SongInfo, NumLoadedSongs ); if ( ( scanptr = strtok( NULL, ",/ \t\n\r" ) ) == NULL ) ParseError( section ); SETTABENTRY_FILENAME( SongInfo, NumLoadedSongs ); SongInfo[ NumLoadedSongs ].songpointer = NULL; if ( ++NumLoadedSongs >= MAX_SONGS ) PANIC( "too many songs." ); } break; // filenames of palette files ----------------------- case _palette : if ( flags & PARSE_PALETTES ) { ASSERT( palette_fnames[ NumLoadedPalettes ] == NULL ); palette_fnames[ NumLoadedPalettes ] = (char *) ALLOCMEM( strlen( scanptr ) + 1 ); ASSERT( palette_fnames[ NumLoadedPalettes ] != NULL ); strcpy( palette_fnames[ NumLoadedPalettes ], scanptr ); if ( ++NumLoadedPalettes >= MAX_PALETTES ) PANIC( "too many palettes." ); } break; default: break; } } SYS_fclose( fp ); if ( display_info ) { MSGOUT( "done.\n" ); } }
static twin_bool_t twin_fbdev_get_vt(twin_fbdev_t *tf, int wanted_vt) { struct vt_stat vts; int ttyfd; char vtname[16]; /* Open tty0 and use it to look for a free vt */ ttyfd = open("/dev/tty0", O_WRONLY); if (ttyfd < 0) { SERROR("can't open /dev/tty0"); ttyfd = open("/dev/vc/0", O_WRONLY); if (ttyfd < 0) { SERROR("can't open /dev/vc/0"); return 0; } } /* Get previous VT */ if (ioctl(ttyfd, VT_GETSTATE, &vts) < 0) { SERROR("can't get current VT"); return 0; } tf->vt_prev = vts.v_active; DEBUG("previous vt: %d\n", tf->vt_prev); /* Sanity check wanted_vt and try to obtain a free VT. This is * all somewhat racy but that's how everybody does it. */ if (wanted_vt > 31) wanted_vt = -1; if (wanted_vt > 0 && (vts.v_state & (1 << wanted_vt))) { IERROR("vt%d is busy\n", wanted_vt); wanted_vt = -1; } if (wanted_vt < 0) if (ioctl(ttyfd, VT_OPENQRY, &wanted_vt) < 0) wanted_vt = -1; if (wanted_vt < 0) { IERROR("can't find a free VT"); return 0; } tf->vt_no = wanted_vt; DEBUG("new vt: %d\n", tf->vt_no); /* we don't need tty0 anymore, close it and open the target VT. */ close(ttyfd); /* lose tty */ setpgrp(); if ((ttyfd = open("/dev/tty", O_RDWR)) >= 0) { ioctl(ttyfd, TIOCNOTTY, 0); close(ttyfd); } sprintf(vtname, "/dev/tty%d", tf->vt_no); tf->vt_fd = open(vtname, O_RDWR | O_NONBLOCK); if (tf->vt_fd < 0) { sprintf(vtname, "/dev/vc/%d", tf->vt_no); tf->vt_fd = open(vtname, O_RDWR | O_NONBLOCK); } if (tf->vt_fd < 0) { SERROR("can't open tty %d", tf->vt_no); return 0; } /* set new controlling terminal */ ioctl(tf->vt_fd, TIOCSCTTY, 1); /* set keyboard mode */ ioctl(tf->vt_fd, KDSKBMODE, K_XLATE); tf->vt_active = tf->active = 0; return 1; }
static twin_bool_t twin_fbdev_apply_config(twin_fbdev_t *tf) { off_t off, pgsize = getpagesize(); struct fb_cmap cmap; size_t len; /* Tweak fields to default to 32 bpp argb and virtual == phys */ tf->fb_var.xres_virtual = tf->fb_var.xres; tf->fb_var.yres_virtual = tf->fb_var.yres; tf->fb_var.bits_per_pixel = 32; tf->fb_var.red.length = 8; tf->fb_var.green.length = 8; tf->fb_var.blue.length = 8; tf->fb_var.transp.length = 8; tf->fb_var.red.offset = 0; tf->fb_var.green.offset = 0; tf->fb_var.blue.offset = 0; tf->fb_var.transp.offset = 0; /* Apply fbdev settings */ if (ioctl(tf->fb_fd, FBIOPUT_VSCREENINFO, &tf->fb_var) < 0) { SERROR("can't set fb mode"); return 0; } /* Get new fbdev configuration */ if (ioctl(tf->fb_fd, FBIOGET_VSCREENINFO, tf->fb_var) < 0) { SERROR("can't get framebuffer config"); return 0; } DEBUG("fbdev set config set to:\n"); DEBUG(" xres = %d\n", tf->fb_var.xres); DEBUG(" yres = %d\n", tf->fb_var.yres); DEBUG(" xres_virtual = %d\n", tf->fb_var.xres_virtual); DEBUG(" yres_virtual = %d\n", tf->fb_var.yres_virtual); DEBUG(" bits_per_pix = %d\n", tf->fb_var.bits_per_pixel); DEBUG(" red.len/off = %d/%d\n", tf->fb_var.red.length, tf->fb_var.red.offset); DEBUG(" green.len/off = %d/%d\n", tf->fb_var.green.length, tf->fb_var.green.offset); DEBUG(" blue.len/off = %d/%d\n", tf->fb_var.blue.length, tf->fb_var.blue.offset); DEBUG(" trans.len/off = %d/%d\n", tf->fb_var.transp.length, tf->fb_var.transp.offset); /* Check bits per pixel */ if (tf->fb_var.bits_per_pixel != 32) { SERROR("can't set fb bpp to 32"); return 0; } /* Set colormap */ cmap.start = 0; cmap.len = 256; cmap.red = tf->cmap[0]; cmap.green = tf->cmap[1]; cmap.blue = tf->cmap[2]; cmap.transp = NULL; ioctl(tf->fb_fd, FBIOPUTCMAP, &cmap); /* Get remaining settings */ ioctl(tf->fb_fd, FBIOGET_FSCREENINFO, &tf->fb_fix); DEBUG(" line_lenght = %d\n", tf->fb_fix.line_length); /* Map the fb */ off = (off_t)tf->fb_fix.smem_start & (pgsize - 1); len = (size_t)tf->fb_fix.smem_len + off + (pgsize - 1); len &= ~(pgsize - 1); tf->fb_len = len; tf->fb_base = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, tf->fb_fd, 0); if (tf->fb_base == MAP_FAILED) { SERROR("can't mmap framebuffer"); return 0; } tf->fb_ptr = tf->fb_base + off; return 1; }
int evsql_result_next (struct evsql_result *res, ...) { va_list vargs; struct evsql_item_info *col; size_t col_idx, row_idx = res->row_offset; err_t err; // ensure that evsql_result_begin has been called assert(res->info); // check if we're past the end if (row_idx >= evsql_result_rows(res)) return 0; // varargs va_start(vargs, res); for (col = res->info->columns, col_idx = 0; col->type; col++, col_idx++) { const char *value = NULL; size_t length = 0; // check for NULLs, then try and get the field value if (evsql_result_null(res, row_idx, col_idx)) { if (!col->flags.null_ok) XERROR(err = EINVAL, "r%zu:c%zu: NULL", row_idx, col_idx); } else if (evsql_result_field(res, row_idx, col_idx, &value, &length)) { SERROR(err = EINVAL); } // read the arg switch (col->type) { case EVSQL_TYPE_BINARY: { struct evsql_item_binary *item_ptr = va_arg(vargs, struct evsql_item_binary *); if (value) { item_ptr->ptr = value; item_ptr->len = length; } } break; case EVSQL_TYPE_STRING: { const char **str_ptr = va_arg(vargs, const char **); if (value) { *str_ptr = value; } } break; case EVSQL_TYPE_UINT16: { uint16_t *uval_ptr = va_arg(vargs, uint16_t *); if (!value) break; if (length != sizeof(uint16_t)) XERROR(err = EINVAL, "r%zu:c%zu: wrong size for uint16_t: %zu", row_idx, col_idx, length); int16_t sval = ntohs(*((int16_t *) value)); if (sval < 0) XERROR(err = ERANGE, "r%zu:c%zu: out of range for uint16_t: %hd", row_idx, col_idx, (signed short) sval); *uval_ptr = sval; } break; case EVSQL_TYPE_UINT32: { uint32_t *uval_ptr = va_arg(vargs, uint32_t *); if (!value) break; if (length != sizeof(uint32_t)) XERROR(err = EINVAL, "r%zu:c%zu: wrong size for uint32_t: %zu", row_idx, col_idx, length); int32_t sval = ntohl(*((int32_t *) value)); if (sval < 0) XERROR(err = ERANGE, "r%zu:c%zu: out of range for uint32_t: %ld", row_idx, col_idx, (signed long) sval); *uval_ptr = sval; } break; case EVSQL_TYPE_UINT64: { uint64_t *uval_ptr = va_arg(vargs, uint64_t *); if (!value) break; if (length != sizeof(uint64_t)) XERROR(err = EINVAL, "r%zu:c%zu: wrong size for uint64_t: %zu", row_idx, col_idx, length); int64_t sval = ntohq(*((int64_t *) value)); if (sval < 0) XERROR(err = ERANGE, "r%zu:c%zu: out of range for uint64_t: %lld", row_idx, col_idx, (signed long long) sval); *uval_ptr = sval; } break; default: XERROR(err = EINVAL, "r%zu:c%zu: invalid type: %d", row_idx, col_idx, col->type); } } // advance row index res->row_offset++; // row handled succesfully return 1; error: return -err; }