[telepathy-sofiasip/master] Implemented Maemo IP heartbeat support
Mikhail Zabaluev
mikhail.zabaluev at nokia.com
Fri Jul 24 12:10:27 PDT 2009
---
configure.ac | 24 ++++++++++++-
src/Makefile.am | 9 +++--
src/sip-connection-manager.c | 83 ++++++++++++++++++------------------------
3 files changed, 63 insertions(+), 53 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3ffe04f..a97bf8f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@ AS_VERSION(THIS_PACKAGE, TELEPATHY_SIP_VERSION,
AM_INIT_AUTOMAKE([1.8 -Wno-portability])
AM_PROG_LIBTOOL
-AM_CONFIG_HEADER(config.h)
+AC_CONFIG_HEADER([config.h])
dnl check for tools
AC_PROG_CC
@@ -101,6 +101,28 @@ PKG_CHECK_MODULES(TELEPATHY_GLIB, [telepathy-glib >= 0.7.17])
AC_SUBST(TELEPATHY_GLIB_CFLAGS)
AC_SUBST(TELEPATHY_GLIB_LIBS)
+dnl Check for optional IP heartbeat support
+AC_ARG_WITH(iphb,
+ AC_HELP_STRING([--with-iphb],[Use IP heartbeat support in Maemo]),
+ [],
+ [with_iphb=no]
+)
+if test "x$with_iphb" != xno; then
+ AC_CHECK_LIB(iphb, [iphb_open],
+ [
+ AC_DEFINE([HAVE_LIBIPHB], [], [IP heartbeat library is available])
+ IPHB_CFLAGS='-I$(includedir)/iphbd'
+ IPHB_LIBS=-liphb
+ ],
+ [AC_MSG_ERROR([IP heartbeat library not found])]
+ )
+else
+ IPHB_CFLAGS=
+ IPHB_LIBS=
+fi
+AC_SUBST(IPHB_CFLAGS)
+AC_SUBST(IPHB_LIBS)
+
dnl Check for code generation tools
XSLTPROC=
AC_CHECK_PROGS([XSLTPROC], [xsltproc])
diff --git a/src/Makefile.am b/src/Makefile.am
index 753bd0d..26bf44b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,10 +14,11 @@ managerdir = $(datadir)/telepathy/managers
# ----------------------------------------------------------------------
# Headers and libraries
-AM_CFLAGS = $(ERROR_CFLAGS) @DBUS_CFLAGS@ @GLIB_CFLAGS@ @SOFIA_SIP_UA_CFLAGS@ \
- @TELEPATHY_GLIB_CFLAGS@ @COVERAGE_CFLAGS@ \
- -I$(top_builddir) -I$(top_srcdir)
-ALL_LIBS = @DBUS_LIBS@ @GLIB_LIBS@ @SOFIA_SIP_UA_LIBS@ @TELEPATHY_GLIB_LIBS@
+AM_CPPFLAGS = $(DBUS_CFLAGS) $(GLIB_CFLAGS) $(SOFIA_SIP_UA_CFLAGS) \
+ $(TELEPATHY_GLIB_CFLAGS) $(IPHB_CFLAGS)
+AM_CFLAGS = $(ERROR_CFLAGS) $(COVERAGE_CFLAGS)
+ALL_LIBS = $(DBUS_LIBS) $(GLIB_LIBS) $(SOFIA_SIP_UA_LIBS) \
+ $(TELEPATHY_GLIB_LIBS) $(IPHB_LIBS)
# ----------------------------------------------------------------------
# Build targets
diff --git a/src/sip-connection-manager.c b/src/sip-connection-manager.c
index 9386158..bf6890c 100644
--- a/src/sip-connection-manager.c
+++ b/src/sip-connection-manager.c
@@ -24,9 +24,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <dbus/dbus-protocol.h>
@@ -36,6 +37,10 @@
#include <tpsip/sofia-decls.h>
#include <sofia-sip/su_glib.h>
+#ifdef HAVE_LIBIPHB
+#include <libiphb.h>
+#endif
+
#include "sip-connection-manager.h"
#include "sip-connection.h"
@@ -201,13 +206,18 @@ struct _TpsipConnectionManagerPrivate
{
su_root_t *sofia_root;
+#ifdef HAVE_LIBIPHB
+ iphb_t heartbeat;
+ int heartbeat_interval;
su_wait_t heartbeat_wait[1];
int heartbeat_wait_id;
- int heartbeat_pipe[2];
+#endif
};
#define TPSIP_CONNECTION_MANAGER_GET_PRIVATE(obj) ((obj)->priv)
+#ifdef HAVE_LIBIPHB
+
static void heartbeat_shutdown (TpsipConnectionManager *self);
static int
@@ -215,8 +225,12 @@ heartbeat_wakeup (TpsipConnectionManager *self,
su_wait_t *wait,
void *user_data)
{
+ TpsipConnectionManagerPrivate *priv = TPSIP_CONNECTION_MANAGER_GET_PRIVATE (self);
+
DEBUG("tick");
+ g_assert (priv->heartbeat != NULL);
+
if ((wait->revents & (SU_WAIT_HUP | SU_WAIT_ERR)) != 0)
{
g_warning ("heartbeat descriptor invalidated prematurely with event mask %hd", wait->revents);
@@ -224,21 +238,8 @@ heartbeat_wakeup (TpsipConnectionManager *self,
}
else if ((wait->revents & SU_WAIT_IN) != 0)
{
- ssize_t bytes_read;
- char foo[1];
-
- bytes_read = read (wait->fd, foo, 1);
-
- if (bytes_read < 0)
- {
- g_warning ("error reading from the heartbeat descriptor: %s", strerror (errno));
- heartbeat_shutdown (self);
- }
- else if (bytes_read == 0)
- {
- g_warning ("premature EOF from heartbeat descriptor");
- heartbeat_shutdown (self);
- }
+ iphb_wait (priv->heartbeat, 0, 0, 0);
+ DEBUG("returned from iphb_wait");
}
else
g_assert_not_reached ();
@@ -246,41 +247,28 @@ heartbeat_wakeup (TpsipConnectionManager *self,
return 0;
}
-static gboolean
-heartbeat_pump (gpointer data)
-{
- TpsipConnectionManager *self = TPSIP_CONNECTION_MANAGER (data);
- TpsipConnectionManagerPrivate *priv = TPSIP_CONNECTION_MANAGER_GET_PRIVATE (self);
- ssize_t write_res;
- char foo[1];
-
- DEBUG("tock...");
-
- write_res = write (priv->heartbeat_pipe[1], foo, 1);
-
- if (write_res < 0)
- {
- g_warning ("error writing to the heartbeat pipe: %s", strerror (errno));
- heartbeat_shutdown (self);
- return FALSE;
- }
-
- return TRUE;
-}
+#endif /* HAVE_LIBIPHB */
static void
heartbeat_init (TpsipConnectionManager *self)
{
+#ifdef HAVE_LIBIPHB
TpsipConnectionManagerPrivate *priv = TPSIP_CONNECTION_MANAGER_GET_PRIVATE (self);
int wait_id;
- /* In this testing code, we emulate the heartbeat socket with a
- * timer-driven pipe */
- if (pipe (priv->heartbeat_pipe) != 0)
- g_error ("heartbeat pipe creation failed");
+ priv->heartbeat = iphb_open (&priv->heartbeat_interval);
+
+ if (priv->heartbeat == NULL)
+ {
+ g_warning ("opening IP heartbeat failed: %s", strerror (errno));
+ return;
+ }
+
+ DEBUG("heartbeat opened with interval %d", priv->heartbeat_interval);
su_wait_init (priv->heartbeat_wait);
- if (su_wait_create (priv->heartbeat_wait, priv->heartbeat_pipe[0],
+ if (su_wait_create (priv->heartbeat_wait,
+ iphb_get_fd (priv->heartbeat),
SU_WAIT_IN | SU_WAIT_HUP | SU_WAIT_ERR) != 0)
g_critical ("could not create a wait object");
@@ -289,14 +277,13 @@ heartbeat_init (TpsipConnectionManager *self)
g_return_if_fail (wait_id > 0);
priv->heartbeat_wait_id = wait_id;
-
- /* For testing purposes only */
- g_timeout_add (10000, heartbeat_pump, self);
+#endif /* HAVE_LIBIPHB */
}
static void
heartbeat_shutdown (TpsipConnectionManager *self)
{
+#ifdef HAVE_LIBIPHB
TpsipConnectionManagerPrivate *priv = TPSIP_CONNECTION_MANAGER_GET_PRIVATE (self);
if (priv->heartbeat_wait_id == 0)
@@ -307,8 +294,8 @@ heartbeat_shutdown (TpsipConnectionManager *self)
su_wait_destroy (priv->heartbeat_wait);
- close (priv->heartbeat_pipe[1]);
- close (priv->heartbeat_pipe[0]);
+ iphb_close (priv->heartbeat);
+#endif /* HAVE_LIBIPHB */
}
static void
--
1.5.6.5
More information about the telepathy-commits
mailing list