[Libreoffice-commits] .: Branch 'feature/tubes2' - 5 commits - sc/source tubes/inc

2012-06-29 Thread Matus Kukan
 sc/source/ui/collab/contacts.cxx |   29 +
 sc/source/ui/collab/contacts.hxx |2 +-
 sc/source/ui/collab/sendfunc.cxx |6 +-
 sc/source/ui/collab/sendfunc.hxx |1 -
 sc/source/ui/view/cellsh3.cxx|4 ++--
 tubes/inc/tubes/manager.hxx  |1 +
 6 files changed, 26 insertions(+), 17 deletions(-)

New commits:
commit 9fb21707db92e051493a3e959308a37112d32ffe
Author: Matúš Kukan matus.ku...@gmail.com
Date:   Fri Jun 29 19:30:46 2012 +0200

tubes: fallback to master mode when not possible to init TeleManager as 
slave

diff --git a/sc/source/ui/collab/contacts.cxx b/sc/source/ui/collab/contacts.cxx
index 7ef5ab0..0c70585 100644
--- a/sc/source/ui/collab/contacts.cxx
+++ b/sc/source/ui/collab/contacts.cxx
@@ -76,7 +76,18 @@ class TubeContacts : public ModelessDialog
 pSender = new ScDocFuncSend( *pScDocShell, pReceiver );
 pDocFunc = pSender;
 }
-pSender-InitTeleManager( false );
+// This is a hack to work around:
+//  `error registering client handler: Name
+//  'org.freedesktop.Telepathy.Client.LibreOffice' already in use by 
another process`
+// This happens when there is already slave instance running,
+// so we try to init TeleManager as master.
+bool bIsMaster = false;
+if (!pSender-InitTeleManager( bIsMaster ))
+{
+fprintf( stderr, Trying to initialize TeleManager as master..\n 
);
+bIsMaster = true;
+pSender-InitTeleManager( bIsMaster );
+}
 }
 
 void StartBuddySession()
commit 26ff9e3b06efcefb1b9cda2b41378fcb23a01ece
Author: Matúš Kukan matus.ku...@gmail.com
Date:   Fri Jun 29 19:17:59 2012 +0200

tubes: unref TeleManager if we do not store the pointer

diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx
index f58fd6a..9ab6e78 100644
--- a/sc/source/ui/collab/sendfunc.cxx
+++ b/sc/source/ui/collab/sendfunc.cxx
@@ -302,6 +302,7 @@ bool ScDocFuncSend::InitTeleManager( bool bIsMaster )
 return true;
 }
 fprintf( stderr, Could not connect.\n );
+pManager-unref();
 return false;
 }
 
commit c81e93931f42567f4e662804129d97b6e0cfa0d7
Author: Matúš Kukan matus.ku...@gmail.com
Date:   Fri Jun 29 19:15:40 2012 +0200

tubes: use new TeleManager::get() method without parameter

diff --git a/sc/source/ui/collab/contacts.cxx b/sc/source/ui/collab/contacts.cxx
index bd6e6d4..7ef5ab0 100644
--- a/sc/source/ui/collab/contacts.cxx
+++ b/sc/source/ui/collab/contacts.cxx
@@ -132,9 +132,11 @@ public:
RTL_TEXTENCODING_UTF8 );
 }
 
-void Populate( const TeleManager rManager )
+void Populate( const TeleManager *pManager )
 {
-ContactList *pContacts = rManager.getContactList();
+if (!pManager)
+return ;
+ContactList *pContacts = pManager-getContactList();
 if ( pContacts )
 {
 fprintf( stderr, contacts !\n );
@@ -193,11 +195,11 @@ IMPL_LINK_NOARG( TubeContacts, BtnListenHdl )
 #endif
 
 namespace tubes {
-void createContacts( const TeleManager rManager )
+void createContacts( const TeleManager *pManager )
 {
 #ifdef CONTACTS_DLG
 TubeContacts *pContacts = new TubeContacts();
-pContacts-Populate( rManager );
+pContacts-Populate( pManager );
 #endif
 }
 }
diff --git a/sc/source/ui/collab/contacts.hxx b/sc/source/ui/collab/contacts.hxx
index f7ff6a9..404a6fc 100644
--- a/sc/source/ui/collab/contacts.hxx
+++ b/sc/source/ui/collab/contacts.hxx
@@ -30,7 +30,7 @@
 
 class TeleManager;
 namespace tubes {
-void createContacts( const TeleManager rContacts );
+void createContacts( const TeleManager *pManager );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index 6d3fcf3..e10d5b5 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -60,7 +60,7 @@
 #ifdef ENABLE_TELEPATHY
 #include tubes/manager.hxx
 namespace tubes {
-void createContacts( const TeleManager rContacts );
+void createContacts( const TeleManager *pManager );
 }
 #endif
 
@@ -125,7 +125,7 @@ void ScCellShell::Execute( SfxRequest rReq )
 
 case SID_COLLABORATION:
 #ifdef ENABLE_TELEPATHY
-tubes::createContacts( TeleManager::get( true ) );
+tubes::createContacts( TeleManager::get() );
 #endif
 break;
 
diff --git a/tubes/inc/tubes/manager.hxx b/tubes/inc/tubes/manager.hxx
index 1aba675..c780fd2 100644
--- a/tubes/inc/tubes/manager.hxx
+++ b/tubes/inc/tubes/manager.hxx
@@ -82,6 +82,7 @@ public:
 TeleManager( bool bAcceptIncoming = true, bool bCreateOwnGMainLoop = false 
);
 ~TeleManager();
 
+static TeleManager *get() { return pSingleton; }
 static TeleManager *get( bool bAcceptIncoming );
 voidunref();
 
commit 352c5e358dba7cd575c5579698b2fff348612926

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

2012-03-23 Thread Will Thompson
 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.thomp...@collabora.co.uk
Date:   Fri Mar 23 16:39:43 2012 +

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();
+voidunref();
+
 /** 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();
+
 FileReceivedCallbackmpFileReceivedCallback;
 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.thomp...@collabora.co.uk
Date:   Fri Mar 23 16:25:34 2012 +

tubes: