diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-02-12 09:13:29 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-02-12 09:13:29 +0000 |
commit | 5a3c9eaa4ab85f644aa2b5aa3a796d490f76855c (patch) | |
tree | 5bfb3376d90c6ea0719ee2012499d242fe74921b | |
parent | f55d2ae23805486b3957437693e09173544a32ea (diff) | |
download | gpsd-5a3c9eaa4ab85f644aa2b5aa3a796d490f76855c.tar.gz |
All driver method tables are now const.
This required moving one field, the modifiable cycle time, into the
session structure; the driver type field is now the default value set
on switching to that driver, if the field has not already been set
during a previous activation.
-rw-r--r-- | driver_proto.c | 2 | ||||
-rw-r--r-- | drivers.c | 46 | ||||
-rw-r--r-- | evermore.c | 2 | ||||
-rw-r--r-- | garmin.c | 6 | ||||
-rw-r--r-- | gpsctl.c | 6 | ||||
-rw-r--r-- | gpsd.c | 10 | ||||
-rw-r--r-- | gpsd.h-tail | 5 | ||||
-rw-r--r-- | italk.c | 2 | ||||
-rw-r--r-- | libgpsd_core.c | 6 | ||||
-rw-r--r-- | navcom.c | 2 | ||||
-rw-r--r-- | serial.c | 2 | ||||
-rw-r--r-- | sirf.c | 2 | ||||
-rw-r--r-- | superstar2.c | 2 | ||||
-rw-r--r-- | tsip.c | 2 | ||||
-rw-r--r-- | ubx.c | 2 | ||||
-rw-r--r-- | zodiac.c | 4 |
16 files changed, 52 insertions, 49 deletions
diff --git a/driver_proto.c b/driver_proto.c index f83639ea..20cdbbb8 100644 --- a/driver_proto.c +++ b/driver_proto.c @@ -369,7 +369,7 @@ static void _proto__wrapup(struct gps_device_t *session) /* any driver must use to compile. */ /* This is everything we export */ -struct gps_type_t _proto__binary = { +const struct gps_type_t _proto__binary = { /* Full name of type */ .type_name = "_proto_ binary", /* associated lexer packet type */ @@ -14,8 +14,8 @@ #include "gpsd.h" #include "bits.h" /* for getbeuw(), to extract big-endiamn words */ -extern struct gps_type_t zodiac_binary; -extern struct gps_type_t ubx_binary; +extern const struct gps_type_t zodiac_binary; +extern const struct gps_type_t ubx_binary; ssize_t generic_get(struct gps_device_t *session) { @@ -105,7 +105,7 @@ gps_mask_t nmea_parse_input(struct gps_device_t *session) if ((st=nmea_parse((char *)session->packet.outbuffer, session))==0) { #ifdef NON_NMEA_ENABLE - struct gps_type_t **dp; + const struct gps_type_t **dp; /* maybe this is a trigger string for a driver we know about? */ #ifdef UBX_ENABLE @@ -239,7 +239,7 @@ static void nmea_probe_subtype(struct gps_device_t *session, unsigned int seq) } } -static struct gps_type_t nmea = { +static const struct gps_type_t nmea = { .type_name = "Generic NMEA", /* full name of type */ .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = NULL, /* it's the default */ @@ -329,7 +329,7 @@ static void garmin_nmea_configurator(struct gps_device_t *session, unsigned int } #endif /* ALLOW_RECONFIGURE */ -static struct gps_type_t garmin = { +static const struct gps_type_t garmin = { .type_name = "Garmin Serial", /* full name of type */ .packet_type = GARMIN_PACKET, /* associated lexer packet type */ .trigger = "$PGRMC,", /* Garmin private */ @@ -392,7 +392,7 @@ static void ashtech_ping(struct gps_device_t *session) (void)nmea_send(session, "$PASHQ,RID"); } -static struct gps_type_t ashtech = { +static const struct gps_type_t ashtech = { .type_name = "Ashtech", /* full name of type */ .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = "$PASHR,RID,", /* Ashtech receivers respond thus */ @@ -439,7 +439,7 @@ static void fv18_configure(struct gps_device_t *session, unsigned int seq) } #endif /* ALLOW_RECONFIGURE */ -static struct gps_type_t fv18 = { +static const struct gps_type_t fv18 = { .type_name = "San Jose Navigation FV18", /* full name of type */ .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = "$PFEC,GPint,", /* FV18s should echo the probe */ @@ -489,7 +489,7 @@ static void gpsclock_probe_subtype(struct gps_device_t *session, unsigned int se } } -static struct gps_type_t gpsclock = { +static const struct gps_type_t gpsclock = { .type_name = "Furuno Electric GH-79L4", /* full name of type */ .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = "$PFEC,GPssd", /* GPSclock should return this */ @@ -547,7 +547,7 @@ static void tripmate_configurator(struct gps_device_t *session, unsigned int seq } #endif /* ALLOW_RECONFIGURE */ -static struct gps_type_t tripmate = { +static const struct gps_type_t tripmate = { .type_name = "Delorme TripMate", /* full name of type */ .packet_type = NMEA_PACKET, /* lexer packet type */ .trigger ="ASTRAL", /* tells us to switch */ @@ -590,12 +590,12 @@ static void earthmate_probe_subtype(struct gps_device_t *session, unsigned int s if (seq == 0) { (void)gpsd_write(session, "EARTHA\r\n", 8); (void)usleep(10000); - gpsd_switch_driver(session, "Zodiac Binary"); + (void)gpsd_switch_driver(session, "Zodiac Binary"); } } /*@ -redef @*/ -static struct gps_type_t earthmate = { +static const struct gps_type_t earthmate = { .type_name = "Delorme EarthMate (pre-2003, Zodiac chipset)", .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = "EARTHA", /* Earthmate trigger string */ @@ -770,7 +770,7 @@ static bool tnt_probe(struct gps_device_t *session) return false; } -static struct gps_type_t trueNorth = { +static const struct gps_type_t trueNorth = { .type_name = "True North", /* full name of type */ .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = " TNT1500", @@ -844,7 +844,7 @@ static void oceanserver_configure(struct gps_device_t *session, unsigned int seq } #endif /* ALLOW_RECONFIGURE */ -static struct gps_type_t oceanServer = { +static const struct gps_type_t oceanServer = { .type_name = "OceanServer Digital Compass OS5000", /* full name of type */ .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = "$C,", @@ -888,7 +888,7 @@ static gps_mask_t rtcm104v2_analyze(struct gps_device_t *session) return RTCM2_SET; } -static struct gps_type_t rtcm104v2 = { +static const struct gps_type_t rtcm104v2 = { .type_name = "RTCM104V2", /* full name of type */ .packet_type = RTCM2_PACKET, /* associated lexer packet type */ .trigger = NULL, /* no recognition string */ @@ -932,7 +932,7 @@ static gps_mask_t rtcm104v3_analyze(struct gps_device_t *session) return RTCM3_SET; } -static struct gps_type_t rtcm104v3 = { +static const struct gps_type_t rtcm104v3 = { .type_name = "RTCM104V3", /* full name of type */ .packet_type = RTCM3_PACKET, /* associated lexer packet type */ .trigger = NULL, /* no recognition string */ @@ -973,7 +973,7 @@ static gps_mask_t garmintxt_parse_input(struct gps_device_t *session) } -static struct gps_type_t garmintxt = { +static const struct gps_type_t garmintxt = { .type_name = "Garmin Simple Text", /* full name of type */ .packet_type = RTCM2_PACKET; /* associated lexer packet type */ .trigger = NULL, /* no recognition string */ @@ -1068,7 +1068,7 @@ static void mkt3301_configure(struct gps_device_t *session, unsigned int seq) } #endif /* ALLOW_RECONFIGURE */ -static struct gps_type_t mkt3301 = { +static const struct gps_type_t mkt3301 = { .type_name = "MKT-3301", /* full name of type */ .packet_type = NMEA_PACKET, /* associated lexer packet type */ .trigger = "$PMTK705,", /* MKT-3301s send firmware release name and version */ @@ -1095,14 +1095,14 @@ static struct gps_type_t mkt3301 = { }; #endif /* MKT3301_ENABLE */ -extern struct gps_type_t garmin_usb_binary, garmin_ser_binary; -extern struct gps_type_t sirf_binary, tsip_binary; -extern struct gps_type_t evermore_binary, italk_binary; -extern struct gps_type_t navcom_binary, superstar2_binary; +extern const struct gps_type_t garmin_usb_binary, garmin_ser_binary; +extern const struct gps_type_t sirf_binary, tsip_binary; +extern const struct gps_type_t evermore_binary, italk_binary; +extern const struct gps_type_t navcom_binary, superstar2_binary; /*@ -nullassign @*/ /* the point of this rigamarole is to not have to export a table size */ -static struct gps_type_t *gpsd_driver_array[] = { +static const struct gps_type_t *gpsd_driver_array[] = { #ifdef NMEA_ENABLE &nmea, #ifdef ASHTECH_ENABLE @@ -1176,4 +1176,4 @@ static struct gps_type_t *gpsd_driver_array[] = { NULL, }; /*@ +nullassign @*/ -struct gps_type_t **gpsd_drivers = &gpsd_driver_array[0]; +const struct gps_type_t **gpsd_drivers = &gpsd_driver_array[0]; @@ -488,7 +488,7 @@ static void evermore_wrap(struct gps_device_t *session) /* this is everything we export */ -struct gps_type_t evermore_binary = +const struct gps_type_t evermore_binary = { .type_name = "EverMore binary", /* full name of type */ .packet_type = NMEA_PACKET, /* lexer packet type */ @@ -1156,7 +1156,7 @@ static ssize_t garmin_get_packet(struct gps_device_t *session) return (ssize_t)( 0 == GetPacket( session ) ? 1 : 0); } -struct gps_type_t garmin_usb_binary_old = +const struct gps_type_t garmin_usb_binary_old = { .type_name = "Garmin USB binary", /* full name of type */ .packet_type = GARMIN_PACKET; /* associated lexer packet type */ @@ -1184,7 +1184,7 @@ struct gps_type_t garmin_usb_binary_old = }; #endif /* __UNUSED__ */ -struct gps_type_t garmin_usb_binary = +const struct gps_type_t garmin_usb_binary = { .type_name = "Garmin USB binary", /* full name of type */ .packet_type = GARMIN_PACKET, /* associated lexer packet type */ @@ -1211,7 +1211,7 @@ struct gps_type_t garmin_usb_binary = .cycle = 1, /* updates every second */ }; -struct gps_type_t garmin_ser_binary = +const struct gps_type_t garmin_ser_binary = { .type_name = "Garmin Serial binary", /* full name of type */ .packet_type = GARMIN_PACKET, /* associated lexer packet type */ @@ -78,8 +78,8 @@ int main(int argc, char **argv) bool to_binary = false, to_nmea = false, reset = false; bool lowlevel=false, echo=false; struct gps_data_t *gpsdata = NULL; - struct gps_type_t *forcetype = NULL; - struct gps_type_t **dp; + const struct gps_type_t *forcetype = NULL; + const struct gps_type_t **dp; char cooked[BUFSIZ]; ssize_t cooklen = 0; unsigned int timeout = 4; @@ -458,7 +458,7 @@ int main(int argc, char **argv) * length. This means they don't fit well in the model * assumed by the driver interface. */ - extern struct gps_type_t ubx_binary; + extern const struct gps_type_t ubx_binary; /*@ -usedef @*/ if (session.device_type == &ubx_binary) { if (!ubx_write(session.gpsdata.gps_fd, @@ -211,7 +211,7 @@ void gpsd_report(int errlevel, const char *fmt, ... ) static void usage(void) { - struct gps_type_t **dp; + const struct gps_type_t **dp; (void)printf("usage: gpsd [-b] [-n] [-N] [-D n] [-F sockfile] [-P pidfile] [-S port] [-h] device...\n\ Options include: \n\ @@ -762,21 +762,21 @@ static int handle_gpsd_request(struct subscriber_t* sub, char *buf, int buflen) if (!assign_channel(sub) || sub->device->device_type==NULL) (void)strlcpy(phrase, ",C=?", BUFSIZ); else { - struct gps_type_t *dev = sub->device->device_type; + const struct gps_type_t *dev = sub->device->device_type; double mincycle = (dev->cycle_chars * 10.0) / sub->device->gpsdata.baudrate; if (*p == '=' && privileged_user(sub)) { double cycle = strtod(++p, &p); if (cycle >= mincycle) if (dev->rate_switcher != NULL) if (dev->rate_switcher(sub->device, cycle)) - dev->cycle = cycle; + sub->device->cycle = cycle; } if (dev->rate_switcher == NULL) (void)snprintf(phrase, sizeof(phrase), - ",C=%.2f", dev->cycle); + ",C=%.2f", sub->device->cycle); else (void)snprintf(phrase, sizeof(phrase), - ",C=%.2f %.2f", dev->cycle, mincycle); + ",C=%.2f %.2f", sub->device->cycle, mincycle); } break; case 'D': diff --git a/gpsd.h-tail b/gpsd.h-tail index 923f9b10..96fc5670 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -210,7 +210,7 @@ struct gps_type_t { struct gps_device_t { /* session object, encapsulates all global state */ struct gps_data_t gpsdata; - /*@relnull@*/struct gps_type_t *device_type; + /*@relnull@*/const struct gps_type_t *device_type; struct gps_context_t *context; #ifdef ALLOW_RECONFIGURE bool enable_reconfigure; /* OK to hack GPS settings? */ @@ -219,6 +219,7 @@ struct gps_device_t { struct termios ttyset, ttyset_old; unsigned int baudindex; int saved_baud; + double cycle; struct gps_packet_t packet; char subtype[64]; /* firmware version or subtype ID */ double poll_times[FD_SETSIZE]; /* last daemon poll time */ @@ -353,7 +354,7 @@ struct gps_device_t { #define IS_HIGHEST_BIT(v,m) (v & ~((m<<1)-1))==0 /* here are the available GPS drivers */ -extern struct gps_type_t **gpsd_drivers; +extern const struct gps_type_t **gpsd_drivers; /* gpsd library internal prototypes */ extern gps_mask_t nmea_parse_input(struct gps_device_t *); @@ -343,7 +343,7 @@ static void italk_ping(struct gps_device_t *session) #endif /* __not_yet__ */ /* this is everything we export */ -struct gps_type_t italk_binary = +const struct gps_type_t italk_binary = { .type_name = "iTalk binary", /* full name of type */ .packet_type = ITALK_PACKET, /* associated lexer packet type */ diff --git a/libgpsd_core.c b/libgpsd_core.c index 6c485784..8b4e144c 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -27,7 +27,7 @@ int gpsd_switch_driver(struct gps_device_t *session, char* type_name) { - struct gps_type_t **dp; + const struct gps_type_t **dp; gpsd_report(LOG_PROG, "switch_driver(%s) called...\n", type_name); if (session->device_type != NULL && @@ -47,6 +47,8 @@ int gpsd_switch_driver(struct gps_device_t *session, char* type_name) gpsd_report(LOG_PROG, "selecting %s driver...\n", (*dp)->type_name); gpsd_assert_sync(session); /*@i@*/session->device_type = *dp; + if (session->cycle <= 0) + session->cycle = (*dp)->cycle; if (!session->context->readonly && session->device_type->probe_subtype != NULL) session->device_type->probe_subtype(session, session->packet.counter = 0); #ifdef ALLOW_RECONFIGURE @@ -247,7 +249,7 @@ int gpsd_activate(struct gps_device_t *session, bool reconfigurable) return -1; else { #ifdef NON_NMEA_ENABLE - struct gps_type_t **dp; + const struct gps_type_t **dp; /*@ -mustfreeonly @*/ for (dp = gpsd_drivers; *dp; dp++) { @@ -1238,7 +1238,7 @@ static gps_mask_t navcom_parse_input(struct gps_device_t *session) /* this is everything we export */ -struct gps_type_t navcom_binary = +const struct gps_type_t navcom_binary = { .type_name = "Navcom binary", /* full name of type */ .packet_type = NAVCOM_PACKET, /* lexer packet type */ @@ -193,7 +193,7 @@ void gpsd_set_speed(struct gps_device_t *session, * in hopes it will respond. */ if (isatty(session->gpsdata.gps_fd)!=0 && !session->context->readonly) { - struct gps_type_t **dp; + const struct gps_type_t **dp; if (session->device_type == NULL) { for (dp = gpsd_drivers; *dp; dp++) if ((*dp)->probe_wakeup != NULL) @@ -988,7 +988,7 @@ static bool sirfbin_speed(struct gps_device_t *session, speed_t speed) } /* this is everything we export */ -struct gps_type_t sirf_binary = +const struct gps_type_t sirf_binary = { .type_name = "SiRF binary", /* full name of type */ .packet_type = SIRF_PACKET, /* associated lexer packet type */ diff --git a/superstar2.c b/superstar2.c index ec48844e..5a8284e8 100644 --- a/superstar2.c +++ b/superstar2.c @@ -480,7 +480,7 @@ static void superstar2_set_mode(struct gps_device_t *session, int mode) } } -struct gps_type_t superstar2_binary = { +const struct gps_type_t superstar2_binary = { /* Full name of type */ .type_name = "SuperStarII binary", /* associated lexer packet type */ @@ -822,7 +822,7 @@ static gps_mask_t tsip_parse_input(struct gps_device_t *session) } /* this is everything we export */ -struct gps_type_t tsip_binary = +const struct gps_type_t tsip_binary = { .type_name = "Trimble TSIP", /* full name of type */ .packet_type = TSIP_PACKET, /* associated lexer packet type */ @@ -632,7 +632,7 @@ static bool ubx_speed(struct gps_device_t *session, speed_t speed) } /* This is everything we export */ -struct gps_type_t ubx_binary = { +const struct gps_type_t ubx_binary = { .type_name = "uBlox UBX binary", /* Full name of type */ .packet_type = UBX_PACKET, /* associated lexer packet type */ .trigger = NULL, /* Response string that identifies device (not active) */ @@ -382,7 +382,7 @@ static gps_mask_t zodiac_analyze(struct gps_device_t *session) unsigned int id = (unsigned int)((session->packet.outbuffer[3]<<8) | session->packet.outbuffer[2]); if (session->packet.type != ZODIAC_PACKET) { - struct gps_type_t **dp; + const struct gps_type_t **dp; gpsd_report(LOG_PROG, "zodiac_analyze packet type %d\n",session->packet.type); // Wrong packet type ? // Maybe find a trigger just in case it's an Earthmate @@ -437,7 +437,7 @@ static gps_mask_t zodiac_analyze(struct gps_device_t *session) /* caller needs to specify a wrapup function */ /* this is everything we export */ -struct gps_type_t zodiac_binary = +const struct gps_type_t zodiac_binary = { .type_name = "Zodiac binary", /* full name of type */ .packet_type = ZODIAC_PACKET, /* associated lexer packet type */ |