Re: [gamin] Re: Runtime selectable backends for Gamin [u]



On Tue, 2004-08-24 at 18:33, Martin Schlemmer wrote:
> 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.
> 

If possible I would still appreciate points against proposed patch
(except that it will not apply anymore against cvs :).  If it is the
implementation - I am open to suggestions.

Basically we check each backend in order of preferrence (inotify first,
as it is a configure option for now), and if it cannot init it, it
falls through to the next, instead of just checking one.  I am not
sure how to handle future ones - there might be need for a more
flexible solution as to what order the backends should be checked,
or maybe which one first.  Or somehow through gconf?

Anyhow, if its implementation that bothers, what about attached patch?
(I am not sure if you would want to use gam_backend_remove_all_for in
a global instance later on?)


Regards,
-- 
Martin Schlemmer
Gentoo Linux Developer, Desktop/System Team Developer
Cape Town, South Africa

diff -urN gamin-0.0.7/server/gam_dnotify.c gamin-0.0.7.az/server/gam_dnotify.c
--- gamin-0.0.7/server/gam_dnotify.c	2004-08-24 12:06:19.000000000 +0200
+++ gamin-0.0.7.az/server/gam_dnotify.c	2004-08-25 21:00:34.029629744 +0200
@@ -294,6 +294,10 @@
 
     gam_debug(DEBUG_INFO, "dnotify initialized\n");
 
+    gam_backend_add_subscription = gam_dnotify_add_subscription;
+    gam_backend_remove_subscription = gam_dnotify_remove_subscription;
+    gam_backend_remove_all_for = gam_dnotify_remove_all_for;
+
     return TRUE;
 }
 
diff -urN gamin-0.0.7/server/gam_inotify.c gamin-0.0.7.az/server/gam_inotify.c
--- gamin-0.0.7/server/gam_inotify.c	2004-08-25 20:48:19.845242736 +0200
+++ gamin-0.0.7.az/server/gam_inotify.c	2004-08-25 20:59:33.785788200 +0200
@@ -376,6 +376,10 @@
     int i = 0; // INOTIFY_DEBUG_INODE|INOTIFY_DEBUG_ERRORS|INOTIFY_DEBUG_EVENTS;
     ioctl(fd, INOTIFY_SETDEBUG, &i);
 
+    gam_backend_add_subscription = gam_inotify_add_subscription;
+    gam_backend_remove_subscription = gam_inotify_remove_subscription;
+    gam_backend_remove_all_for = gam_inotify_remove_all_for;
+
     return TRUE;
 }
 
diff -urN gamin-0.0.7/server/gam_poll.c gamin-0.0.7.az/server/gam_poll.c
--- gamin-0.0.7/server/gam_poll.c	2004-08-24 12:07:27.000000000 +0200
+++ gamin-0.0.7.az/server/gam_poll.c	2004-08-25 21:01:28.656325224 +0200
@@ -586,6 +586,10 @@
     }
     tree = gam_tree_new();
 
+    gam_backend_add_subscription = gam_poll_add_subscription;
+    gam_backend_remove_subscription = gam_poll_remove_subscription;
+    gam_backend_remove_all_for = gam_poll_remove_all_for;
+
     gam_debug(DEBUG_INFO, "Initialized Poll\n");
     return TRUE;
 }
diff -urN gamin-0.0.7/server/gam_server.c gamin-0.0.7.az/server/gam_server.c
--- gamin-0.0.7/server/gam_server.c	2004-08-25 20:48:57.543511728 +0200
+++ gamin-0.0.7.az/server/gam_server.c	2004-08-25 21:06:30.795393104 +0200
@@ -63,13 +63,28 @@
 gboolean
 gam_init_subscriptions(void)
 {
+    gboolean ret = FALSE;
+
 #ifdef ENABLE_INOTIFY
-    return (gam_inotify_init());
-#elif linux
-    return (gam_dnotify_init());
-#else
-    return (gam_poll_init());
+    if (ret = gam_inotify_init()) {
+	gam_debug(DEBUG_INFO, "Using INotify as backend\n");
+	return ret;
+    }
+#endif
+#ifdef linux
+    if (ret = gam_dnotify_init()) {
+	gam_debug(DEBUG_INFO, "Using DNotify as backend\n");
+	return ret;
+    }
 #endif
+    if (ret = gam_poll_init()) {
+	gam_debug(DEBUG_INFO, "Using Poll as backend\n");
+	return ret;
+    }
+
+    gam_debug(DEBUG_INFO, "Cannot initialize any backend\n");
+
+    return FALSE;
 }
 
 /**
@@ -113,13 +128,7 @@
 	return (gam_poll_add_subscription(sub));
     }
  ***/
-#ifdef ENABLE_INOTIFY
-    return (gam_inotify_add_subscription(sub));
-#elif linux
-    return (gam_dnotify_add_subscription(sub));
-#else
-    return (gam_poll_add_subscription(sub));
-#endif
+    return (gam_backend_add_subscription(sub));
 }
 
 /**
@@ -132,13 +141,7 @@
 gboolean
 gam_remove_subscription(GamSubscription * sub)
 {
-#ifdef ENABLE_INOTIFY
-    return (gam_inotify_remove_subscription(sub));
-#elif linux
-    return (gam_dnotify_remove_subscription(sub));
-#else
-    return (gam_poll_remove_subscription(sub));
-#endif
+    return (gam_backend_remove_subscription(sub));
 }
 
 /**
diff -urN gamin-0.0.7/server/gam_server.h gamin-0.0.7.az/server/gam_server.h
--- gamin-0.0.7/server/gam_server.h	2004-08-19 12:51:57.000000000 +0200
+++ gamin-0.0.7.az/server/gam_server.h	2004-08-25 20:56:58.021467976 +0200
@@ -9,6 +9,10 @@
 extern "C" {
 #endif
 
+gboolean        (*gam_backend_add_subscription) (GamSubscription *sub);
+gboolean        (*gam_backend_remove_subscription) (GamSubscription *sub);
+gboolean        (*gam_backend_remove_all_for)   (GamListener *listener);
+
 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]