"Initial commit to Gerrit"
[profile/ivi/gpsd.git] / gpsd_dbus.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 #include <sys/types.h>
6 #include <stdio.h>
7 #include "gpsd_config.h"
8 #ifdef DBUS_ENABLE
9 #include <gpsd_dbus.h>
10
11 static DBusConnection *connection = NULL;
12
13 /*
14  * Does what is required to initialize the dbus connection
15  * This is pretty basic at this point, as we don't receive commands via dbus.
16  * Returns 0 when everything is OK.
17  */
18 int initialize_dbus_connection(void)
19 {
20     DBusError error;
21
22     dbus_error_init(&error);
23     connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
24     if (connection == NULL) {
25         /* report error */
26         return 1;
27     }
28     return 0;
29 }
30
31 void send_dbus_fix(struct gps_device_t *channel)
32 {
33 /* sends the current fix data for this channel via dbus */
34     struct gps_data_t *gpsdata;
35     struct gps_fix_t *gpsfix;
36     DBusMessage *message;
37     /*DBusMessageIter   iter; */
38     dbus_uint32_t serial;       /* collected, but not used */
39     char *gpsd_devname;
40     /* this packet format was designed before we split eph */
41     double eph;
42
43     /* if the connection is non existent, return without doing anything */
44     if (connection == NULL)
45         return;
46
47     gpsdata = &(channel->gpsdata);
48     gpsfix = &(gpsdata->fix);
49     /* this packet format was designed before we split eph */
50     eph = EMIX(gpsfix->epx, gpsfix->epy);
51     gpsd_devname = gpsdata->dev.path;
52
53     /* Send the named signel.  */
54     message = dbus_message_new_signal("/org/gpsd", "org.gpsd", "fix");
55     dbus_message_append_args(message,
56                              DBUS_TYPE_DOUBLE, &(gpsfix->time),
57                              DBUS_TYPE_INT32, &(gpsfix->mode),
58                              DBUS_TYPE_DOUBLE, &(gpsfix->ept),
59                              DBUS_TYPE_DOUBLE, &(gpsfix->latitude),
60                              DBUS_TYPE_DOUBLE, &(gpsfix->longitude),
61                              DBUS_TYPE_DOUBLE, &(eph),
62                              DBUS_TYPE_DOUBLE, &(gpsfix->altitude),
63                              DBUS_TYPE_DOUBLE, &(gpsfix->epv),
64                              DBUS_TYPE_DOUBLE, &(gpsfix->track),
65                              DBUS_TYPE_DOUBLE, &(gpsfix->epd),
66                              DBUS_TYPE_DOUBLE, &(gpsfix->speed),
67                              DBUS_TYPE_DOUBLE, &(gpsfix->eps),
68                              DBUS_TYPE_DOUBLE, &(gpsfix->climb),
69                              DBUS_TYPE_DOUBLE, &(gpsfix->epc),
70                              DBUS_TYPE_STRING, &gpsd_devname,
71                              DBUS_TYPE_INVALID);
72     dbus_message_set_no_reply(message, TRUE);
73     dbus_connection_send(connection, message, &serial);
74     dbus_message_unref(message);
75 }
76
77 #endif /* DBUS_ENABLE */