# libgps_core.c

Functions:- | The client interface library for the gpsd daemon.
Notes based on code of Mon Apr 5 21:38:06 2010 -0400
`struct gps_data_t *gps_open(const char *host, const char *port)` | Open a connection to a gps daemon. Try to get a `gps_data_t` structure. If it fails, return a NULL. Test for a specified host and/or port number, using defaults if nothing is specified in the command line invocation. Try to connect to the now defined socket; on error, release the resources and return NULL. On success, initialise an internal struct gps_data_t and return the pointer to it.
`struct gps_data_t *gps_open_r(const char *host, const char *port, struct gps_data_t *gpsdata)` | Variant of `gps_open()` for when re-entrancy is required. Initializes storage passed by the caller.
`int gps_close(struct gps_data_t *gpsdata)` | Close the fd associated with the `gps_data_t` structure and stash the result. If there is a device id stored, NULL it and the associated path. If the device list has any data in it, free this and mark the number of available devices as invalid. Free the `gps_data_t` structure itself and return the stashed `close()` result.
`static void gps_unpack(char *buf, struct gps_data_t *gpsdata)` | Keep looping through the data in `buf` for JSON objects. Each time one is found, analyze it and unpack it into the struct pointed at by gpsdata, setting the gpsdata->set mask appropriately to indicate which data is valid This function is intended for GPSD internal use only and should not be considered a stable part oof the API.
`int gps_poll(struct gps_data_t *gpsdata)` | Poll the daemon and if there is no data or an error, return -1. If there is something to read, clear the buffer, note the time as the received data time and the online time, then unpack the data. If profiling is active, use the received data time, the fix time and the present time to calculate the decode time and the client receipt time.
`int gps_send(struct gps_data_t *gpsdata, const char *fmt, ... )` | Gather up the instructions to a gpsd instance for information to return and write them to the device. If the write fails, return -1. This entry point is deprecated in favor of `gps_stream()`
`bool gps_waiting(struct gps_data_t *gpsdata)` | Return a boolean indicating whether input data is waiting on the daemon socket. Does not block.
`int gps_stream(struct gps_data_t *gpsdata, unsigned int, void *d)` | Set watch and policy flags. This evaluates the flag mask passed as the second argument, composes a corresponding command in the GPSD write protocol, and ships it to the daemon.
| The following three functions are guarded by an `#ifdef` so they only compile if it is required to be able to test the library and set up a command line exerciser interface.
`static void data_dump(struct gps_data_t *collect, time_t now)` | A data dumper used when debugging. It outputs data according to the command line input data.
`static void dumpline(struct gps_data_t *ud UNUSED, char *buf, size_t ulen UNUSED, int level UNUSED)` | A simple call to UNIX `puts()`.
`int main(int argc, char *argv[])` | A simple command line parser and endless loop to exercise the daemon when debugging.