Implementing bluetooth:/// in gnome-vfs
- From: Priit Laes <amd store20 com>
- To: gnome-vfs-list gnome org
- Subject: Implementing bluetooth:/// in gnome-vfs
- Date: Thu, 18 May 2006 18:18:52 +0300
Hello,
Yesterday-today I checked a bit the gnome-vfs sources and wanted to try
something like bluetooth:// wrapper ;)
Would gnome-vfs be the right place for this kind of stuff?
I have included my sort-of-something-very-basic-works concept as an
attachment.
So, please guys - is something like this worth trying?
#include <fcntl.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <libgnomevfs/gnome-vfs-method.h>
#define DEBUG_BT_ENABLE 1
#ifdef DEBUG_BT_ENABLE
#define DEBUG_BT(x) g_print x
#else
#define DEBUG_BT(x)
#endif
static GMutex *bt_lock;
static gboolean bt_available = FALSE;
static int bt_fd;
static GnomeVFSResult
do_open (GnomeVFSMethod *method,
GnomeVFSMethodHandle **method_handle,
GnomeVFSURI *uri,
GnomeVFSOpenMode mode,
GnomeVFSContext *context)
{
DEBUG_BT (("do_open() %s mode %d\n",
gnome_vfs_uri_to_string (uri, 0), mode));
return GNOME_VFS_OK;
}
static gboolean
do_is_local (GnomeVFSMethod *method,
const GnomeVFSURI *uri)
{
DEBUG_BT (("do_is_local() %s\n",
gnome_vfs_uri_to_string (uri, 0)));
return FALSE;
}
static GnomeVFSResult
do_get_file_info (GnomeVFSMethod *method,
GnomeVFSURI *uri,
GnomeVFSFileInfo *file_info,
GnomeVFSFileInfoOptions options,
GnomeVFSContext *context)
{
DEBUG_BT (("do_get_file_info() %s\n",
gnome_vfs_uri_to_string (uri, 0)));
if (!bt_available) {
return GNOME_VFS_ERROR_NOT_SUPPORTED;
}
if (strcmp (uri->text, "/") == 0) {
file_info->name = g_strdup ("Bluetooth localhost");
file_info->mime_type = g_strdup ("x-directory/normal");
file_info->type = GNOME_VFS_FILE_TYPE_DIRECTORY;
file_info->valid_fields = GNOME_VFS_FILE_INFO_FIELDS_TYPE |
GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE;
} else {
return GNOME_VFS_ERROR_NOT_FOUND;
}
return GNOME_VFS_OK;
}
static GnomeVFSMethod method = {
sizeof(GnomeVFSMethod),
do_open,
NULL, /* do_create, */
NULL, /* do_close, */
NULL, /* do_read, */
NULL, /* do_write, */
NULL, /* do_seek, */
NULL, /* do_tell, */
NULL, /* do_truncate_handle, */
NULL, /* do_open_directory, */
NULL, /* do_close_directory, */
NULL, /* do_read_directory, */
// NULL, /* do_get_file_info, */
do_get_file_info,
NULL, /* do_get_file_info_from_handle, */
do_is_local,
NULL, /* do_make_directory, */
NULL, /* do_remove_directory, */
NULL, /* do_move, */
NULL, /* do_unlink, */
NULL, /* do_check_same_fs, */
NULL, /* do_set_file_info, */
NULL, /* do_truncate, */
NULL, /* do_find_directory, */
NULL, /* do_create_symbolic_link, */
NULL, /* do_monitor_add, */
NULL, /* do_monitor_cancel, */
NULL, /* do_file_control, */
NULL, /* do_forget_cache, */
NULL /* go_get_volume_free_space, */
};
GnomeVFSMethod *
vfs_module_init (const char *method_name, const char *args)
{
struct hci_filter flt;
int dev = 0;
bt_lock = g_mutex_new ();
DEBUG_BT (("<-- Bluetooth module init called -->\n"));
// TODO: Currently we open only the first device...
bt_fd = hci_open_dev (dev);
fcntl (bt_fd, F_SETFL, O_NONBLOCK);
if (bt_fd < 0) {
DEBUG_BT (("<-- %s: no Bluetooth device found -->\n",
__FUNCTION__));
bt_available = FALSE;
return &method;
}
hci_filter_clear (&flt);
hci_filter_set_ptype (HCI_EVENT_PKT, &flt);
hci_filter_set_event (EVT_INQUIRY_RESULT, &flt);
hci_filter_set_event (EVT_INQUIRY_COMPLETE, &flt);
hci_filter_set_event (EVT_CONN_REQUEST, &flt);
hci_filter_set_event (EVT_CONN_COMPLETE, &flt);
hci_filter_set_event (EVT_REMOTE_NAME_REQ_COMPLETE, &flt);
if (setsockopt (bt_fd, SOL_HCI, HCI_FILTER, &flt, sizeof (&flt)) < 0) {
DEBUG_BT (("<-- %s: error setting filter flags for device -->\n",
__FUNCTION__));
hci_close_dev (bt_fd);
bt_available = FALSE;
return &method;
}
bt_available = TRUE;
return &method;
}
void
vfs_module_shutdown (GnomeVFSMethod *method)
{
if (bt_available) {
bt_available = FALSE;
}
hci_close_dev (bt_fd);
g_mutex_free (bt_lock);
DEBUG_BT (("<-- Bluetooth module shutdown called -->\n"));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]