Browse Source

Add a json_get_double helper

master
ckolivas 10 years ago committed by Con Kolivas
parent
commit
6b9c558abc
  1. 20
      src/ckpool.c
  2. 1
      src/ckpool.h

20
src/ckpool.c

@ -997,6 +997,26 @@ out:
return ret; return ret;
} }
bool json_get_double(double *store, json_t *val, const char *res)
{
json_t *entry = json_object_get(val, res);
bool ret = false;
if (!entry) {
LOGDEBUG("Json did not find entry %s", res);
goto out;
}
if (!json_is_real(entry)) {
LOGWARNING("Json entry %s is not a double", res);
goto out;
}
*store = json_real_value(entry);
LOGDEBUG("Json found entry %s: %f", res, *store);
ret = true;
out:
return ret;
}
static bool json_get_bool(bool *store, json_t *val, const char *res) static bool json_get_bool(bool *store, json_t *val, const char *res)
{ {
json_t *entry = json_object_get(val, res); json_t *entry = json_object_get(val, res);

1
src/ckpool.h

@ -214,5 +214,6 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req);
int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret);
bool json_get_string(char **store, json_t *val, const char *res); bool json_get_string(char **store, json_t *val, const char *res);
bool json_get_int(int *store, json_t *val, const char *res); bool json_get_int(int *store, json_t *val, const char *res);
bool json_get_double(double *store, json_t *val, const char *res);
#endif /* CKPOOL_H */ #endif /* CKPOOL_H */

Loading…
Cancel
Save