diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2010-03-30 04:48:33 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2010-03-30 04:48:33 -0400 |
commit | b6745e1d1878d305a71ef6eb6b78be47a2254f23 (patch) | |
tree | c13d064445aa958db91c2cc6d02f9f980f4d42eb /shared_json.c | |
parent | 72b545ecfa35b652d94f658eefda16d01c9d69f3 (diff) | |
download | gpsd-b6745e1d1878d305a71ef6eb6b78be47a2254f23.tar.gz |
Split out some functions from gpsd_json.c that are used by libgps.
Applications shouldn't need to carry around all that structure-dumping code,
Diffstat (limited to 'shared_json.c')
-rw-r--r-- | shared_json.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/shared_json.c b/shared_json.c new file mode 100644 index 00000000..79ab00b0 --- /dev/null +++ b/shared_json.c @@ -0,0 +1,96 @@ +/**************************************************************************** + +NAME + shared_json.c - move data between in-core and JSON structures + +DESCRIPTION + This module uses the generic JSON parser to get data from JSON +representations to gps.h structures. These functions are used in both +the daemon and the client library. + +PERMISSIONS + Written by Eric S. Raymond, 2009 + This file is Copyright (c) 2010 by the GPSD project + BSD terms apply: see the file COPYING in the distribution root for details. + +***************************************************************************/ + +#include <math.h> +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <ctype.h> + +#include "gpsd.h" +#include "gps_json.h" + +int json_device_read(const char *buf, + /*@out@*/struct devconfig_t *dev, + /*@null@*/const char **endptr) +{ + /*@ -fullinitblock @*/ + const struct json_attr_t json_attrs_device[] = { + {"class", t_check, .dflt.check = "DEVICE"}, + + {"path", t_string, .addr.string = dev->path, + .len = sizeof(dev->path)}, + {"activated", t_real, .addr.real = &dev->activated}, + {"flags", t_integer, .addr.integer = &dev->flags}, + {"driver", t_string, .addr.string = dev->driver, + .len = sizeof(dev->driver)}, + {"subtype", t_string, .addr.string = dev->subtype, + .len = sizeof(dev->subtype)}, + {"native", t_integer, .addr.integer = &dev->driver_mode, + .dflt.integer = DEVDEFAULT_NATIVE}, + {"bps", t_uinteger, .addr.uinteger = &dev->baudrate, + .dflt.uinteger = DEVDEFAULT_BPS}, + {"parity", t_character, .addr.character = &dev->parity, + .dflt.character = DEVDEFAULT_PARITY}, + {"stopbits", t_uinteger, .addr.uinteger = &dev->stopbits, + .dflt.uinteger = DEVDEFAULT_STOPBITS}, + {"cycle", t_real, .addr.real = &dev->cycle, + .dflt.real = NAN}, + {"mincycle", t_real, .addr.real = &dev->mincycle, + .dflt.real = NAN}, + {NULL}, + }; + /*@ +fullinitblock @*/ + int status; + + status = json_read_object(buf, json_attrs_device, endptr); + if (status != 0) + return status; + + return 0; +} + +int json_watch_read(const char *buf, + /*@out@*/struct policy_t *ccp, + /*@null@*/const char **endptr) +{ + /*@ -fullinitblock @*/ + struct json_attr_t chanconfig_attrs[] = { + {"class", t_check, .dflt.check = "WATCH"}, + + {"enable", t_boolean, .addr.boolean = &ccp->watcher, + .dflt.boolean = true}, + {"json", t_boolean, .addr.boolean = &ccp->json, + .nodefault = true}, + {"raw", t_integer, .addr.integer = &ccp->raw, + .nodefault = true}, + {"nmea", t_boolean, .addr.boolean = &ccp->nmea, + .nodefault = true}, + {"scaled", t_boolean, .addr.boolean = &ccp->scaled}, + {"timing", t_boolean, .addr.boolean = &ccp->timing}, + {"device", t_string, .addr.string = ccp->devpath, + .len = sizeof(ccp->devpath)}, + {NULL}, + }; + /*@ +fullinitblock @*/ + int status; + + status = json_read_object(buf, chanconfig_attrs, endptr); + return status; +} + +/* shared_json.c ends here */ |