diff options
-rw-r--r-- | sc/source/ui/collab/collab.cxx | 14 | ||||
-rw-r--r-- | sc/source/ui/collab/sendfunc.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/inc/collab.hxx | 15 | ||||
-rw-r--r-- | tubes/inc/tubes/manager.hxx | 17 | ||||
-rw-r--r-- | tubes/qa/test_manager.cxx | 20 | ||||
-rw-r--r-- | tubes/source/manager.cxx | 9 |
6 files changed, 49 insertions, 34 deletions
diff --git a/sc/source/ui/collab/collab.cxx b/sc/source/ui/collab/collab.cxx index 4c11fb7aaf5d..35fa9b190051 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 adda0d2414da..6980eddd78b3 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 c761e9d214cb..faf81454e864 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 defb4f9ec262..f7edbfa2ff84 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 f76353d70f00..ebd31762b5b4 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 8a4c0c68ed0b..088080d7f1bd 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 ); } |