/** * Execute a tokenized command and display its output. * * @param conn The connection to lldpd. * @param fmt Output format. * @param argc Number of arguments. * @param argv Array of arguments. * @return 0 if an error occurred, 1 otherwise */ static int cmd_exec(lldpctl_conn_t *conn, const char *fmt, int argc, const char **argv) { /* Init output formatter */ struct writer *w; if (strcmp(fmt, "plain") == 0) w = txt_init(stdout); else if (strcmp(fmt, "keyvalue") == 0) w = kv_init(stdout); else if (strcmp(fmt, "json") == 0) w = json_init(stdout, 1); else if (strcmp(fmt, "json0") == 0) w = json_init(stdout, 0); #ifdef USE_XML else if (strcmp(fmt, "xml") == 0) w = xml_init(stdout); #endif else { log_warnx("lldpctl", "unknown output format \"%s\"", fmt); w = txt_init(stdout); } /* Execute command */ int rc = commands_execute(conn, w, root, argc, argv, is_privileged()); if (rc != 0) { log_info("lldpctl", "an error occurred while executing last command"); w->finish(w); return 0; } w->finish(w); return 1; }
static void set_device_time() { http_session_t handle; http_resp_t *resp = NULL; char buf[MAX_DOWNLOAD_DATA]; int64_t timestamp, offset; int size = 0; int status = 0; char url_name[MAX_URL_LEN]; memset(url_name, 0, sizeof(url_name)); strncpy(url_name, EVRYTHNG_GET_TIME_URL, strlen(EVRYTHNG_GET_TIME_URL)); wmprintf("Get time from : %s\r\n", url_name); status = httpc_get(url_name, &handle, &resp, NULL); if (status != WM_SUCCESS) { wmprintf("Getting URL failed"); return; } size = http_read_content(handle, buf, MAX_DOWNLOAD_DATA); if (size <= 0) { wmprintf("Reading time failed\r\n"); goto out_time; } /* If timezone is present in PSM Get on http://api.evrythng.com/time?tz=<timezone> The data will look like this { "timestamp":1429514751927, "offset":-18000000, "localTime":"2015-04-20T02:25:51.927-05:00", "nextChange":1446361200000 } If timezone is not presentin PSM Get on http://api.evrythng.com/time The data will look like this { "timestamp":1429514751927 } */ jsontok_t json_tokens[9]; jobj_t json_obj; if (json_init(&json_obj, json_tokens, 10, buf, size) != WM_SUCCESS) { wmprintf("Wrong json string\r\n"); goto out_time; } if (json_get_val_int64(&json_obj, "timestamp", ×tamp) == WM_SUCCESS) { if (json_get_val_int64(&json_obj, "offset", &offset) != WM_SUCCESS) { offset = 0; } timestamp = timestamp + offset; } wmtime_time_set_posix(timestamp/1000); out_time: http_close_session(&handle); return; }
int test_main (void) { json_ctx_t json_ctx; size_t i; test_init (); json_init (&json_ctx, 0, stdout); json_document_begin (&json_ctx); json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); json_attr_object_begin (&json_ctx, "functions"); json_attr_object_begin (&json_ctx, TEST_NAME); json_attr_string (&json_ctx, "bench-variant", "default"); json_array_begin (&json_ctx, "ifuncs"); FOR_EACH_IMPL (impl, 0) json_element_string (&json_ctx, impl->name); json_array_end (&json_ctx); json_array_begin (&json_ctx, "results"); for (i = 1; i < 32; ++i) { do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 0); do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 1); do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, -1); } for (i = 1; i < 10 + CHARBYTESLOG; ++i) { do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 0); do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 0); do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 1); do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 1); do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, -1); do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, -1); do_test (&json_ctx, 0, CHARBYTES * i, 2 << i, MIDCHAR, 1); do_test (&json_ctx, CHARBYTES * i, CHARBYTES * (i + 1), 2 << i, LARGECHAR, 1); } for (i = 1; i < 8; ++i) { do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, 0); do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, 0); do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, 1); do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, 1); do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, -1); do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, -1); } json_array_end (&json_ctx); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); json_document_end (&json_ctx); return ret; }
// called at the top of each minute void schedule_update(int hour, int min) { #define UPDATE_SPREAD_HOURS 4 // # hours to spread updates over #define UPDATE_SPREAD_MIN (UPDATE_SPREAD_HOURS * 60) #define UPDATE_START_HOUR 2 // 2 AM UTC, 2(3) PM NZT(NZDT) #define UPDATE_END_HOUR (UPDATE_START_HOUR + UPDATE_SPREAD_HOURS) bool update = (hour >= UPDATE_START_HOUR && hour < UPDATE_END_HOUR); // don't let Kiwis hit github.com all at once! int mins; if (update) { mins = min + (hour - UPDATE_START_HOUR) * 60; //printf("UPDATE: %02d:%02d waiting for %d min = %d min(sn=%d)\n", hour, min, // mins, serial_number % UPDATE_SPREAD_MIN, serial_number); update = update && (mins == (serial_number % UPDATE_SPREAD_MIN)); if (update) { printf("TLIMIT-IP 24hr cache cleared\n"); json_init(&cfg_ipl, (char *) "{}"); // clear 24hr ip address connect time limit cache } } daily_restart = update && !update_on_startup && (admcfg_bool("daily_restart", NULL, CFG_REQUIRED) == true); if (update || update_on_startup) { lprintf("UPDATE: check scheduled %s\n", update_on_startup? "(startup)":""); update_on_startup = false; update_pending = true; check_for_update(WAIT_UNTIL_NO_USERS, NULL); } }
static void action_led_callback(const char* json_str, size_t size) { jobj_t json; jsontok_t json_tokens[JSON_NUM_TOKENS]; int err = json_init(&json, json_tokens, JSON_NUM_TOKENS, (char*)json_str, size); if (err != WM_SUCCESS) { wmprintf("Wrong json string\n\r"); return; } output_gpio_cfg_t led; char type[32]; if (json_get_val_str(&json, "type", type, sizeof(type)) != WM_SUCCESS) { wmprintf("type doesn't exist\r\n"); return; } if (strcmp(type, "_led1") == 0) { led = led_1; } else if (strcmp(type, "_led2") == 0) { led = led_2; } else { wmprintf("not expected type value\r\n"); return; } if (json_get_composite_object(&json, "customFields") != WM_SUCCESS) { wmprintf("Custom fields doesn't exist\n\r"); return; } char status[16]; if (json_get_val_str(&json, "status", status, sizeof(status)) != WM_SUCCESS) { wmprintf("Status doesn't exist\n\r"); return; } json_release_composite_object(&json); wmprintf("Received action: type = \"%s\", status = \"%s\"\n\r", type, status); if (strcmp(status, "0") == 0) { led_off(led); } else if (strcmp(status, "1") == 0) { led_on(led); } }
json_t *json_integer(int value) { json_integer_t *integer = malloc(sizeof(json_integer_t)); if(!integer) return NULL; json_init(&integer->json, JSON_INTEGER); integer->value = value; return &integer->json; }
json_t *json_real(double value) { json_real_t *real = malloc(sizeof(json_real_t)); if(!real) return NULL; json_init(&real->json, JSON_REAL); real->value = value; return &real->json; }
/* * JSON OBJECT */ my_bool json_object_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ return json_init( initid , args , message , JSON_OBJECT ); }
/* * JSON ARRAY */ my_bool json_array_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ return json_init( initid , args , message , JSON_ARRAY ); }
/* * JSON VALUES */ my_bool json_values_init( UDF_INIT *initid , UDF_ARGS *args , char *message ){ return json_init( initid , args , message , JSON_VALUES ); }
json_t *json_object(void) { json_object_t *object = jsonp_malloc(sizeof(json_object_t)); if(!object) return NULL; json_init(&object->json, JSON_OBJECT); if(hashtable_init(&object->hashtable)) { jsonp_free(object); return NULL; } object->serial = 0; object->visited = 0; return &object->json; }
json_t *json_object(void) { json_object_t *object = malloc(sizeof(json_object_t)); if(!object) return NULL; json_init(&object->json, JSON_OBJECT); if(hashtable_init(&object->hashtable, hash_string, string_equal, free, value_decref)) { free(object); return NULL; } object->visited = 0; return &object->json; }
int test_main (void) { json_ctx_t json_ctx; test_init (); json_init (&json_ctx, 0, stdout); json_document_begin (&json_ctx); json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); json_attr_object_begin (&json_ctx, "functions"); json_attr_object_begin (&json_ctx, "memmove"); json_attr_string (&json_ctx, "bench-variant", "walk"); json_array_begin (&json_ctx, "ifuncs"); FOR_EACH_IMPL (impl, 0) json_element_string (&json_ctx, impl->name); json_array_end (&json_ctx); json_array_begin (&json_ctx, "results"); /* Non-overlapping buffers. */ for (size_t i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) { do_test (&json_ctx, i, false); do_test (&json_ctx, i + 1, false); } /* Overlapping buffers. */ for (size_t i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) { do_test (&json_ctx, i, true); do_test (&json_ctx, i + 1, true); } json_array_end (&json_ctx); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); json_document_end (&json_ctx); return ret; }
static PyObject * PongoDict_json(PongoDict *self, PyObject *args) { char *key = NULL, *val = NULL; Py_ssize_t klen, vlen; PyObject *ret = Py_None; dbtype_t dict, obj, k; jsonctx_t *jctx; if (!PyArg_ParseTuple(args, "|s#s#:json", &key, &klen, &val, &vlen)) return NULL; dblock(self->ctx); dict = self->dbptr; jctx = json_init(self->ctx); if (key) { if (val) { // 2-arg form is dict.json('key', 'value') // inserts dict['key'] = json_parse('value') k = dbstring_new(self->ctx, key, klen); obj = json_parse(jctx, val, vlen); dbobject_setitem(SELF_CTX_AND_DBPTR, k, obj, self->ctx->sync); } else { // 1-arg form is replace dict.items with parsed json obj = json_parse(jctx, key, klen); dict.ptr = dbptr(self->ctx, dict); obj.ptr = dbptr(self->ctx, obj); dict.ptr->obj = obj.ptr->obj; } Py_INCREF(ret); } else { // The 0-arg form is to generate the json string from dictionary // contents json_emit(jctx, dict); if (jctx->outstr) ret = PyUnicode_FromStringAndSize( (const char*)jctx->outstr, jctx->outlen); } json_cleanup(jctx); dbunlock(self->ctx); return ret; }
result_t core_init(uint flags) { if (BIT_CHECK(flags, CORE_INIT_CRASHDUMP)) { if (IS_FAIL(crash_init())) return RET_FAIL; } if (IS_FAIL(mem_init(BIT_CHECK(flags, CORE_INIT_TRACEMEM)))) return RET_FAIL; if (IS_FAIL(log_init())) return RET_FAIL; if (BIT_CHECK(flags, CORE_INIT_ERRORS)) { if (IS_FAIL(err_init())) return RET_FAIL; } rand_seed(); if (BIT_CHECK(flags, CORE_INIT_JSON)) { if (IS_FAIL(json_init())) return RET_FAIL; } if (BIT_CHECK(flags, CORE_INIT_FILEIO)) { if (IS_FAIL(fio_initmgr())) return RET_FAIL; } if (BIT_CHECK(flags, CORE_INIT_TIMER)) { if (IS_FAIL(timer_initmgr())) return RET_FAIL; } if (BIT_CHECK(flags, CORE_INIT_SOCKET)) { if (IS_FAIL(sock_init())) return RET_FAIL; } return RET_OK; }
json_t *json_array(void) { json_array_t *array = malloc(sizeof(json_array_t)); if(!array) return NULL; json_init(&array->json, JSON_ARRAY); array->entries = 0; array->size = 8; array->table = malloc(array->size * sizeof(json_t *)); if(!array->table) { free(array); return NULL; } array->visited = 0; return &array->json; }
json_t *json_string_nocheck(const char *value) { json_string_t *string; if(!value) return NULL; string = malloc(sizeof(json_string_t)); if(!string) return NULL; json_init(&string->json, JSON_STRING); string->value = strdup(value); if(!string->value) { free(string); return NULL; } return &string->json; }
json_t *json_object(void) { json_object_t *object = (json_object_t *) jsonp_malloc(sizeof(json_object_t)); if(!object) return NULL; json_init(&object->json, JSON_OBJECT); if(hashtable_init(&object->hashtable, hash_key, key_equal, jsonp_free, value_decref)) { jsonp_free(object); return NULL; } object->serial = 0; object->visited = 0; return &object->json; }
int test_main (void) { json_ctx_t json_ctx; size_t i; bench_start (); json_init (&json_ctx, 2, stdout); json_attr_object_begin (&json_ctx, TEST_NAME); /* Create 2 test arrays, one with 10% zeroes, 10% negative values, 79% positive values and 1% infinity/NaN. The other contains 50% inf, 50% NaN. This relies on rand behaving correctly. */ for (i = 0; i < SIZE; i++) { int x = rand () & 255; arr1[i] = (x < 25) ? 0.0 : ((x < 50) ? -1 : 100); if (x == 255) arr1[i] = __builtin_inf (); if (x == 254) arr1[i] = __builtin_nan ("0"); arr2[i] = (x < 128) ? __builtin_inf () : __builtin_nan ("0"); } for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++) { json_attr_object_begin (&json_ctx, test_list[i].name); do_one_test (&json_ctx, test_list[i].fn, arr2, SIZE, "inf/nan"); json_attr_object_end (&json_ctx); } for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++) { json_attr_object_begin (&json_ctx, test_list[i].name); do_one_test (&json_ctx, test_list[i].fn, arr1, SIZE, "normal"); json_attr_object_end (&json_ctx); } json_attr_object_end (&json_ctx); return 0; }
inline void setup() { #ifdef DEBUG_PRINT Serial.begin(9600); #endif gsm.Reset(); gsm.PowerOn(); //gsm.TurnOn(9600); gsm.setRxHandler(EVENT_WebSocket_RecvByte); gsm.setTxHandler(EVENT_WebSocket_Send); pinMode(Keyboard_Pin_DATA, OUTPUT); pinMode(Keyboard_Pin_LATCH, OUTPUT); pinMode(Keyboard_Pin_CLK, OUTPUT); pinMode(Keyboard_Pin_5V, OUTPUT); digitalWrite(Keyboard_Pin_5V, HIGH); // json json_init(&json_parser); }
int test_main (void) { json_ctx_t json_ctx; size_t i; test_init (); json_init (&json_ctx, 0, stdout); json_document_begin (&json_ctx); json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); json_attr_object_begin (&json_ctx, "functions"); json_attr_object_begin (&json_ctx, "memcpy"); json_attr_string (&json_ctx, "bench-variant", "walk"); json_array_begin (&json_ctx, "ifuncs"); FOR_EACH_IMPL (impl, 0) json_element_string (&json_ctx, impl->name); json_array_end (&json_ctx); json_array_begin (&json_ctx, "results"); for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) { /* Test length alignments from 0-16 bytes. */ for (int j = 0; j < 8; j++) { do_test (&json_ctx, i + j); do_test (&json_ctx, i + 16 - j); } } json_array_end (&json_ctx); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); json_document_end (&json_ctx); return ret; }
json_t *json_object(void) { json_object_t *object = jsonp_malloc(sizeof(json_object_t)); if(!object) return NULL; if (!hashtable_seed) { /* Autoseed */ json_object_seed(0); } json_init(&object->json, JSON_OBJECT); if(hashtable_init(&object->hashtable)) { jsonp_free(object); return NULL; } object->serial = 0; return &object->json; }
int main (int argc, char **argv) { timing_t cur; size_t iters = 0, num_threads = 1; unsigned long res; json_ctx_t json_ctx; double d_total_s, d_total_i; struct sigaction act; if (argc == 1) num_threads = 1; else if (argc == 2) { long ret; errno = 0; ret = strtol(argv[1], NULL, 10); if (errno || ret == 0) usage(argv[0]); num_threads = ret; } else usage(argv[0]); init_random_values (); json_init (&json_ctx, 0, stdout); json_document_begin (&json_ctx); json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); json_attr_object_begin (&json_ctx, "functions"); json_attr_object_begin (&json_ctx, "malloc"); json_attr_object_begin (&json_ctx, ""); TIMING_INIT (res); (void) res; memset (&act, 0, sizeof (act)); act.sa_handler = &alarm_handler; sigaction (SIGALRM, &act, NULL); alarm (BENCHMARK_DURATION); cur = do_benchmark (num_threads, &iters); struct rusage usage; getrusage(RUSAGE_SELF, &usage); d_total_s = cur; d_total_i = iters; json_attr_double (&json_ctx, "duration", d_total_s); json_attr_double (&json_ctx, "iterations", d_total_i); json_attr_double (&json_ctx, "time_per_iteration", d_total_s / d_total_i); json_attr_double (&json_ctx, "max_rss", usage.ru_maxrss); json_attr_double (&json_ctx, "threads", num_threads); json_attr_double (&json_ctx, "min_size", MIN_ALLOCATION_SIZE); json_attr_double (&json_ctx, "max_size", MAX_ALLOCATION_SIZE); json_attr_double (&json_ctx, "random_seed", RAND_SEED); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); json_document_end (&json_ctx); return 0; }
static int test_main (void) { json_ctx_t json_ctx; size_t i; test_init (); json_init (&json_ctx, 0, stdout); json_document_begin (&json_ctx); json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); json_attr_object_begin (&json_ctx, "functions"); json_attr_object_begin (&json_ctx, "memmove"); json_attr_string (&json_ctx, "bench-variant", "default"); json_array_begin (&json_ctx, "ifuncs"); FOR_EACH_IMPL (impl, 0) json_element_string (&json_ctx, impl->name); json_array_end (&json_ctx); json_array_begin (&json_ctx, "results"); for (i = 0; i < 14; ++i) { do_test (&json_ctx, 0, 32, 1 << i); do_test (&json_ctx, 32, 0, 1 << i); do_test (&json_ctx, 0, i, 1 << i); do_test (&json_ctx, i, 0, 1 << i); } for (i = 0; i < 32; ++i) { do_test (&json_ctx, 0, 32, i); do_test (&json_ctx, 32, 0, i); do_test (&json_ctx, 0, i, i); do_test (&json_ctx, i, 0, i); } for (i = 3; i < 32; ++i) { if ((i & (i - 1)) == 0) continue; do_test (&json_ctx, 0, 32, 16 * i); do_test (&json_ctx, 32, 0, 16 * i); do_test (&json_ctx, 0, i, 16 * i); do_test (&json_ctx, i, 0, 16 * i); } for (i = 32; i < 64; ++i) { do_test (&json_ctx, 0, 0, 32 * i); do_test (&json_ctx, i, 0, 32 * i); do_test (&json_ctx, 0, i, 32 * i); do_test (&json_ctx, i, i, 32 * i); } json_array_end (&json_ctx); json_attr_object_end (&json_ctx); json_attr_object_end (&json_ctx); json_document_end (&json_ctx); return ret; }
int config_init() { for (size_t i = 0; i < KEYS_COUNT; i++) { keys[i].key_len = strlen((char *)keys[i].key); fields[i].len = strlen((char *)fields[i].tag); } default_config.Phone[0] = '\0'; default_config.fw[sizeof(default_config.fw) - 1] = '\0'; strncpy(default_config.fw, "default", sizeof(default_config.fw) - 1); default_config.port = AK308_IO_MODE_SEPARATE; default_config.wakeup = AK308_SOURCE_ACTIVE; default_config.wakeup_active_interval = 100; default_config.wakeup_inactive_interval = 100; default_config.wakeup_sms_on_active[0] = '\0'; default_config.wakeup_sms_on_inactive[0] = '\0'; default_config.vcc_expanded = false; default_config.vcc_as_di = false; default_config.vcc_threshold = 26; default_config.vcc_active_time = 100; default_config.vcc_inactive_time = 100; default_config.vcc_sms_on_active[0] = '\0'; default_config.vcc_sms_on_inactive[0] = '\0'; default_config.vcc_transmit = false; default_config.accell_expanded = false; default_config.accell_as_di = false; default_config.accell_sense = 5; default_config.accell_active_time = 5; default_config.accell_inactive_time = 30; default_config.accell_sms_on_active[0] = '\0'; default_config.accell_sms_on_inactive[0] = '\0'; default_config.accell_transmit = false; default_config.fuel_threshold = 5; default_config.fuel_period = 60; default_config.DriveInterval = 15; default_config.DrivePPP = 4; default_config.wait_expanded = true; default_config.SleepDelayInterval = 1; default_config.SleepWakeupInterval = 30; default_config.wait_after_fuel = true; default_config.wait_to_active_fuel = true; default_config.sleep_expanded = true; default_config.SleepDeepDelayInterval = 60; default_config.SleepDeepMaxGPSSearchTime = 5; default_config.SleepDeepMaxGSMSearchTime = 5; default_config.SleepDeepWakeupInterval = 3; default_config.sleep_after_fuel = true; default_config.sleep_to_active_fuel = true; default_config.input1_expanded = false; default_config.Input1Mode = AK308_INPUT_MODE_UNCONNECTED; default_config.Input1ActiveInterval = 100; default_config.Input1InactiveInterval = 100; default_config.Input1SMSOnActive[0] = '\0'; default_config.Input1SMSOnInactive[0] = '\0'; default_config.input2_expanded = false; default_config.Input2Mode = AK308_INPUT_MODE_UNCONNECTED; default_config.Input2ActiveInterval = 10; default_config.Input2InactiveInterval = 10; default_config.Input2SMSOnActive[0] = '\0'; default_config.Input2SMSOnInactive[0] = '\0'; default_config.cog = false; default_config.altitude = false; default_config.timestamp = time(NULL); memset(default_config.info, 0, sizeof(default_config.info)); json_init(); return 0; }
int main (int argc, char **argv) { unsigned long i, k; struct timespec runtime; timing_t start, end; bool detailed = false; json_ctx_t json_ctx; if (argc == 2 && !strcmp (argv[1], "-d")) detailed = true; bench_start (); memset (&runtime, 0, sizeof (runtime)); unsigned long iters, res; #ifdef BENCH_INIT BENCH_INIT (); #endif TIMING_INIT (res); iters = 1000 * res; json_init (&json_ctx, 2, stdout); /* Begin function. */ json_attr_object_begin (&json_ctx, FUNCNAME); for (int v = 0; v < NUM_VARIANTS; v++) { /* Run for approximately DURATION seconds. */ clock_gettime (CLOCK_MONOTONIC_RAW, &runtime); runtime.tv_sec += DURATION; double d_total_i = 0; timing_t total = 0, max = 0, min = 0x7fffffffffffffff; int64_t c = 0; while (1) { for (i = 0; i < NUM_SAMPLES (v); i++) { uint64_t cur; TIMING_NOW (start); for (k = 0; k < iters; k++) BENCH_FUNC (v, i); TIMING_NOW (end); TIMING_DIFF (cur, start, end); if (cur > max) max = cur; if (cur < min) min = cur; TIMING_ACCUM (total, cur); /* Accumulate timings for the value. In the end we will divide by the total iterations. */ RESULT_ACCUM (cur, v, i, c * iters, (c + 1) * iters); d_total_i += iters; } c++; struct timespec curtime; memset (&curtime, 0, sizeof (curtime)); clock_gettime (CLOCK_MONOTONIC_RAW, &curtime); if (TIMESPEC_AFTER (curtime, runtime)) goto done; } double d_total_s; double d_iters; done: d_total_s = total; d_iters = iters; /* Begin variant. */ json_attr_object_begin (&json_ctx, VARIANT (v)); json_attr_double (&json_ctx, "duration", d_total_s); json_attr_double (&json_ctx, "iterations", d_total_i); json_attr_double (&json_ctx, "max", max / d_iters); json_attr_double (&json_ctx, "min", min / d_iters); json_attr_double (&json_ctx, "mean", d_total_s / d_total_i); if (detailed) { json_array_begin (&json_ctx, "timings"); for (int i = 0; i < NUM_SAMPLES (v); i++) json_element_double (&json_ctx, RESULT (v, i)); json_array_end (&json_ctx); } /* End variant. */ json_attr_object_end (&json_ctx); } /* End function. */ json_attr_object_end (&json_ctx); return 0; }
int config_init() { for (size_t i = 0; i < KEYS_COUNT; i++) { keys[i].key_len = strlen((char *)keys[i].key); fields[i].len = strlen((char *)fields[i].tag); } default_config.Phone[0] = '\0'; default_config.fw[sizeof(default_config.fw) - 1] = '\0'; strncpy(default_config.fw, "default", sizeof(default_config.fw) - 1); default_config.DriveInterval = 15; default_config.DrivePPP = 4; default_config.ParkInterval = 30; default_config.ParkPPP = 1; default_config.bDisableStatic = true; default_config.input1_expanded = false; default_config.Input1Mode = 0; default_config.Input1SMSOnActive[0] = '\0'; default_config.input2_expanded = true; default_config.Input2Mode = 1; default_config.Input2SMSOnActive[0] = '\0'; default_config.input3_expanded = false; default_config.Input3Mode = 0; default_config.Input3SMSOnActive[0] = '\0'; default_config.input4_expanded = false; default_config.Input4Mode = 0; default_config.Input4SMSOnActive[0] = '\0'; default_config.sms_a1[0] = '\0'; default_config.sms_a2[0] = '\0'; default_config.sms_a3[0] = '\0'; default_config.sms_a4[0] = '\0'; default_config.sms_d1[0] = '\0'; default_config.sms_d2[0] = '\0'; default_config.sms_d3[0] = '\0'; default_config.sms_d4[0] = '\0'; default_config.audio_expanded = false; default_config.nCMIC = 12; default_config.nCLVL = 85; default_config.EchoModel = 4000; default_config.EchoLevel = 20; default_config.EchoPatterns = 4; default_config.requested_fw_ver = 0; default_config.actual_fw_ver = 0; default_config.need_profile = true; default_config.timestamp = time(NULL); json_init(); return 0; }