[Libreoffice-commits] .: Branch 'feature/tubes2' - 4 commits - tubes/inc tubes/qa tubes/source

Will Thompson wjt at kemper.freedesktop.org
Fri Mar 23 03:24:31 PDT 2012


 tubes/inc/tubes/contact-list.hxx |    5 ----
 tubes/inc/tubes/manager.hxx      |    8 ++++++-
 tubes/qa/test_manager.cxx        |   12 +++++-----
 tubes/source/contact-list.cxx    |   43 ++++----------------------------------
 tubes/source/manager.cxx         |   44 ++++++++++++++++++++++++++++++---------
 5 files changed, 53 insertions(+), 59 deletions(-)

New commits:
commit b0e448bda00bfd8a1632bb596deef14b0ab1a7a9
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Fri Mar 23 10:24:11 2012 +0000

    tubes: add a hack to give time for caps to propagate :(

diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index d3eeefe..e503b03 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -602,6 +602,12 @@ bool TeleManager::startBuddySession( TpAccount *pAccount, TpContact *pBuddy )
 }
 
 
+static gboolean timeout_cb( void* pData)
+{
+    g_main_loop_quit( reinterpret_cast<GMainLoop*>( pData));
+    return FALSE;
+}
+
 void TeleManager::prepareAccountManager()
 {
     INFO_LOGGER( "TeleManager::prepareAccountManager");
@@ -634,6 +640,11 @@ void TeleManager::prepareAccountManager()
     tp_proxy_prepare_async( pImpl->mpAccountManager, NULL, TeleManager_AccountManagerReadyHandler, this);
 
     iterateLoop( &TeleManager::isAccountManagerReadyHandlerInvoked);
+
+    /* Hack to make sure that our capabilities update from one account has
+     * propagated via the network and back to the other account. Sorry. */
+    g_timeout_add_seconds( 2, timeout_cb, pImpl->mpLoop);
+    g_main_loop_run( pImpl->mpLoop);
 }
 
 
commit 3620eefce92c42a96e3390d525a2d145e4e944bf
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Fri Mar 23 10:18:41 2012 +0000

    fixup!

diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx
index 4e588ad..c2fbe89 100644
--- a/tubes/qa/test_manager.cxx
+++ b/tubes/qa/test_manager.cxx
@@ -79,9 +79,9 @@ public:
     CPPUNIT_TEST( testSetupManager2 );
     CPPUNIT_TEST( testConnect1 );
     CPPUNIT_TEST( testConnect2 );
-    CPPUNIT_TEST( testContactList );
     CPPUNIT_TEST( testPrepareAccountManager1 );
     CPPUNIT_TEST( testPrepareAccountManager2 );
+    CPPUNIT_TEST( testContactList );
     CPPUNIT_TEST( testStartBuddySession1 );
     CPPUNIT_TEST( testStartBuddySession2 );
     CPPUNIT_TEST( testSendPacket );
commit c18eb9f45c89a6a568e49836a2530670dbf79ffa
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Fri Mar 23 10:18:25 2012 +0000

    WIP

