[Libreoffice-commits] .: Branch 'feature/tubes2' - 2 commits - sc/source

Eike Rathke erack at kemper.freedesktop.org
Wed Mar 28 11:25:07 PDT 2012


 sc/source/ui/collab/sendfunc.cxx |   72 ++++++++++++++++++++++++++-------------
 1 file changed, 48 insertions(+), 24 deletions(-)

New commits:
commit eb452d90e6f8afdff69649881f8b7f2ff0f7b047
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Mar 28 20:24:32 2012 +0200

    tubes: shared_ptr for ScDocFunc chains and ScCollaboration

diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx
index c753eee..26f1ef5 100644
--- a/sc/source/ui/collab/sendfunc.cxx
+++ b/sc/source/ui/collab/sendfunc.cxx
@@ -256,20 +256,19 @@ public:
 
 class ScDocFuncRecv : public ScDocFunc
 {
-    ScDocFunc *mpChain;
-    ScCollaboration* mpCollab;
+    boost::shared_ptr<ScDocFuncDirect>  mpChain;
+    boost::shared_ptr<ScCollaboration>  mpCollab;
 public:
     // FIXME: really ScDocFunc should be an abstract base
-    ScDocFuncRecv( ScDocShell& rDocSh, ScDocFunc *pChain )
+    ScDocFuncRecv( ScDocShell& rDocSh, boost::shared_ptr<ScDocFuncDirect>& pChain )
         : ScDocFunc( rDocSh ),
-          mpChain( pChain ),
-          mpCollab( NULL)
+          mpChain( pChain )
     {
         fprintf( stderr, "Receiver created !\n" );
     }
     virtual ~ScDocFuncRecv() {}
 
-    void SetCollaboration( ScCollaboration* pCollab )
+    void SetCollaboration( boost::shared_ptr<ScCollaboration>& pCollab )
     {
         mpCollab = pCollab;
     }
@@ -380,8 +379,8 @@ void ScDocFuncRecv::fileReceived( rtl::OUString *pStr )
 
 class ScDocFuncSend : public ScDocFunc
 {
-    ScDocFuncRecv *mpChain;
-    ScCollaboration* mpCollab;
+    boost::shared_ptr<ScDocFuncRecv>    mpChain;
+    boost::shared_ptr<ScCollaboration>  mpCollab;
 
     void SendMessage( ScChangeOpWriter &rOp )
     {
@@ -424,16 +423,15 @@ class ScDocFuncSend : public ScDocFunc
 public:
     // FIXME: really ScDocFunc should be an abstract base, so
     // we don't need the rDocSh hack/pointer
-    ScDocFuncSend( ScDocShell& rDocSh, ScDocFuncRecv *pChain )
+    ScDocFuncSend( ScDocShell& rDocSh, boost::shared_ptr<ScDocFuncRecv>& pChain )
             : ScDocFunc( rDocSh ),
-            mpChain( pChain ),
-            mpCollab( NULL)
+            mpChain( pChain )
     {
         fprintf( stderr, "Sender created !\n" );
     }
     virtual ~ScDocFuncSend() {}
 
-    void SetCollaboration( ScCollaboration* pCollab )
+    void SetCollaboration( boost::shared_ptr<ScCollaboration>& pCollab )
     {
         mpCollab = pCollab;
     }
@@ -562,20 +560,28 @@ public:
 
 SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc()
 {
-    // FIXME: the chains should be auto-ptrs, so should be collab
+    // With ScDocFuncDirect shared_ptr it should even be possible during
+    // runtime to replace a ScDocFuncDirect instance with a ScDocFuncSend
+    // chained instance (holding the same ScDocFuncDirect instance) and vice
+    // versa.
     bool bIsMaster = false;
     if (getenv ("INTERCEPT"))
-        return new ScDocFuncSend( *this, new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) ) );
+    {
+        boost::shared_ptr<ScDocFuncDirect> pDirect( new ScDocFuncDirect( *this ) );
+        boost::shared_ptr<ScDocFuncRecv> pReceiver( new ScDocFuncRecv( *this, pDirect ) );
+        return new ScDocFuncSend( *this, pReceiver );
+    }
     else if (isCollabMode( bIsMaster ))
     {
-        ScDocFuncRecv* pReceiver = new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) );
+        boost::shared_ptr<ScDocFuncDirect> pDirect( new ScDocFuncDirect( *this ) );
+        boost::shared_ptr<ScDocFuncRecv> pReceiver( new ScDocFuncRecv( *this, pDirect ) );
         ScDocFuncSend* pSender = new ScDocFuncSend( *this, pReceiver );
-        bool bOk = true;
-        ScCollaboration* pCollab = new ScCollaboration();
+        boost::shared_ptr<ScCollaboration> pCollab( new ScCollaboration );
         pCollab->sigPacketReceived.connect(
-            boost::bind( &ScDocFuncRecv::packetReceived, pReceiver, _1, _2 ));
+                boost::bind( &ScDocFuncRecv::packetReceived, pReceiver, _1, _2 ));
         pCollab->sigFileReceived.connect(
-            boost::bind( &ScDocFuncRecv::fileReceived, pReceiver, _1));
+                boost::bind( &ScDocFuncRecv::fileReceived, pReceiver, _1));
+        bool bOk = true;
         bOk = bOk && pCollab->initManager(!bIsMaster);
         if (bIsMaster)
         {
@@ -590,7 +596,7 @@ SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc()
         else
         {
             fprintf( stderr, "Could not start collaboration.\n");
-            delete pCollab;
+            // pCollab shared_ptr will be destructed
         }
         return pSender;
     }
