Commit 1d27a433 authored by Darin Adler's avatar Darin Adler

reviewed by: Robin Slomkowski <rslomkow@eazel.com>

	Update FAM support so it works fine on systems with and without
	libfam installed. So if you build Nautilus with FAM, then you can
	run it on a system with or without FAM.

	* configure.in:
	* libnautilus-extensions/Makefile.am:
	Remove the FAM_LIBS part.

	* libnautilus-extensions/nautilus-monitor.c: (get_fam_connection):
	Load the module before the FAMOpen2 call, and get all the function
	pointers.
	(get_event_uri), (process_fam_notifications),
	(nautilus_monitor_file), (nautilus_monitor_directory),
	(nautilus_monitor_cancel): Use the new CALL_FAM macro so we can
	use the function pointers when we call FAM.
parent 8466a210
2001-04-27 Darin Adler <darin@eazel.com>
reviewed by: Robin Slomkowski <rslomkow@eazel.com>
Update FAM support so it works fine on systems with and without
libfam installed. So if you build Nautilus with FAM, then you can
run it on a system with or without FAM.
* configure.in:
* libnautilus-extensions/Makefile.am:
Remove the FAM_LIBS part.
* libnautilus-extensions/nautilus-monitor.c: (get_fam_connection):
Load the module before the FAMOpen2 call, and get all the function
pointers.
(get_event_uri), (process_fam_notifications),
(nautilus_monitor_file), (nautilus_monitor_directory),
(nautilus_monitor_cancel): Use the new CALL_FAM macro so we can
use the function pointers when we call FAM.
2001-04-27 Andy Hertzfeld <andy@eazel.com>
* components/news/nautilus-news.c: (go_to_uri):
......
......@@ -171,19 +171,16 @@ dnl ====================================
AC_CHECK_FUNCS( setenv unsetenv putenv )
dnl Check for fam (/imon) support
dnl ====================================
dnl Check for FAM header -- we find the library at runtime
dnl ====================================
AC_CHECK_HEADERS(fam.h)
AC_CHECK_LIB(fam, FAMOpen, [FAM_LIBS="-lfam"])
AC_SUBST(FAM_LIBS)
dnl ====================================
dnl = Use x86 optimized music routines?
dnl ====================================
_system_is_x86="no"
AC_CHECK_HEADER( asm/vm86.h, _system_is_x86="yes" )
AM_CONDITIONAL(X86_OPTIMIZED, test "x$_system_is_x86" = "xyes")
dnl ====================================
......
......@@ -41,7 +41,6 @@ libnautilus_extensions_la_LDFLAGS = \
$(BONOBO_PRINT_LIBS) \
$(BONOBOX_LIBS) \
$(ESD_LIBS) \
$(FAM_LIBS) \
$(FREETYPE2_LIBS) \
$(GCONF_LIBS) \
$(GHTTP_LIBS) \
......
......@@ -33,10 +33,62 @@
#include "nautilus-file-changes-queue.h"
#include <fam.h>
#include <gdk/gdk.h>
#include <gmodule.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-util.h>
#include <libgnomevfs/gnome-vfs-utils.h>
/* Turn off this to make FAM calls the normal way rather than using
* GModule. This can be useful to check that the parameters to all the
* functions are still correct, but it won't link without configure
* and makefile changes.
*/
#define USE_FAM_AS_MODULE
#ifndef USE_FAM_AS_MODULE
#define CALL_FAM(f) FAM##f
#else /* USE_FAM_AS_MODULE */
typedef struct {
const char *name;
gpointer *function;
} ModuleSymbolPair;
static int (* pointer_FAMCancelMonitor) (FAMConnection *fc,
const FAMRequest *fr);
static int (* pointer_FAMClose) (FAMConnection *fc);
static int (* pointer_FAMMonitorDirectory) (FAMConnection *fc,
const char *filename,
FAMRequest *fr,
void *user_data);
static int (* pointer_FAMMonitorFile) (FAMConnection *fc,
const char *filename,
FAMRequest *fr,
void *user_data);
static int (* pointer_FAMOpen2) (FAMConnection *connection,
const char *name);
static int (* pointer_FAMNextEvent) (FAMConnection *fc,
FAMEvent *fe);
static int (* pointer_FAMPending) (FAMConnection *fc);
static const ModuleSymbolPair fam_symbols[] = {
#define IMPORT_FAM(f) { "FAM" #f, (gpointer *) &pointer_FAM##f },
IMPORT_FAM (CancelMonitor)
IMPORT_FAM (Close)
IMPORT_FAM (MonitorDirectory)
IMPORT_FAM (MonitorFile)
IMPORT_FAM (NextEvent)
IMPORT_FAM (Open2)
IMPORT_FAM (Pending)
#undef IMPORT_FAM
};
#define CALL_FAM(f) (* pointer_FAM##f)
#endif /* USE_FAM_AS_MODULE */
struct NautilusMonitor {
FAMRequest request;
};
......@@ -53,23 +105,47 @@ get_fam_connection (void)
{
static gboolean tried_connection;
static FAMConnection connection;
#ifdef USE_FAM_AS_MODULE
char *path;
GModule *module;
guint i;
#endif
/* Only try once. */
if (!tried_connection) {
if (FAMOpen2 (&connection, "Nautilus") != 0) {
got_connection = FALSE;
} else {
/* Register our callback into the gtk loop. */
gdk_input_add (FAMCONNECTION_GETFD (&connection),
GDK_INPUT_READ,
process_fam_notifications,
NULL);
got_connection = TRUE;
if (tried_connection) {
if (!got_connection) {
return NULL;
}
} else {
tried_connection = TRUE;
}
if (!got_connection) {
return NULL;
#ifdef USE_FAM_AS_MODULE
path = g_module_build_path (NULL, "fam");
module = g_module_open (path, 0);
g_free (path);
if (module == NULL) {
return NULL;
}
for (i = 0; i < EEL_N_ELEMENTS (fam_symbols); i++) {
if (!g_module_symbol (module,
fam_symbols[i].name,
fam_symbols[i].function)) {
return NULL;
}
}
#endif
if (CALL_FAM (Open2) (&connection, "Nautilus") != 0) {
return NULL;
}
/* Make the main loop's select function watch the FAM
* connection's file descriptor for us.
*/
gdk_input_add (FAMCONNECTION_GETFD (&connection),
GDK_INPUT_READ,
process_fam_notifications,
NULL);
got_connection = TRUE;
}
return &connection;
}
......@@ -92,7 +168,7 @@ get_event_uri (const FAMEvent *event)
const char *base_path;
char *path, *uri;
/* FAM doesn't tell us when something is a full path, and when
/* FAM doesn't tell us when something is a full path and when
* it's just partial so we have to look and see if it starts
* with a /.
*/
......@@ -124,11 +200,11 @@ process_fam_notifications (gpointer callback_data, int fd, GdkInputCondition con
/* Process all the pending events right now. */
while (FAMPending (connection)) {
if (FAMNextEvent (connection, &event) != 1) {
while (CALL_FAM (Pending) (connection)) {
if (CALL_FAM (NextEvent) (connection, &event) != 1) {
g_warning ("connection to FAM died");
gdk_input_remove (fd);
FAMClose (connection);
CALL_FAM (Close) (connection);
got_connection = FALSE;
return;
}
......@@ -245,7 +321,7 @@ nautilus_monitor_file (const char *uri)
}
monitor = g_new0 (NautilusMonitor, 1);
FAMMonitorFile (connection, path, &monitor->request, NULL);
CALL_FAM (MonitorFile) (connection, path, &monitor->request, NULL);
g_free (path);
......@@ -276,7 +352,7 @@ nautilus_monitor_directory (const char *uri)
}
monitor = g_new0 (NautilusMonitor, 1);
FAMMonitorDirectory (connection, path, &monitor->request, NULL);
CALL_FAM (MonitorDirectory) (connection, path, &monitor->request, NULL);
g_assert (g_hash_table_lookup (get_request_hash_table (),
GINT_TO_POINTER (FAMREQUEST_GETREQNUM (&monitor->request))) == NULL);
......@@ -313,7 +389,7 @@ nautilus_monitor_cancel (NautilusMonitor *monitor)
connection = get_fam_connection ();
g_return_if_fail (connection != NULL);
FAMCancelMonitor (connection, &monitor->request);
CALL_FAM (CancelMonitor) (connection, &monitor->request);
g_free (monitor);
#endif
}
......@@ -41,7 +41,6 @@ libnautilus_extensions_la_LDFLAGS = \
$(BONOBO_PRINT_LIBS) \
$(BONOBOX_LIBS) \
$(ESD_LIBS) \
$(FAM_LIBS) \
$(FREETYPE2_LIBS) \
$(GCONF_LIBS) \
$(GHTTP_LIBS) \
......
......@@ -33,10 +33,62 @@
#include "nautilus-file-changes-queue.h"
#include <fam.h>
#include <gdk/gdk.h>
#include <gmodule.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-util.h>
#include <libgnomevfs/gnome-vfs-utils.h>
/* Turn off this to make FAM calls the normal way rather than using
* GModule. This can be useful to check that the parameters to all the
* functions are still correct, but it won't link without configure
* and makefile changes.
*/
#define USE_FAM_AS_MODULE
#ifndef USE_FAM_AS_MODULE
#define CALL_FAM(f) FAM##f
#else /* USE_FAM_AS_MODULE */
typedef struct {
const char *name;
gpointer *function;
} ModuleSymbolPair;
static int (* pointer_FAMCancelMonitor) (FAMConnection *fc,
const FAMRequest *fr);
static int (* pointer_FAMClose) (FAMConnection *fc);
static int (* pointer_FAMMonitorDirectory) (FAMConnection *fc,
const char *filename,
FAMRequest *fr,
void *user_data);
static int (* pointer_FAMMonitorFile) (FAMConnection *fc,
const char *filename,
FAMRequest *fr,
void *user_data);
static int (* pointer_FAMOpen2) (FAMConnection *connection,
const char *name);
static int (* pointer_FAMNextEvent) (FAMConnection *fc,
FAMEvent *fe);
static int (* pointer_FAMPending) (FAMConnection *fc);
static const ModuleSymbolPair fam_symbols[] = {
#define IMPORT_FAM(f) { "FAM" #f, (gpointer *) &pointer_FAM##f },
IMPORT_FAM (CancelMonitor)
IMPORT_FAM (Close)
IMPORT_FAM (MonitorDirectory)
IMPORT_FAM (MonitorFile)
IMPORT_FAM (NextEvent)
IMPORT_FAM (Open2)
IMPORT_FAM (Pending)
#undef IMPORT_FAM
};
#define CALL_FAM(f) (* pointer_FAM##f)
#endif /* USE_FAM_AS_MODULE */
struct NautilusMonitor {
FAMRequest request;
};
......@@ -53,23 +105,47 @@ get_fam_connection (void)
{
static gboolean tried_connection;
static FAMConnection connection;
#ifdef USE_FAM_AS_MODULE
char *path;
GModule *module;
guint i;
#endif
/* Only try once. */
if (!tried_connection) {
if (FAMOpen2 (&connection, "Nautilus") != 0) {
got_connection = FALSE;
} else {
/* Register our callback into the gtk loop. */
gdk_input_add (FAMCONNECTION_GETFD (&connection),
GDK_INPUT_READ,
process_fam_notifications,
NULL);
got_connection = TRUE;
if (tried_connection) {
if (!got_connection) {
return NULL;
}
} else {
tried_connection = TRUE;
}
if (!got_connection) {
return NULL;
#ifdef USE_FAM_AS_MODULE
path = g_module_build_path (NULL, "fam");
module = g_module_open (path, 0);
g_free (path);
if (module == NULL) {
return NULL;
}
for (i = 0; i < EEL_N_ELEMENTS (fam_symbols); i++) {
if (!g_module_symbol (module,
fam_symbols[i].name,
fam_symbols[i].function)) {
return NULL;
}
}
#endif
if (CALL_FAM (Open2) (&connection, "Nautilus") != 0) {
return NULL;
}
/* Make the main loop's select function watch the FAM
* connection's file descriptor for us.
*/
gdk_input_add (FAMCONNECTION_GETFD (&connection),
GDK_INPUT_READ,
process_fam_notifications,
NULL);
got_connection = TRUE;
}
return &connection;
}
......@@ -92,7 +168,7 @@ get_event_uri (const FAMEvent *event)
const char *base_path;
char *path, *uri;
/* FAM doesn't tell us when something is a full path, and when
/* FAM doesn't tell us when something is a full path and when
* it's just partial so we have to look and see if it starts
* with a /.
*/
......@@ -124,11 +200,11 @@ process_fam_notifications (gpointer callback_data, int fd, GdkInputCondition con
/* Process all the pending events right now. */
while (FAMPending (connection)) {
if (FAMNextEvent (connection, &event) != 1) {
while (CALL_FAM (Pending) (connection)) {
if (CALL_FAM (NextEvent) (connection, &event) != 1) {
g_warning ("connection to FAM died");
gdk_input_remove (fd);
FAMClose (connection);
CALL_FAM (Close) (connection);
got_connection = FALSE;
return;
}
......@@ -245,7 +321,7 @@ nautilus_monitor_file (const char *uri)
}
monitor = g_new0 (NautilusMonitor, 1);
FAMMonitorFile (connection, path, &monitor->request, NULL);
CALL_FAM (MonitorFile) (connection, path, &monitor->request, NULL);
g_free (path);
......@@ -276,7 +352,7 @@ nautilus_monitor_directory (const char *uri)
}
monitor = g_new0 (NautilusMonitor, 1);
FAMMonitorDirectory (connection, path, &monitor->request, NULL);
CALL_FAM (MonitorDirectory) (connection, path, &monitor->request, NULL);
g_assert (g_hash_table_lookup (get_request_hash_table (),
GINT_TO_POINTER (FAMREQUEST_GETREQNUM (&monitor->request))) == NULL);
......@@ -313,7 +389,7 @@ nautilus_monitor_cancel (NautilusMonitor *monitor)
connection = get_fam_connection ();
g_return_if_fail (connection != NULL);
FAMCancelMonitor (connection, &monitor->request);
CALL_FAM (CancelMonitor) (connection, &monitor->request);
g_free (monitor);
#endif
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment