[gupnp] Fallback to Linux CM if available



commit 9a0697cc5454483229f1b2c3e4a07982c1089a96
Author: Jens Georg <mail jensge org>
Date:   Sun Aug 19 14:13:21 2012 +0200

    Fallback to Linux CM if available
    
    If one of the other dynamic context managers was not available, we would
    fall-back to the static CM.
    
    This patch changes this so we fall-back to the dynamic Linux CM instead
    if it's available.

 configure.ac                     |   42 +++++++++++++++++++-------------------
 libgupnp/Makefile.am             |    9 +++++--
 libgupnp/gupnp-context-manager.c |   15 ++++++++++---
 3 files changed, 38 insertions(+), 28 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9fd040e..8fbb92e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,6 +74,22 @@ if test "x$with_context_manager" = "xnone"; then
         esac
 fi
 
+AC_CHECK_HEADERS([sys/socket.h linux/rtnetlink.h],
+                [ HAVE_NETLINK=yes ],
+                [ HAVE_NETLINK=no ],
+                [ #ifdef HAVE_SYS_SOCKET_H
+                  #include <sys/socket.h>
+                  #endif
+                ])
+AM_CONDITIONAL([HAVE_NETLINK], [test "x$HAVE_NETLINK" = "xyes"])
+AC_SUBST(HAVE_NETLINK)
+
+AC_CHECK_HEADERS([linux/wireless.h], [], [],
+                [ #ifdef HAVE_SYS_SOCKET_H
+                  #include <sys/socket.h>
+                  #endif
+                ])
+
 AC_MSG_CHECKING([Context Manager backend to use])
 AC_MSG_RESULT([${with_context_manager}])
 
@@ -90,27 +106,11 @@ if test "x$with_context_manager" = "xconnman"; then
 fi
 
 USE_NETLINK=no
-if test "x$with_context_manager" = "xlinux"; then
-       dnl check for netlink (Linux)
-       AC_CHECK_HEADERS([sys/socket.h linux/rtnetlink.h],
-                        [ USE_NETLINK=yes ],
-                        [ USE_NETLINK=no ],
-                        [ #ifdef HAVE_SYS_SOCKET_H
-                          #include <sys/socket.h>
-                          #endif
-                        ])
-       if test "x$USE_NETLINK" = "xno"
-       then
-               AC_MSG_NOTICE([No rtnetlink found, falling back to unix context
-                              manager])
-       else
-               AC_CHECK_HEADERS([linux/wireless.h], [], [],
-                                [ #ifdef HAVE_SYS_SOCKET_H
-                                  #include <sys/socket.h>
-                                  #endif
-                                ])
-       fi
-fi
+AS_IF([test "x$with_context_manager" = "xlinux"],
+      [AS_IF([test "x$HAVE_NETLINK" = "xno"],
+             [AC_MSG_NOTICE([No rtnetlink found, falling back to static context manager])],
+             [USE_NETLINK=yes])
+      ],[])
 
 AM_CONDITIONAL(USE_NETLINK, test "x$USE_NETLINK" = "xyes")
 AC_SUBST(USE_NETLINK)
diff --git a/libgupnp/Makefile.am b/libgupnp/Makefile.am
index 24e04e0..46a37b4 100644
--- a/libgupnp/Makefile.am
+++ b/libgupnp/Makefile.am
@@ -14,11 +14,14 @@ CONTEXT_MANAGER_CFLAGS = -DUSE_CONNMAN
 endif
 endif
 
+if HAVE_NETLINK
+CONTEXT_MANAGER_IMPL += \
+	gupnp-linux-context-manager.c \
+	gupnp-linux-context-manager.h
+endif
+
 if USE_NETLINK
 NETLINK_CFLAGS = -DUSE_NETLINK
-CONTEXT_MANAGER_IMPL += \
-			  gupnp-linux-context-manager.c		\
-			  gupnp-linux-context-manager.h
 else
 NETLINK_CFLAGS =
 endif
diff --git a/libgupnp/gupnp-context-manager.c b/libgupnp/gupnp-context-manager.c
index 37cf713..9291c6c 100644
--- a/libgupnp/gupnp-context-manager.c
+++ b/libgupnp/gupnp-context-manager.c
@@ -313,6 +313,10 @@ gupnp_context_manager_new (GMainContext *main_context,
     return gupnp_context_manager_create (port);
 }
 
+#ifdef HAVE_LINUX_RTNETLINK_H
+#include "gupnp-linux-context-manager.h"
+#endif
+
 /**
  * gupnp_context_manager_create:
  * @port: Port to create contexts for, or 0 if you don't care what port is used.
@@ -345,14 +349,17 @@ gupnp_context_manager_create (guint port)
 
        if (gupnp_connman_manager_is_available ())
                 impl_type = GUPNP_TYPE_CONNMAN_MANAGER;
-
-#elif USE_NETLINK
-#include "gupnp-linux-context-manager.h"
-        impl_type = GUPNP_TYPE_LINUX_CONTEXT_MANAGER;
 #endif
 
         if (impl_type == G_TYPE_INVALID)
+            /* Either user requested us to use the Linux CM explicitly or we
+             * are using one of the DBus managers but it's not available, so we
+             * fall-back to it. */
+#if defined (USE_NETLINK) || defined (HAVE_LINUX_RTNETLINK_H)
+                impl_type = GUPNP_TYPE_LINUX_CONTEXT_MANAGER;
+#else
                 impl_type = GUPNP_TYPE_UNIX_CONTEXT_MANAGER;
+#endif
 
         impl = g_object_new (impl_type,
                              "port", port,



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