cleanup specfile for packaging
[profile/ivi/gpsd.git] / gpsclient.c
1 /*
2  * This file is Copyright (c) 2010 by the GPSD project
3  * BSD terms apply: see the file COPYING in the distribution root for details.
4  *
5  * Python binding for selected libgps library functions
6  */
7 #include <Python.h>
8
9 #include <stdio.h>
10 #include "gps.h"
11 #include "gpsdclient.h"
12
13 /*
14  * Client utility functions
15  */
16
17 static PyObject *
18 gpsclient_deg_to_str(PyObject *self, PyObject *args)
19 {
20     int fmt;
21     double degrees;
22
23     if (!PyArg_ParseTuple(args, "id", &fmt, &degrees))
24         return NULL;
25     return Py_BuildValue("s", deg_to_str((enum deg_str_type)fmt, degrees));
26 }
27
28 static PyObject *
29 gpsclient_gpsd_units(PyObject *self, PyObject *args)
30 {
31     if (!PyArg_ParseTuple(args, ""))
32         return NULL;
33     return Py_BuildValue("i", (int)gpsd_units());
34 }
35
36 /*
37  * Miscellanea
38  */
39
40 static PyObject *
41 gpsclient_wgs84_separation(PyObject *self, PyObject *args)
42 {
43     const double lat, lon;
44     double sep;
45
46     if (!PyArg_ParseTuple(args, "dd", &lat, &lon))
47         return NULL;
48     sep = wgs84_separation(lat, lon);
49     return Py_BuildValue("d", sep);
50 }
51
52 /* List of functions defined in the module */
53
54 static PyMethodDef gpsclient_methods[] = {
55     {"wgs84_separation",        gpsclient_wgs84_separation,     METH_VARARGS,
56      PyDoc_STR("Return WGS84 geodetic separation in meters.")},
57     {"deg_to_str",              gpsclient_deg_to_str,           METH_VARARGS,
58      PyDoc_STR("String-format a latitude/longitude.")},
59     {"gpsd_units",              gpsclient_gpsd_units,           METH_VARARGS,
60      PyDoc_STR("Deduce a set of units from locale and environment.")},
61     {NULL,              NULL}           /* sentinel */
62 };
63
64 PyDoc_STRVAR(module_doc,
65 "Python wrapper for selected libgps library routines.\n\
66 ");
67
68 PyMODINIT_FUNC
69 initclienthelpers(void)
70 {
71     PyObject *m;
72
73     m = Py_InitModule3("gps.clienthelpers", gpsclient_methods, module_doc);
74
75     PyModule_AddIntConstant(m, "deg_dd", deg_dd);
76     PyModule_AddIntConstant(m, "deg_ddmm", deg_ddmm);
77     PyModule_AddIntConstant(m, "deg_ddmmss", deg_ddmmss);
78
79     PyModule_AddIntConstant(m, "unspecified", unspecified);
80     PyModule_AddIntConstant(m, "imperial", imperial);
81     PyModule_AddIntConstant(m, "nautical", nautical);
82     PyModule_AddIntConstant(m, "metric", metric);
83 }
84