int db_list_contains(brain_t brain, enum list type, word_t word) { PGresult *res; const char *param[3]; char tmp[3][32]; if (brain == 0 || word == 0) return -EINVAL; if (db_connect()) return -EDB; SET_PARAM(param, tmp, 0, brain); SET_PARAM(param, tmp, 1, type); SET_PARAM(param, tmp, 2, word); res = PQexecPrepared(conn, "list_get", 3, param, NULL, NULL, 0); if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail; if (PQntuples(res) == 0) goto not_found; PQclear(res); return OK; fail: log_error("db_list_contains", PQresultStatus(res), PQresultErrorMessage(res)); PQclear(res); return -EDB; not_found: PQclear(res); return -ENOTFOUND; }
static void cmd_webserver(Stream *chp, int argc, char* argv[]) { if (argc < 1) { chprintf(chp, "Usage: webserver on|off|info|auth\r\n"); } else if (strncasecmp("on", argv[0], 2) == 0) { chprintf(chp, "***** HTTP SERVER ON *****\r\n"); SET_BYTE_PARAM(HTTP_ON, 1); wifi_restart(); } else if (strncasecmp("off", argv[0], 2) == 0) { chprintf(chp, "***** HTTP SERVER OFF *****\r\n"); SET_BYTE_PARAM(HTTP_ON, 0); wifi_restart(); } else if (strncasecmp("info", argv[0], 2) == 0) { chprintf(chp, "Webserver is %s\r\n", (GET_BYTE_PARAM(HTTP_ON) ? "on" : "off")); } else if (strncasecmp("auth", argv[0], 3) == 0) { chprintf(chp, "Enter username: "******"Enter password: "******"Ok\r\n"); } } }
char* parseFreq(char* val, char* buf, bool tx) { uint32_t f = 0; if (sscanf(val, "%ld", &f) == 1) { if (f < TRX_MIN_FREQUENCY) sprintf(buf, "ERROR. Frequency is below lower limit"); else if (f > TRX_MAX_FREQUENCY) sprintf(buf, "ERROR. Frequency is above upper limit"); else { sprintf(buf, "OK"); if (tx) { SET_PARAM(TRX_TX_FREQ, &f); radio_setFreq(f, 0); } else { SET_PARAM(TRX_RX_FREQ, &f); radio_setFreq(0, f); } } } else sprintf(buf, "ERROR. Couldn't parse input. Wrong format?"); return buf; }
static void trgt_param_set(struct iscsi_target *target, struct iscsi_param_info *info) { struct iscsi_trgt_param *param = &target->trgt_param; u32 *iparam = info->target_param; if (SET_PARAM(param, info, iparam, wthreads)) wthread_start(target); SET_PARAM(param, info, iparam, target_type); SET_PARAM(param, info, iparam, queued_cmnds); }
/* * Function to be called internally for raising an event */ static void raise_event(event_id_t e, str *param, unsigned int *val, unsigned int *thr, str *user, str *number, unsigned int *ruleid) { #define SET_PARAM(pname, ptype) \ if (evi_param_set_ ##ptype (pname ## _p, pname) < 0) { \ LM_ERR("cannot set " # pname "parameter\n"); \ return; \ } SET_PARAM(param, str); SET_PARAM(val, int); SET_PARAM(thr, int); SET_PARAM(user, str); SET_PARAM(number, str); SET_PARAM(ruleid, int); #undef SET_PARAM if (evi_raise_event(e, event_params) < 0) LM_ERR("cannot raise event\n"); }
int db_list_iter(brain_t brain, enum list type, int (*callback)(void *data, word_t ref, const char *word), void *data) { PGresult *res; unsigned int num, i; const char *param[2]; char tmp[2][32]; if (brain == 0) return -EINVAL; if (db_connect()) return -EDB; SET_PARAM(param, tmp, 0, brain); SET_PARAM(param, tmp, 1, type); res = PQexecPrepared(conn, "list_iter", 2, param, NULL, NULL, 0); if (PQresultStatus(res) != PGRES_TUPLES_OK) goto fail; num = PQntuples(res); for (i = 0; i < num; i++) { word_t ref; char *word; int ret; GET_VALUE(res, i, 0, ref); word = PQgetvalue(res, i, 1); if (word == NULL) goto fail; ret = callback(data, ref, word); if (ret) goto fail; } PQclear(res); return OK; fail: log_error("db_list_iter", PQresultStatus(res), PQresultErrorMessage(res)); PQclear(res); return -EDB; }
static void cmd_mycall(Stream *chp, int argc, char *argv[]) { addr_t x; if (argc > 0) { str2addr(&x, argv[0], false); SET_PARAM(MYCALL, &x); chprintf(chp, "Ok\r\n"); } else { GET_PARAM(MYCALL, &x); chprintf(chp, "MYCALL %s\r\n", addr2str(buf, &x)); } }
static void cmd_dest(Stream *chp, int argc, char *argv[]) { addr_t x; if (argc > 0) { str2addr(&x, argv[0], false); SET_PARAM(DEST, &x); chprintf(chp, "Ok\r\n"); } else { GET_PARAM(DEST, &x); chprintf(chp, "DEST %s\r\n", addr2str(buf, &x)); } }
char* parseDigipathTokens(int argc, char* argv[], char* buf) { __digilist_t digis; uint8_t ndigis; if (argc==1 && strncasecmp("off", argv[0], 3)==0) ndigis = 0; else { ndigis = args2digis(digis, argc, argv); SET_PARAM(DIGIS, digis); } SET_BYTE_PARAM(NDIGIS, ndigis); sprintf(buf, "OK"); return buf; }
int db_list_zap(brain_t brain, enum list type) { PGresult *res; const char *param[2]; char tmp[2][32]; if (brain == 0) return -EINVAL; if (db_connect()) return -EDB; SET_PARAM(param, tmp, 0, brain); SET_PARAM(param, tmp, 1, type); res = PQexecPrepared(conn, "list_zap", 2, param, NULL, NULL, 0); if (PQresultStatus(res) != PGRES_COMMAND_OK) goto fail; PQclear(res); return OK; fail: log_error("db_list_zap", PQresultStatus(res), PQresultErrorMessage(res)); PQclear(res); return -EDB; }
char* parseTurnLimit(char* val, char* buf) { uint16_t turn = 0; if (sscanf(val, "%hu", &turn) == 1) { if (turn > 360) sprintf(buf, "ERROR. Turn angle must be less than 360 degrees"); else { sprintf(buf, "OK"); SET_PARAM(TRACKER_TURN_LIMIT, &turn); } } else sprintf(buf, "ERROR. Couldn't parse input. Wrong format?"); return buf; }
void ParameterSetValueById(uint16_t id, const void *value) { if (id < PARAMETERS_TOTAL) { switch(onboardParameters[id].dataType) { case PARAMETERS_DATATYPE_UINT8: SET_PARAM(uint8_t); break; case PARAMETERS_DATATYPE_INT8: SET_PARAM(int8_t); break; case PARAMETERS_DATATYPE_UINT16: SET_PARAM(uint16_t); break; case PARAMETERS_DATATYPE_INT16: SET_PARAM(int16_t); break; case PARAMETERS_DATATYPE_UINT32: SET_PARAM(uint32_t); break; case PARAMETERS_DATATYPE_INT32: SET_PARAM(int32_t); break; case PARAMETERS_DATATYPE_UINT64: SET_PARAM(uint64_t); break; case PARAMETERS_DATATYPE_INT64: SET_PARAM(int64_t); break; case PARAMETERS_DATATYPE_REAL32: SET_PARAM(float); break; case PARAMETERS_DATATYPE_REAL64: SET_PARAM(double); break; default: break; } } }
static void cmd_softap(Stream *chp, int argc, char* argv[]) { if (argc < 1) { chprintf(chp, "Usage: softap info|auth\r\n"); } else if (strncasecmp("info", argv[0], 2) == 0) { chprintf(chp, " AP SSID: %s\r\n", wifi_doCommand("AP.SSID", buf)); chprintf(chp, " AP IP address: %s\r\n", wifi_doCommand("AP.IP", buf)); } else if (strncasecmp("auth", argv[0], 3) == 0) { chprintf(chp, "Enter password: "******"Ok\r\n"); } else chprintf(chp, "ERROR. AP password must be at least 8 characters\r\n"); } }
static void __disp_resc_dev_data(struct disp_vsync_info *vsync, struct disp_resc_param *dev_par, struct disp_syncgen_par *sgpar) { struct nxp_lcd_plat_data *plcd = &resc_data; struct disp_vsync_info *vsc = &__resc_vsync; struct disp_resc_param *dst = (struct disp_resc_param *)plcd->dev_param; struct disp_resc_param *src = dev_par; if (dev_par) { SET_PARAM(src, dst, clip_left); SET_PARAM(src, dst, clip_right); SET_PARAM(src, dst, hs_delay); SET_PARAM(src, dst, sync2in_vs); SET_PARAM(src, dst, h_f_on); SET_PARAM(src, dst, v_f_on); SET_PARAM(src, dst, h_f_coe); SET_PARAM(src, dst, v_f_coe); } if (sgpar) plcd->sync_gen = sgpar; SET_VSYNC_INFO(vsync, plcd->vsync); }
static void __disp_hdmi_dev_data(struct disp_vsync_info *vsync, struct disp_hdmi_param *dev_par, struct disp_syncgen_par *sgpar) { struct nxp_lcd_plat_data *plcd = &hdmi_data; struct disp_vsync_info *vsc = &__hdmi_vsync; struct disp_hdmi_param *dst = (struct disp_hdmi_param *)plcd->dev_param; struct disp_hdmi_param *src = dev_par; if (dev_par) { switch (src->preset) { case 0: vsc->h_active_len = 1280, vsc->v_active_len = 720; break; case 1: vsc->h_active_len = 1920, vsc->v_active_len = 1080; break; default: printk("***** %s: NOT SUPPORT HDMI RESOLUTION PRESET (%d) *****\n", __func__, src->preset); return; } SET_PARAM(src, dst, preset); } if (sgpar) plcd->sync_gen = sgpar; SET_VSYNC_INFO(vsync, plcd->vsync); }
static void __disp_lcd_dev_data(struct disp_vsync_info *vsync, void *dev_par, struct disp_syncgen_par *sgpar) { struct nxp_lcd_plat_data *plcd = &lcd_data; struct disp_lcd_param *dst = (struct disp_lcd_param *)plcd->dev_param; struct disp_lcd_param *src = dev_par; if (src) { SET_PARAM(src, dst, lcd_format); SET_PARAM(src, dst, lcd_mpu_type); SET_PARAM(src, dst, invert_field); SET_PARAM(src, dst, swap_RB); SET_PARAM(src, dst, yc_order); SET_PARAM(src, dst, lcd_init); SET_PARAM(src, dst, lcd_exit); } if (sgpar) plcd->sync_gen = sgpar; if (plcd->vsync && vsync) *plcd->vsync = *vsync; }
static void __disp_mipi_dev_data(struct disp_vsync_info *vsync, struct disp_mipi_param *dev_par, struct disp_syncgen_par *sgpar) { struct nxp_lcd_plat_data *plcd = &mipi_data; struct disp_mipi_param *src = dev_par; struct disp_mipi_param *dst = (struct disp_mipi_param *)plcd->dev_param; if (dev_par) { SET_PARAM(src, dst, pllpms); SET_PARAM(src, dst, bandctl); SET_PARAM(src, dst, pllctl); SET_PARAM(src, dst, phyctl); SET_PARAM(src, dst, lcd_init); SET_PARAM(src, dst, lcd_exit); } if (sgpar) plcd->sync_gen = sgpar; SET_VSYNC_INFO(vsync, plcd->vsync); }
void sal_op_set_from(SalOp *op, const char *from){ SET_PARAM(op,from); }
static void __disp_lvds_dev_data(struct disp_vsync_info *vsync, struct disp_lvds_param *dev_par, struct disp_syncgen_par *sgpar) { struct nxp_lcd_plat_data *plcd = &lvds_data; struct disp_lvds_param *dst = (struct disp_lvds_param *)plcd->dev_param; struct disp_lvds_param *src = dev_par; if (dev_par) { SET_PARAM(src, dst, lcd_format); SET_PARAM(src, dst, inv_hsync); SET_PARAM(src, dst, inv_vsync); SET_PARAM(src, dst, inv_de); SET_PARAM(src, dst, inv_inclk_pol); SET_PARAM(src, dst, loc_enable); SET_PARAM(src, dst, loc_map[0]); SET_PARAM(src, dst, loc_map[1]); SET_PARAM(src, dst, loc_map[2]); SET_PARAM(src, dst, loc_map[3]); SET_PARAM(src, dst, loc_map[4]); SET_PARAM(src, dst, loc_map[5]); SET_PARAM(src, dst, loc_map[6]); SET_PARAM(src, dst, loc_map[7]); SET_PARAM(src, dst, loc_map[8]); SET_PARAM(src, dst, loc_mask[0]); SET_PARAM(src, dst, loc_mask[1]); SET_PARAM(src, dst, loc_pol[0]); SET_PARAM(src, dst, loc_pol[1]); } if (sgpar) plcd->sync_gen = sgpar; if (plcd->vsync && vsync) *plcd->vsync = *vsync; }
static void sess_param_set(struct iscsi_sess_param *param, struct iscsi_param_info *info) { u32 *iparam = info->session_param; SET_PARAM(param, info, iparam, initial_r2t); SET_PARAM(param, info, iparam, immediate_data); SET_PARAM(param, info, iparam, max_connections); SET_PARAM(param, info, iparam, max_recv_data_length); SET_PARAM(param, info, iparam, max_xmit_data_length); SET_PARAM(param, info, iparam, max_burst_length); SET_PARAM(param, info, iparam, first_burst_length); SET_PARAM(param, info, iparam, default_wait_time); SET_PARAM(param, info, iparam, default_retain_time); SET_PARAM(param, info, iparam, max_outstanding_r2t); SET_PARAM(param, info, iparam, data_pdu_inorder); SET_PARAM(param, info, iparam, data_sequence_inorder); SET_PARAM(param, info, iparam, error_recovery_level); SET_PARAM(param, info, iparam, header_digest); SET_PARAM(param, info, iparam, data_digest); SET_PARAM(param, info, iparam, ofmarker); SET_PARAM(param, info, iparam, ifmarker); SET_PARAM(param, info, iparam, ofmarkint); SET_PARAM(param, info, iparam, ifmarkint); }
/***************************************************************************** * OpenDecoder: open the encoder. *****************************************************************************/ static int OpenEncoder(vlc_object_t *p_this) { encoder_t *p_enc = (encoder_t *)p_this; config_ChainParse(p_enc, ENC_CFG_PREFIX, ppsz_enc_options, p_enc->p_cfg); int i_aot; switch (p_enc->fmt_out.i_codec) { case VLC_CODEC_MP4A: i_aot = var_InheritInteger(p_enc, ENC_CFG_PREFIX "profile"); break; case VLC_FOURCC('l', 'a', 'a', 'c'): i_aot = PROFILE_AAC_LC; break; case VLC_FOURCC('h', 'a', 'a', 'c'): i_aot = PROFILE_AAC_HE; break; case VLC_FOURCC('s', 'a', 'a', 'c'): i_aot = PROFILE_AAC_HE_v2; break; default: return VLC_EGENERIC; } if (p_enc->fmt_in.audio.i_channels != 2) if (i_aot == PROFILE_AAC_HE_v2 || i_aot == PROFILE_AAC_ELD) { msg_Err(p_enc, "Selected profile %d can only be used with stereo", i_aot); return VLC_EGENERIC; } uint16_t channel_config; CHANNEL_MODE mode; switch (p_enc->fmt_in.audio.i_channels) { case 1: mode = MODE_1; channel_config = AOUT_CHAN_CENTER; break; case 2: mode = MODE_2; channel_config = AOUT_CHANS_STEREO; break; case 3: mode = MODE_1_2; channel_config = AOUT_CHANS_3_0; break; case 4: mode = MODE_1_2_1; channel_config = AOUT_CHANS_4_CENTER_REAR; break; case 5: mode = MODE_1_2_2; channel_config = AOUT_CHANS_5_0; break; case 6: mode = MODE_1_2_2_1; channel_config = AOUT_CHANS_5_1; break; case 8: mode = MODE_1_2_2_2_1; channel_config = AOUT_CHANS_7_1; break; default: msg_Err(p_enc, "we do not support > 8 input channels, this input has %i", p_enc->fmt_in.audio.i_channels); return VLC_EGENERIC; } p_enc->fmt_in.audio.i_physical_channels = channel_config; msg_Info(p_enc, "Initializing AAC Encoder, %i channels", p_enc->fmt_in.audio.i_channels); /* Allocate the memory needed to store the encoder's structure */ encoder_sys_t *p_sys = (encoder_sys_t *)malloc(sizeof(encoder_sys_t)); if (unlikely(!p_sys)) return VLC_ENOMEM; p_enc->p_sys = p_sys; p_enc->fmt_in.i_codec = VLC_CODEC_S16N; p_enc->fmt_out.i_cat = AUDIO_ES; p_enc->fmt_out.i_codec = VLC_CODEC_MP4A; p_sys->i_pts_last = 0; AACENC_ERROR erraac; erraac = aacEncOpen(&p_sys->handle, 0, p_enc->fmt_in.audio.i_channels); if (erraac != AACENC_OK) { msg_Err(p_enc, "Unable to open encoder: %s", fdkaac_error(erraac)); free(p_sys); return VLC_EGENERIC; } #define SET_PARAM(P, V) do { \ AACENC_ERROR err = aacEncoder_SetParam(p_sys->handle, AACENC_ ## P, V); \ if (err != AACENC_OK) { \ msg_Err(p_enc, "Couldn't set " #P " to value %d: %s", V, fdkaac_error(err)); \ goto error; \ } \ } while(0) SET_PARAM(AOT, i_aot); bool b_eld_sbr = var_InheritBool(p_enc, ENC_CFG_PREFIX "sbr"); if (i_aot == PROFILE_AAC_ELD && b_eld_sbr) SET_PARAM(SBR_MODE, 1); SET_PARAM(SAMPLERATE, p_enc->fmt_out.audio.i_rate); SET_PARAM(CHANNELMODE, mode); SET_PARAM(CHANNELORDER, CH_ORDER_WG4); int i_vbr = var_InheritInteger(p_enc, ENC_CFG_PREFIX "vbr"); if (i_vbr != 0) { if ((i_aot == PROFILE_AAC_HE || i_aot == PROFILE_AAC_HE_v2) && i_vbr > 3) { msg_Warn(p_enc, "Maximum VBR quality for this profile is 3, setting vbr=3"); i_vbr = 3; } SET_PARAM(BITRATEMODE, i_vbr); } else { int i_bitrate = p_enc->fmt_out.i_bitrate; if (i_bitrate == 0) { i_bitrate = 96 * p_enc->fmt_in.audio.i_channels * p_enc->fmt_out.audio.i_rate / 44; if (i_aot == PROFILE_AAC_HE || i_aot == PROFILE_AAC_HE_v2 || b_eld_sbr) i_bitrate /= 2; p_enc->fmt_out.i_bitrate = i_bitrate; msg_Info(p_enc, "Setting optimal bitrate of %i", i_bitrate); } SET_PARAM(BITRATE, i_bitrate); } SET_PARAM(TRANSMUX, 0); SET_PARAM(SIGNALING_MODE, (int)var_InheritInteger(p_enc, ENC_CFG_PREFIX "signaling")); SET_PARAM(AFTERBURNER, !!var_InheritBool(p_enc, ENC_CFG_PREFIX "afterburner")); #undef SET_PARAM erraac = aacEncEncode(p_sys->handle, NULL, NULL, NULL, NULL); if (erraac != AACENC_OK) { msg_Err(p_enc, "Unable to initialize the encoder: %s", fdkaac_error(erraac)); goto error; } AACENC_InfoStruct info = { 0 }; erraac = aacEncInfo(p_sys->handle, &info); if (erraac != AACENC_OK) { msg_Err(p_enc, "Unable to get the encoder info: %s", fdkaac_error(erraac)); goto error; } /* The maximum packet size is 6144 bits aka 768 bytes per channel. */ p_sys->i_maxoutputsize = 768*p_enc->fmt_in.audio.i_channels; p_enc->fmt_in.audio.i_bitspersample = 16; p_sys->i_frame_size = info.frameLength; p_sys->i_encoderdelay = info.encoderDelay; p_enc->fmt_out.i_extra = info.confSize; if (p_enc->fmt_out.i_extra) { p_enc->fmt_out.p_extra = malloc(p_enc->fmt_out.i_extra); if (p_enc->fmt_out.p_extra == NULL) { msg_Err(p_enc, "Unable to allocate fmt_out.p_extra"); goto error; } memcpy(p_enc->fmt_out.p_extra, info.confBuf, p_enc->fmt_out.i_extra); } p_enc->pf_encode_audio = EncodeAudio; #ifndef NDEBUG // TODO: Add more debug info to this config printout msg_Dbg(p_enc, "fmt_out.p_extra = %i", p_enc->fmt_out.i_extra); #endif return VLC_SUCCESS; error: CloseEncoder(p_this); return VLC_EGENERIC; }
VALUE rb_create_instance(VALUE rb_obj, ...) { VAR_DECLARATIONS /* initialize ap for use with the va_arg and va_end macros */ va_start(ap, rb_obj); switch (type(rb_obj)) { CASE(bernoulli) VALUE rb_p; double p; SET_KLASS(bernoulli); rb_p = GET_NEXT_ARG(ap); p = NUM2DBL(rb_p); CHECK_NUMBER(p); /* 0 < p < 1 */ CHECK_PROBABILITY_EXCL(p); /* p parameter correct */ RANDVAR_INIT(bernoulli); SET_PARAM(bernoulli, p); CASE_END CASE(beta) VALUE rb_alpha, rb_beta; double alpha, beta; SET_KLASS(beta); rb_alpha = GET_NEXT_ARG(ap); rb_beta = GET_NEXT_ARG(ap); alpha = NUM2DBL(rb_alpha); beta = NUM2DBL(rb_beta); CHECK_NUMBER(alpha); CHECK_NUMBER(beta); /* alpha > 0 */ CHECK_POSITIVE(alpha); /* beta > 0 */ CHECK_POSITIVE(beta); /* alpha and beta parameters correct */ RANDVAR_INIT(beta); SET_PARAM(beta, alpha); SET_PARAM(beta, beta); CASE_END CASE(binomial) VALUE rb_n, rb_p; long n; double p; SET_KLASS(binomial); rb_n = GET_NEXT_ARG(ap); rb_p = GET_NEXT_ARG(ap); CHECK_RB_INTEGER(rb_n, "n"); n = NUM2LONG(rb_n); p = NUM2DBL(rb_p); CHECK_NUMBER(p); /* n >= 0 */ CHECK_NON_NEGATIVE(n); /* 0 <= p <= 1 */ CHECK_PROBABILITY(p); /* n and p parameters correct */ RANDVAR_INIT(binomial); SET_PARAM(binomial, n); SET_PARAM(binomial, p); CASE_END CASE(chi_squared) VALUE rb_k; long k; SET_KLASS(chi_squared); rb_k = GET_NEXT_ARG(ap); CHECK_RB_INTEGER(rb_k, "k"); k = NUM2LONG(rb_k); /* k > 0 */ CHECK_POSITIVE(k); /* k parameter correct */ RANDVAR_INIT(chi_squared); SET_PARAM(chi_squared, k); CASE_END CASE(continuous_uniform) VALUE rb_a, rb_b; double a,b; SET_KLASS(continuous_uniform); rb_a = GET_NEXT_ARG(ap); rb_b = GET_NEXT_ARG(ap); a = NUM2DBL(rb_a); b = NUM2DBL(rb_b); CHECK_NUMBER(a); CHECK_NUMBER(b); /* a < b */ CHECK_LESS_THAN(a,b); /* a and b parameters correct */ RANDVAR_INIT(continuous_uniform); SET_PARAM(continuous_uniform, a); SET_PARAM(continuous_uniform, b); CASE_END CASE(discrete_uniform) VALUE rb_a, rb_b; long a,b; SET_KLASS(discrete_uniform); rb_a = GET_NEXT_ARG(ap); rb_b = GET_NEXT_ARG(ap); CHECK_RB_INTEGER(rb_a, "a"); CHECK_RB_INTEGER(rb_b, "b"); a = NUM2LONG(rb_a); b = NUM2LONG(rb_b); /* a < b */ CHECK_LESS_THAN(a,b); /* a and b parameters correct */ RANDVAR_INIT(discrete_uniform); SET_PARAM(discrete_uniform, a); SET_PARAM(discrete_uniform, b); CASE_END CASE(exponential) VALUE rb_mean; double mean; SET_KLASS(exponential); rb_mean = GET_NEXT_ARG(ap); mean = NUM2DBL(rb_mean); CHECK_NUMBER(mean); /* mean > 0 */ CHECK_POSITIVE(mean); /* mean parameter correct */ RANDVAR_INIT(exponential); SET_PARAM(exponential, mean); CASE_END CASE(f) VALUE rb_d1, rb_d2; double d1, d2; SET_KLASS(f); rb_d1 = GET_NEXT_ARG(ap); rb_d2 = GET_NEXT_ARG(ap); d1 = NUM2DBL(rb_d1); d2 = NUM2DBL(rb_d2); CHECK_NUMBER(d1); CHECK_NUMBER(d2); /* d1 > 0 */ /* d2 > 0 */ CHECK_POSITIVE(d1); CHECK_POSITIVE(d2); /* d1, d2 parameters correct */ RANDVAR_INIT(f); SET_PARAM(f, d1); SET_PARAM(f, d2); CASE_END CASE(negative_binomial) VALUE rb_r, rb_p; long r; double p; SET_KLASS(negative_binomial); rb_r = GET_NEXT_ARG(ap); rb_p = GET_NEXT_ARG(ap); CHECK_RB_INTEGER(rb_r, "r"); r = NUM2LONG(rb_r); p = NUM2DBL(rb_p); CHECK_NUMBER(p); /* r > 0 */ CHECK_POSITIVE(r); /* 0 < p < 0 */ CHECK_PROBABILITY_EXCL(p); /* r and p parameters correct */ RANDVAR_INIT(negative_binomial); SET_PARAM(negative_binomial, r); SET_PARAM(negative_binomial, p); CASE_END CASE(normal) VALUE rb_mu, rb_sigma; double mu, sigma; SET_KLASS(normal); rb_mu = GET_NEXT_ARG(ap); rb_sigma = GET_NEXT_ARG(ap); mu = NUM2DBL(rb_mu); sigma = NUM2DBL(rb_sigma); CHECK_NUMBER(mu); CHECK_NUMBER(sigma); /* sigma > 0 */ CHECK_POSITIVE(sigma); /* sigma parameter correct */ RANDVAR_INIT(normal); SET_PARAM(normal, mu); SET_PARAM(normal, sigma); CASE_END CASE(pareto) VALUE rb_a, rb_m; double a, m; SET_KLASS(pareto); rb_a = GET_NEXT_ARG(ap); rb_m = GET_NEXT_ARG(ap); a = NUM2DBL(rb_a); m = NUM2DBL(rb_m); CHECK_NUMBER(a); CHECK_NUMBER(m); /* a > 0 */ CHECK_POSITIVE(a); /* m > 0 */ CHECK_POSITIVE(m); /* a and m parameters correct */ RANDVAR_INIT(pareto); SET_PARAM(pareto, a); SET_PARAM(pareto, m); CASE_END CASE(poisson) VALUE rb_mean; double mean; SET_KLASS(poisson); rb_mean = GET_NEXT_ARG(ap); mean = NUM2DBL(rb_mean); CHECK_NUMBER(mean); /* mean > 0 */ CHECK_POSITIVE(mean); /* ensure no overflow */ if (mean > LONG_MAX - 0.05 * LONG_MAX) rb_raise(rb_eArgError, "outcomes may overflow"); /* mean parameter correct */ RANDVAR_INIT(poisson); SET_PARAM(poisson, mean); CASE_END CASE(rademacher) SET_KLASS(rademacher); RANDVAR_INIT(rademacher); CASE_END CASE(rayleigh) VALUE rb_sigma; double sigma; SET_KLASS(rayleigh); rb_sigma = GET_NEXT_ARG(ap); sigma = NUM2DBL(rb_sigma); CHECK_NUMBER(sigma); /* sigma > 0 */ CHECK_POSITIVE(sigma); RANDVAR_INIT(rayleigh); SET_PARAM(rayleigh, sigma); CASE_END CASE(rectangular) SET_KLASS(rectangular); RANDVAR_INIT(rectangular); CASE_END default: rb_rv = Qnil; } /* switch */ va_end(ap); return rb_rv; }
void sal_op_set_to(SalOp *op, const char *to){ SET_PARAM(op,to); }
void __sal_op_set_network_origin(SalOp *op, const char *origin){ SET_PARAM(op,origin); }
void __sal_op_set_remote_contact(SalOp *op, const char* remote_contact){ SET_PARAM(op,remote_contact); }