[Libreoffice-commits] .: Branch 'feature/tubes2' - 5 commits - sc/source tubes/inc tubes/qa tubes/source
Will Thompson
wjt at kemper.freedesktop.org
Fri Mar 23 09:43:05 PDT 2012
sc/source/ui/collab/collab.cxx | 22 +++++++++----
sc/source/ui/collab/sendfunc.cxx | 8 ++--
sc/source/ui/inc/collab.hxx | 15 ++++++---
tubes/inc/tubes/manager.hxx | 56 ++++++++++-----------------------
tubes/qa/test_manager.cxx | 20 ++++++++----
tubes/source/contact-list.cxx | 1
tubes/source/manager.cxx | 65 ++++++++++++++++++++++++---------------
7 files changed, 103 insertions(+), 84 deletions(-)
New commits:
commit 513b203bfa7deea7c2cdc68373bb729fe2caf835
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Fri Mar 23 16:39:43 2012 +0000
tubes: add a shared TeleManager singleton
Yes, this is in addition to the existing TeleManagerImpl singleton. This
class needs to be properly split in half: one Manager part from which
the UI can request new sessions and which signals the appearance of new
incoming sessions, and another Session part representing the shared
editing session (which in turn owns one or more Conferences, which owns
exactly one tube, as now). The Manager will dispatch incoming files to
the appropriate Conference by UUID or similar.
But for now, Michael is opening a new window with the received file,
so we want incoming and outgoing events to go to both windows so that it
works well enough for a demo.
diff --git a/sc/source/ui/collab/collab.cxx b/sc/source/ui/collab/collab.cxx
index 35fa9b1..cf8777c 100644
--- a/sc/source/ui/collab/collab.cxx
+++ b/sc/source/ui/collab/collab.cxx
@@ -47,7 +47,9 @@ ScCollaboration::~ScCollaboration()
g_object_unref( mpAccount);
if (mpContact)
g_object_unref( mpContact);
- delete mpManager;
+
+ mpManager->unref();
+ mpManager = NULL;
}
@@ -75,13 +77,13 @@ void ScCollaboration::packetReceivedCallback( TeleConference *pConference )
bool ScCollaboration::initManager()
{
- mpManager = new TeleManager();
+ mpManager = TeleManager::get();
mpManager->sigPacketReceived.connect(
boost::bind( &ScCollaboration::packetReceivedCallback, this, _1 ));
- bool bOk = mpManager->connect();
+ mpManager->connect();
mpManager->prepareAccountManager();
mpManager->setFileReceivedCallback( file_recv_cb, (void *)this );
- return bOk;
+ return true;
}
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx
index f7edbfa..6d26b02 100644
--- a/tubes/inc/tubes/manager.hxx
+++ b/tubes/inc/tubes/manager.hxx
@@ -80,6 +80,9 @@ public:
TeleManager( bool bCreateOwnGMainLoop = false );
~TeleManager();
+ static TeleManager *get();
+ void unref();
+
/** Prepare the Telepathy Account Manager. Requires connect() to have succeeded.
Invokes an async call that is not ready until meAccountManagerStatus is
@@ -227,13 +230,19 @@ private:
static sal_uInt32 nRefCount;
static rtl::OString aNameSuffix;
+ /* FIXME: double-singletonning is bad. These two are used by ::get and
+ * ::unref, and are a quick hack so that we can have a demo working.
+ */
+ static TeleManager* pSingleton;
+ static sal_uInt32 nAnotherRefCount;
+ TUBES_DLLPRIVATE static ::osl::Mutex& GetAnotherMutex();
+
FileReceivedCallback mpFileReceivedCallback;
void *mpFileReceivedCallbackData;
friend class TeleManagerImpl; // access to mutex
TUBES_DLLPRIVATE static ::osl::Mutex& GetMutex();
-
};
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index 088080d..e0e2425 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -70,6 +70,9 @@ TeleManagerImpl* TeleManager::pImpl = NULL;
sal_uInt32 TeleManager::nRefCount = 0;
rtl::OString TeleManager::aNameSuffix;
+sal_uInt32 TeleManager::nAnotherRefCount = 0;
+TeleManager* TeleManager::pSingleton = NULL;
+
/** Refcounted singleton implementation class. */
class TeleManagerImpl
@@ -386,6 +389,27 @@ TeleManager::~TeleManager()
}
}
+TeleManager *
+TeleManager::get()
+{
+ MutexGuard aGuard( GetAnotherMutex());
+ if (!pSingleton)
+ pSingleton = new TeleManager();
+
+ nAnotherRefCount++;
+ return pSingleton;
+}
+
+void
+TeleManager::unref()
+{
+ MutexGuard aGuard( GetAnotherMutex());
+ if (--nAnotherRefCount == 0) {
+ delete pSingleton;
+ pSingleton = NULL;
+ }
+}
+
bool TeleManager::connect()
{
@@ -931,6 +955,18 @@ Mutex& TeleManager::GetMutex()
return *pMutex;
}
+Mutex& TeleManager::GetAnotherMutex()
+{
+ static Mutex* pMutex = NULL;
+ if (!pMutex)
+ {
+ MutexGuard aGuard( Mutex::getGlobalMutex());
+ if (!pMutex)
+ pMutex = new Mutex;
+ }
+ return *pMutex;
+}
+
// static
void TeleManager::addSuffixToNames( const char* pName )
commit d084e062feff59e6522eb1fe3e00505d6754dd57
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Fri Mar 23 16:25:34 2012 +0000
tubes: replace packetReceived link with a boost signal
diff --git a/sc/source/ui/collab/collab.cxx b/sc/source/ui/collab/collab.cxx
index 4c11fb7..35fa9b1 100644
--- a/sc/source/ui/collab/collab.cxx
+++ b/sc/source/ui/collab/collab.cxx
@@ -31,10 +31,8 @@
#include <tubes/conference.hxx>
#include <tubes/contact-list.hxx>
-ScCollaboration::ScCollaboration( const Link& rLinkPacket,
- const Link& rLinkFile )
+ScCollaboration::ScCollaboration( const Link& rLinkFile )
:
- maLinkPacket( rLinkPacket ),
maLinkFile( rLinkFile ),
mpAccount( NULL),
mpContact( NULL),
@@ -69,9 +67,17 @@ extern "C" {
}
}
+void ScCollaboration::packetReceivedCallback( TeleConference *pConference )
+{
+ /* Relay the signal out⦠*/
+ sigPacketReceived( pConference);
+}
+
bool ScCollaboration::initManager()
{
- mpManager = new TeleManager( maLinkPacket );
+ mpManager = new TeleManager();
+ mpManager->sigPacketReceived.connect(
+ boost::bind( &ScCollaboration::packetReceivedCallback, this, _1 ));
bool bOk = mpManager->connect();
mpManager->prepareAccountManager();
mpManager->setFileReceivedCallback( file_recv_cb, (void *)this );
diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx
index adda0d2..6980edd 100644
--- a/sc/source/ui/collab/sendfunc.cxx
+++ b/sc/source/ui/collab/sendfunc.cxx
@@ -260,7 +260,7 @@ public:
mpCollab = pCollab;
}
- DECL_LINK( ReceiverCallback, TeleConference* );
+ void packetReceived( TeleConference* pConference);
DECL_LINK( ReceiveFileCallback, rtl::OUString * );
void RecvMessage( const rtl::OString &rString )
@@ -300,12 +300,11 @@ public:
}
};
-IMPL_LINK( ScDocFuncRecv, ReceiverCallback, TeleConference*, pConference )
+void ScDocFuncRecv::packetReceived( TeleConference* pConference)
{
rtl::OString aStr;
if (mpCollab && mpCollab->recvPacket( aStr, pConference))
RecvMessage( aStr);
- return 0;
}
IMPL_LINK( ScDocFuncRecv, ReceiveFileCallback, rtl::OUString *, pStr )
@@ -552,8 +551,9 @@ SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc()
ScDocFuncSend* pSender = new ScDocFuncSend( *this, pReceiver );
bool bOk = true;
ScCollaboration* pCollab = new ScCollaboration(
- LINK( pReceiver, ScDocFuncRecv, ReceiverCallback),
LINK( pReceiver, ScDocFuncRecv, ReceiveFileCallback) );
+ pCollab->sigPacketReceived.connect(
+ boost::bind( &ScDocFuncRecv::packetReceived, pReceiver, _1 ));
bOk = bOk && pCollab->initManager();
if (!strcmp( pEnv, "master"))
{
diff --git a/sc/source/ui/inc/collab.hxx b/sc/source/ui/inc/collab.hxx
index c761e9d..faf8145 100644
--- a/sc/source/ui/inc/collab.hxx
+++ b/sc/source/ui/inc/collab.hxx
@@ -31,6 +31,7 @@
#include <sal/config.h>
#include <tools/link.hxx>
+#include <boost/signals2.hpp>
typedef struct _TpContact TpContact;
typedef struct _TpAccount TpAccount;
@@ -43,25 +44,29 @@ class ScCollaboration
public:
/** @param rLink
- Callback when a packet is received, called with TeleConference*
- @param rLink
Callback when a file is received, called with TeleConference*
*/
- ScCollaboration( const Link& rLinkPacket,
- const Link& rLinkFile );
+ ScCollaboration( const Link& rLinkFile );
~ScCollaboration();
bool initManager();
bool initAccountContact();
bool startCollaboration();
+
bool sendPacket( const rtl::OString& rString );
+ /** Emitted when a packet is received
+ */
+ boost::signals2::signal<void (TeleConference*)> sigPacketReceived;
bool recvPacket( rtl::OString& rString, TeleConference* pConference );
+
void sendFile( rtl::OUString &rFileURL );
void receivedFile( rtl::OUString &rFileURL );
+ /* Internal callbacks */
+ void packetReceivedCallback( TeleConference *pConference );
+
private:
- Link maLinkPacket;
Link maLinkFile;
TpAccount* mpAccount;
TpContact* mpContact;
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx
index defb4f9..f7edbfa 100644
--- a/tubes/inc/tubes/manager.hxx
+++ b/tubes/inc/tubes/manager.hxx
@@ -40,6 +40,7 @@
#include <tools/link.hxx>
#include <telepathy-glib/telepathy-glib.h>
#include <vector>
+#include <boost/signals2.hpp>
// For testing purposes, we might need more in future.
#define LIBO_TUBES_DBUS_MSG_METHOD "LibOMsg"
@@ -72,15 +73,11 @@ public:
/** Prepare tube manager with account and service to be offered/listened
to.
- @param rLink
- Callback when a packet is received. Called with a TeleConference*
- pointing to the instance that received the packet.
-
@param bCreateOwnGMainLoop
Whether to create and iterate an own GMainLoop. For testing
purposes when no GMainLoop is available.
*/
- TeleManager( const Link& rLink, bool bCreateOwnGMainLoop = false );
+ TeleManager( bool bCreateOwnGMainLoop = false );
~TeleManager();
/** Prepare the Telepathy Account Manager. Requires connect() to have succeeded.
@@ -139,8 +136,12 @@ public:
*/
sal_uInt32 sendPacket( const TelePacket& rPacket ) const;
- /** Calls the callback Link set with ctor. */
- long callbackOnRecieved( TeleConference* pConference ) const;
+ /** Emitted when a packet is received, with a TeleConference*
+ pointing to the instance that received the packet.
+ */
+ boost::signals2::signal<void (TeleConference*)> sigPacketReceived;
+ /* FIXME: listen to a signal on the conference rather than having it call us */
+ void callbackOnRecieved( TeleConference* pConference ) const;
/** Pop a received data packet.
@@ -218,8 +219,6 @@ public:
static void TransferDone( EmpathyFTHandler *handler, TpFileTransferChannel *, gpointer user_data);
private:
-
- Link maLink;
TeleConferenceVector maConferences;
bool mbChannelReadyHandlerInvoked : 1;
diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx
index f76353d..ebd3176 100644
--- a/tubes/qa/test_manager.cxx
+++ b/tubes/qa/test_manager.cxx
@@ -65,7 +65,8 @@ public:
void testDestroyManager2();
void testDestroyAccepterContact();
void testFailAlways();
- DECL_STATIC_LINK( TestTeleTubes, ReceiverCallback, TeleConference* );
+
+ void ReceiverCallback( TeleConference* pConference );
GMainLoop* mpMainLoop;
void spinMainLoop();
@@ -107,6 +108,8 @@ private:
bool maFileSentSuccess;
rtl::OUString maFileReceivedUri;
+
+ sal_uInt32 mnPacketReceivedEmissions;
};
// static, not members, so they actually survive cppunit test iteration
@@ -130,7 +133,8 @@ timed_out (void *user_data)
TestTeleTubes::TestTeleTubes()
: maTestConfigIniURL(getURLFromSrc("/tubes/qa/test-config.ini")),
- maTestConfig(maTestConfigIniURL)
+ maTestConfig(maTestConfigIniURL),
+ mnPacketReceivedEmissions(0)
{
TeleManager::addSuffixToNames( "TeleTest");
@@ -207,12 +211,12 @@ void TestTeleTubes::testContactList()
void TestTeleTubes::testSetupManager1()
{
- mpManager1 = new TeleManager( STATIC_LINK( this, TestTeleTubes, ReceiverCallback), true);
+ mpManager1 = new TeleManager( true);
}
void TestTeleTubes::testSetupManager2()
{
- mpManager2 = new TeleManager( STATIC_LINK( this, TestTeleTubes, ReceiverCallback));
+ mpManager2 = new TeleManager();
}
void TestTeleTubes::testPrepareAccountManager1()
@@ -229,14 +233,14 @@ void TestTeleTubes::testPrepareAccountManager2()
CPPUNIT_ASSERT( eStatus == TeleManager::AMS_PREPARED);
}
-IMPL_STATIC_LINK_NOINSTANCE( TestTeleTubes, ReceiverCallback, TeleConference*, pConference )
+void TestTeleTubes::ReceiverCallback( TeleConference* pConference )
{
SAL_INFO( "tubes", "TestTeleTubes::ReceiverCallback: " << pConference);
if (pConference)
{
// we could pop a packet here
+ mnPacketReceivedEmissions++;
}
- return 0;
}
void TestTeleTubes::testStartBuddySession1()
@@ -270,8 +274,11 @@ void TestTeleTubes::testConnect2()
void TestTeleTubes::testSendPacket()
{
TelePacket aPacket( "", RTL_CONSTASCII_STRINGPARAM( "from 1 to 2"));
+
+ mpManager1->sigPacketReceived.connect( boost::bind( &TestTeleTubes::ReceiverCallback, this, _1 ) );
nSentPackets = mpManager1->sendPacket( aPacket);
CPPUNIT_ASSERT( nSentPackets == 2); // expect out+in conference, as own instance accepted self
+ CPPUNIT_ASSERT( mnPacketReceivedEmissions == 2 );
}
void TestTeleTubes::testReceivePacket()
@@ -285,6 +292,7 @@ void TestTeleTubes::testReceivePacket()
*/
sal_uInt32 nExpectedPackets = nSentPackets * 2;
bool bOk;
+
do
{
do
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index 8a4c0c6..088080d 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -354,9 +354,8 @@ static void TeleManager_AccountManagerReadyHandler(
}
-TeleManager::TeleManager( const Link& rLink, bool bCreateOwnGMainLoop )
+TeleManager::TeleManager( bool bCreateOwnGMainLoop )
:
- maLink( rLink),
mbChannelReadyHandlerInvoked( false)
{
// The glib object types need to be initialized, else we aren't going
@@ -719,13 +718,11 @@ sal_uInt32 TeleManager::sendPacket( const TelePacket& rPacket ) const
}
-long TeleManager::callbackOnRecieved( TeleConference* pConference ) const
+void TeleManager::callbackOnRecieved( TeleConference* pConference ) const
{
INFO_LOGGER( "TeleManager::callbackOnRecieved");
- if (maLink.IsSet())
- return maLink.Call( pConference);
- return 0;
+ sigPacketReceived( pConference );
}
commit 6720ad10f1cc6d315a48f18152e50bd4f2d234f5
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Fri Mar 23 16:11:16 2012 +0000
ContactList: ask for avatar data for our contacts
diff --git a/tubes/source/contact-list.cxx b/tubes/source/contact-list.cxx
index 317f5d7..c74a950 100644
--- a/tubes/source/contact-list.cxx
+++ b/tubes/source/contact-list.cxx
@@ -59,6 +59,7 @@ ContactList::ContactList(TpAccountManager *pAccountManager)
*/
tp_simple_client_factory_add_contact_features_varargs (factory,
TP_CONTACT_FEATURE_ALIAS,
+ TP_CONTACT_FEATURE_AVATAR_DATA,
TP_CONTACT_FEATURE_CAPABILITIES,
TP_CONTACT_FEATURE_INVALID);
}
commit f3daeda5362615db38bb42be847486d72daa8653
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Fri Mar 23 15:40:25 2012 +0000
tubes: delete MainLoopFlusher
This doesn't actually seem to have any effect on the test passing or
failing.
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx
index 3d557ad..defb4f9 100644
--- a/tubes/inc/tubes/manager.hxx
+++ b/tubes/inc/tubes/manager.hxx
@@ -238,34 +238,6 @@ private:
};
-/** The most ugly workaround for not having a GMainLoop running, i.e. in
- cppunittest.
- */
-class MainLoopFlusher
-{
-public:
- explicit MainLoopFlusher( const TeleManager* pManager )
- :
- mpManager( pManager)
- {
- flush();
- }
-
- ~MainLoopFlusher()
- {
- flush();
- }
-
- void flush() const
- {
- mpManager->flushLoop();
- }
-
-private:
- const TeleManager* mpManager;
-};
-
-
#endif // INCLUDED_TUBES_MANAGER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index 87f1f11..8a4c0c6 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -394,8 +394,6 @@ bool TeleManager::connect()
MutexGuard aGuard( GetMutex());
- MainLoopFlusher aFlusher( this);
-
/* TODO: also check whether client could be registered and retry if not? */
SAL_INFO_IF( pImpl->mpDBus && pImpl->mpClient, "tubes", "TeleManager::connect: already connected");
if (pImpl->mpDBus && pImpl->mpClient)
@@ -510,8 +508,6 @@ bool TeleManager::startGroupSession( const rtl::OUString& rUConferenceRoom, cons
{
INFO_LOGGER( "TeleManager::startGroupSession");
- MainLoopFlusher aFlusher( this);
-
if (!getMyAccount())
return false;
@@ -574,8 +570,6 @@ bool TeleManager::startBuddySession( TpAccount *pAccount, TpContact *pBuddy )
{
INFO_LOGGER( "TeleManager::startBuddySession");
- MainLoopFlusher aFlusher( this);
-
OString aSessionId( TeleManager::createUuid());
TeleConferencePtr pConference( new TeleConference( this, NULL, NULL, aSessionId));
@@ -622,8 +616,6 @@ void TeleManager::prepareAccountManager()
MutexGuard aGuard( GetMutex());
- MainLoopFlusher aFlusher( this);
-
SAL_INFO_IF( pImpl->meAccountManagerStatus == AMS_PREPARED, "tubes",
"TeleManager::prepareAccountManager: already prepared");
if (pImpl->meAccountManagerStatus == AMS_PREPARED)
@@ -677,8 +669,6 @@ TpAccount* TeleManager::getAccount( const rtl::OString& rAccountID )
{
INFO_LOGGER( "TeleManager::getMyAccount");
- MainLoopFlusher aFlusher( this);
-
SAL_WARN_IF( pImpl->meAccountManagerStatus != AMS_PREPARED, "tubes",
"TeleManager::getMyAccount: Account Manager not prepared");
if (pImpl->meAccountManagerStatus != AMS_PREPARED)
@@ -715,8 +705,6 @@ sal_uInt32 TeleManager::sendPacket( const TelePacket& rPacket ) const
{
INFO_LOGGER( "TeleManager::sendPacket");
- MainLoopFlusher aFlusher( this);
-
sal_uInt32 nSent = 0;
// Access to data ByteStream array forces reference count of one, provide
// non-const instance here before passing it down to each conference.
@@ -785,8 +773,6 @@ void TeleManager::disconnect()
{
INFO_LOGGER( "TeleManager::disconnect");
- //! No MainLoopFlusher here!
-
if (!pImpl->mpClient)
return;
@@ -818,8 +804,6 @@ void TeleManager::acceptTube( TpAccount* pAccount, TpChannel* pChannel, const ch
SAL_INFO( "tubes", "TeleManager::acceptTube: address " << pAddress);
- MainLoopFlusher aFlusher( this);
-
SAL_WARN_IF( !pChannel || !pAddress, "tubes", "TeleManager::acceptTube: no channel or no address");
if (!pChannel || !pAddress)
return;
commit 3d8389c5eb032d69c609680cfa8473a5ab267b42
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Fri Mar 23 15:04:11 2012 +0000
tubes: reinstate erroneously-commented unrefs
I think I commented these out while hunting stack corruption.
diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx
index 5bd0f62..87f1f11 100644
--- a/tubes/source/manager.cxx
+++ b/tubes/source/manager.cxx
@@ -187,14 +187,14 @@ void TeleManager::TransferDone( EmpathyFTHandler *handler, TpFileTransferChannel
pManager->mpFileReceivedCallback( aUri, pManager->mpFileReceivedCallbackData);
- //g_object_unref( handler);
+ g_object_unref( handler);
}
static void TeleManager_TransferError( EmpathyFTHandler *handler, const GError *error, void*)
{
SAL_INFO( "tubes", "TeleConference_TransferError: " << error->message);
- //g_object_unref( handler);
+ g_object_unref( handler);
}
static void
More information about the Libreoffice-commits
mailing list