struct sockaddr_rc _rcvr_addr = { 0 };
+static gint fd;
+
static gboolean
channel_cb_connect(GIOChannel * src, GIOCondition condition, gpointer data)
{
gint error, size = sizeof(error);
-if (*_rcvr_mac != '/' && (getsockopt(_fd, SOL_SOCKET, SO_ERROR, &error, &size) || error)) {
+if (*_rcvr_mac != '/' && (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &size) || error)) {
g_printf("Error connecting to receiver; retrying...\n");
/* Try again. */
rcvr_disconnect();
rcvr_connect_later();
} else {
g_printf("Connected to receiver!\n");
- set_conn_state(RCVR_UP);
- _input_sid = g_io_add_watch_full(_channel, G_PRIORITY_LOW,
- G_IO_IN | G_IO_PRI,
- channel_cb_input, NULL, NULL);
+ gps_conn_set_state(RCVR_UP);
+ _input_sid = g_io_add_watch_full(_channel, G_PRIORITY_LOW, G_IO_IN | G_IO_PRI, channel_cb_input, NULL, NULL);
}
_connect_sid = 0;
rcvr_connect_bt(void)
{
int r, e;
-r = connect(_fd, (struct sockaddr *)&_rcvr_addr, sizeof(_rcvr_addr));
+r = connect(fd, (struct sockaddr *)&_rcvr_addr, sizeof(_rcvr_addr));
e = errno;
/* The socket is non blocking so handle it */
gint
scan_start_search(ScanInfo * scan_info)
{
-scan_info->sid = g_idle_add((GSourceFunc) scan_bluetooth_idle, scan_info);
+scan_info->sid = g_idle_add((GSourceFunc)scan_bluetooth_idle, scan_info);
return 0;
}
}
/* Close the file descriptor. */
-if (_fd != -1) {
- close(_fd);
- _fd = -1;
+if (fd != -1) {
+ close(fd);
+ fd = -1;
}
}
/**
* Connect to the receiver.
- * This method assumes that _fd is -1 and _channel is NULL. If unsure, call
+ * This method assumes that fd is -1 and _channel is NULL. If unsure, call
* rcvr_disconnect() first.
* Since this is an idle function, this function returns whether or not it
* should be called again, which is always FALSE.
#ifndef DEBUG_GPS
/* Create the file descriptor. */
if (*_rcvr_mac == '/')
- _fd = open(_rcvr_mac, O_RDONLY);
+ fd = open(_rcvr_mac, O_RDONLY);
else
- _fd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
+ fd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
/* If file descriptor creation failed, try again later. Note that
* there is no need to call rcvr_disconnect() because the file
* descriptor creation is the first step, so if it fails, there's
* nothing to clean up. */
- if (_fd == -1) {
+ if (fd == -1) {
g_printf("Failed to create socket\n");
rcvr_connect_later();
} else {
_gps_read_buf_last = _gps_read_buf + GPS_READ_BUF_SIZE - 1;
/* Create channel and add watches. */
- _channel = g_io_channel_unix_new(_fd);
+ _channel = g_io_channel_unix_new(fd);
g_io_channel_set_encoding(_channel, NULL, NULL);
g_io_channel_set_flags(_channel, G_IO_FLAG_NONBLOCK, NULL);
_error_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE,
}
#else
/* We're in DEBUG mode, so instead of connecting, skip to FIXED. */
- set_conn_state(RCVR_FIXED);
+ gps_conn_set_state(RCVR_FIXED);
#endif
}
devid = hci_get_route(NULL);
-ii = (inquiry_info *) malloc(255 * sizeof(inquiry_info));
+ii = (inquiry_info *)malloc(255 * sizeof(inquiry_info));
num_rsp = hci_inquiry(devid, 4, 255, NULL, &ii, IREQ_CACHE_FLUSH);
if (num_rsp < 0) {
ba2str(&ii[i].bdaddr, addr);
memset(name, 0, sizeof(name));
- if (hci_read_remote_name
- (sock, &ii[i].bdaddr, sizeof(name), name, 0))
+ if (hci_read_remote_name(sock, &ii[i].bdaddr, sizeof(name), name, 0))
strcpy(name, _("Unknown"));
gtk_list_store_append(scan_info->store, &iter);
#include "settings.h"
#include "ui-common.h"
+static guint errors;
+static gint fd;
+
+void rcvr_connect_later(); /* Forward declaration. */
+
/*****************************************************************************/
static gboolean
{
_gps_read_buf_curr = _gps_read_buf;
_gps_read_buf_last = _gps_read_buf + GPS_READ_BUF_SIZE - 1;
-set_conn_state(RCVR_UP);
+gps_conn_set_state(RCVR_UP);
_input_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, G_IO_IN | G_IO_PRI, channel_cb_input, NULL, NULL);
_connect_sid = 0;
+errors=0;
return FALSE;
}
}
/* Close the file descriptor. */
-if (_fd != -1) {
- close(_fd);
- _fd = -1;
+if (fd != -1) {
+ close(fd);
+ fd = -1;
}
if (_rfcomm_req_proxy) {
dbus_g_proxy_call(_rfcomm_req_proxy,
- BTCOND_RFCOMM_CANCEL_CONNECT_REQ, &error,
- G_TYPE_STRING, _rcvr_mac, G_TYPE_STRING,
- "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
+ BTCOND_RFCOMM_CANCEL_CONNECT_REQ, &error,
+ G_TYPE_STRING, _rcvr_mac, G_TYPE_STRING,
+ "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
error = NULL;
dbus_g_proxy_call(_rfcomm_req_proxy,
- BTCOND_RFCOMM_DISCONNECT_REQ, &error,
- G_TYPE_STRING, _rcvr_mac, G_TYPE_STRING,
- "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
+ BTCOND_RFCOMM_DISCONNECT_REQ, &error,
+ G_TYPE_STRING, _rcvr_mac, G_TYPE_STRING,
+ "SPP", G_TYPE_INVALID, G_TYPE_INVALID);
}
}
-void rcvr_connect_later(); /* Forward declaration. */
-
void
-rcvr_connect_fd(gchar * fdpath)
+rcvr_connect_fd(gchar *fdpath)
{
/* If file descriptor creation failed, try again later. */
-if (-1 == (_fd = open(fdpath, O_RDONLY))) {
+if (-1 == (fd = open(fdpath, O_RDONLY))) {
rcvr_disconnect();
rcvr_connect_later();
} else {
*_gps_read_buf_curr = '\0';
/* Create channel and add watches. */
- _channel = g_io_channel_unix_new(_fd);
+ _channel = g_io_channel_unix_new(fd);
g_io_channel_set_flags(_channel, G_IO_FLAG_NONBLOCK, NULL);
- _error_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE,
- G_IO_ERR | G_IO_HUP, channel_cb_error, NULL, NULL);
- _connect_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE,
- G_IO_OUT, channel_cb_connect, NULL, NULL);
- }
+ _error_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, G_IO_ERR | G_IO_HUP, channel_cb_error, NULL, NULL);
+ _connect_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, G_IO_OUT, channel_cb_connect, NULL, NULL);
+}
g_free(fdpath);
}
-void rcvr_connect_response(DBusGProxy * proxy, DBusGProxyCall * call_id)
+void
+rcvr_connect_response(DBusGProxy * proxy, DBusGProxyCall * call_id)
{
GError *error = NULL;
gchar *fdpath = NULL;
if (_conn_state == RCVR_DOWN && _rcvr_mac) {
- if (!dbus_g_proxy_end_call(_rfcomm_req_proxy, call_id, &error,
- G_TYPE_STRING, &fdpath, G_TYPE_INVALID)) {
+ if (!dbus_g_proxy_end_call(_rfcomm_req_proxy, call_id, &error, G_TYPE_STRING, &fdpath, G_TYPE_INVALID)) {
if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
/* If we're already connected, it's not an error, unless
* they don't give us the file descriptor path, in which
rcvr_disconnect();
/* Ask user to re-connect. */
- confirm = hildon_note_new_confirmation(GTK_WINDOW(_window),
- _("Failed to connect to GPS receiver. Retry?"));
+ confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), _("Failed to connect to GPS receiver. Retry?"));
if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm)))
rcvr_connect_later(); /* Try again later. */
else
- set_conn_state(RCVR_OFF);
+ gps_conn_set_state(RCVR_OFF);
gtk_widget_destroy(confirm);
return;
/**
* Connect to the receiver.
- * This method assumes that _fd is -1 and _channel is NULL. If unsure, call
+ * This method assumes that fd is -1 and _channel is NULL. If unsure, call
* rcvr_disconnect() first.
* Since this is an idle function, this function returns whether or not it
* should be called again, which is always FALSE.
*/
-gboolean rcvr_connect_now()
+gboolean
+rcvr_connect_now()
{
if (_conn_state == RCVR_DOWN && _rcvr_mac) {
-#ifndef DEBUG
+#ifndef DEBUG_GPS
if (*_rcvr_mac != '/') {
if (_rfcomm_req_proxy) {
gint mybool = TRUE;
G_TYPE_BOOLEAN, &mybool,
G_TYPE_INVALID);
}
- } else
+ } else {
rcvr_connect_fd(g_strdup(_rcvr_mac));
-
+ }
#else
/* We're in DEBUG mode, so instead of connecting, skip to FIXED. */
printf("FIXED!\n");
- set_conn_state(RCVR_FIXED);
+ gps_conn_set_state(RCVR_FIXED);
#endif
}
void
rcvr_connect_later()
{
-_clater_sid = g_timeout_add(1000, (GSourceFunc) rcvr_connect_now, NULL);
+_clater_sid = g_timeout_add(1000, (GSourceFunc)rcvr_connect_now, NULL);
}
+/**
+ * Bluetooth device scanning functions below
+ */
static void
-scan_cb_dev_found(DBusGProxy * sig_proxy, const gchar * bda,
- const gchar * name, gpointer * class, guchar rssi, gint coff,
- ScanInfo * scan_info)
+scan_cb_dev_found(DBusGProxy *sig_proxy, const gchar *bda, const gchar *name, gpointer *class, guchar rssi, gint coff, ScanInfo *scan_info)
{
GtkTreeIter iter;
gtk_list_store_append(scan_info->store, &iter);
scan_cb_search_complete(DBusGProxy * sig_proxy, ScanInfo * scan_info)
{
gtk_widget_destroy(scan_info->banner);
-dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_DEV_FOUND_SIG,
- G_CALLBACK(scan_cb_dev_found), scan_info);
-dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG,
- G_CALLBACK(scan_cb_search_complete), scan_info);
+dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_CALLBACK(scan_cb_dev_found), scan_info);
+dbus_g_proxy_disconnect_signal(sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_CALLBACK(scan_cb_search_complete), scan_info);
}
gint
scan_start_search(ScanInfo * scan_info)
{
GError *error = NULL;
-DBusGConnection *dbus_conn;
- /* Initialize D-Bus. */
- if (NULL == (dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error))) {
- g_printerr("Failed to open connection to D-Bus: %s.\n",
- error->message);
- return 1;
- }
+if (NULL == (scan_info->req_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTSEARCH_SERVICE, BTSEARCH_REQ_PATH, BTSEARCH_REQ_INTERFACE))) {
+ g_printerr("Failed to create D-Bus request proxy for btsearch.");
+ return 2;
+}
- if (NULL == (scan_info->req_proxy = dbus_g_proxy_new_for_name(dbus_conn,
- BTSEARCH_SERVICE,
- BTSEARCH_REQ_PATH,
- BTSEARCH_REQ_INTERFACE)))
- {
- g_printerr
- ("Failed to create D-Bus request proxy for btsearch.");
- return 2;
- }
+if (NULL == (scan_info->sig_proxy = dbus_g_proxy_new_for_name(dbus_conn, BTSEARCH_SERVICE, BTSEARCH_SIG_PATH, BTSEARCH_SIG_INTERFACE))) {
+ g_printerr("Failed to create D-Bus signal proxy for btsearch.");
+ return 2;
+}
- if (NULL == (scan_info->sig_proxy = dbus_g_proxy_new_for_name(dbus_conn,
- BTSEARCH_SERVICE,
- BTSEARCH_SIG_PATH,
- BTSEARCH_SIG_INTERFACE)))
- {
- g_printerr("Failed to create D-Bus signal proxy for btsearch.");
- return 2;
- }
+dbus_g_object_register_marshaller(_bt_maemo_VOID__STRING_STRING_POINTER_UCHAR_UINT,
+ G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UCHAR, G_TYPE_UINT, G_TYPE_INVALID);
- dbus_g_object_register_marshaller(_bt_maemo_VOID__STRING_STRING_POINTER_UCHAR_UINT,
- G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, DBUS_TYPE_G_UCHAR_ARRAY,
- G_TYPE_UCHAR, G_TYPE_UINT, G_TYPE_INVALID);
-
- dbus_g_proxy_add_signal(scan_info->sig_proxy,
- BTSEARCH_DEV_FOUND_SIG,
- G_TYPE_STRING,
- G_TYPE_STRING,
- DBUS_TYPE_G_UCHAR_ARRAY,
- G_TYPE_UCHAR, G_TYPE_UINT, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(scan_info->sig_proxy, BTSEARCH_DEV_FOUND_SIG,
- G_CALLBACK(scan_cb_dev_found), scan_info,
- NULL);
-
- dbus_g_proxy_add_signal(scan_info->sig_proxy,
- BTSEARCH_SEARCH_COMPLETE_SIG, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(scan_info->sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG,
- G_CALLBACK(scan_cb_search_complete),
- scan_info, NULL);
+dbus_g_proxy_add_signal(scan_info->sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_TYPE_STRING, G_TYPE_STRING, DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UCHAR, G_TYPE_UINT, G_TYPE_INVALID);
+dbus_g_proxy_connect_signal(scan_info->sig_proxy, BTSEARCH_DEV_FOUND_SIG, G_CALLBACK(scan_cb_dev_found), scan_info, NULL);
- error = NULL;
- if (!dbus_g_proxy_call(scan_info->req_proxy, BTSEARCH_START_SEARCH_REQ,
- &error, G_TYPE_INVALID, G_TYPE_INVALID)) {
- if (error->domain == DBUS_GERROR
- && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
- g_printerr("Caught remote method exception %s: %s",
- dbus_g_error_get_name(error), error->message);
- } else
- g_printerr("Error: %s\n", error->message);
- return 3;
+dbus_g_proxy_add_signal(scan_info->sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_TYPE_INVALID);
+dbus_g_proxy_connect_signal(scan_info->sig_proxy, BTSEARCH_SEARCH_COMPLETE_SIG, G_CALLBACK(scan_cb_search_complete), scan_info, NULL);
+
+error = NULL;
+if (!dbus_g_proxy_call(scan_info->req_proxy, BTSEARCH_START_SEARCH_REQ, &error, G_TYPE_INVALID, G_TYPE_INVALID)) {
+ if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) {
+ g_printerr("Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
+ } else {
+ g_printerr("Error: %s\n", error->message);
}
+ return 3;
+}
return 0;
}