[Libreoffice-commits] .: Branch 'feature/tubes2' - 2 commits - configure.in tubes/inc tubes/source

Will Thompson wjt at kemper.freedesktop.org
Thu Apr 5 02:53:50 PDT 2012


 configure.in                   |    2 
 tubes/inc/tubes/conference.hxx |   19 +----
 tubes/source/conference.cxx    |  149 ++++++++++++-----------------------------
 3 files changed, 50 insertions(+), 120 deletions(-)

New commits:
commit 263dece8f15e448709d6e4753c5287eae368f147
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Thu Apr 5 10:53:21 2012 +0100

    conference: remove a stray dbus-glib import.
    
    This is no longer needed since the switch to using GDBus for the tube
    connection.

diff --git a/tubes/inc/tubes/conference.hxx b/tubes/inc/tubes/conference.hxx
index 088bf4b..6841f9a 100644
--- a/tubes/inc/tubes/conference.hxx
+++ b/tubes/inc/tubes/conference.hxx
@@ -37,7 +37,6 @@
 #include <boost/enable_shared_from_this.hpp>
 #include <rtl/ustring.hxx>
 #include <telepathy-glib/telepathy-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
 #include <queue>
 
 typedef ::std::queue<TelePacket> TelePacketQueue;
commit d157e12e3f204fe41fa37f27e1e6eaf7f29eda20
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Sun Apr 1 15:50:20 2012 +0100

    tubes: use tp_dbus_tube_channel_offer/accept_async
    
    I added these to the recently-released telepathy-glib 0.18.0 mainly to
    let us simplify the code here. With this new API, tp-glib takes care of
    waiting for the state changes, creating the GDBusConnection, etc.

diff --git a/configure.in b/configure.in
index 34a8b8b..ebdf217 100644
--- a/configure.in
+++ b/configure.in
@@ -8369,7 +8369,7 @@ AC_MSG_CHECKING([whether to enable Telepathy support])
 if test "$_os" != "WINNT" -a "$_os" != "Darwin" -a "$enable_telepathy" = "yes"; then
     ENABLE_TELEPATHY="TRUE"
     AC_MSG_RESULT([yes])
-    PKG_CHECK_MODULES( TELEPATHY, telepathy-glib >= 0.17.1 glib-2.0 gobject-2.0 gthread-2.0 gio-2.0 dbus-1 dbus-glib-1 )
+    PKG_CHECK_MODULES( TELEPATHY, telepathy-glib >= 0.18.0 glib-2.0 gobject-2.0 gthread-2.0 gio-2.0 )
 else
     AC_MSG_RESULT([no])
 fi
diff --git a/tubes/inc/tubes/conference.hxx b/tubes/inc/tubes/conference.hxx
index fca6e2e..088bf4b 100644
--- a/tubes/inc/tubes/conference.hxx
+++ b/tubes/inc/tubes/conference.hxx
@@ -84,20 +84,14 @@ public:
     bool                    offerTube();
     bool                    acceptTube();
     /// got tube accepted on other end as well?
-    bool                    isTubeOpen() const { return meTubeChannelState == TP_TUBE_CHANNEL_STATE_OPEN; }
+    bool                    isTubeOpen() const { return mpTube != NULL; }
 
     // Only for callbacks.
     void                    setTubeOfferedHandlerInvoked( bool b ) { mbTubeOfferedHandlerInvoked = b; }
     bool                    isTubeOfferedHandlerInvoked() const { return mbTubeOfferedHandlerInvoked; }
-    bool                    isTubeChannelStateChangedToOpen() const
-                                { return meTubeChannelState == TP_TUBE_CHANNEL_STATE_OPEN; };
-    void                    setTubeChannelState( TpTubeChannelState eState ) { meTubeChannelState = eState; }
-
-    static void             TubeChannelStateChangedHandler(TpChannel*, guint, void*, GObject*);
-    static void             TubeOfferedHandler(TpChannel* pChannel, const gchar* pAddress, const GError* pError,
-                                               gpointer pUserData, GObject*pWeakObject);
-    static void             TubeAcceptedHandler(TpChannel* pChannel, const gchar* pAddress, const GError* pError,
-                                               gpointer pUserData, GObject*pWeakObject);
+
+    static void             TubeOfferedHandler(GObject* pSource, GAsyncResult* pResult, gpointer pUserData);
+    static void             TubeAcceptedHandler(GObject* pSource, GAsyncResult* pResult, gpointer pUserData);
     static void             FTReady( EmpathyFTHandler *handler, GError *error, gpointer user_data);
 
     static void             methodCallHandler(GDBusConnection*       pConnection,
@@ -110,9 +104,8 @@ public:
                                               void*                  pUserData);
 
 private:
-    bool                    tryToOpen();
     bool                    spinUntilTubeEstablished();
