The branch, sushant, has been updated.

- Log -----------------------------------------------------------------

commit 09f3903768c0530fa629051199e6598b305ddce4
Author: Sushant Raikar <[email protected]>
Date:   Sat Jul 12 23:06:05 2014 +0530

    versioning with cursor

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 4088aa8..29fbaca 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -320,7 +320,7 @@ struct BufferView::Private
         /// Send to all remote_views_ except the one with connection 
p_excl_conn
         void send(FuncRequest const & cmd, SocketConnection *p_excl_conn = 0);
         ///
-        int try_recv(FuncRequest & cmd, int & target_version , DocIterator & 
docit_ );
+        int try_recv(FuncRequest & cmd, int & target_version);
 
 
        // not to be used in local BufferView
@@ -394,9 +394,6 @@ void BufferView::Private::send(FuncRequest const & cmd, 
SocketConnection *p_excl
        //my local version after dispatching
        lh.attach_rversion(HistoryQ.size());
        
-       DocIterator docit_= cursor_;
-       lh.attach_DocIt(docit_);
-
         vector<BufferView *>::const_iterator it = remote_views_.begin();
         for (; it != remote_views_.end(); ++it) {
                
@@ -420,7 +417,7 @@ void BufferView::Private::send(FuncRequest const & cmd, 
SocketConnection *p_excl
 }
 
 
-int BufferView::Private::try_recv(FuncRequest & cmd, int & version , 
DocIterator & docit_) {
+int BufferView::Private::try_recv(FuncRequest & cmd, int & version ) {
 
         vector<unsigned char> v;
         int rv = p_conn_->try_recv_chunk(v);
@@ -448,10 +445,7 @@ int BufferView::Private::try_recv(FuncRequest & cmd, int & 
version , DocIterator
        }               
        if(!lh.get_LFUN(cmd))
                LYXERR(Debug::ACTION,"cmd not received");
-       if(lh.get_DocIt(docit_)){
-               // adjust cursor based on History Q
-               cursor_.setCursor(docit_);
-       }       
+
 
        return 0;
 }
@@ -566,8 +560,6 @@ BufferView 
*BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_cl
         d->remote_views_.push_back(p_bv);
         d->timer_.start();
 
-printf("\n My client id %d",d->client_id);
-printf("\n his client id %d",remote_client_id);
         return p_bv;
 }
 
@@ -577,6 +569,14 @@ void BufferView::cursorChanged(FuncRequest const & LFUN, 
DocIterator diff, DocIt
        if(!d->remote_views_.empty() && !lyxaction.funcHasFlag(LFUN.action(), 
LyXAction::NoUpdate)){
                d -> historyQInsert(LFUN, diff, cursor, d -> client_id);
                d -> historyQDisplay();
+
+               vector<BufferView *>::const_iterator it = 
d->remote_views_.begin();
+               for (; it != d->remote_views_.end(); ++it) {
+                       // re adjust local cursor
+                       DocIterator currentBufferPos = (*it)->d->cursor_;       
                                
+                       currentBufferPos.addDiff(cursor, diff, 
(*it)->d->client_id <  d->client_id );
+                       (*it)->d->cursor_.setCursor(currentBufferPos);  
+               }
        }
 }
 
@@ -597,8 +597,8 @@ void BufferView::periodicTimer()
                         FuncRequest cmd;
 
                        int target_version;
-                       DocIterator remote_docit;
-                        rv = (*it)->d->try_recv(cmd, target_version, 
remote_docit);
+                       
+                        rv = (*it)->d->try_recv(cmd, target_version);
 
 
                         if (rv == 0) {
@@ -610,6 +610,8 @@ void BufferView::periodicTimer()
                                        << " button[" << cmd.button() << ']');
 
                                // adjust remote cursor
+                               DocIterator remote_docit;
+                               remote_docit = (*it)->d->cursor_;
                                d->adjustCursor(remote_docit, 
(*it)->d->client_id, target_version);
                                (*it)->d->cursor_.setCursor(remote_docit);
                                
@@ -627,7 +629,7 @@ void BufferView::periodicTimer()
 
                                        DocIterator diff = after - before;      
                
-
+                                       // re adjust local cursor
                                        DocIterator currentBufferPos = 
d->cursor_;                                      
                                        currentBufferPos.addDiff(before, diff, 
d->client_id <  (*it)->d->client_id );
                                        d->cursor_.setCursor(currentBufferPos); 
@@ -1554,7 +1556,7 @@ void BufferView::dispatch(FuncRequest const & cmd, 
DispatchResult & dr, bool ena
 
        FuncCode const act = cmd.action();
 
-       if (enable_send && !lyxaction.funcHasFlag(cmd.action(), 
LyXAction::NoUpdate) && act != LFUN_COLLABORATE_BIND && act != 
LFUN_COLLABORATE_CONNECT && act != LFUN_COLLABORATE_SPEED) 
+       if (enable_send && act != LFUN_COLLABORATE_BIND && act != 
LFUN_COLLABORATE_CONNECT && act != LFUN_COLLABORATE_SPEED) 
                d->send(cmd); 
        switch (act) {
 

commit 9756070416a1c7b36d6579a1473e01f631054f1c
Author: Sushant Raikar <[email protected]>
Date:   Sat Jul 12 21:55:51 2014 +0530

    issue with same cursor location

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 4e0ea84..4088aa8 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -362,7 +362,8 @@ void BufferView::Private::adjustCursor(DocIterator & 
cursor, int client_id, int
        for(; it != HistoryQ.end(); ++it){
                printf("\ngoing through version %d",it->first);
                if(it -> second.client_id != client_id){
-                       cursor.addDiff(it -> second.CursorLocation, it -> 
second.diff, client_id < it -> second.client_id  );
+                       if(comparator >= it -> second.CursorLocation)
+                               cursor.addDiff(it -> second.CursorLocation, it 
-> second.diff, client_id < it -> second.client_id  );
                }
        }
        
@@ -373,12 +374,13 @@ void BufferView::Private::historyQDisplay() {
 
        ostringstream oss;
        oss << '\n';
-       printf("\n version : LFUN : cursorLocation : diff \n");
+       printf("\n version : LFUN : cursorLocation : diff : client\n");
        map<int, HistoryQEntry>::const_iterator it = HistoryQ.begin();
        for(; it != HistoryQ.end(); ++it){
        oss << it -> first << ":" << it -> second.LFUN.getArg(0) 
        << ":" << it -> second.CursorLocation 
-       << ":" << it -> second.diff << "\n";
+       << ":" << it -> second.diff 
+       << ":" << it -> second.client_id << "\n";
        }       
        
        printf("%s", oss.str().c_str()); 
@@ -524,12 +526,10 @@ BufferView 
*BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_cl
                istringstream iss(s);
                iss >> d->client_id;
                iss >> remote_version;
-               iss.ignore(1);
-                               
-               if(iss.tellg() != -1){
-                       string sleft = iss.str().substr(iss.tellg());           
    
-                       buffer().readString(sleft);
-               }
+               
+               string sleft = iss.str().substr(iss.tellg());               
+               buffer().readString(sleft);
+               
                 message(_("Connected to remote LyX instance"));
 
         } else {
@@ -543,7 +543,7 @@ BufferView 
*BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_cl
                // send client its id
                v << remote_client_id << " ";
                // send latest version I am in
-               v << d->HistoryQ.size()-1;
+               v << (int)d->HistoryQ.size()-1;
 
                
 
@@ -552,7 +552,8 @@ BufferView 
*BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_cl
                 if (p_conn->send_string(s) != 0)
                         return 0;
                message(_("New client succesfully connected."));
-        }
+                       
+               }
         BufferView *p_bv = new BufferView(buffer());
         /// @TODO Just a random size in the hope that we skip some crash
         p_bv->resize(320, 200);
@@ -564,13 +565,17 @@ BufferView 
*BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_cl
        p_bv->d->remote_version = remote_version;
         d->remote_views_.push_back(p_bv);
         d->timer_.start();
+
+printf("\n My client id %d",d->client_id);
+printf("\n his client id %d",remote_client_id);
         return p_bv;
 }
 
 void BufferView::cursorChanged(FuncRequest const & LFUN, DocIterator diff, 
DocIterator cursor)
 {
-       if(!d->client_id && !lyxaction.funcHasFlag(LFUN.action(), 
LyXAction::NoUpdate)){
-               d -> historyQInsert(LFUN, diff, cursor, 0);
+       // not remote view 
+       if(!d->remote_views_.empty() && !lyxaction.funcHasFlag(LFUN.action(), 
LyXAction::NoUpdate)){
+               d -> historyQInsert(LFUN, diff, cursor, d -> client_id);
                d -> historyQDisplay();
        }
 }
diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp
index f86e211..ad30e26 100644
--- a/src/DocIterator.cpp
+++ b/src/DocIterator.cpp
@@ -723,7 +723,7 @@ void DocIterator::addDiff(DocIterator const & wrt, 
DocIterator const & diff, boo
 
        //if this cursor is in front of wrt or 
        // if this cursor = wrt and its client_id is less than wrt
-       if( *this > wrt || (!priority && *this == wrt) ){
+       if( *this > wrt || (priority && *this == wrt) ){
        
 
                size_t i = 0;

-----------------------------------------------------------------------

Summary of changes:
 src/BufferView.cpp  |   59 ++++++++++++++++++++++++++++----------------------
 src/DocIterator.cpp |    2 +-
 2 files changed, 34 insertions(+), 27 deletions(-)


hooks/post-receive
-- 
Repositories for GSOC work

Reply via email to