diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-02-16 09:36:14 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-02-16 09:36:14 -0500 |
commit | a3766b700808d486762edc7c814ac43412c9296b (patch) | |
tree | f8ed51a4cc727028e7ef151d685dd0bbdac0c5d3 /gpsd.c | |
parent | 75960886a963dfc8ad828ee5ac056bea46588482 (diff) | |
download | gpsd-a3766b700808d486762edc7c814ac43412c9296b.tar.gz |
Refactoring step, no logic changes. All regression tests pass.
Diffstat (limited to 'gpsd.c')
-rw-r--r-- | gpsd.c | 71 |
1 files changed, 34 insertions, 37 deletions
@@ -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) { |