-    bool                    setTube( const char* pTube );
+    bool                    setTube( GDBusConnection* pTube);
 
     rtl::OString            maSessionId;
     TeleManager*            mpManager;
@@ -122,7 +115,6 @@ private:
     GDBusConnection*        mpTube;
     guint                   maObjectRegistrationId;
     TelePacketQueue         maPacketQueue;
-    TpTubeChannelState      meTubeChannelState;
 
     bool                    mbTubeOfferedHandlerInvoked : 1;
 
diff --git a/tubes/source/conference.cxx b/tubes/source/conference.cxx
index 1cd9248..3df23c6 100644
--- a/tubes/source/conference.cxx
+++ b/tubes/source/conference.cxx
@@ -142,80 +142,62 @@ static void TeleConference_ChannelCloseHandler(
 
 
 void TeleConference::TubeOfferedHandler(
-        TpChannel*      pBaseChannel,
-        const gchar*    pAddress,
-        const GError*   pError,
-        gpointer        pUserData,
-        GObject*        /*weak_object*/
-        )
+        GObject*      pSource,
+        GAsyncResult* pResult,
+        gpointer      pUserData)
 {
     INFO_LOGGER_F( "TeleConference::TubeOfferedHandler");
 
     TeleConference* pConference = reinterpret_cast<TeleConference*>(pUserData);
-    SAL_WARN_IF( !pConference, "tubes", "TeleConference_TubeOfferedHandler: no conference");
+    SAL_WARN_IF( !pConference, "tubes", "TeleConference::TubeOfferedHandler: no conference");
     if (!pConference)
         return;
 
     pConference->setTubeOfferedHandlerInvoked( true);
 
+    TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pSource);
+    GError* pError = NULL;
+    GDBusConnection* pTube = tp_dbus_tube_channel_offer_finish(
+            pChannel, pResult, &pError);
+
     // "can't find contact ... presence" means contact is not a contact.
     /* FIXME: detect and handle */
-    SAL_WARN_IF( pError, "tubes", "TeleConference::TubeOfferedHandler: entered with error: " << pError->message);
-    if (pError)
-        return;
-
-    SAL_WARN_IF( !pAddress, "tubes", "TeleConference::TubeOfferedHandler: no address");
-    if (!pAddress)
-        return;
-
-    TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pBaseChannel);
-    SAL_WARN_IF( pChannel != pConference->getChannel(), "tubes", "TeleConference::TubeOfferedHandler: not my channel");
-    if ((pChannel) != pConference->getChannel())
+    SAL_WARN_IF( !pTube, "tubes", "TeleConference::TubeOfferedHandler: entered with error: " << pError->message);
+    if (pError) {
+        g_error_free( pError);
         return;
+    }
 
-    pConference->mpAddress = g_strdup( pAddress );
-    pConference->tryToOpen();
+    pConference->setTube( pTube);
 }
 
 
-bool TeleConference::tryToOpen()
-{
-    if (mpTube)
-        return true;
-
-    if (!isTubeOpen())
-        return false;
-
-    if (!mpAddress)
-        return false;
-
-    return setTube( mpAddress);
-}
-
-void TeleConference::TubeChannelStateChangedHandler(
-        TpChannel*  pBaseChannel,
-        guint       nState,
-        gpointer    pUserData,
-        GObject*    /*weak_object*/
-        )
+void TeleConference::TubeAcceptedHandler(
+        GObject*      pSource,
+        GAsyncResult* pResult,
+        gpointer      pUserData)
 {
-    INFO_LOGGER_F( "TeleConference::TubeChannelStateChangedHandler");
-
-    SAL_INFO( "tubes", "TeleConference::TubeChannelStateChangedHandler: state: " << static_cast<sal_uInt32>(nState));
+    INFO_LOGGER_F( "TeleConference::TubeAcceptedHandler");
 
     TeleConference* pConference = reinterpret_cast<TeleConference*>(pUserData);
-    SAL_WARN_IF( !pConference, "tubes", "TeleConference_DBusMessageHandler: no conference");
+    SAL_WARN_IF( !pConference, "tubes", "TeleConference::TubeAcceptedHandler: no conference");
     if (!pConference)
         return;
 
-    TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pBaseChannel);
-    SAL_WARN_IF( pChannel != pConference->getChannel(), "tubes",
-            "TeleConference::TubeChannelStateChangedHandler: not my channel");
-    if (pChannel != pConference->getChannel())
+    pConference->setTubeOfferedHandlerInvoked( true);
+
+    TpDBusTubeChannel* pChannel = TP_DBUS_TUBE_CHANNEL( pSource);
+    GError* pError = NULL;
+    GDBusConnection* pTube = tp_dbus_tube_channel_accept_finish(
+            pChannel, pResult, &pError);
+
+    SAL_WARN_IF( !pTube, "tubes", "TeleConference::TubeAcceptedHandler: entered with error: " << pError->message);
+    if (pError) {
+        g_error_free( pError);
         return;
+    }
 