commit e41d2677b159f8179829b0cdcb290bc581c628ff
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Mar 28 20:24:23 2012 +0200

    tubes: TeleManager::get() takes an argument
    
    initialize with same mode as collaboration

diff --git a/sc/source/ui/collab/sendfunc.cxx b/sc/source/ui/collab/sendfunc.cxx
index 3dddabf..c753eee 100644
--- a/sc/source/ui/collab/sendfunc.cxx
+++ b/sc/source/ui/collab/sendfunc.cxx
@@ -68,6 +68,18 @@ ScBaseCell *stringToCell( const rtl::OUString &rString )
     return NULL;
 }
 
+bool isCollabMode( bool& rbMaster )
+{
+    const char* pEnv = getenv ("LIBO_TUBES");
+    if (pEnv)
+    {
+        rbMaster = !strcmp( pEnv, "master");
+        return true;
+    }
+    rbMaster = false;
+    return false;
+}
+
 
 // Ye noddy mangling - needs improvement ...
 // method name ';' then arguments ; separated
@@ -452,7 +464,14 @@ public:
             SendFile( rText );
 
         if ( rtl::OUString( rText ) == "contacts" )
-            tubes::createContacts( TeleManager::get() );
+        {
+            // For TeleManager::get() use the same master/slave mode we have
+            // for collaboration, if any. This is a hack anyway so don't care
+            // whether we really are in collab mode or not.
+            bool bIsMaster = false;
+            isCollabMode( bIsMaster );
+            tubes::createContacts( TeleManager::get( bIsMaster ) );
+        }
 
         return true; // needs some code auditing action
     }
@@ -544,10 +563,10 @@ public:
 SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc()
 {
     // FIXME: the chains should be auto-ptrs, so should be collab
-    const char* pEnv;
+    bool bIsMaster = false;
     if (getenv ("INTERCEPT"))
         return new ScDocFuncSend( *this, new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) ) );
-    else if ((pEnv = getenv ("LIBO_TUBES")) != NULL)
+    else if (isCollabMode( bIsMaster ))
     {
         ScDocFuncRecv* pReceiver = new ScDocFuncRecv( *this, new ScDocFuncDirect( *this ) );
         ScDocFuncSend* pSender = new ScDocFuncSend( *this, pReceiver );
@@ -557,7 +576,6 @@ SC_DLLPRIVATE ScDocFunc *ScDocShell::CreateDocFunc()
             boost::bind( &ScDocFuncRecv::packetReceived, pReceiver, _1, _2 ));
         pCollab->sigFileReceived.connect(
             boost::bind( &ScDocFuncRecv::fileReceived, pReceiver, _1));
-        bool bIsMaster = !strcmp( pEnv, "master");
         bOk = bOk && pCollab->initManager(!bIsMaster);
         if (bIsMaster)
         {


More information about the Libreoffice-commits mailing list