void test_tags() { struct tag t; char test[2048]; strcpy(test,"<tag type=tab col=30>"); (void) read_tag(test, &t); print_tag(stdout, &t); printf("\ntype=%s\n", get_key_value(&t,"type")); strcpy(test,"<tag type=name name=\"Hebekiah the Jesuit\">"); (void) read_tag(test, &t); print_tag(stdout, &t); printf("\nname=%s\n", get_key_value(&t,"name")); };
static char * get_pa_var (const char *key, const char *pa, struct gc_arena *gc) { char k[64]; char v[256]; const char *content = pa; while (true) { const int status = get_key_value(content, k, v, sizeof(k), sizeof(v), &content); if (status) { if (!strcmp(key, k)) return string_alloc(v, gc); } else return NULL; /* advance to start of next key */ if (*content == ',') ++content; while (*content && isspace(*content)) ++content; } }
// @return: need free. char *getconfdir(void *cfgdata,const char *section, const char *key, int isnull, char *notfound) { const char *cp; char *v; cp = get_key_value(cfgdata,section, key, NULL); if (!cp && !isnull) { printf("Config Item: [%s] %s: not set\n", section, key); exit(1); } else if (!cp && isnull) { if(notfound) { cp = notfound; goto process; } else return notfound; } else { process: v = xstrdup(cp); if(v[strlen(v)-1] == '/') v[strlen(v)-1] = 0; return v; } }
/*! find hardware code for the exit/power key */ u16 ap_usb_upg_get_code(u32 index, u16 *code) { u8 v_key = V_KEY_CANCEL; u16 cnt = 2; switch(index) { case USB_UPGRD_CODE_EXIT: v_key = V_KEY_CANCEL; break; case USB_UPGRD_CODE_POWER: v_key = V_KEY_POWER; break; case USB_UPGRD_CODE_MENU: v_key = V_KEY_MENU; break; default: MT_ASSERT(0); break; } cnt = 2; //code[0] = get_key_value(0, v_key); code[1] = get_key_value(1, v_key); return cnt; }
double getconfloat(void *cfgdata,const char *section, const char *key, int isnull, double notfound, double min, double max) { const char *cp; double v; cp = get_key_value(cfgdata,section, key, NULL); if (!cp && !isnull) { printf("Config Item: [%s] %s: not set\n", section, key); exit(1); } else if (!cp && isnull) return notfound; else { v = atof(cp); if (max && (v < min || v > max)) { printf("Config Item: [%s] %s: set error\n", section, key); exit(1); } return v; } }
static bool read_script(struct key *key) { static struct buffer input_buffer; static const char *line = ""; enum status_code code; if (!line || !*line) { if (input_buffer.data && *input_buffer.data == ':') { line = "<Enter>"; memset(&input_buffer, 0, sizeof(input_buffer)); } else if (!io_get(&script_io, &input_buffer, '\n', true)) { io_done(&script_io); return false; } else { line = input_buffer.data; } } code = get_key_value(&line, key); if (code != SUCCESS) die("Error reading script: %s", get_status_message(code)); return true; }
int UsrAccConfig::deal_file_manage(const std::string &line, const int &pos) { std::string key; std::string value; get_key_value(line,pos,key,value); if (key == "Call_record_write_switch") { call_record_write_switch_ = atoi(value.c_str()); } else if (key == "call_record_write_periodic") { call_record_write_periodic_ = atoi(value.c_str()) * 60; } else if (key == "call_record_save_path") { call_record_save_path_ = value.c_str(); } else if (key == "call_record_file_prefix") { call_record_file_prefix_ = value.c_str(); } else if (key == "sms_record_write_switch") { sms_record_write_switch_ = atoi(value.c_str()); } else if (key == "sms_record_write_periodic") { sms_record_write_periodic_ = atoi(value.c_str()) * 60; } else if (key == "sms_record_save_path") { sms_record_save_path_ = value.c_str(); } else if (key == "sms_record_file_prefix") { sms_record_file_prefix_ = value.c_str(); } else if (key == "user_op_write_switch") { user_op_write_switch_ = atoi(value.c_str()); } else if (key == "user_op_write_periodic") { user_op_write_periodic_ = atoi(value.c_str()) * 60; } else if (key == "user_op_save_path") { user_op_save_path_ = value.c_str(); } else if (key == "user_op_file_prefix") { user_op_file_prefix_ = value.c_str(); } else { printf("unknown key \" %s \" in section \" BusinessInfo \".\n", key.c_str()); return -1; } return 0; }
/* Unregister the caller thread as trace user */ void stm_trace_free_thread_channel(void) { int channel = get_key_value(); if (channel) { ioctl(fd, STM_RELEASE_CHANNEL, channel-1); pthread_setspecific(channel_key, 0); } stm_trace_close(); }
/* pretend the specified key has been pressed - allows user menu to trigger keypress events */ int command_keypress(char *text, int len) { text = getparams(text); if (*text) { Uint32 value = get_key_value(text); if (value) do_keypress(value); } return 1; }
/* pretend the specified key has been pressed - allows user menu to trigger keypress events */ int command_keypress(char *text, int len) { text = getparams(text); if (*text) { Uint32 value = get_key_value(text); if (value) keypress_root_common(value, 0); } return 1; }
int UsrAccConfig::deal_system(const std::string &line, const int &pos) { std::string key; std::string value; get_key_value(line, pos, key, value); if (key == "module_id") { module_id_ = atoi(value.c_str()); } else { printf("unknown key \" %s \" in section \" System \".\n", key.c_str()); return -1; } return 0; }
/* Retreive the channel ID if already registered if not already registered then register this thread */ int stm_trace_get_thread_channel(int *channel) { int channel_id = get_key_value(); if (channel_id) channel_id--; else if (stm_trace_register_thread(&channel_id)) return -1; *channel = channel_id; return 0; }
int UsrAccConfig::deal_logger_configuration(const std::string &line, const int &pos) { std::string key; std::string value; get_key_value(line, pos, key, value); if (key == "logger_config_file") { logger_config_file_ = value; } else { printf("unknown key \" %s \" in section \" LoggerConfiguration \".\n", key.c_str()); return -1; } return 0; }
// @return: need free. char *getconfstring(void *cfgdata,const char *section, const char *key, int isnull, char *notfound, char **values, int *ivalues, int valnum, int *retival) { const char *cp; int i; cp = get_key_value(cfgdata,section, key, NULL); if (!cp && !isnull) { printf("Config Item: [%s] %s: not set\n", section, key); exit(1); } else if (!cp && isnull) { if(notfound) { cp = notfound; goto process; } else return notfound; } else { process: if (valnum == 0) return xstrdup(cp); for (i = 0;i < valnum;++i) { if (strcasecmp(cp, values[i]) == 0) break; } if (i == valnum) { printf("Config Item: [%s] %s: set error\n", section, key); exit(1); } if (ivalues && retival) { *retival = ivalues[i]; return NULL; } else if (ivalues && !retival) { printf("return value variable pointer isn't set.\n"); exit(1); } else return xstrdup(cp); } }
// @return: need free. char *getconfmulti(void *cfgdata,const char *section, const char *key, int isnull, char *notfound, const char *sepstr, char ***values, int *valnum) { const char *cp; char *v, **vv; int i, n, len; cp = get_key_value(cfgdata,section, key, NULL); if (!cp && !isnull) { printf("Config Item: [%s] %s: not set\n", section, key); exit(1); } else if (!cp && isnull) { if(notfound) { cp = notfound; goto process; } else { *values = NULL; *valnum = 0; return notfound; } } else { process: len = strlen(cp); v = xmalloc(len + 1); strcpy(v,cp); strsqueeze(v); //trimid(cp, v, 1); 注意: 只能用于ascii和gbk n = strfragnum(v, sepstr); vv = (char **)xcalloc(n, sizeof(char *)); split(v, sepstr, vv, n); for (i = 0;i < n;++i) { trim(vv[i]); if (*vv[i] == 0) { printf("Config Item: [%s] %s: set error\n", section, key); xfree(v); xfree(vv); exit(1); } } *values = vv; *valnum = n; return v; } }
int UsrAccConfig::deal_mem(const std::string &line, const int &pos) { std::string key; std::string value; get_key_value(line, pos, key, value); if (key == "tid_num_seg") { // to do ... std::string tmp = ""; TidParam tid_param; while ((tmp = split_first(value, ";")) != "") { std::string tmp2 = split_first(tmp, ":"); CommonLogger::instance().log_info(" tmp is %s", tmp.c_str()); CommonLogger::instance().log_info(" tmp2 is %s", tmp2.c_str()); if (tmp2 != "" && tmp != "") { tid_param.min_tid = atoi(tmp2.c_str()); tid_param.max_tid = atoi(tmp.c_str()); tid_num_seg_list_.push_back(tid_param); } } if (value != "") { std::string tmp = split_first(value, ":"); if (tmp != "" && value != "") { tid_param.min_tid = atoi(tmp.c_str()); tid_param.max_tid = atoi(value.c_str()); tid_num_seg_list_.push_back(tid_param); } } } else if (key == "usr_count") { usr_count_ = atoi(value.c_str()); } else if (key == "usr_hash_count") { usr_hash_count_ = atoi(value.c_str()); } else if (key == "app_req_queue_block_num") { app_req_queue_block_num_ = atoi(value.c_str()); } else if (key == "app_req_queue_block_size") { app_req_queue_block_size_ = atoi(value.c_str()); } else if (key == "servlogic_req_queue_block_num") { servlogic_req_queue_block_num_ = atoi(value.c_str()); } else if (key == "servlogic_req_queue_block_size") { servlogic_req_queue_block_size_ = atoi(value.c_str()); } else if (key == "user_op_queue_block_num") { user_op_queue_block_num_ = atoi(value.c_str()); } else if (key == "user_op_queue_block_size") { user_op_queue_block_size_ = atoi(value.c_str()); } else { printf("unknown key \" %s \" in section \" MEM \".\n", key.c_str()); return -1; } return 0; }
void test_regex( std::ostream & f ){ f << get_valid() << "\n" << get_wiki() << "\n" << get_parent_begin() << "\n" << get_parent_end() << "\n" << get_tag_begin() << "\n" << get_tag_end() << "\n" << get_allow_link() << "\n" << get_allow_global() << "\n" << get_table_key_begin() << "\n" << get_table_end() << "\n" << get_key_value() << "\n" << get_allow_type() << "\n" << std::endl; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(key_sampling, ev, data) { PROCESS_BEGIN(); static struct etimer et; static int previous_key_value = 0; static char debounce_check = 0; int current_key_value; etimer_set(&et, CLOCK_SECOND / 50); while(1) { PROCESS_WAIT_EVENT_UNTIL((ev == PROCESS_EVENT_TIMER) || (ev == PROCESS_EVENT_MSG)); if(ev == PROCESS_EVENT_TIMER) { /* Handle sensor reading. */ PRINTF("Key sample\n"); current_key_value = get_key_value(); if(debounce_check != 0) { /* Check if key remained constant */ if(previous_key_value == current_key_value) { sensors_changed(&button_sensor); key_value = current_key_value; debounce_check = 0; } else { /* Bouncing */ previous_key_value = current_key_value; } } else /* Check for new key change */ if(current_key_value != previous_key_value) { previous_key_value = current_key_value; debounce_check = 1; } etimer_reset(&et); } else { /* ev == PROCESS_EVENT_MSG */ if(*(buttons_status_t *)data == BUTTONS_STATUS_NOT_ACTIVE) { /* Stop sampling */ etimer_stop(&et); } else if((*(buttons_status_t *)data == BUTTONS_STATUS_ACTIVE)) { /* restart sampling */ etimer_restart(&et); } } } PROCESS_END(); }
void pal_dump_key_value(void) { int i; int ret; char value[MAX_VALUE_LEN] = {0x0}; while (strcmp(key_list[i], LAST_KEY)) { printf("%s:", key_list[i]); if (ret = get_key_value(key_list[i], value) < 0) { printf("\n"); } else { printf("%s\n", value); } i++; memset(value, 0, MAX_VALUE_LEN); } }
int UsrAccConfig::deal_app_req_server(const std::string &line, const int &pos) { std::string key; std::string value; get_key_value(line, pos, key, value); if (key == "app_serv_port") { app_serv_port_ = atoi(value.c_str()); CommonLogger::instance().log_info(" app_serv_port_ is %u", app_serv_port_); } else if (key == "app_max_connection_count") { app_max_connection_count_ = atoi(value.c_str()); } else if (key == "app_overtime"){ app_overtime_ = atoi(value.c_str()); } else{ printf("unknown key \" %s \" in section \" AppReqServer \".\n", key.c_str()); return -1; } return 0; }
boolean InfoFile_GetValueByKey(char * pInfoBuffer, long * pValue, char * KEY) { char * key = NULL; char * value = NULL; const char *p = NULL; const char *p1 = NULL; boolean bFound = FALSE; p = pInfoBuffer; p1 = p; if(!p1) { return FALSE; } while (TRUE) { p1 = get_key_value(p1, &key, &value); if(!p1) break; if(0 == (stricmp(key, KEY))) { bFound = TRUE; if(pValue) *pValue = atol(value); } if (NULL != key) free(key); if (NULL != value) free(value); if(TRUE == bFound) { break; } } return bFound; }
int pal_get_key_value(char *key, char *value) { int ret; int i; i = 0; while(strcmp(key_list[i], LAST_KEY)) { if (!strcmp(key, key_list[i])) { // Key is valid if ((ret = get_key_value(key, value)) < 0 ) { syslog(LOG_ALERT, "pal_get_key_value: get_key_value failed. %d", ret); return ret; } return ret; } i++; } return -1; }
// @return: need free. char *getconfpath(void *cfgdata,const char *section, const char *key, int isnull, char *notfound,char *home,char *dir) { const char *cp; char *v,path[1024]; cp = get_key_value(cfgdata,section, key, NULL); if (!cp && !isnull) { printf("Config Item: [%s] %s: not set\n", section, key); exit(1); } else if (!cp && isnull) { if(notfound) { cp = notfound; goto process; } else return notfound; } else { process: if(cp[0] != '/') { path[0] = 0; if (home) { strcpy(path, home); strcat(path,"/");} if (dir) { strcat(path, dir); strcat(path,"/");} strcat(path, cp); v = xstrdup(path); } else { v = xstrdup(cp); } return v; } }
/* This function locate the specified key in the etc file. */ static int etc_LocateKeyValue(FILE* fp, const char* pKey, BOOL bCurSection, char* pValue, int iLen, FILE* bak_fp, char* nextSection) { char szBuff[ETC_MAXLINE + 1 + 1]; char* current; char* value; int ret; while (TRUE) { int bufflen; if (!fgets(szBuff, ETC_MAXLINE, fp)) return ETC_FILEIOFAILED; bufflen = strlen (szBuff); if (szBuff [bufflen - 1] == '\n') szBuff [bufflen - 1] = '\0'; ret = get_key_value (szBuff, ¤t, &value); if (ret < 0) continue; else if (ret > 0) { fseek (fp, -bufflen, SEEK_CUR); return ETC_KEYNOTFOUND; } if (strcmp (current, pKey) == 0) { if (pValue) strncpy (pValue, value, iLen); return ETC_OK; } else if (bak_fp && *current != '\0') fprintf (bak_fp, "%s=%s\n", current, value); } return ETC_KEYNOTFOUND; }
int UsrAccConfig::deal_serv_logic(const std::string &line, const int &pos) { std::string key; std::string value; get_key_value(line,pos,key,value); if (key == "serv_logic_server") { // todo ... std::string tmp = ""; ServerInfo server_info; while ((tmp = split_first(value, ";")) != "") { std::string tmp2 = split_first(tmp, ":"); if (tmp2 != "" && tmp != "") { server_info.ip = tmp2; server_info.port = atoi(tmp.c_str()); serv_logic_server_list_.push_back(server_info); } } if (value != "") { std::string tmp = split_first(value, ":"); if (tmp != "" && value != "") { server_info.ip = tmp; server_info.port = atoi(value.c_str()); serv_logic_server_list_.push_back(server_info); } } } else if (key == "heartbeat_timeinterval") { heartbeat_timeinterval_ = atoi(value.c_str()); } else { printf("unknown key \" %s \" in section \" CecsInfo \".\n", key.c_str()); return -1; } return 0; }
/* Walk all references for an ObjectIndex and construct the hprof INST dump. */ static void dump_instance(JNIEnv *env, ObjectIndex object_index, RefIndex list) { jvmtiPrimitiveType primType; SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ObjectIndex class_index; jlong size; ClassIndex cnum; char *sig; void *elements; jint num_elements; jint num_bytes; ObjectIndex *values; FieldInfo *fields; jvalue *fvalues; jint n_fields; jboolean skip_fields; jint n_fields_set; ObjectKind kind; TraceIndex trace_index; jboolean is_array; jboolean is_prim_array; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind == OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); size = (jlong)object_get_size(object_index); trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); class_index = class_get_object_index(cnum); values = NULL; elements = NULL; num_elements = 0; num_bytes = 0; n_fields = 0; skip_fields = JNI_FALSE; n_fields_set = 0; fields = NULL; fvalues = NULL; index = list; is_array = JNI_FALSE; is_prim_array = JNI_FALSE; if ( sig[0] != JVM_SIGNATURE_ARRAY ) { if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 1 ) { /* Trouble getting all the fields, can't trust field index values */ skip_fields = JNI_TRUE; /* It is assumed that the reason why we didn't get the fields * was because the class is not prepared. */ if ( gdata->debugflags & DEBUGFLAG_UNPREPARED_CLASSES ) { if ( list != 0 ) { dump_ref_list(list); debug_message("Instance of unprepared class with refs: %s\n", sig); } else { debug_message("Instance of unprepared class without refs: %s\n", sig); } HPROF_ERROR(JNI_FALSE, "Big Trouble with unprepared class instances"); } } if ( n_fields > 0 ) { fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } } else { is_array = JNI_TRUE; if ( sig[0] != 0 && sigToPrimSize(sig+1) != 0 ) { is_prim_array = JNI_TRUE; } } while ( index != 0 ) { RefInfo *info; jvalue ovalue; static jvalue empty_value; info = get_info(index); /* Process reference objects, many not used right now. */ switch ( info->flavor ) { case INFO_OBJECT_REF_DATA: switch ( info->refKind ) { case JVMTI_HEAP_REFERENCE_SIGNERS: case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN: case JVMTI_HEAP_REFERENCE_CLASS_LOADER: case JVMTI_HEAP_REFERENCE_INTERFACE: case JVMTI_HEAP_REFERENCE_STATIC_FIELD: case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: /* Should never be seen on an instance dump */ HPROF_ASSERT(0); break; case JVMTI_HEAP_REFERENCE_FIELD: if ( skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(is_array!=JNI_TRUE); ovalue = empty_value; ovalue.i = info->object_index; fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, 0); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: /* We get each object element one at a time. */ HPROF_ASSERT(is_array==JNI_TRUE); HPROF_ASSERT(is_prim_array!=JNI_TRUE); if ( num_elements <= info->index ) { int nbytes; if ( values == NULL ) { num_elements = info->index + 1; nbytes = num_elements*(int)sizeof(ObjectIndex); values = (ObjectIndex*)HPROF_MALLOC(nbytes); (void)memset(values, 0, nbytes); } else { void *new_values; int new_size; int obytes; obytes = num_elements*(int)sizeof(ObjectIndex); new_size = info->index + 1; nbytes = new_size*(int)sizeof(ObjectIndex); new_values = (void*)HPROF_MALLOC(nbytes); (void)memcpy(new_values, values, obytes); (void)memset(((char*)new_values)+obytes, 0, nbytes-obytes); HPROF_FREE(values); num_elements = new_size; values = new_values; } } HPROF_ASSERT(values[info->index]==0); values[info->index] = info->object_index; break; default: /* Ignore, not needed */ break; } break; case INFO_PRIM_FIELD_DATA: if ( skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->primType!=0); HPROF_ASSERT(info->length==-1); HPROF_ASSERT(info->refKind==JVMTI_HEAP_REFERENCE_FIELD); HPROF_ASSERT(is_array!=JNI_TRUE); ovalue = get_key_value(index); fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, info->primType); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case INFO_PRIM_ARRAY_DATA: /* Should only be one, and it's handled below */ HPROF_ASSERT(info->refKind==0); /* We assert that nothing else was saved with this array */ HPROF_ASSERT(index==list&&info->next==0); HPROF_ASSERT(is_array==JNI_TRUE); HPROF_ASSERT(is_prim_array==JNI_TRUE); primType = info->primType; elements = get_key_elements(index, primType, &num_elements, &num_bytes); HPROF_ASSERT(info->length==num_elements); size = num_bytes; break; default: HPROF_ASSERT(0); break; } index = info->next; } if ( is_array == JNI_TRUE ) { if ( is_prim_array == JNI_TRUE ) { HPROF_ASSERT(values==NULL); io_heap_prim_array(object_index, trace_serial_num, (jint)size, num_elements, sig, elements); } else { HPROF_ASSERT(elements==NULL); io_heap_object_array(object_index, trace_serial_num, (jint)size, num_elements, sig, values, class_index); } } else { io_heap_instance_dump(cnum, object_index, trace_serial_num, class_index, (jint)size, sig, fields, fvalues, n_fields); } if ( values != NULL ) { HPROF_FREE(values); } if ( fvalues != NULL ) { HPROF_FREE(fvalues); } if ( elements != NULL ) { /* Do NOT free elements, it's a key in the table, leave it be */ } }
/* Walk all references for an ObjectIndex and construct the hprof CLASS dump. */ static void dump_class_and_supers(JNIEnv *env, ObjectIndex object_index, RefIndex list) { SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ClassIndex super_cnum; ObjectIndex super_index; LoaderIndex loader_index; ObjectIndex signers_index; ObjectIndex domain_index; FieldInfo *fields; jvalue *fvalues; jint n_fields; jboolean skip_fields; jint n_fields_set; jlong size; ClassIndex cnum; char *sig; ObjectKind kind; TraceIndex trace_index; Stack *cpool_values; ConstantPoolValue *cpool; jint cpool_count; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind != OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); if ( class_get_status(cnum) & CLASS_DUMPED ) { return; } class_add_status(cnum, CLASS_DUMPED); size = (jlong)object_get_size(object_index); super_index = 0; super_cnum = class_get_super(cnum); if ( super_cnum != 0 ) { super_index = class_get_object_index(super_cnum); if ( super_index != 0 ) { dump_class_and_supers(env, super_index, object_get_references(super_index)); } } trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); loader_index = class_get_loader(cnum); signers_index = 0; domain_index = 0; /* Get field information */ n_fields = 0; skip_fields = JNI_FALSE; n_fields_set = 0; fields = NULL; fvalues = NULL; if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 1 ) { /* Problems getting all the fields, can't trust field index values */ skip_fields = JNI_TRUE; /* Class with no references at all? (ok to be unprepared if list==0?) */ if ( list != 0 ) { /* It is assumed that the reason why we didn't get the fields * was because the class is not prepared. */ if ( gdata->debugflags & DEBUGFLAG_UNPREPARED_CLASSES ) { dump_ref_list(list); debug_message("Unprepared class with references: %s\n", sig); } HPROF_ERROR(JNI_FALSE, "Trouble with unprepared classes"); } /* Why would an unprepared class contain references? */ } if ( n_fields > 0 ) { fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } /* We use a Stack just because it will automatically expand as needed */ cpool_values = stack_init(16, 16, sizeof(ConstantPoolValue)); cpool = NULL; cpool_count = 0; index = list; while ( index != 0 ) { RefInfo *info; jvalue ovalue; static jvalue empty_value; info = get_info(index); switch ( info->flavor ) { case INFO_OBJECT_REF_DATA: switch ( info->refKind ) { case JVMTI_HEAP_REFERENCE_FIELD: case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: /* Should never be seen on a class dump */ HPROF_ASSERT(0); break; case JVMTI_HEAP_REFERENCE_STATIC_FIELD: if ( skip_fields == JNI_TRUE ) { break; } ovalue = empty_value; ovalue.i = info->object_index; fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, 0); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: { ConstantPoolValue cpv; ObjectIndex cp_object_index; SiteIndex cp_site_index; ClassIndex cp_cnum; cp_object_index = info->object_index; HPROF_ASSERT(cp_object_index!=0); cp_site_index = object_get_site(cp_object_index); HPROF_ASSERT(cp_site_index!=0); cp_cnum = site_get_class_index(cp_site_index); cpv.constant_pool_index = info->index; cpv.sig_index = class_get_signature(cp_cnum); cpv.value.i = cp_object_index; stack_push(cpool_values, (void*)&cpv); cpool_count++; break; } case JVMTI_HEAP_REFERENCE_SIGNERS: signers_index = info->object_index; break; case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN: domain_index = info->object_index; break; case JVMTI_HEAP_REFERENCE_CLASS_LOADER: case JVMTI_HEAP_REFERENCE_INTERFACE: default: /* Ignore, not needed */ break; } break; case INFO_PRIM_FIELD_DATA: if ( skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->primType!=0); HPROF_ASSERT(info->length==-1); HPROF_ASSERT(info->refKind==JVMTI_HEAP_REFERENCE_STATIC_FIELD); ovalue = get_key_value(index); fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, info->primType); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case INFO_PRIM_ARRAY_DATA: default: /* Should never see these */ HPROF_ASSERT(0); break; } index = info->next; } /* Get constant pool data if we have any */ HPROF_ASSERT(cpool_count==stack_depth(cpool_values)); if ( cpool_count > 0 ) { cpool = (ConstantPoolValue*)stack_element(cpool_values, 0); } io_heap_class_dump(cnum, sig, object_index, trace_serial_num, super_index, loader_object_index(env, loader_index), signers_index, domain_index, (jint)size, cpool_count, cpool, n_fields, fields, fvalues); stack_term(cpool_values); if ( fvalues != NULL ) { HPROF_FREE(fvalues); } }
/* Wants: mode request key */ static enum status_code option_bind_command(int argc, const char *argv[]) { enum request request; struct keymap *keymap; int key; if (argc < 3) return ERROR_WRONG_NUMBER_OF_ARGUMENTS; if (!(keymap = get_keymap(argv[0]))) return ERROR_UNKNOWN_KEY_MAP; key = get_key_value(argv[1]); if (key == ERR) return ERROR_UNKNOWN_KEY; request = get_request(argv[2]); if (request == REQ_UNKNOWN) { static const struct enum_map_entry obsolete[] = { ENUM_MAP_ENTRY("cherry-pick", REQ_NONE), ENUM_MAP_ENTRY("screen-resize", REQ_NONE), ENUM_MAP_ENTRY("tree-parent", REQ_PARENT), }; int alias; if (map_enum(&alias, obsolete, argv[2])) { if (alias != REQ_NONE) add_keybinding(keymap, alias, key); return ERROR_OBSOLETE_REQUEST_NAME; } } if (request == REQ_UNKNOWN) { enum run_request_flag flags = RUN_REQUEST_FORCE; if (strchr("!?@<", *argv[2])) { while (*argv[2]) { if (*argv[2] == '@') { flags |= RUN_REQUEST_SILENT; } else if (*argv[2] == '?') { flags |= RUN_REQUEST_CONFIRM; } else if (*argv[2] == '<') { flags |= RUN_REQUEST_EXIT; } else if (*argv[2] != '!') { break; } argv[2]++; } } else if (*argv[2] == ':') { argv[2]++; flags |= RUN_REQUEST_INTERNAL; } else { return ERROR_UNKNOWN_REQUEST_NAME; } return add_run_request(keymap, key, argv + 2, flags) ? SUCCESS : ERROR_OUT_OF_MEMORY; } add_keybinding(keymap, request, key); return SUCCESS; }
s32 populate_inst(ocrParamList_t **inst_param, ocrMappable_t **instance, s32 *type_counts, char ***factory_names, void ***all_factories, ocrMappable_t ***all_instances, type_enum index, dictionary *dict, char *secname) { s32 i, low, high, j; char *inststr; char key[MAX_KEY_SZ]; void *factory; s32 value; read_range(dict, secname, "id", &low, &high); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "type"); INI_GET_STR (key, inststr, ""); for (i = 0; i < type_counts[index]; i++) { if (factory_names[index][i] && (0 == strncmp(factory_names[index][i], inststr, strlen(factory_names[index][i])))) break; } if (factory_names[index][i] == NULL || strncmp(factory_names[index][i], inststr, strlen(factory_names[index][i]))) { DPRINTF(DEBUG_LVL_WARN, "Unknown type %s\n", inststr); return 0; } // find factory based on i factory = all_factories[index][i]; // Use the factory's instantiate() to create instance switch (index) { case guid_type: for (j = low; j<=high; j++) { ALLOC_PARAM_LIST(inst_param[j], paramListGuidProviderInst_t); instance[j] = (ocrMappable_t *)((ocrGuidProviderFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created guid provider of type %s, index %d\n", inststr, j); } break; case memplatform_type: for (j = low; j<=high; j++) { ALLOC_PARAM_LIST(inst_param[j], paramListMemPlatformInst_t); instance[j] = (ocrMappable_t *)((ocrMemPlatformFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created memplatform of type %s, index %d\n", inststr, j); } break; case memtarget_type: for (j = low; j<=high; j++) { ALLOC_PARAM_LIST(inst_param[j], paramListMemTargetInst_t); instance[j] = (ocrMappable_t *)((ocrMemTargetFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created memtarget of type %s, index %d\n", inststr, j); } break; case allocator_type: for (j = low; j<=high; j++) { ALLOC_PARAM_LIST(inst_param[j], paramListAllocatorInst_t); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "size"); INI_GET_INT (key, value, -1); ((paramListAllocatorInst_t *)inst_param[j])->size = value; instance[j] = (ocrMappable_t *)((ocrAllocatorFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created allocator of type %s, index %d\n", inststr, j); } break; case compplatform_type: for (j = low; j<=high; j++) { compPlatformType_t mytype = -1; TO_ENUM (mytype, inststr, compPlatformType_t, compplatform_types, compPlatformMax_id); switch (mytype) { case compPlatformPthread_id: { ALLOC_PARAM_LIST(inst_param[j], paramListCompPlatformPthread_t); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "ismasterthread"); INI_GET_BOOL (key, value, -1); ((paramListCompPlatformPthread_t *)inst_param[j])->isMasterThread = value; snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "stacksize"); INI_GET_INT (key, value, -1); ((paramListCompPlatformPthread_t *)inst_param[j])->stackSize = (value==-1)?0:value; if (key_exists(dict, secname, "binding")) { value = get_key_value(dict, secname, "binding", j-low); // printf("Binding value for %s;%d is %d\n", secname, j-low, value); } // else printf("No binding for %s\n", secname); } break; default: ALLOC_PARAM_LIST(inst_param[j], paramListCompPlatformInst_t); break; } instance[j] = (ocrMappable_t *)((ocrCompPlatformFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created compplatform of type %s, index %d\n", inststr, j); } break; case comptarget_type: for (j = low; j<=high; j++) { ALLOC_PARAM_LIST(inst_param[j], paramListCompTargetInst_t); instance[j] = (ocrMappable_t *)((ocrCompTargetFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created comptarget of type %s, index %d\n", inststr, j); } break; case workpile_type: for (j = low; j<=high; j++) { ALLOC_PARAM_LIST(inst_param[j], paramListWorkpileInst_t); instance[j] = (ocrMappable_t *)((ocrWorkpileFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created workpile of type %s, index %d\n", inststr, j); } break; case worker_type: for (j = low; j<=high; j++) { workerType_t mytype = -1; TO_ENUM (mytype, inststr, workerType_t, worker_types, workerMax_id); switch (mytype) { case workerHc_id: { ALLOC_PARAM_LIST(inst_param[j], paramListWorkerHcInst_t); ((paramListWorkerHcInst_t *)inst_param[j])->workerId = j; // using "id" for now; TODO: decide if a separate key is needed } break; default: ALLOC_PARAM_LIST(inst_param[j], paramListWorkerInst_t); break; } instance[j] = (ocrMappable_t *)((ocrWorkerFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created worker of type %s, index %d\n", inststr, j); } break; case scheduler_type: for (j = low; j<=high; j++) { schedulerType_t mytype = -1; TO_ENUM (mytype, inststr, schedulerType_t, scheduler_types, schedulerMax_id); switch (mytype) { case schedulerHc_id: { ALLOC_PARAM_LIST(inst_param[j], paramListSchedulerHcInst_t); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "workeridfirst"); INI_GET_INT (key, value, -1); ((paramListSchedulerHcInst_t *)inst_param[j])->workerIdFirst = value; } break; default: ALLOC_PARAM_LIST(inst_param[j], paramListSchedulerInst_t); break; } instance[j] = (ocrMappable_t *)((ocrSchedulerFactory_t *)factory)->instantiate(factory, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created scheduler of type %s, index %d\n", inststr, j); } break; case policydomain_type: for (j = low; j<=high; j++) { ocrTaskFactory_t *tf; ocrTaskTemplateFactory_t *ttf; ocrDataBlockFactory_t *dbf; ocrEventFactory_t *ef; ocrPolicyCtxFactory_t *cf; ocrGuidProvider_t *gf; ocrLockFactory_t *lf; ocrAtomic64Factory_t *af; s32 low, high; s32 schedulerCount, workerCount, computeCount, workpileCount, allocatorCount, memoryCount; schedulerCount = read_range(dict, secname, "scheduler", &low, &high); workerCount = read_range(dict, secname, "worker", &low, &high); computeCount = read_range(dict, secname, "comptarget", &low, &high); workpileCount = read_range(dict, secname, "workpile", &low, &high); allocatorCount = read_range(dict, secname, "allocator", &low, &high); memoryCount = read_range(dict, secname, "memtarget", &low, &high); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "taskfactory"); INI_GET_STR (key, inststr, ""); tf = create_factory_task(inststr, NULL); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "tasktemplatefactory"); INI_GET_STR (key, inststr, ""); ttf = create_factory_tasktemplate(inststr, NULL); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "datablockfactory"); INI_GET_STR (key, inststr, ""); dbf = create_factory_datablock(inststr, NULL); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "eventfactory"); INI_GET_STR (key, inststr, ""); ef = create_factory_event(inststr, NULL); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "contextfactory"); INI_GET_STR (key, inststr, ""); cf = create_factory_context(inststr, NULL); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "sync"); INI_GET_STR (key, inststr, ""); lf = create_factory_lock(inststr, NULL); snprintf(key, MAX_KEY_SZ, "%s:%s", secname, "sync"); INI_GET_STR (key, inststr, ""); af = create_factory_atomic64(inststr, NULL); // Ugly but special case read_range(dict, secname, "guid", &low, &high); ASSERT (low == high); // We don't expect more than one guid provider gf = (ocrGuidProvider_t *)(all_instances[guid_type][low]); ASSERT (gf); ALLOC_PARAM_LIST(inst_param[j], paramListPolicyDomainInst_t); instance[j] = (ocrMappable_t *)((ocrPolicyDomainFactory_t *)factory)->instantiate(factory, schedulerCount, workerCount, computeCount, workpileCount, allocatorCount, memoryCount, tf, ttf, dbf, ef, cf, gf, lf, af, NULL, inst_param[j]); if (instance[j]) DPRINTF(DEBUG_LVL_INFO, "Created policy domain of index %d\n", j); setBootPD((ocrPolicyDomain_t *)instance[j]); } break; default: DPRINTF(DEBUG_LVL_WARN, "Error: %d index unexpected\n", index); break; } return 0; }
/** * \class ds::EngineSettings */ EngineSettings::EngineSettings() : mLoadedAnySettings(false) { mLoadedAnySettings = false; mStartupInfo.str(""); // Default file names. const std::string DEFAULT_FILENAME("engine.xml"); std::string appFilename = DEFAULT_FILENAME, localFilename, commandLineAppConfig, projectPath; std::vector<std::string> args = ds::Environment::getCommandLineParams(); for(const auto& arg : args) { std::string key, value; if(!get_key_value(arg, key, value)) continue; if(key == "app_settings") { appFilename = value; if(localFilename.empty()) localFilename = value; } else if(key == "local_settings") { localFilename = value; } else if(key == "local_path") { // The local path and filename need to be parsed here. Poco::Path p(value); const std::string& fn(p.getFileName()); const std::string full(p.toString()); projectPath = full.substr(0, full.length() - (fn.length() + 1)); localFilename = fn; } else if (key == "configuration" || key == "config") { commandLineAppConfig = value; } } if(localFilename.empty()) localFilename = DEFAULT_FILENAME; // I have all the argument-supplied paths and filenames. Now I can // start reading my settings files. // APP SETTINGS // Find my app settings/ directory. This will vary based on whether I'm in a dev environment or // in a production, but I will have a settings/ folder either at or above me. const std::string appSettingsPath = ds::Environment::getAppFolder(ds::Environment::SETTINGS()); if(appSettingsPath.empty()){ //throw std::runtime_error("Missing application settings folder"); std::cout << "Couldn't find the application settings folder, that could be a problem." << std::endl; } Poco::Path appP(appSettingsPath); appP.append(appFilename); std::string appFullPath = appP.toString(); if(safeFileExistsCheck(appFullPath)){ mLoadedAnySettings = true; mStartupInfo << "EngineSettings: Reading app settings from " << appFullPath << std::endl; readFrom(appFullPath, false); } // LOCAL SETTINGS // The project path is taken from the supplied arguments, if it existed, or else it's // pulled from the settings I just loaded. If neither has it, then I guess no local settings. if(projectPath.empty()) { projectPath = getText("project_path", 0, projectPath); } else { // If it exists, then make sure then any project_path in the settings is the same. No one // should ever use that, but let's be safe. ds::cfg::Settings::Editor ed(*this, Editor::SET_MODE); ed.setText("project_path", projectPath); } if(!projectPath.empty()) { // Set the global project path PROJECT_PATH = projectPath; std::string localSettingsPath = ds::Environment::getLocalSettingsPath(localFilename); if(safeFileExistsCheck(localSettingsPath)){ mLoadedAnySettings = true; mStartupInfo << "EngineSettings: Reading app settings from " << localSettingsPath << std::endl; readFrom(localSettingsPath, true); } // Load the configuration settings, which can be used to modify settings even more. // Currently used to provide alternate layout sizes. ds::Environment::loadSettings("configuration.xml", CONFIGURATION_SETTINGS); CONFIGURATION_FOLDER = commandLineAppConfig.empty() ? CONFIGURATION_SETTINGS.getText("folder", 0, "") : commandLineAppConfig; // If the folder exists, then apply any changes to the engine file if(!CONFIGURATION_FOLDER.empty()) { const std::string app = ds::Environment::expand("%APP%/settings/%CFG_FOLDER%/" + appFilename); const std::string local = ds::Environment::expand("%LOCAL%/settings/%PP%/%CFG_FOLDER%/" + appFilename); if(safeFileExistsCheck(app)){ mLoadedAnySettings = true; mStartupInfo << "EngineSettings: Reading app settings from " << app << std::endl; readFrom(app, true); } if(safeFileExistsCheck(local)){ mLoadedAnySettings = true; mStartupInfo << "EngineSettings: Reading app settings from " << local << std::endl; readFrom(local, true); } } } }