Kaydet (Commit) 70a5f05a authored tarafından Eike Rathke's avatar Eike Rathke Kaydeden (comit) Matúš Kukan

tubes: wrapper to enable tubes

If environment variable LIBO_TUBES is set, Calc's ScDocFuncSend and
ScDocFuncRecv act over tubes.
üst 14efb92f
/* -*- 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: */
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "cell.hxx" #include "cell.hxx"
#include "docsh.hxx" #include "docsh.hxx"
#include "docfunc.hxx" #include "docfunc.hxx"
#include "collab.hxx"
#include <tubes/conference.hxx>
// new file send/recv fun ... // new file send/recv fun ...
#include <unotools/tempfile.hxx> #include <unotools/tempfile.hxx>
...@@ -233,16 +235,25 @@ public: ...@@ -233,16 +235,25 @@ public:
class ScDocFuncRecv : public ScDocFunc class ScDocFuncRecv : public ScDocFunc
{ {
ScDocFunc *mpChain; ScDocFunc *mpChain;
ScCollaboration* mpCollab;
public: public:
// FIXME: really ScDocFunc should be an abstract base // FIXME: really ScDocFunc should be an abstract base
ScDocFuncRecv( ScDocShell& rDocSh, ScDocFunc *pChain ) ScDocFuncRecv( ScDocShell& rDocSh, ScDocFunc *pChain )
: ScDocFunc( rDocSh ), : ScDocFunc( rDocSh ),
mpChain( pChain ) mpChain( pChain ),
mpCollab( NULL)
{ {
fprintf( stderr, "Receiver created !\n" ); fprintf( stderr, "Receiver created !\n" );
} }
virtual ~ScDocFuncRecv() {} virtual ~ScDocFuncRecv() {}
void SetCollaboration( ScCollaboration* pCollab )
{
mpCollab = pCollab;
}
DECL_LINK( ReceiverCallback, TeleConference* );
void RecvMessage( const rtl::OString &rString ) void RecvMessage( const rtl::OString &rString )
{ {
try { try {
...@@ -280,14 +291,26 @@ public: ...@@ -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 class ScDocFuncSend : public ScDocFunc
{ {
ScDocFuncRecv *mpChain; ScDocFuncRecv *mpChain;
ScCollaboration* mpCollab;
void SendMessage( ScChangeOpWriter &rOp ) void SendMessage( ScChangeOpWriter &rOp )
{ {
fprintf( stderr, "Op: '%s'\n", rOp.toString().getStr() ); 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 ) void SendFile( const rtl::OUString &rURL )
...@@ -321,12 +344,18 @@ public: ...@@ -321,12 +344,18 @@ public:
// we don't need the rDocSh hack/pointer // we don't need the rDocSh hack/pointer
ScDocFuncSend( ScDocShell& rDocSh, ScDocFuncRecv *pChain ) ScDocFuncSend( ScDocShell& rDocSh, ScDocFuncRecv *pChain )
: ScDocFunc( rDocSh ), : ScDocFunc( rDocSh ),
mpChain( pChain ) mpChain( pChain ),
mpCollab( NULL)
{ {
fprintf( stderr, "Sender created !\n" ); fprintf( stderr, "Sender created !\n" );
} }
virtual ~ScDocFuncSend() {} virtual ~ScDocFuncSend() {}
void SetCollaboration( ScCollaboration* pCollab )
{
mpCollab = pCollab;
}
virtual void EnterListAction( sal_uInt16 nNameResId ) virtual void EnterListAction( sal_uInt16 nNameResId )
{ {
// Want to group these operations for the other side ... // Want to group these operations for the other side ...
...@@ -441,9 +470,30 @@ public: ...@@ -441,9 +470,30 @@ public:
SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc() 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")) if (getenv ("INTERCEPT"))
return new ScDocFuncSend( *this, new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) ) ); 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 else
return new ScDocFuncDirect( *this ); return new ScDocFuncDirect( *this );
} }
......
/* -*- 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: */
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#define INCLUDED_TUBES_CONFERENCE_HXX #define INCLUDED_TUBES_CONFERENCE_HXX
#include <sal/config.h> #include <sal/config.h>
#include "tubes/tubesdllapi.h"
#include "tubes/packet.hxx" #include "tubes/packet.hxx"
#include "tubes/file-transfer-helper.h" #include "tubes/file-transfer-helper.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
...@@ -65,7 +66,7 @@ public: ...@@ -65,7 +66,7 @@ public:
bool sendPacket( TelePacket& rPacket ) const; bool sendPacket( TelePacket& rPacket ) const;
/** Pop a received packet. */ /** Pop a received packet. */
bool popPacket( TelePacket& rPacket ); TUBES_DLLPUBLIC bool popPacket( TelePacket& rPacket );
/** Queue incoming data as TelePacket */ /** Queue incoming data as TelePacket */
void queue( const char* pDBusSender, const char* pPacket, int nSize ); void queue( const char* pDBusSender, const char* pPacket, int nSize );
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <salhelper/thread.hxx> #include <salhelper/thread.hxx>
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <tools/link.hxx>
#include <telepathy-glib/telepathy-glib.h> #include <telepathy-glib/telepathy-glib.h>
#include <vector> #include <vector>
...@@ -70,11 +71,15 @@ public: ...@@ -70,11 +71,15 @@ public:
/** Prepare tube manager with account and service to be offered/listened /** Prepare tube manager with account and service to be offered/listened
to. to.
@param rLink
Callback when a packet is received. Called with a TeleConference*
pointing to the instance that received the packet.
@param bCreateOwnGMainLoop @param bCreateOwnGMainLoop
Whether to create and iterate an own GMainLoop. For testing Whether to create and iterate an own GMainLoop. For testing
purposes when no GMainLoop is available. purposes when no GMainLoop is available.
*/ */
TeleManager( bool bCreateOwnGMainLoop = false ); TeleManager( const Link& rLink, bool bCreateOwnGMainLoop = false );
~TeleManager(); ~TeleManager();
/** Prepare the Telepathy Account Manager. /** Prepare the Telepathy Account Manager.
...@@ -109,9 +114,9 @@ public: ...@@ -109,9 +114,9 @@ public:
The account to use. This must be a valid Jabber account. The account to use. This must be a valid Jabber account.
@param pBuddy @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 ); void unregisterConference( TeleConferencePtr pConference );
...@@ -128,6 +133,9 @@ public: ...@@ -128,6 +133,9 @@ public:
*/ */
sal_uInt32 sendPacket( const TelePacket& rPacket ) const; sal_uInt32 sendPacket( const TelePacket& rPacket ) const;
/** Calls the callback Link set with ctor. */
long callbackOnRecieved( TeleConference* pConference ) const;
/** Pop a received data packet. /** Pop a received data packet.
XXX This needs to be elaborated to pop from a specific conference, or XXX This needs to be elaborated to pop from a specific conference, or
...@@ -205,6 +213,7 @@ public: ...@@ -205,6 +213,7 @@ public:
private: private:
Link maLink;
TeleConferenceVector maConferences; TeleConferenceVector maConferences;
bool mbChannelReadyHandlerInvoked : 1; bool mbChannelReadyHandlerInvoked : 1;
......
...@@ -65,6 +65,7 @@ public: ...@@ -65,6 +65,7 @@ public:
void testDestroyManager2(); void testDestroyManager2();
void testDestroyAccepterContact(); void testDestroyAccepterContact();
void testFailAlways(); void testFailAlways();
DECL_STATIC_LINK( TestTeleTubes, ReceiverCallback, TeleConference* );
GMainLoop* mpMainLoop; GMainLoop* mpMainLoop;
void spinMainLoop(); void spinMainLoop();
...@@ -213,12 +214,12 @@ void TestTeleTubes::testContactList() ...@@ -213,12 +214,12 @@ void TestTeleTubes::testContactList()
void TestTeleTubes::testSetupManager1() void TestTeleTubes::testSetupManager1()
{ {
mpManager1 = new TeleManager( true); mpManager1 = new TeleManager( STATIC_LINK( this, TestTeleTubes, ReceiverCallback), true);
} }
void TestTeleTubes::testSetupManager2() void TestTeleTubes::testSetupManager2()
{ {
mpManager2 = new TeleManager; mpManager2 = new TeleManager( STATIC_LINK( this, TestTeleTubes, ReceiverCallback));
} }
void TestTeleTubes::testPrepareAccountManager1() void TestTeleTubes::testPrepareAccountManager1()
...@@ -235,6 +236,16 @@ void TestTeleTubes::testPrepareAccountManager2() ...@@ -235,6 +236,16 @@ void TestTeleTubes::testPrepareAccountManager2()
CPPUNIT_ASSERT( eStatus == TeleManager::AMS_PREPARED); 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() void TestTeleTubes::testStartBuddySession1()
{ {
TpAccount *pAcc1 = mpManager1->getAccount(maOffererIdentifier); TpAccount *pAcc1 = mpManager1->getAccount(maOffererIdentifier);
......
...@@ -442,6 +442,8 @@ void TeleConference::queue( const char* pDBusSender, const char* pPacketData, in ...@@ -442,6 +442,8 @@ void TeleConference::queue( const char* pDBusSender, const char* pPacketData, in
INFO_LOGGER( "TeleConference::queue"); INFO_LOGGER( "TeleConference::queue");
maPacketQueue.push( TelePacket( pDBusSender, pPacketData, nPacketSize)); maPacketQueue.push( TelePacket( pDBusSender, pPacketData, nPacketSize));
getManager()->callbackOnRecieved( this);
} }
......
...@@ -338,8 +338,9 @@ static void TeleManager_AccountManagerReadyHandler( ...@@ -338,8 +338,9 @@ static void TeleManager_AccountManagerReadyHandler(
} }
TeleManager::TeleManager( bool bCreateOwnGMainLoop ) TeleManager::TeleManager( const Link& rLink, bool bCreateOwnGMainLoop )
: :
maLink( rLink),
mbChannelReadyHandlerInvoked( false) mbChannelReadyHandlerInvoked( false)
{ {
MutexGuard aGuard( GetMutex()); MutexGuard aGuard( GetMutex());
...@@ -705,6 +706,16 @@ sal_uInt32 TeleManager::sendPacket( const TelePacket& rPacket ) const ...@@ -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 ) bool TeleManager::popPacket( TelePacket& rPacket )
{ {
INFO_LOGGER( "TeleManager::popPacket"); INFO_LOGGER( "TeleManager::popPacket");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment