summaryrefslogtreecommitdiff
path: root/gpsd.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-02-16 09:36:14 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-02-16 09:36:14 -0500
commita3766b700808d486762edc7c814ac43412c9296b (patch)
treef8ed51a4cc727028e7ef151d685dd0bbdac0c5d3 /gpsd.c
parent75960886a963dfc8ad828ee5ac056bea46588482 (diff)
downloadgpsd-a3766b700808d486762edc7c814ac43412c9296b.tar.gz
Refactoring step, no logic changes. All regression tests pass.
Diffstat (limited to 'gpsd.c')
-rw-r--r--gpsd.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/gpsd.c b/gpsd.c
index 6994160e..811f749a 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -1312,67 +1312,64 @@ static void pseudonmea_report(struct subscriber_t *sub,
}
}
-static void json_report(struct subscriber_t *sub,
- gps_mask_t changed,
- struct gps_device_t *device)
-/* report in JSON format to a subscriber */
+static void json_inner_report(gps_mask_t changed,
+ struct gps_data_t *datap,
+ struct policy_t *policy,
+ /*@out@*/char *buf, size_t buflen)
+/* report the session state in JSON */
{
- char buf[GPS_JSON_RESPONSE_MAX * 4];
-
buf[0] = '\0';
+
if ((changed & REPORT_IS) != 0) {
- json_tpv_dump(&device->gpsdata,
- buf, sizeof(buf));
- (void)throttled_write(sub, buf, strlen(buf));
+ json_tpv_dump(datap, buf+strlen(buf), buflen-strlen(buf));
}
if ((changed & NOISE_IS) != 0) {
- json_noise_dump(&device->gpsdata,
- buf, sizeof(buf));
- (void)throttled_write(sub, buf, strlen(buf));
+ json_noise_dump(datap, buf+strlen(buf), buflen-strlen(buf));
}
if ((changed & SATELLITE_IS) != 0) {
- json_sky_dump(&device->gpsdata,
- buf, sizeof(buf));
- (void)throttled_write(sub, buf, strlen(buf));
+ json_sky_dump(datap, buf+strlen(buf), buflen-strlen(buf));
}
- /*
- * Subframe reporting works a bit differently because
- * it has to be enabled at device level in order for
- * *any* subscriber to see it, but *not all* subscribers
- * necessarily want it. So we leave it up to the device
- * drivers to decide whether to turn subframe reporting on,
- * and just pass the through here.
- */
+
if ((changed & SUBFRAME_IS) != 0) {
- json_subframe_dump(&device->gpsdata, buf, sizeof(buf));
- (void)throttled_write(sub, buf, strlen(buf));
+ json_subframe_dump(datap, buf+strlen(buf), buflen-strlen(buf));
}
+
#ifdef COMPASS_ENABLE
if ((changed & ATT_IS) != 0) {
- json_att_dump(&device->gpsdata,
- buf, sizeof(buf));
- (void)throttled_write(sub, buf, strlen(buf));
+ json_att_dump(datap, buf+strlen(buf), buflen-strlen(buf));
}
#endif /* COMPASS_ENABLE */
+
#ifdef RTCM104V2_ENABLE
if ((changed & RTCM2_IS) != 0) {
- json_rtcm2_dump(&device->gpsdata.rtcm2,
- device->gpsdata.dev.path,
- buf, sizeof(buf));
- (void)throttled_write(sub, buf, strlen(buf));
+ json_rtcm2_dump(&datap->rtcm2, datap->dev.path,
+ buf+strlen(buf), buflen-strlen(buf));
}
#endif /* RTCM104V2_ENABLE */
+
#ifdef AIVDM_ENABLE
if ((changed & AIS_IS) != 0) {
- json_aivdm_dump(&device->gpsdata.ais,
- device->gpsdata.dev.path,
- sub->policy.scaled,
- buf, sizeof(buf));
- (void)throttled_write(sub, buf, strlen(buf));
+ json_aivdm_dump(&datap->ais, datap->dev.path,
+ policy->scaled,
+ buf+strlen(buf), buflen-strlen(buf));
}
#endif /* AIVDM_ENABLE */
+}
+
+static void json_report(struct subscriber_t *sub,
+ gps_mask_t changed,
+ struct gps_device_t *device)
+/* report in JSON format to a subscriber */
+{
+ char buf[GPS_JSON_RESPONSE_MAX * 4];
+
+ json_inner_report(changed,
+ &device->gpsdata, &sub->policy,
+ buf, sizeof(buf));
+ if (buf[0] != '\0')
+ (void)throttled_write(sub, buf, strlen(buf));
#ifdef TIMING_ENABLE
if (buf[0] != '\0' && sub->policy.timing) {