diff options
author | Eike Rathke <erack@redhat.com> | 2012-03-23 10:55:09 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2012-07-17 16:39:40 +0200 |
commit | 70a5f05a4f08b45acc13df80e7b7ee5cb2610c52 (patch) | |
tree | 0361115ff2ee66fa37b7b9e20fd806d3b05c95de | |
parent | 14efb92f907215f72cf841da98996bc9d39fc9e7 (diff) |
tubes: wrapper to enable tubes
If environment variable LIBO_TUBES is set, Calc's ScDocFuncSend and
ScDocFuncRecv act over tubes.
-rw-r--r-- | sc/source/ui/collab/collab.cxx | 99 | ||||
-rw-r--r-- | sc/source/ui/collab/sendfunc.cxx | 58 | ||||
-rw-r--r-- | sc/source/ui/inc/collab.hxx | 67 | ||||
-rw-r--r-- | tubes/inc/tubes/conference.hxx | 3 | ||||
-rw-r--r-- | tubes/inc/tubes/manager.hxx | 15 | ||||
-rw-r--r-- | tubes/qa/test_manager.cxx | 15 | ||||
-rw-r--r-- | tubes/source/conference.cxx | 2 | ||||
-rw-r--r-- | tubes/source/manager.cxx | 13 |
8 files changed, 261 insertions, 11 deletions
diff --git a/sc/source/ui/collab/collab.cxx b/sc/source/ui/collab/collab.cxx new file mode 100644 index 000000000000..bc0c99e8a05e --- /dev/null +++ b/sc/source/ui/collab/collab.cxx @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Red Hat, Inc., Eike Rathke <erack@redhat.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include "collab.hxx" +#include <tubes/manager.hxx> +#include <tubes/conference.hxx> +#include <tubes/contact-list.hxx> + +ScCollaboration::ScCollaboration( const Link& rLink ) + : + maLink( rLink), + mpAccount( NULL), + mpContact( NULL), + mpManager( NULL) +{ +} + + +ScCollaboration::~ScCollaboration() +{ + if (mpAccount) + g_object_unref( mpAccount); + if (mpContact) + g_object_unref( mpContact); + delete mpManager; +} + + +bool ScCollaboration::initManager() +{ + mpManager = new TeleManager( maLink); + bool bOk = mpManager->connect(); + return bOk; +} + + +bool ScCollaboration::initAccountContact() +{ + ContactList aContacts; + AccountContactPairV aVec( aContacts.getContacts()); + if (aVec.empty()) + return false; + + /* TODO: select a pair, for now just take the first */ + mpAccount = aVec[0].first; + mpContact = aVec[0].second; + return true; +} + + +bool ScCollaboration::startCollaboration() +{ + bool bOk = mpManager->startBuddySession( mpAccount, mpContact); + return bOk; +} + + +bool ScCollaboration::sendPacket( const rtl::OString& rString ) +{ + TelePacket aPacket( "sender", rString.getStr(), rString.getLength()); + bool bOk = mpManager->sendPacket( aPacket); + return bOk; +} + + +bool ScCollaboration::recvPacket( rtl::OString& rString, TeleConference* pConference ) +{ + TelePacket aPacket; + bool bOk = (pConference ? pConference->popPacket( aPacket) : mpManager->popPacket( aPacket)); + rString = rtl::OString( aPacket.getData(), aPacket.getSize()); + return bOk; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx index 9d9a10c37297..ed089558ee25 100644 --- a/sc/source/ui/collab/sendfunc.cxx +++ b/sc/source/ui/collab/sendfunc.cxx @@ -33,6 +33,8 @@ #include "cell.hxx" #include "docsh.hxx" #include "docfunc.hxx" +#include "collab.hxx" +#include <tubes/conference.hxx> // new file send/recv fun ... #include <unotools/tempfile.hxx> @@ -233,16 +235,25 @@ public: class ScDocFuncRecv : public ScDocFunc { ScDocFunc *mpChain; + ScCollaboration* mpCollab; public: // FIXME: really ScDocFunc should be an abstract base ScDocFuncRecv( ScDocShell& rDocSh, ScDocFunc *pChain ) : ScDocFunc( rDocSh ), - mpChain( pChain ) + mpChain( pChain ), + mpCollab( NULL) { fprintf( stderr, "Receiver created !\n" ); } virtual ~ScDocFuncRecv() {} + void SetCollaboration( ScCollaboration* pCollab ) + { + mpCollab = pCollab; + } + + DECL_LINK( ReceiverCallback, TeleConference* ); + void RecvMessage( const rtl::OString &rString ) { try { @@ -280,14 +291,26 @@ public: } }; +IMPL_LINK( ScDocFuncRecv, ReceiverCallback, TeleConference*, pConference ) +{ + rtl::OString aStr; + if (mpCollab && mpCollab->recvPacket( aStr, pConference)) + RecvMessage( aStr); + return 0; +} + class ScDocFuncSend : public ScDocFunc { ScDocFuncRecv *mpChain; + ScCollaboration* mpCollab; void SendMessage( ScChangeOpWriter &rOp ) { fprintf( stderr, "Op: '%s'\n", rOp.toString().getStr() ); - mpChain->RecvMessage( rOp.toString() ); + if (mpCollab) + mpCollab->sendPacket( rOp.toString()); + else + mpChain->RecvMessage( rOp.toString() ); } void SendFile( const rtl::OUString &rURL ) @@ -321,12 +344,18 @@ public: // we don't need the rDocSh hack/pointer ScDocFuncSend( ScDocShell& rDocSh, ScDocFuncRecv *pChain ) : ScDocFunc( rDocSh ), - mpChain( pChain ) + mpChain( pChain ), + mpCollab( NULL) { fprintf( stderr, "Sender created !\n" ); } virtual ~ScDocFuncSend() {} + void SetCollaboration( ScCollaboration* pCollab ) + { + mpCollab = pCollab; + } + virtual void EnterListAction( sal_uInt16 nNameResId ) { // Want to group these operations for the other side ... @@ -441,9 +470,30 @@ public: SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc() { - // FIXME: the chains should be auto-ptrs. + // FIXME: the chains should be auto-ptrs, so should be collab if (getenv ("INTERCEPT")) return new ScDocFuncSend( *this, new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) ) ); + else if (getenv ("LIBO_TUBES")) + { + ScDocFuncRecv* pReceiver = new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) ); + ScDocFuncSend* pSender = new ScDocFuncSend( *this, pReceiver ); + bool bOk = true; + ScCollaboration* pCollab = new ScCollaboration( LINK( pReceiver, ScDocFuncRecv, ReceiverCallback)); + bOk = bOk && pCollab->initManager(); + bOk = bOk && pCollab->initAccountContact(); + bOk = bOk && pCollab->startCollaboration(); + if (bOk) + { + pReceiver->SetCollaboration( pCollab); + pSender->SetCollaboration( pCollab); + } + else + { + fprintf( stderr, "Could not start collaboration.\n"); + delete pCollab; + } + return pSender; + } else return new ScDocFuncDirect( *this ); } diff --git a/sc/source/ui/inc/collab.hxx b/sc/source/ui/inc/collab.hxx new file mode 100644 index 000000000000..8ef392ff2829 --- /dev/null +++ b/sc/source/ui/inc/collab.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Red Hat, Inc., Eike Rathke <erack@redhat.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#ifndef INCLUDED_SC_COLLAB_HXX +#define INCLUDED_SC_COLLAB_HXX + +#include <sal/config.h> +#include <tools/link.hxx> + +typedef struct _TpContact TpContact; +typedef struct _TpAccount TpAccount; +class TeleManager; +class TeleConference; +namespace rtl { class OString; } + +class ScCollaboration +{ +public: + + /** @param rLink + Callback when a packet is received, called with TeleConference* + */ + ScCollaboration( const Link& rLink ); + ~ScCollaboration(); + + bool initManager(); + bool initAccountContact(); + bool startCollaboration(); + bool sendPacket( const rtl::OString& rString ); + bool recvPacket( rtl::OString& rString, TeleConference* pConference ); + +private: + + Link maLink; + TpAccount* mpAccount; + TpContact* mpContact; + TeleManager* mpManager; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tubes/inc/tubes/conference.hxx b/tubes/inc/tubes/conference.hxx index 7c5fd30bd994..8a891d579a36 100644 --- a/tubes/inc/tubes/conference.hxx +++ b/tubes/inc/tubes/conference.hxx @@ -30,6 +30,7 @@ #define INCLUDED_TUBES_CONFERENCE_HXX #include <sal/config.h> +#include "tubes/tubesdllapi.h" #include "tubes/packet.hxx" #include "tubes/file-transfer-helper.h" #include <boost/shared_ptr.hpp> @@ -65,7 +66,7 @@ public: bool sendPacket( TelePacket& rPacket ) const; /** Pop a received packet. */ - bool popPacket( TelePacket& rPacket ); + TUBES_DLLPUBLIC bool popPacket( TelePacket& rPacket ); /** Queue incoming data as TelePacket */ void queue( const char* pDBusSender, const char* pPacket, int nSize ); diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx index 0d2ef3eec745..aa6a027726af 100644 --- a/tubes/inc/tubes/manager.hxx +++ b/tubes/inc/tubes/manager.hxx @@ -36,6 +36,7 @@ #include <rtl/ustring.hxx> #include <salhelper/thread.hxx> #include <rtl/ref.hxx> +#include <tools/link.hxx> #include <telepathy-glib/telepathy-glib.h> #include <vector> @@ -70,11 +71,15 @@ 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( bool bCreateOwnGMainLoop = false ); + TeleManager( const Link& rLink, bool bCreateOwnGMainLoop = false ); ~TeleManager(); /** Prepare the Telepathy Account Manager. @@ -109,9 +114,9 @@ public: The account to use. This must be a valid Jabber account. @param pBuddy - The buddy to be connected. Must be a contact of rAccount. + The buddy to be connected. Must be a contact of pAccount. */ - bool startBuddySession( TpAccount *pAccount, TpContact *pBuddy); + bool startBuddySession( TpAccount *pAccount, TpContact *pBuddy ); void unregisterConference( TeleConferencePtr pConference ); @@ -128,6 +133,9 @@ public: */ sal_uInt32 sendPacket( const TelePacket& rPacket ) const; + /** Calls the callback Link set with ctor. */ + long callbackOnRecieved( TeleConference* pConference ) const; + /** Pop a received data packet. XXX This needs to be elaborated to pop from a specific conference, or @@ -205,6 +213,7 @@ public: private: + Link maLink; TeleConferenceVector maConferences; bool mbChannelReadyHandlerInvoked : 1; diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx index 540728a5fa39..31148efe5f13 100644 --- a/tubes/qa/test_manager.cxx +++ b/tubes/qa/test_manager.cxx @@ -65,6 +65,7 @@ public: void testDestroyManager2(); void testDestroyAccepterContact(); void testFailAlways(); + DECL_STATIC_LINK( TestTeleTubes, ReceiverCallback, TeleConference* ); GMainLoop* mpMainLoop; void spinMainLoop(); @@ -213,12 +214,12 @@ void TestTeleTubes::testContactList() void TestTeleTubes::testSetupManager1() { - mpManager1 = new TeleManager( true); + mpManager1 = new TeleManager( STATIC_LINK( this, TestTeleTubes, ReceiverCallback), true); } void TestTeleTubes::testSetupManager2() { - mpManager2 = new TeleManager; + mpManager2 = new TeleManager( STATIC_LINK( this, TestTeleTubes, ReceiverCallback)); } void TestTeleTubes::testPrepareAccountManager1() @@ -235,6 +236,16 @@ void TestTeleTubes::testPrepareAccountManager2() CPPUNIT_ASSERT( eStatus == TeleManager::AMS_PREPARED); } +IMPL_STATIC_LINK_NOINSTANCE( TestTeleTubes, ReceiverCallback, TeleConference*, pConference ) +{ + SAL_INFO( "tubes", "TestTeleTubes::ReceiverCallback: " << pConference); + if (pConference) + { + // we could pop a packet here + } + return 0; +} + void TestTeleTubes::testStartBuddySession1() { TpAccount *pAcc1 = mpManager1->getAccount(maOffererIdentifier); diff --git a/tubes/source/conference.cxx b/tubes/source/conference.cxx index 88ec817a3170..d48807d1b933 100644 --- a/tubes/source/conference.cxx +++ b/tubes/source/conference.cxx @@ -442,6 +442,8 @@ void TeleConference::queue( const char* pDBusSender, const char* pPacketData, in INFO_LOGGER( "TeleConference::queue"); maPacketQueue.push( TelePacket( pDBusSender, pPacketData, nPacketSize)); + + getManager()->callbackOnRecieved( this); } diff --git a/tubes/source/manager.cxx b/tubes/source/manager.cxx index cb9e5d7a72b0..fd852ae170dd 100644 --- a/tubes/source/manager.cxx +++ b/tubes/source/manager.cxx @@ -338,8 +338,9 @@ static void TeleManager_AccountManagerReadyHandler( } -TeleManager::TeleManager( bool bCreateOwnGMainLoop ) +TeleManager::TeleManager( const Link& rLink, bool bCreateOwnGMainLoop ) : + maLink( rLink), mbChannelReadyHandlerInvoked( false) { MutexGuard aGuard( GetMutex()); @@ -705,6 +706,16 @@ sal_uInt32 TeleManager::sendPacket( const TelePacket& rPacket ) const } +long TeleManager::callbackOnRecieved( TeleConference* pConference ) const +{ + INFO_LOGGER( "TeleManager::callbackOnRecieved"); + + if (maLink.IsSet()) + return maLink.Call( pConference); + return 0; +} + + bool TeleManager::popPacket( TelePacket& rPacket ) { INFO_LOGGER( "TeleManager::popPacket"); |