-    pConference->setTubeChannelState( static_cast<TpTubeChannelState>(nState));
-    pConference->tryToOpen();
+    pConference->setTube( pTube);
 }
 
 
@@ -227,7 +209,6 @@ TeleConference::TeleConference( TeleManager* pManager, TpAccount* pAccount, TpDB
         mpChannel( NULL),
         mpAddress( NULL),
         mpTube( NULL),
-        meTubeChannelState( TP_TUBE_CHANNEL_STATE_NOT_OFFERED),
         mbTubeOfferedHandlerInvoked( false)
 {
     setChannel( pAccount, pChannel );
@@ -249,28 +230,9 @@ void TeleConference::setChannel( TpAccount *pAccount, TpDBusTubeChannel* pChanne
         g_object_unref( mpAccount);
 
     mpChannel = pChannel;
-    if (mpChannel) {
+    if (mpChannel)
         g_object_ref( mpChannel);
 
-        /* TODO: remember the TpProxySignalConnection and disconnect in finalize */
-        GError* pError = NULL;
-        TpProxySignalConnection* pProxySignalConnection =
-            tp_cli_channel_interface_tube_connect_to_tube_channel_state_changed(
-                    TP_CHANNEL( mpChannel),
-                    &TeleConference::TubeChannelStateChangedHandler,
-                    this,
-                    NULL,
-                    NULL,
-                    &pError);
-
-        if (!pProxySignalConnection || pError)
-        {
-            SAL_WARN_IF( pError, "tubes",
-                "TeleConference::setChannel: channel state changed error: " << pError->message);
-            g_error_free( pError);
-        }
-    }
-
     mpAccount = pAccount;
     if (mpAccount)
         g_object_ref( mpAccount);
@@ -280,7 +242,6 @@ void TeleConference::setChannel( TpAccount *pAccount, TpDBusTubeChannel* pChanne
 bool TeleConference::spinUntilTubeEstablished()
 {
     mpManager->iterateLoop( this, &TeleConference::isTubeOfferedHandlerInvoked);
-    mpManager->iterateLoop( this, &TeleConference::isTubeChannelStateChangedToOpen);
 
     bool bOpen = isTubeOpen();
     SAL_INFO( "tubes", "TeleConference::spinUntilTubeEstablished: tube open: " << bOpen);
@@ -297,10 +258,9 @@ bool TeleConference::acceptTube()
     if (!mpChannel || mpTube)
         return false;
 
-    tp_cli_channel_type_dbus_tube_call_accept( TP_CHANNEL( mpChannel), -1,
-            TP_SOCKET_ACCESS_CONTROL_CREDENTIALS,
-            &TeleConference::TubeOfferedHandler,
-            this, NULL, NULL);
+    tp_dbus_tube_channel_accept_async( mpChannel,
+            &TeleConference::TubeAcceptedHandler,
+            this);
     return spinUntilTubeEstablished();
 }
 
@@ -313,44 +273,23 @@ bool TeleConference::offerTube()
     if (!mpChannel)
         return false;
 
-    // We must pass a hash table, it could be empty though.
-    /* TODO: anything meaningful to go in here? */
-    GHashTable* pParams = tp_asv_new(
-            "LibreOffice", G_TYPE_STRING, "Collaboration",
-            NULL);
-
-    tp_cli_channel_type_dbus_tube_call_offer(
-            TP_CHANNEL( mpChannel),                 // proxy
-            -1,                                     // timeout_ms
-            pParams,                                // in_parameters
-            TP_SOCKET_ACCESS_CONTROL_CREDENTIALS,   // in_access_control
-            &TeleConference::TubeOfferedHandler,    // callback
-            this,                                   // user_data
-            NULL,                                   // destroy
-            NULL);                                  // weak_object
-
-    g_hash_table_unref( pParams);
+    tp_dbus_tube_channel_offer_async(
+            mpChannel,
+            NULL, // no parameters for now
+            &TeleConference::TubeOfferedHandler,
+            this);
+
     return spinUntilTubeEstablished();
 }
 
 
-bool TeleConference::setTube(  const char* pAddress )
+bool TeleConference::setTube( GDBusConnection* pTube)
 {
     INFO_LOGGER( "TeleConference::setTube");
 
     OSL_ENSURE( !mpTube, "TeleConference::setTube: already tubed");
 
-    GError *aError = NULL;
-
-    mpTube = g_dbus_connection_new_for_address_sync( pAddress,
-            G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
-            NULL, NULL, &aError);
-    if (!mpTube)
-    {
-        SAL_WARN( "tubes", "TeleConference::setTube: no dbus connection: " << aError->message);
-        g_clear_error( &aError);
-        return false;
-    }
+    mpTube = pTube;
 
     GDBusNodeInfo *introspection_data;
     guint registration_id;


More information about the Libreoffice-commits mailing list