The branch, sushant, has been updated. - Log -----------------------------------------------------------------
commit 04e8f9dd461d0e2f8ded527658295cabe2fc76d1 Author: Sushant Raikar <[email protected]> Date: Tue Jul 8 23:52:15 2014 +0530 same local and remote Cursor pos handled diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 092a9c5..4e0ea84 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -357,11 +357,12 @@ void BufferView::Private::adjustCursor(DocIterator & cursor, int client_id, int map<int, HistoryQEntry>::const_iterator it = HistoryQ.find(version); - ++it; + if(it != HistoryQ.end()) + ++it; 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); + cursor.addDiff(it -> second.CursorLocation, it -> second.diff, client_id < it -> second.client_id ); } } @@ -505,6 +506,8 @@ BufferView::~BufferView() BufferView *BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_client) { int remote_version = 0; + // @FIXME shouldn't be zero + int remote_client_id = 0; if (is_client) { int rv; string s; @@ -519,20 +522,31 @@ BufferView *BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_cl } while (rv == -EWOULDBLOCK); /// @TODO Check for parsing errors (e.g., mismatching LyX versions) istringstream iss(s); + iss >> d->client_id; iss >> remote_version; iss.ignore(1); - - string sleft = iss.str().substr(iss.tellg()); - buffer().readString(sleft); + + if(iss.tellg() != -1){ + string sleft = iss.str().substr(iss.tellg()); + buffer().readString(sleft); + } message(_("Connected to remote LyX instance")); + } else { ostringstream oss; message(_("New client connected. Sending buffer...")); buffer().write(oss); + remote_client_id = d->remote_views_.size() +1; + ostringstream v; + // send client its id + v << remote_client_id << " "; + // send latest version I am in v << d->HistoryQ.size()-1; + + string s = v.str() + " " + oss.str(); if (p_conn->send_string(s) != 0) @@ -545,7 +559,7 @@ BufferView *BufferView::addRemoteBufferView(SocketConnection *p_conn, bool is_cl p_bv->d->p_conn_ = p_conn; p_bv->d->client_conn_ = is_client; // unique client id - p_bv->d->client_id = d->remote_views_.size() + 1; + p_bv->d->client_id = remote_client_id; // every new client that connects will be in 0th version p_bv->d->remote_version = remote_version; d->remote_views_.push_back(p_bv); @@ -607,10 +621,10 @@ void BufferView::periodicTimer() if(!lyxaction.funcHasFlag(cmd.action(), LyXAction::NoUpdate)){ DocIterator diff = after - before; - + DocIterator currentBufferPos = d->cursor_; - currentBufferPos.addDiff(before, diff); + currentBufferPos.addDiff(before, diff, d->client_id < (*it)->d->client_id ); d->cursor_.setCursor(currentBufferPos); d->historyQInsert(cmd, diff, before, (*it)->d->client_id); @@ -1575,9 +1589,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr, bool ena string sarg = cmd.getArg(0); int time = d->timer_.interval(); if(sarg[0] == '+') - time += 1000; - else if(sarg[0] == '-' && (time - 1000) > 0 ) - time -= 1000; + time += 3000; + else if(sarg[0] == '-' && (time - 3000) > 0 ) + time -= 3000; d->timer_.setInterval(time); break; } diff --git a/src/DocIterator.cpp b/src/DocIterator.cpp index 12eca65..f86e211 100644 --- a/src/DocIterator.cpp +++ b/src/DocIterator.cpp @@ -713,7 +713,7 @@ DocIterator & operator-(DocIterator const & dit1, DocIterator const & dit2) return dit; } -void DocIterator::addDiff(DocIterator const & wrt, DocIterator const & diff) +void DocIterator::addDiff(DocIterator const & wrt, DocIterator const & diff, bool priority) { /* ostringstream oss; @@ -721,14 +721,16 @@ void DocIterator::addDiff(DocIterator const & wrt, DocIterator const & diff) printf("\nbefore: %s",oss.str().c_str()); */ - if( *this > wrt){ + //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) ){ size_t i = 0; size_t least = slices_.size() < wrt.depth()? slices_.size() : wrt.depth(); // untill same innermost inset - while(i < least && slices_[i] == wrt[i]) + while(i < least && slices_[i] == wrt[i] && *this != wrt) ++i; // to avoid same cursor location @@ -740,6 +742,7 @@ void DocIterator::addDiff(DocIterator const & wrt, DocIterator const & diff) } } + /* ostringstream oss1; oss1 << *this; diff --git a/src/DocIterator.h b/src/DocIterator.h index cbf28c4..acf15aa 100644 --- a/src/DocIterator.h +++ b/src/DocIterator.h @@ -208,7 +208,8 @@ public: /// are we some 'extension' (i.e. deeper nested) of the given iterator bool hasPart(DocIterator const & it) const; - void addDiff(DocIterator const & wrt, DocIterator const & diff); + // third para is comparison (>) between client_id of this DOcit and client_id of wrt + void addDiff(DocIterator const & wrt, DocIterator const & diff, bool has_high_priority); /// write serialized data to os friend std::ostream & diff --git a/src/support/Socket.cpp b/src/support/Socket.cpp index 91770a2..d12b7ff 100644 --- a/src/support/Socket.cpp +++ b/src/support/Socket.cpp @@ -164,7 +164,7 @@ int Socket::bind(std::string const & host, std::string const & port) { int Socket::accept(SocketConnection **p_pconn) { int fd = ::accept(sockfd, (struct sockaddr *)NULL, (socklen_t *)NULL); if (fd < 0) { - logsyserr("accept() failed"); + //logsyserr("accept() failed"); return -1; } *p_pconn = new SocketConnection(fd); ----------------------------------------------------------------------- Summary of changes: src/BufferView.cpp | 36 +++++++++++++++++++++++++----------- src/DocIterator.cpp | 9 ++++++--- src/DocIterator.h | 3 ++- src/support/Socket.cpp | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) hooks/post-receive -- Repositories for GSOC work
