Patch for visor support in gpilotd
- From: Dave Camp <campd oit edu>
- To: gnome-pilot-list gnome org
- Subject: Patch for visor support in gpilotd
- Date: 31 Jul 2000 10:26:16 -0700
The enclosed patch adds some support to gpilotd for the USB cradle
that the handspring visor. It uses the usbdevfs to find out when the
cradle is activated.
There isn't any support for the control panel applet/configuration
druid yet. To get this patch to work you have to configure the device
by hand, and add a 'type=1' line to the [DeviceN] section of
~/.gnome/gnome-pilot.d/gpilotd/. I'll be working on the capplet stuff
soon.
This patch requires that you pass --enable-usb-visor to the configure
script.
Comments appreciated,
-dave
Index: acconfig.h
===================================================================
RCS file: /cvs/gnome/gnome-pilot/acconfig.h,v
retrieving revision 1.7
diff -u -r1.7 acconfig.h
--- acconfig.h 2000/07/01 00:58:48 1.7
+++ acconfig.h 2000/07/31 17:16:17
@@ -19,3 +19,4 @@
#undef USE_XOPEN_SOURCE
#undef GNOME_ICONDIR
#undef USING_OAF
+#undef WITH_USB_VISOR
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-pilot/configure.in,v
retrieving revision 1.95
diff -u -r1.95 configure.in
--- configure.in 2000/07/18 02:23:34 1.95
+++ configure.in 2000/07/31 17:16:18
@@ -66,6 +66,16 @@
AC_DEFINE_UNQUOTED(GNOME_PILOT_PATCHLEVEL, $GNOME_PILOT_PATCHLEVEL)
AC_DEFINE_UNQUOTED(GNOME_PILOT_VERSION, "$GNOME_PILOT_VERSION")
+AC_ARG_ENABLE([usb-visor],[ --enable-usb-visor=[no/yes] Enable support for the Handspring USB cradle.],[
+ do_usb=$enableval
+],[
+ do_usb=no
+])
+
+if test x"$do_usb" = xyes ; then
+ AC_DEFINE(WITH_USB_VISOR)
+fi
+
AM_PATH_GLIB(1.2.0,,AC_MSG_ERROR(Test for GLIB failed.),[glib gmodule])
PILOT_LINK_CHECK(0.9.3)
Index: gpilotd/gpilot-structures.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/gpilotd/gpilot-structures.c,v
retrieving revision 1.19
diff -u -r1.19 gpilot-structures.c
--- gpilotd/gpilot-structures.c 2000/05/10 03:53:03 1.19
+++ gpilotd/gpilot-structures.c 2000/07/31 17:16:21
@@ -107,6 +107,7 @@
{
gchar prefix[40];
gchar tmp[40];
+
g_return_val_if_fail (device != NULL,-1);
g_return_val_if_fail (prefix != NULL,-1);
@@ -118,29 +119,42 @@
device->name = gnome_config_get_string(tmp);
g_free (device->port);
device->port = gnome_config_get_string("device");
-
- device->fd=open(device->port,O_RDWR|O_NOCTTY|O_NONBLOCK);
- if(device->fd < 0) {
- g_warning(_("Could not open device %s (%s): reason: \"%s\"."),
- device->name,device->port,
- g_strerror(errno));
+ device->type = gnome_config_get_int ("type=0");
+ if (device->type > PILOT_DEVICE_USB_VISOR
+ || device->type < PILOT_DEVICE_SERIAL) {
+ g_warning ("Invalid device type read. Using serial.");
+ device->type = PILOT_DEVICE_SERIAL;
+ }
+
+ if (device->type == PILOT_DEVICE_SERIAL) {
+ device->fd=open(device->port,O_RDWR|O_NOCTTY|O_NONBLOCK);
+ if(device->fd < 0) {
+ g_warning(_("Could not open device %s (%s): reason: \"%s\"."),
+ device->name,device->port,
+ g_strerror(errno));
#ifdef GUI
- gpilot_gui_warning_dialog(_("GnomePilot could not open device %s (%s).\n"
- "Reason: \"%s\"."),
- device->name,device->port,
- g_strerror(errno));
+ gpilot_gui_warning_dialog(_("GnomePilot could not open device %s (%s).\n"
+ "Reason: \"%s\"."),
+ device->name,device->port,
+ g_strerror(errno));
#endif
- g_free(device->name);
- g_free(device->port);
- close(device->fd);
- device->name=NULL;
- device->port=NULL;
- device->fd = 0;
- gnome_config_pop_prefix ();
- return -1;
+ g_free(device->name);
+ g_free(device->port);
+ close(device->fd);
+ device->name=NULL;
+ device->port=NULL;
+ device->fd = 0;
+ gnome_config_pop_prefix ();
+ return -1;
+ }
+ device->io = g_io_channel_unix_new(device->fd);
+ g_io_channel_ref(device->io);
+ } else {
+ device->fd = -1;
+ device->io = NULL;
+ device->device_exists = FALSE;
}
- device->io = g_io_channel_unix_new(device->fd);
- g_io_channel_ref(device->io);
+
device->speed = (guint)gnome_config_get_int("speed=57600");
gnome_config_pop_prefix ();
return 0;
Index: gpilotd/gpilot-structures.h
===================================================================
RCS file: /cvs/gnome/gnome-pilot/gpilotd/gpilot-structures.h,v
retrieving revision 1.10
diff -u -r1.10 gpilot-structures.h
--- gpilotd/gpilot-structures.h 2000/04/04 23:19:11 1.10
+++ gpilotd/gpilot-structures.h 2000/07/31 17:16:21
@@ -16,6 +16,11 @@
void gpilot_context_init_user (GPilotContext *context);
void gpilot_context_free (GPilotContext *context);
+typedef enum GPilotDeviceType {
+ PILOT_DEVICE_SERIAL,
+ PILOT_DEVICE_USB_VISOR
+} GPilotDeviceType;
+
typedef struct GPilotDevice {
gchar *name;
gchar *port;
@@ -26,6 +31,9 @@
GIOChannel *io; /* the g_io_channel is used for the polling */
guint in_handle; /* these two handles are used to be able to */
guint err_handle; /* pause the daemon's polling by g_source_remove */
+
+ GPilotDeviceType type;
+ gboolean device_exists : 1; /* whether the usb cradle is active */
} GPilotDevice;
GPilotDevice *gpilot_device_new (void);
Index: gpilotd/gpilotd.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/gpilotd/gpilotd.c,v
retrieving revision 1.91
diff -u -r1.91 gpilotd.c
--- gpilotd/gpilotd.c 2000/07/03 00:30:49 1.91
+++ gpilotd/gpilotd.c 2000/07/31 17:16:24
@@ -22,6 +22,7 @@
#include <pi-version.h>
#include <sys/wait.h>
#include <sys/stat.h>
+#include <sys/sysmacros.h> /* for minor() */
#include <pwd.h>
#include "orbit_daemon_glue.h"
@@ -94,8 +95,11 @@
addr.pi_family = PI_AF_SLP;
strcpy(addr.pi_device,device->port);
+ close (device->fd);
+
ret = pi_bind(sd, (struct sockaddr*)&addr, sizeof(addr));
- if (ret != 0) {
+ if (ret == -1) {
+ perror ("pi_bind");
g_warning(_("Unable to bind to pilot"));
if (error) *error = 1;
return 0;
@@ -108,7 +112,7 @@
return 0;
}
- sd = pi_accept_to(sd, NULL,0,1000); /* set timeout to 1 second */
+ sd = pi_accept_to(sd, NULL,0,2000); /* set timeout to 1 second */
if (sd == -1) {
g_warning("pi_accept: %s", strerror(errno));
if (error) *error = 2;
@@ -520,17 +524,80 @@
return FALSE;
}
+#ifdef WITH_USB_VISOR
+
+static const gchar *
+get_usb_procentry (gchar *port)
+{
+ struct stat statbuf;
+ static gchar buf[PATH_MAX + 1];
+
+ if (stat (port, &statbuf) == 0) {
+ g_snprintf (buf, PATH_MAX, "/proc/bus/usb/001/%03d",
+ minor (statbuf.st_rdev) + 1);
+ }
+
+ return buf;
+}
+
+static guint
+check_usb (GPilotContext *context)
+{
+ GPilotDevice *device;
+ struct stat statbuf;
+ GList *devices = context->devices;
+
+ if (context->paused) {
+ return TRUE;
+ }
+
+ /* Check for an entry in the usb device file system for each visor
+ * device. If the device goes from nonexistent to existent, then
+ * the device has been activated and we sync */
+ while (devices) {
+ device = devices->data;
+ if (device->type != PILOT_DEVICE_USB_VISOR)
+ continue;
+
+ if (stat (get_usb_procentry (device->port), &statbuf) == 0) {
+ if (!device->device_exists) {
+ device->device_exists = TRUE;
+ sleep (1);
+ sync_device (device, context);
+ }
+ } else {
+ device->device_exists = FALSE;
+ }
+ devices = devices->next;
+ }
+
+ return TRUE;
+}
+
+#endif
+
void monitor_channel(GPilotDevice *dev,GPilotContext *context) {
g_assert (context != NULL);
+
+ if (dev->type == PILOT_DEVICE_SERIAL) {
+ dev->in_handle = g_io_add_watch(dev->io,
+ G_IO_IN,
+ (GIOFunc)device_in,
+ (gpointer)context);
+ dev->err_handle = g_io_add_watch(dev->io,
+ G_IO_ERR|G_IO_PRI|G_IO_HUP|G_IO_NVAL,
+ (GIOFunc)device_err,
+ (gpointer)context);
+ } else {
+#ifdef WITH_USB_VISOR
+ gtk_timeout_add (1000, (GtkFunction)check_usb, context);
+ dev->in_handle = -1;
+ dev->err_handle = -1;
+#else
+ g_warning ("USB Visor support not compiled in.");
+#endif
+ }
- dev->in_handle = g_io_add_watch(dev->io,
- G_IO_IN,
- (GIOFunc)device_in,
- (gpointer)context);
- dev->err_handle = g_io_add_watch(dev->io,
- G_IO_ERR|G_IO_PRI|G_IO_HUP|G_IO_NVAL,
- (GIOFunc)device_err,
- (gpointer)context);
g_message(_("Watching %s (%s)"),dev->name,dev->port);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]