On Tue, 2004-08-24 at 10:42, Daniel Veillard wrote: > On Mon, Aug 23, 2004 at 12:32:48AM +0200, Martin Schlemmer [c] wrote: > > Hi > > > > Attached patch allows Gamin to select backend at runtime. > > I guess it could be a more generic interface, but this allows > > for minimum changes. > > > > Comments welcome. > > Could you post it to the gamin list ? > http://mail.gnome.org/mailman/listinfo/gamin-list > > the code is using dnotify and polling at the same time now, so it's > more complex than what your patch suggests. > I should admit that it is not the most elegant solution, and will not scale if more backends are used (will there be much more added or in pipe-line to be added?). I however wanted an easy way to integrate both dnotify and inotify support without recompiling, and currently it seems to be working fine with dnotify - having a bit of issues getting inotify working with devicemapper ... I however do not see concern with dnotify also using polling, and would appreciate enlightenment. Regards, -- Martin Schlemmer
diff -urN gamin-0.0.6/server/gam_server.c gamin-0.0.6.az/server/gam_server.c
--- gamin-0.0.6/server/gam_server.c 2004-08-19 12:54:45.000000000 +0200
+++ gamin-0.0.6.az/server/gam_server.c 2004-08-23 00:22:48.136493880 +0200
@@ -41,6 +41,7 @@
#endif
static const char *session;
+static int gam_backend;
/**
* gam_shutdown:
@@ -63,13 +64,36 @@
gboolean
gam_init_subscriptions(void)
{
+ gboolean ret;
+
+ gam_backend = 0;
+
#ifdef USE_INOTIFY
- return (gam_inotify_init());
-#elif linux
- return (gam_dnotify_init());
-#else
- return (gam_poll_init());
+ if ((!gam_backend) && (ret = gam_inotify_init())) {
+ gam_backend = BACKEND_INOTIFY;
+ gam_debug(DEBUG_INFO, "Using INotify as backend\n");
+ return ret;
+ }
#endif
+#ifdef linux
+ if ((!gam_backend) && (ret = gam_dnotify_init())) {
+ gam_backend = BACKEND_DNOTIFY;
+ gam_debug(DEBUG_INFO, "Using DNotify as backend\n");
+ return ret;
+ }
+#endif
+ if (!gam_backend) {
+ ret = gam_poll_init();
+ if (ret) {
+ gam_backend = BACKEND_POLL;
+ gam_debug(DEBUG_INFO, "Using Poll as backend\n");
+ }
+ return ret;
+ }
+
+ gam_debug(DEBUG_INFO, "Cannot initialize any backend\n");
+
+ return FALSE;
}
/**
@@ -113,13 +137,21 @@
return (gam_poll_add_subscription(sub));
}
***/
+ switch (gam_backend) {
#ifdef USE_INOTIFY
- return (gam_inotify_add_subscription(sub));
-#elif linux
- return (gam_dnotify_add_subscription(sub));
-#else
- return (gam_poll_add_subscription(sub));
+ case BACKEND_INOTIFY:
+ return (gam_inotify_add_subscription(sub));
+ break;
#endif
+#ifdef linux
+ case BACKEND_DNOTIFY:
+ return (gam_dnotify_add_subscription(sub));
+ break;
+#endif
+ case BACKEND_POLL:
+ return (gam_poll_add_subscription(sub));
+ break;
+ }
}
/**
@@ -132,13 +164,21 @@
gboolean
gam_remove_subscription(GamSubscription * sub)
{
+ switch (gam_backend) {
#ifdef USE_INOTIFY
- return (gam_inotify_remove_subscription(sub));
-#elif linux
- return (gam_dnotify_remove_subscription(sub));
-#else
- return (gam_poll_remove_subscription(sub));
+ case BACKEND_INOTIFY:
+ return (gam_inotify_remove_subscription(sub));
+ break;
+#endif
+#ifdef linux
+ case BACKEND_DNOTIFY:
+ return (gam_dnotify_remove_subscription(sub));
+ break;
#endif
+ case BACKEND_POLL:
+ return (gam_poll_remove_subscription(sub));
+ break;
+ }
}
/**
diff -urN gamin-0.0.6/server/gam_server.h gamin-0.0.6.az/server/gam_server.h
--- gamin-0.0.6/server/gam_server.h 2004-08-19 12:51:57.000000000 +0200
+++ gamin-0.0.6.az/server/gam_server.h 2004-08-23 00:20:01.420838512 +0200
@@ -9,6 +9,10 @@
extern "C" {
#endif
+#define BACKEND_INOTIFY 1
+#define BACKEND_DNOTIFY 2
+#define BACKEND_POLL 3
+
gboolean gam_init_subscriptions (void);
gboolean gam_add_subscription (GamSubscription *sub);
gboolean gam_remove_subscription (GamSubscription *sub);
Attachment:
signature.asc
Description: This is a digitally signed message part