double constant_transducer::compute_robustness() { // TODO exception if parameter not found for some reason ? For now, we get 0. as a default silent value. if (!param.empty()) { get_param(param, value); } double t0 = (*trace_data_ptr->begin())[0] ; for (auto step = trace_data_ptr->begin(); step != trace_data_ptr->end(); step++) { double t = (*step)[0]-t0; z.appendSample(t, value); if (t>end_time) break; } return z.front().value; }
int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char if_name[MAX_STRING_LEN], mode[32]; assert(result); init_result(result); if (num_param(param) > 1) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, if_name, sizeof(if_name))) return SYSINFO_RET_FAIL; if (FAIL == get_ifmib_general(if_name)) return SYSINFO_RET_FAIL; SET_UI64_RESULT(result, ifmd.ifmd_data.ifi_collisions); return SYSINFO_RET_OK; }
static int web_set_time_expression(AGENT_RESULT *result, struct web *opt, const char *params, int param_id) { char time_tmp[WEB_MAX_TIME_STRLEN] = {0}; int i; if (get_param(params, param_id, time_tmp, WEB_MAX_TIME_STRLEN)) goto failed; zbx_remove_whitespace(time_tmp); for (i = 0; WEB_CURL_TIME[i].time_name != NULL; i++) { if (!strncmp(WEB_CURL_TIME[i].time_name, time_tmp, strlen(time_tmp))) { opt->curl_time_flag = WEB_CURL_TIME[i].curl_time_flag; return SUCCEED; } } failed: SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Invalid TIME parameter", NULL)); return FAIL; }
int NET_IF_COLLISIONS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char if_name[MAX_STRING_LEN]; net_stat_t ns; int ret = SYSINFO_RET_OK; if (num_param(param) > 1) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, if_name, sizeof(if_name))) return SYSINFO_RET_FAIL; if (SYSINFO_RET_OK == get_net_stat(if_name, &ns)) { SET_UI64_RESULT(result, ns.colls); } else ret = SYSINFO_RET_FAIL; return ret; }
int main (int argc, char **argv) { int i; char *dims; char isCGI=0; char **cgivars; if (argc > 1) { cgivars = getCLIvars(argc,argv); } else { cgivars = getcgivars(); if (cgivars) isCGI = 1; } if (!cgivars) { usage(argc,argv); exit (-1); } dims = get_param (cgivars,"Dims"); if (!dims) { fprintf (stderr,"Dims parameter not set.\n"); usage(argc,argv); exit (-1); } if (isCGI) fprintf (stdout,"Content-type: text/plain\n\n"); fprintf (stdout,"Wave\tTime\tMin\tMax\tMean\tGeoMean\tSigma\tCentroid_x\tCentroid_y\tCentroid_z\tGeoSigma\n"); /* This dumps stuff directly on stdout */ Get_Image_Stats (dims); for(i=0; cgivars[i]; i++) free (cgivars[i]); free (cgivars); return (0); }
static int VFS_FS_INODE_FREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char mountPoint[MAX_STRING_LEN]; double value = 0; assert(result); init_result(result); if(num_param(param) > 1) return SYSINFO_RET_FAIL; if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0) return SYSINFO_RET_FAIL; if(get_fs_inodes_stat(mountPoint, NULL, &value, NULL) != SYSINFO_RET_OK) return SYSINFO_RET_FAIL; SET_UI64_RESULT(result, value); return SYSINFO_RET_OK; }
float command_line_params::get_value_as_float(const char *pKey, uint32_t key_index, float def, float l, float h, uint32_t value_index, bool *pSuccess) const { if (pSuccess) *pSuccess = false; param_map_const_iterator it = get_param(pKey, key_index); if (it == end()) return def; if (value_index >= it->second.m_values.size()) { vogl::console::debug("%s: Trying to retrieve value %u of command line parameter %s, but this parameter only has %u values\n", VOGL_FUNCTION_INFO_CSTR, value_index, pKey, it->second.m_values.size()); return def; } float val; const char *p = it->second.m_values[value_index].get_ptr(); if (!string_ptr_to_float(p, val)) { vogl::console::warning("Invalid value specified for float parameter \"%s\", using default value of %f\n", pKey, def); return def; } // Let's assume +-cNearlyInfinite implies no clamping. if ((l != -math::cNearlyInfinite) && (val < l)) { vogl::console::warning("Value %f for parameter \"%s\" is out of range, clamping to %f\n", val, pKey, l); val = l; } else if ((h != math::cNearlyInfinite) && (val > h)) { vogl::console::warning("Value %f for parameter \"%s\" is out of range, clamping to %f\n", val, pKey, h); val = h; } if (pSuccess) *pSuccess = true; return val; }
WebInputTemp::WebInputTemp(Params &p): InputTemp(p) { ioDoc->friendlyNameSet("WebInputTemp"); ioDoc->descriptionSet(_("Temperature input read from a web document")); ioDoc->paramAdd("url", _("URL where to download the document from.\n" "If URL begins with file:// the data is read from the local file"), IODoc::TYPE_STRING, true); ioDoc->paramAdd("file_type",_("File type of the document. Values can be xml, json or text."), IODoc::TYPE_STRING, true); ioDoc->paramAdd("path",_("The path where to found the value. This value can take multiple values " "depending on the file type. If file_type is JSON, the json file " "downloaded will be read, and the informations will be extracted from " "the path. for example weather[0]/description, try to read the " "description value of the 1 element of the array of the weather object.\n" "If file_type is XML, the path is an xpath expression; Look here for " "syntax : http://www.w3schools.com/xsl/xpath_syntax.asp " "If file_type is TEXT, the downloaded file is returned as " "plain text file, and path must be in the form line/pos/separator " "Line is read, and is split using separator as delimiters " "The value returned is the value at pos in the split list. " "If the separator is not found, the whole line is returned. " "Example the file contains \n" "10.0,10.1,10.2,10.3\n" "20.0,20.1,20.2,20.3\n" "If the path is 2/4/, the value returne wil be 20.3\n"), IODoc::TYPE_STRING, true); cInfoDom("input") << "WebInputTemp::WebInputTemp()"; Calaos::StartReadRules::Instance().addIO(); // Add input to WebCtrl instance WebCtrl::Instance(p).Add(get_param("path"), readTime, [=]() { readValue(); Calaos::StartReadRules::Instance().ioRead(); }); }
/****************************************************************************** * * * Function: process_trap_for_interface * * * * Purpose: add trap to all matching items for the specified interface * * * * Return value: SUCCEED - a matching item was found * * FAIL - no matching item was found (including fallback items) * * * * Author: Rudolfs Kreicbergs * * * ******************************************************************************/ static int process_trap_for_interface(zbx_uint64_t interfaceid, char *trap, zbx_timespec_t *ts) { DC_ITEM *items = NULL; char cmd[MAX_STRING_LEN], params[MAX_STRING_LEN], regex[MAX_STRING_LEN]; int count, i, ret = FAIL, fallback = -1; count = DCconfig_get_snmp_items_by_interfaceid(interfaceid, &items); for (i = 0; i < count; i++) { if (0 == parse_command(items[i].key_orig, cmd, sizeof(cmd), params, sizeof(params))) continue; if (0 == strcmp(cmd, "snmptrap.fallback")) { fallback = i; continue; } if (0 != strcmp(cmd, "snmptrap") || 0 != get_param(params, 1, regex, sizeof(regex))) continue; if (NULL == zbx_regexp_match(trap, regex, NULL)) continue; ret = SUCCEED; set_item_value(&items[i], trap, ts); } if (FAIL == ret && -1 != fallback) { ret = SUCCEED; set_item_value(&items[fallback], trap, ts); } zbx_free(items); return ret; }
long long cmdline_parse_int(const char *param, long long default_value) { char value_buffer[32]; char *p = value_buffer; bool negative = false; long long value = 0; if (!get_param(param, value_buffer, sizeof(value_buffer))) return default_value; if (strncmp(p, "0x", 2) == 0) { p += 2; do { if (*p >= '0' && *p <= '9') value = (value << 4) + *p - '0'; else if (*p >= 'A' && *p <= 'F') value = (value << 4) + *p - 'A'; else if (*p >= 'a' && *p <= 'f') value = (value << 4) + *p - 'a'; else return default_value; p++; } while (*p != 0); } else { if (*p == '-' || *p == '+') negative = (*p++ == '-'); do { if (*p >= '0' && *p <= '9') value = (value * 10) + *p - '0'; else return default_value; p++; } while (*p != 0); } return negative ? -value : value; }
int OLD_SENSOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char key[MAX_STRING_LEN]; int ret; assert(result); init_result(result); if(num_param(param) > 1) { return SYSINFO_RET_FAIL; } if(get_param(param, 1, key, MAX_STRING_LEN) != 0) { return SYSINFO_RET_FAIL; } if(strcmp(key,"temp1") == 0) { ret = get_sensor("temp1", flags, result); } else if(strcmp(key,"temp2") == 0) { ret = get_sensor("temp2", flags, result); } else if(strcmp(key,"temp3") == 0) { ret = get_sensor("temp3", flags, result); } else { ret = SYSINFO_RET_FAIL; } return ret; }
int SYSTEM_CPU_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char tmp[16]; int name; long ncpu; if (1 < num_param(param)) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, tmp, sizeof(tmp)) || '\0' == *tmp || 0 == strcmp(tmp, "online")) name = _SC_NPROCESSORS_ONLN; else if (0 == strcmp(tmp, "max")) name = _SC_NPROCESSORS_CONF; else return SYSINFO_RET_FAIL; if (-1 == (ncpu = sysconf(name))) return SYSINFO_RET_FAIL; SET_UI64_RESULT(result, ncpu); return SYSINFO_RET_OK; }
int init_zappy(t_master *content, int ac, char **av) { srand(time(NULL)); content->max_clients = 0; content->width = 0; content->height = 0; content->delay = 0; content->nbr_egg = 0; content->nbr_player = 0; content->port = NULL; content->teams = NULL; content->clients = NULL; content->cases = NULL; if (!get_param(ac, av, content) || !check_param(content)) return (usage(av[0])); set_timeout(content); set_delays(content); create_map(content); minerals_gen(content); init_server(&(content->server), content->port); print_creation(content); return (0); }
static int get_params() { FILE *params_file = fopen("params", "r"); param_id_t param_id; if (!params_file) { return 0; } while (fgets(buf, BUF_SIZE, params_file)) { param_id_t my_param_id; buf[strlen(buf)-1] = 0; if (get_param(buf, &my_param_id) == SUCCEED) param_id = my_param_id; else if (!strncmp(buf, "yes", 3)) params[param_id] = GRT_TRUE; else if (!strncmp(buf, "no", 3)) params[param_id] = GRT_FALSE; else if (buf[0] != '%' && buf[0] != 0) { if (param_id < NUM_PARAMS) params[param_id] = atoi(buf); } } fclose(params_file); return 1; }
static int VFS_FS_INODE_PFREE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char mountPoint[MAX_STRING_LEN]; zbx_uint64_t tot_val = 0; zbx_uint64_t free_val = 0; assert(result); init_result(result); if(num_param(param) > 1) return SYSINFO_RET_FAIL; if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0) return SYSINFO_RET_FAIL; if(get_fs_inodes_stat(mountPoint, &tot_val, &free_val, NULL) != SYSINFO_RET_OK) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, (100.0 * (double)free_val) / (double)tot_val); return SYSINFO_RET_OK; }
static int VFS_FS_INODE_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char mountPoint[MAX_STRING_LEN]; double tot_val = 0; double usg_val = 0; assert(result); init_result(result); if(num_param(param) > 1) return SYSINFO_RET_FAIL; if(get_param(param, 1, mountPoint, MAX_STRING_LEN) != 0) return SYSINFO_RET_FAIL; if(get_fs_inodes_stat(mountPoint, &tot_val, NULL, &usg_val) != SYSINFO_RET_OK) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, (100.0 * usg_val) / tot_val); return SYSINFO_RET_OK; }
int SYSTEM_CPU_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char mode[128]; int sysinfo_name = -1; long ncpu = 0; if(num_param(param) > 1) { return SYSINFO_RET_FAIL; } if(get_param(param, 1, mode, sizeof(mode)) != 0) { mode[0] = '\0'; } if(mode[0] == '\0') { /* default parameter */ zbx_snprintf(mode, sizeof(mode), "online"); } if(0 == strncmp(mode, "online", sizeof(mode))) { sysinfo_name = _SC_NPROCESSORS_ONLN; } else if(0 == strncmp(mode, "max", sizeof(mode))) { sysinfo_name = _SC_NPROCESSORS_CONF; } if ( -1 == sysinfo_name || (-1 == (ncpu = sysconf(sysinfo_name)) && EINVAL == errno) ) return SYSINFO_RET_FAIL; SET_UI64_RESULT(result, ncpu); return SYSINFO_RET_OK; }
int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { const MODE_FUNCTION fl[] = { {"total", VM_MEMORY_TOTAL}, {"active", VM_MEMORY_ACTIVE}, {"inactive", VM_MEMORY_INACTIVE}, {"wired", VM_MEMORY_WIRED}, {"anon", VM_MEMORY_ANON}, {"exec", VM_MEMORY_EXEC}, {"file", VM_MEMORY_FILE}, {"free", VM_MEMORY_FREE}, {"used", VM_MEMORY_USED}, {"pused", VM_MEMORY_PUSED}, {"available", VM_MEMORY_AVAILABLE}, {"pavailable", VM_MEMORY_PAVAILABLE}, {"buffers", VM_MEMORY_BUFFERS}, {"cached", VM_MEMORY_CACHED}, {"shared", VM_MEMORY_SHARED}, {NULL, 0} }; char mode[MAX_STRING_LEN]; int i; if (1 < num_param(param)) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, mode, sizeof(mode)) || '\0' == *mode) strscpy(mode, "total"); for (i = 0; NULL != fl[i].mode; i++) if (0 == strcmp(mode, fl[i].mode)) return (fl[i].function)(result); return SYSINFO_RET_FAIL; }
int SYSTEM_CPU_NUM(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { SYSTEM_INFO sysInfo; char mode[128]; assert(result); init_result(result); if(num_param(param) > 1) { return SYSINFO_RET_FAIL; } if(get_param(param, 1, mode, sizeof(mode)) != 0) { mode[0] = '\0'; } if(mode[0] == '\0') { /* default parameter */ zbx_snprintf(mode, sizeof(mode), "online"); } if(0 != strncmp(mode, "online", sizeof(mode))) { return SYSINFO_RET_FAIL; } GetSystemInfo(&sysInfo); SET_UI64_RESULT(result, sysInfo.dwNumberOfProcessors); return SYSINFO_RET_OK; }
/* * Internal wrapper function which must be called for _all_ output * to the log file. It takes care of opening the log file if it * isn't open, buffering data if it's in the process of being * opened asynchronously, etc. */ static void logwrite(struct LogContext *ctx, void *data, int len) { /* * In state L_CLOSED, we call logfopen, which will set the state * to one of L_OPENING, L_OPEN or L_ERROR. Hence we process all of * those three _after_ processing L_CLOSED. */ #ifdef PERSOPORT if( timestamp_newfile ) { if (ctx->state == L_OPEN) { logfclose(ctx);} timestamp_newfile = 0 ; } #endif if (ctx->state == L_CLOSED) logfopen(ctx); if (ctx->state == L_OPENING) { bufchain_add(&ctx->queue, data, len); } else if (ctx->state == L_OPEN) { assert(ctx->lgfp); #ifdef PERSOPORT if( !get_param("PUTTY") ) { if( timestamp_newline ) { log_writetimestamp( ctx ) ; timestamp_newline = 0 ; } char * c = (char*)(data+len-1) ; if( c[0]=='\n' ) timestamp_newline = 1 ; } #endif if (fwrite(data, 1, len, ctx->lgfp) < (size_t)len) { logfclose(ctx); ctx->state = L_ERROR; /* Log state is L_ERROR so this won't cause a loop */ logevent(ctx->frontend, "Disabled writing session log due to error while writing"); } } /* else L_ERROR, so ignore the write */ }
// --------------------------------------------------------------------------- // // ----------- bGenericXMLBaseElement* bToolShape::load(){ bGenericXMLBaseElement* groot=bStdToolGeom::load(); bGenericXMLBaseElement* elt=NULL; if(!groot){ return(NULL); } bGenericXMLBaseElement* root=get_param(groot,"private"); if(!root){ _gapp->classMgr()->ReleaseXMLInstance(groot); return(NULL); } char val[_values_length_max_]; for(;;){ elt=_gapp->classMgr()->NthElement(root,1,"bool"); if(!elt){ break; } elt->getvalue(val); _ctr=atoi(val); elt=_gapp->classMgr()->NthElement(root,2,"bool"); if(!elt){ break; } elt->getvalue(val); _opn=atoi(val); elt=_gapp->classMgr()->NthElement(root,1,"int"); if(!elt){ _cm=1; break; } elt->getvalue(val); _cm=atoi(val); break; } _gapp->classMgr()->ReleaseXMLInstance(groot); return(NULL); }
bool load_map(std::deque<AObject*> &map, std::string &map_name, t_param_map &map_param, AObject *m_player) { std::fstream my_file; my_file.open(map_name.c_str(), std::fstream::in); if (!my_file.good()) { if (!my_file.is_open()) my_file.close(); return (false); } if (get_param(map_param, my_file) == false || get_item(map, my_file, m_player) == false) { nb_player = 0; my_file.close(); return (false); } nb_player = 0; generate_Grass(map, map_param); my_file.close(); return (true); }
int main(int argc, char *argv[]){ struct ev_loop *loop = ev_default_loop(0); int i; struct ev_io socket_accept; get_param(argc, argv); // options.faddr = "0.0.0.0:8765"; // options.baddr = ""; // options.cryptoMethod = "RC4"; // options.secret = "secret"; // options.clientMod = 1; build_server(); ev_io_init(&socket_accept, accept_cb, serv_sock, EV_READ); ev_io_start(loop, &socket_accept); while(1) { ev_loop(loop, 0); } return 0; }
void paramline_to_argcv (const char *cmdp, int *argcp, char ***argvp) { int len; int argc; char **argv; len = strlen (cmdp); argc = count_params (cmdp, len); argv = malloc((argc+1) * sizeof *argv); if (!argv) argc = -1; else { int i; for (i = 0; i < argc; ++i) argv[i] = get_param (&cmdp, &len); argv[i] = 0; *argcp = argc; *argvp = argv; } }
void AudioPlayer::hasChanged() { if (!isEnabled()) return; std::string answer; switch (astatus) { default: case AudioError: answer = "onerror"; break; case AudioPlay: answer = "onplay"; break; case AudioPause: answer = "onpause"; break; case AudioStop: answer = "onstop"; break; case AudioSongChange: answer = "onsongchange"; break; case AudioPlaylistChange: answer = "onplaylistchange"; break; case AudioVolumeChange: answer = "onvolumechange"; break; } EmitSignalIO(); EventManager::create(CalaosEvent::EventIOChanged, { { "id", get_param("id") }, { "state", answer } }); }
static int web_set_required_response(AGENT_RESULT *result, struct web *opt, const char *params, int param_id) { char req_code_tmp[WEB_MAX_HTTP_CODE_STRLEN] = {0}; zbx_uint64_t req_code_test; if (get_param(params, param_id, req_code_tmp, WEB_MAX_HTTP_CODE_STRLEN)) goto failed; if (strlen(req_code_tmp)) { if (is_uint_range(req_code_tmp, &req_code_test, WEB_MIN_HTTP_CODE, WEB_MAX_HTTP_CODE)) goto failed; opt->required_response = (int) req_code_test; return SUCCEED; } else { opt->required_response = WEB_DEF_HTTP_CODE; return SUCCEED; } failed: SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Invalid RESPONSE CODE parameter", NULL)); return FAIL; }
/****************************************************************************** * * * Function: get_value_aggregate * * * * Purpose: retrieve data from Zabbix server (aggregate items) * * * * Parameters: item - item we are interested in * * * * Return value: SUCCEED - data successfully retrieved and stored in result * * and result_str (as string) * * NOTSUPPORTED - requested item is not supported * * * * Author: Alexei Vladishev * * * * Comments: * * * ******************************************************************************/ int get_value_aggregate(DC_ITEM *item, AGENT_RESULT *result) { const char *__function_name = "get_value_aggregate"; char tmp[8], params[MAX_STRING_LEN], groups[MAX_STRING_LEN], itemkey[MAX_STRING_LEN], funcp[32]; int grp_func, item_func, ret = SUCCEED; zabbix_log(LOG_LEVEL_DEBUG, "In %s() key:'%s'", __function_name, item->key_orig); if (ITEM_VALUE_TYPE_FLOAT != item->value_type && ITEM_VALUE_TYPE_UINT64 != item->value_type) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Value type must be Numeric for aggregate items")); return NOTSUPPORTED; } if (2 != parse_command(item->key, tmp, sizeof(tmp), params, sizeof(params))) return NOTSUPPORTED; if (0 == strcmp(tmp, "grpmin")) grp_func = ZBX_GRP_FUNC_MIN; else if (0 == strcmp(tmp, "grpavg")) grp_func = ZBX_GRP_FUNC_AVG; else if (0 == strcmp(tmp, "grpmax")) grp_func = ZBX_GRP_FUNC_MAX; else if (0 == strcmp(tmp, "grpsum")) grp_func = ZBX_GRP_FUNC_SUM; else return NOTSUPPORTED; if (4 != num_param(params)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters")); return NOTSUPPORTED; } if (0 != get_param(params, 1, groups, sizeof(groups))) return NOTSUPPORTED; if (0 != get_param(params, 2, itemkey, sizeof(itemkey))) return NOTSUPPORTED; if (0 != get_param(params, 3, tmp, sizeof(tmp))) return NOTSUPPORTED; if (0 == strcmp(tmp, "min")) item_func = ZBX_DB_GET_HIST_MIN; else if (0 == strcmp(tmp, "avg")) item_func = ZBX_DB_GET_HIST_AVG; else if (0 == strcmp(tmp, "max")) item_func = ZBX_DB_GET_HIST_MAX; else if (0 == strcmp(tmp, "sum")) item_func = ZBX_DB_GET_HIST_SUM; else if (0 == strcmp(tmp, "count")) item_func = ZBX_DB_GET_HIST_COUNT; else if (0 == strcmp(tmp, "last")) item_func = ZBX_DB_GET_HIST_VALUE; else { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter")); return NOTSUPPORTED; } if (0 != get_param(params, 4, funcp, sizeof(funcp))) return NOTSUPPORTED; if (SUCCEED != evaluate_aggregate(item, result, grp_func, groups, itemkey, item_func, funcp)) ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
static int req_intf(struct sigma_cmd *cmd) { return get_param(cmd, "interface") == NULL ? -1 : 0; }
void vik_layer_marshall_params ( VikLayer *vl, guint8 **data, gint *datalen ) { VikLayerParam *params = vik_layer_get_interface(vl->type)->params; VikLayerFuncGetParam get_param = vik_layer_get_interface(vl->type)->get_param; GByteArray* b = g_byte_array_new (); gint len; #define vlm_append(obj, sz) \ len = (sz); \ g_byte_array_append ( b, (guint8 *)&len, sizeof(len) ); \ g_byte_array_append ( b, (guint8 *)(obj), len ); vlm_append(vl->name, strlen(vl->name)); if ( params && get_param ) { VikLayerParamData d; guint16 i, params_count = vik_layer_get_interface(vl->type)->params_count; for ( i = 0; i < params_count; i++ ) { g_debug("%s: %s", __FUNCTION__, params[i].name); d = get_param(vl, i, FALSE); switch ( params[i].type ) { case VIK_LAYER_PARAM_STRING: // Remember need braces as these are macro calls, not single statement functions! if ( d.s ) { vlm_append(d.s, strlen(d.s)); } else { // Need to insert empty string otherwise the unmarshall will get confused vlm_append("", 0); } break; /* print out the string list in the array */ case VIK_LAYER_PARAM_STRING_LIST: { GList *list = d.sl; /* write length of list (# of strings) */ gint listlen = g_list_length ( list ); g_byte_array_append ( b, (guint8 *)&listlen, sizeof(listlen) ); /* write each string */ while ( list ) { gchar *s = (gchar *) list->data; vlm_append(s, strlen(s)); list = list->next; } break; } default: vlm_append(&d, sizeof(d)); break; } } } *data = b->data; *datalen = b->len; g_byte_array_free ( b, FALSE ); #undef vlm_append }
// --------------------------------------------------------------------------- // // ----------- bGenericXMLBaseElement* bToolGeomWithJoin::load(){ bGenericXMLBaseElement* groot=bStdToolGeom::load(); bGenericXMLBaseElement* elt=NULL; bGenericType* tp=NULL; long k=1; _use_nea=false; _k_nea=0; _use_dir=false; _k_dir=0; _use_ang=false; _k_ang=0; _use_end=false; _k_end=0; if(!groot){ return(NULL); } bGenericXMLBaseElement* root=get_param(groot,"join"); if(!root){ return(groot); } char val[_values_length_max_]; for(k=1;k<=_gapp->typesMgr()->count();k++){ _tp_use.add(&tp); } k=1; for(;;){ elt=_gapp->classMgr()->NthElement(root,1,"bool"); if(!elt){ break; } elt->getvalue(val); _use_nea=atoi(val); elt=_gapp->classMgr()->NthElement(root,2,"bool"); if(!elt){ break; } elt->getvalue(val); _use_dir=atoi(val); elt=_gapp->classMgr()->NthElement(root,3,"bool"); if(!elt){ break; } elt->getvalue(val); _use_ang=atoi(val); elt=_gapp->classMgr()->NthElement(root,4,"bool"); if(!elt){ break; } elt->getvalue(val); _use_end=atoi(val); elt=_gapp->classMgr()->NthElement(root,1,"string"); if(!elt){ break; } elt->getvalue(val); _k_nea=val[0]; elt=_gapp->classMgr()->NthElement(root,2,"string"); if(!elt){ break; } elt->getvalue(val); _k_dir=val[0]; elt=_gapp->classMgr()->NthElement(root,3,"string"); if(!elt){ break; } elt->getvalue(val); _k_ang=val[0]; elt=_gapp->classMgr()->NthElement(root,4,"string"); if(!elt){ break; } elt->getvalue(val); _k_end=val[0]; while((elt=_gapp->classMgr()->NthElement(root,k,"name"))){ elt->getvalue(val); tp=_gapp->typesMgr()->get(_gapp->typesMgr()->index(val)); _tp_use.put(_gapp->typesMgr()->index(val),&tp); k++; } break; } if(!_gapp->xmapMgr()->find('JNea')){ _use_nea=false; _k_nea=0; } if(!_gapp->xmapMgr()->find('JDir')){ _use_dir=false; _k_dir=0; } if(!_gapp->xmapMgr()->find('JAng')){ _use_ang=false; _k_ang=0; } if(!_gapp->xmapMgr()->find('JEnd')){ _use_end=false; _k_end=0; } return(groot); }