diff --git a/tubes/inc/tubes/contact-list.hxx b/tubes/inc/tubes/contact-list.hxx
index bf1e0f7..a17b110 100644
--- a/tubes/inc/tubes/contact-list.hxx
+++ b/tubes/inc/tubes/contact-list.hxx
@@ -42,12 +42,9 @@ typedef ::std::vector< AccountContactPair > AccountContactPairV;
 class TUBES_DLLPUBLIC ContactList
 {
 public:
-    ContactList();
+    ContactList(TpAccountManager *pAccountManager);
     ~ContactList();
 
-    typedef void (*PrepareCallback)( GError *errorOr0, void *user_data );
-    void                    prepare( PrepareCallback callback, void *user_data );
-
     AccountContactPairV     getContacts();
 
 private:
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx
index aa6a027..3d557ad 100644
--- a/tubes/inc/tubes/manager.hxx
+++ b/tubes/inc/tubes/manager.hxx
@@ -33,6 +33,7 @@
 #include "tubes/tubesdllapi.h"
 #include "tubes/conference.hxx"
 #include "tubes/packet.hxx"
+#include "tubes/contact-list.hxx"
 #include <rtl/ustring.hxx>
 #include <salhelper/thread.hxx>
 #include <rtl/ref.hxx>
@@ -82,7 +83,7 @@ public:
     TeleManager( const Link& rLink, bool bCreateOwnGMainLoop = false );
     ~TeleManager();
 
-    /** Prepare the Telepathy Account Manager.
+    /** Prepare the Telepathy Account Manager. Requires connect() to have succeeded.
 
         Invokes an async call that is not ready until meAccountManagerStatus is
         set! Until that is AMS_PREPARED nothing else will work.
@@ -92,6 +93,11 @@ public:
     void                    prepareAccountManager();
     AccountManagerStatus    getAccountManagerStatus() const;
 
+    /** Fetches the contact list. Returns 0 before connect() is called successfully.
+        Is non-functional until prepareAccountManager().
+     */
+    ContactList*            getContactList();
+
 #if 0
     /** Start a group session in a MUC.
 
diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx
index 31148ef..4e588ad 100644
--- a/tubes/qa/test_manager.cxx
+++ b/tubes/qa/test_manager.cxx
@@ -168,14 +168,14 @@ void TestTeleTubes::spinMainLoop()
 
 void TestTeleTubes::testContactList()
 {
-    ContactList cl;
-    cl.prepare( TeleTestTubes_ContactListPrepared, this );
-    spinMainLoop();
+    CPPUNIT_ASSERT( mpManager1);
+    CPPUNIT_ASSERT( mpManager1->getAccountManagerStatus() == TeleManager::AMS_PREPARED);
+
+    ContactList *cl = mpManager1->getContactList();
 
-    /* Okay, now everything's prepared, we can get contacts synchronously. */
     AccountContactPairV pairs;
 
-    pairs = cl.getContacts();
+    pairs = cl->getContacts();
     guint i;
 
     /* FIXME: this is racy, because we can't be 100% sure that MC has finished
diff --git a/tubes/source/contact-list.cxx b/tubes/source/contact-list.cxx
index 602bb63..4cedc50 100644
--- a/tubes/source/contact-list.cxx
+++ b/tubes/source/contact-list.cxx
@@ -34,11 +34,12 @@
 #include <tubes/contact-list.hxx>
 #include <tubes/manager.hxx>
 
-ContactList::ContactList()
+ContactList::ContactList(TpAccountManager *pAccountManager)
+    : mpAccountManager(pAccountManager)
 {
-    g_type_init();
-
-    mpAccountManager = tp_account_manager_dup ();
+    SAL_WARN_IF( !mpAccountManager, "tubes",
+        "ContactList::ContactList: passed a null account manager");
+    g_object_ref( mpAccountManager);
 
     /* Tell the client factory (which creates and prepares proxy objects) to
      * get the features we need ready before giving us any objects.
@@ -80,40 +81,6 @@ contact_supports_libo_dtube (TpContact *contact)
         TP_HANDLE_TYPE_CONTACT, TeleManager::getFullServiceName().getStr());
 }
 
-typedef ::std::pair< ContactList::PrepareCallback, void * > Foo;
-
-static void
-account_manager_prepared_cb (GObject *object,
-    GAsyncResult *res,
-    gpointer user_data)
-{
-    Foo *data = reinterpret_cast<Foo *>(user_data);
-    GError *error = NULL;
-
-    if (!tp_proxy_prepare_finish (object, res, &error))
-    {
-        data->first( error, data->second );
-        g_clear_error(&error);
-    }
-    else
-    {
-        data->first( NULL, data->second );
-    }
-
-    delete data;
-}
-
-void ContactList::prepare(
-    ContactList::PrepareCallback callback,
-    void* user_data)
-{
-    Foo *data = new Foo(callback, user_data);
-
-    /* This will call back immediately (in an idle) if the manager is already
-     * prepared, which is fine-ish */
-    tp_proxy_prepare_async (mpAccountManager, NULL, account_manager_prepared_cb, data);
-}
-
 AccountContactPairV ContactList::getContacts()
 {
   GList *accounts;
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index 8b8655f..d3eeefe 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -82,6 +82,7 @@ public:
     TpAccountManager*                   mpAccountManager;
     TeleManager::AccountManagerStatus   meAccountManagerStatus;
     bool                                mbAccountManagerReadyHandlerInvoked;
+    ContactList*                        mpContactList;
 
                             TeleManagerImpl();
                             ~TeleManagerImpl();
@@ -400,6 +401,15 @@ bool TeleManager::connect()
     if (!pFactory)
         return false;
 
+    TpAccountManager* pAccountManager = tp_account_manager_new_with_factory (
+        TP_SIMPLE_CLIENT_FACTORY (pFactory));
+    tp_account_manager_set_default( pAccountManager);
+
+    /* Takes our ref. */
+    pImpl->mpAccountManager = pAccountManager;
+
+    pImpl->mpContactList = new ContactList(pAccountManager);
+
     pImpl->mpClient = tp_simple_handler_new_with_factory(
             TP_SIMPLE_CLIENT_FACTORY (pFactory), // factory
             FALSE,                          // bypass_approval
@@ -613,13 +623,10 @@ void TeleManager::prepareAccountManager()
     SAL_WARN_IF( pImpl->meAccountManagerStatus != AMS_UNINITIALIZED, "tubes",
             "TeleManager::prepareAccountManager: yet another attempt");
 
+    SAL_WARN_IF( !pImpl->mpAccountManager, "tubes",
+            "TeleManager::prepareAccountManager: called before ::connect()");
     if (!pImpl->mpAccountManager)
-    {
-        pImpl->mpAccountManager = tp_account_manager_dup();
-        SAL_WARN_IF( !pImpl->mpAccountManager, "tubes", "TeleManager::prepareAccountManager: no account manager");
-        if (!pImpl->mpAccountManager)
-            return;
-    }
+        return;
 
     pImpl->meAccountManagerStatus = AMS_INPREPARATION;
     setAccountManagerReadyHandlerInvoked( false);
@@ -647,6 +654,10 @@ bool TeleManager::isAccountManagerReadyHandlerInvoked() const
     return pImpl->mbAccountManagerReadyHandlerInvoked;
 }
 
+ContactList* TeleManager::getContactList()
+{
+    return pImpl->mpContactList;
+}
 
 TpAccount* TeleManager::getAccount( const rtl::OString& rAccountID )
 {
@@ -962,6 +973,8 @@ TeleManagerImpl::~TeleManagerImpl()
         g_object_unref( mpDBus);
     if (mpAccountManager)
         g_object_unref( mpAccountManager);
+    if (mpContactList)
+        delete mpContactList;
     if (mpLoop)
         g_main_loop_unref( mpLoop);
 }
commit d6b62dcfc14538a5c1f3dad915af4b9cf2ad9982
Author: Will Thompson <will.thompson at collabora.co.uk>
Date:   Fri Mar 23 09:33:31 2012 +0000

    TeleManager: make g_type_init() the first thing done

diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index fd852ae..8b8655f 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -343,15 +343,15 @@ TeleManager::TeleManager( const Link& rLink, bool bCreateOwnGMainLoop )
         maLink( rLink),
         mbChannelReadyHandlerInvoked( false)
 {
+    // The glib object types need to be initialized, else we aren't going
+    // anywhere.
+    g_type_init();
+
     MutexGuard aGuard( GetMutex());
     ++nRefCount;
     if (!pImpl)
         pImpl = new TeleManagerImpl;
 
-    // The glib object types need to be initialized, else we aren't going
-    // anywhere.
-    g_type_init();
-
     // We need a main loop, else no callbacks.
     /* TODO: could the loop be run in another thread? */
     if (bCreateOwnGMainLoop && !pImpl->mpLoop)


More information about the Libreoffice-commits mailing list