• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

AbiCollab.h

Go to the documentation of this file.
00001 /*
00002  * AbiCollab - Code to enable the modification of remote documents.
00003  * Copyright (C) 2005 by Martin Sevior
00004  * Copyright (C) 2006,2007 by Marc Maurer <uwog@uwog.net>
00005  * Copyright (C) 2007 by One Laptop Per Child
00006  * Copyright (C) 2008 by AbiSource Corporation B.V.
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation; either version 2
00011  * of the License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00021  * 02110-1301 USA.
00022  */
00023 
00024 #ifndef ABI_COLLAB_H
00025 #define ABI_COLLAB_H
00026 
00027 #include <map>
00028 #include <string>
00029 #include <vector>
00030 #include "ev_EditBits.h"
00031 #include "ev_MouseListener.h"
00032 #include "ut_types.h"
00033 #include "pt_Types.h"
00034 #include "px_ChangeRecord.h"
00035 #include "stdio.h"
00036 #include "xav_Listener.h"
00037 #include "pl_Listener.h"
00038 #include "ut_string_class.h"
00039 #include "ut_uuid.h"
00040 
00041 #include <account/xp/Buddy.h>
00042 #include <packet/xp/AbiCollab_Packet.h>
00043 #include <session/xp/AbiCollab_Import.h>
00044 #include <session/xp/AbiCollab_Export.h>
00045 
00046 class FL_DocLayout;
00047 class PD_Document;
00048 class PX_ChangeRecord;
00049 class CommandLine;
00050 class Buddy;
00051 class AccountHandler;
00052 
00053 enum SessionTakeoverState
00054 {
00055     STS_NONE,
00056     STS_SENT_TAKEOVER_REQUEST,
00057     STS_SENT_TAKEOVER_ACK,
00058     STS_SENT_SESSION_RECONNECT_REQUEST
00059 };
00060 
00061 class ChangeAdjust
00062 {
00063 friend class AbiCollab_ImportRuleSet;
00064 
00065 public:
00066     ChangeAdjust(const AbstractChangeRecordSessionPacket& packet, PT_DocPosition iOrigDocPos, const std::string& sRemoteDocUUID);
00067     ~ChangeAdjust();
00068 
00069     PT_DocPosition              getLocalPos() const { return m_iLocalPos; }
00070     void                        setLocalPos(PT_DocPosition iLocalPos) { m_iLocalPos = iLocalPos; }
00071     UT_sint32                   getLocalLength() const { return m_pPacket->getLength(); }
00072     UT_sint32                   getLocalAdjust() const { return m_pPacket->getAdjust(); }
00073     UT_sint32                   getLocalRev() const { return m_pPacket->getRev(); }
00074 
00075     PT_DocPosition              getRemoteDocPos() const { return m_iRemoteDocPos; }
00076     const std::string&      getRemoteDocUUID() const { return m_sRemoteDocUUID; }
00077 
00078 private:
00079     // locally generated data (possibly in response to remotely generated data)
00080     const AbstractChangeRecordSessionPacket*    m_pPacket;
00081     PT_DocPosition                              m_iLocalPos;
00082 
00083     // remotely generated data
00084     PT_DocPosition                              m_iRemoteDocPos;
00085     std::string     m_sRemoteDocUUID;
00086 };
00087 
00088 class AbiCollab;
00089 class SessionRecorderInterface
00090 {
00091 public:
00092     SessionRecorderInterface( AbiCollab* Session ) : m_pAbiCollab(Session) {}
00093     virtual ~SessionRecorderInterface() {}
00094     virtual void storeOutgoing(const Packet* pPacket ) = 0;
00095     virtual void storeOutgoing(const Packet* pPacket, BuddyPtr toBuddy) = 0;
00096     virtual void storeIncoming(const Packet* pPacket, BuddyPtr fromBuddy) = 0;
00097 protected:
00098     AbiCollab*      m_pAbiCollab;
00099 };
00100 
00101 class AbiCollab : public EV_MouseListener
00102 {
00103     friend class ABI_Collab_Export;
00104 
00105 public:
00106     // master constructor
00107     AbiCollab(PD_Document* pDoc,
00108                     const std::string& sSessionId,
00109                     AccountHandler* pAclAccount,
00110                     bool bLocallyOwned);
00111 
00112     // slave constructor
00113     AbiCollab(const std::string& sSessionId,
00114                     PD_Document* pDoc,
00115                     const std::string& docUUID,
00116                     UT_sint32 iRev,
00117                     BuddyPtr pControler,
00118                     AccountHandler* pAclAccount,
00119                     bool m_bLocallyOwned);
00120 
00121     virtual ~AbiCollab();
00122 
00123     // collaborator management
00124     void                                addCollaborator(BuddyPtr pCollaborator);
00125     void                                removeCollaborator(BuddyPtr pCollaborator);
00126     const std::map<BuddyPtr, std::string>&      getCollaborators() const
00127         { return m_vCollaborators; }
00128     bool                                isController(BuddyPtr pCollaborator) const
00129         { return m_pController == pCollaborator; }
00130     bool                                isLocallyOwned() const
00131         { return m_bLocallyOwned; }
00132     const std::vector<std::string>&     getAcl()
00133         { return m_vAcl; }
00134     AccountHandler*                     getAclAccount()
00135         { return m_pAclAccount; }
00136     void                                setAcl(const std::vector<std::string> vAcl);
00137     void                                appendAcl(const std::string& sBuddyDescriptor);
00138 
00139 
00140     // import/export management
00141     ABI_Collab_Import*                  getImport(void)
00142         { return &m_Import; }
00143     ABI_Collab_Export*                  getExport(void)
00144         { return &m_Export; }
00145     void                                push(SessionPacket* pPacket);
00146     bool                                push(SessionPacket* pPacket, BuddyPtr collaborator);
00147     void                                maskExport();
00148     virtual const std::vector<SessionPacket*>&  unmaskExport();
00149     bool                                isExportMasked(void) const
00150         { return m_bExportMasked; }
00151     void                                import(SessionPacket* pPacket, BuddyPtr collaborator);
00152     void                                addChangeAdjust(ChangeAdjust* pAdjust);
00153     const AbstractChangeRecordSessionPacket* getActivePacket() const
00154         { return m_pActivePacket; }
00155 
00156     // document management
00157     PD_Document*                        getDocument(void) const
00158         { return m_pDoc; }
00159 
00160     const std::string& getSessionId() const
00161         { return m_sId; }
00162     bool                                isLocallyControlled() const
00163         { return m_pController == NULL; }
00164 
00165     void                                setIsReverting(bool bIsReverting)
00166         { m_bIsReverting = bIsReverting; }
00167 
00168     // session takeover
00169     void                                initiateSessionTakeover(BuddyPtr pNewMaster);
00170 
00171     // session recording functionality
00172     bool                                isRecording()
00173         { return m_pRecorder != NULL; }
00174     void                                startRecording(SessionRecorderInterface* pRecorder);
00175     void                                stopRecording();
00176 
00177     // mouse listener functionality
00178     virtual void                        signalMouse(EV_EditBits eb, UT_sint32 xPos, UT_sint32 yPos);
00179     virtual void                        removeMouse(EV_Mouse* pMouse);
00180 
00181 protected:
00182     // TODO: make all Packets shared pointers, so this isn't needed anymore
00183     class SessionPacketVector : public std::vector<SessionPacket*>
00184     {
00185     public:
00186         ~SessionPacketVector() { clear(); } // so it's autocleaned on destroy!
00187         void clear()
00188         {
00189             for (size_t i=0; i<size(); ++i)
00190             {
00191                 DELETEP((*this)[i]);
00192             }
00193             std::vector<SessionPacket*>::clear();
00194         };
00195     } m_vecMaskedPackets; // packets that are generated during the import of a packet
00196 
00197 private:
00198     // collaborator management
00199     void                                _removeCollaborator(BuddyPtr pCollaborator, const std::string& docUUID);
00200     void                                _checkRevokeAccess(BuddyPtr pCollaborator);
00201 
00202 
00203     // document management
00204     void                                _setDocument(PD_Document* pDoc);
00205     void                                _setDocListenerId(UT_uint32 iDocListenerId)
00206         { m_iDocListenerId = iDocListenerId; }
00207 
00208     void                                _fillRemoteRev(Packet* pPacket, BuddyPtr pBuddy);
00209 
00210     // mouse listener functionality
00211     void                                _releaseMouseDrag();
00212 
00213     // session takeover
00214     bool                                _handleSessionTakeover(AbstractSessionTakeoverPacket* pPacket, BuddyPtr collaborator);
00215     bool                                _hasAckedSessionTakeover(BuddyPtr collaborator);
00216     bool                                _allSlavesAckedSessionTakeover();
00217     void                                _switchMaster();
00218     void                                _becomeMaster();
00219     bool                                _restartAsSlave(const std::string& sDocUUID, UT_sint32 iRev);
00220     void                                _shutdownAsMaster();
00221     bool                                _allSlavesReconnected();
00222     void                                _checkRestartAsMaster();
00223     void                                _restartAsMaster();
00224     void                                _pushOutgoingQueue();
00225 
00226     PD_Document *                       m_pDoc;
00227     ABI_Collab_Import                   m_Import;
00228     ABI_Collab_Export                   m_Export;
00229 
00230     // buddy <-> remote document UUID mapping
00231     std::map<BuddyPtr, std::string>     m_vCollaborators;
00232     std::vector<std::string>            m_vAcl;
00233     AccountHandler*                     m_pAclAccount;
00234     UT_uint32                           m_iDocListenerId;
00235     bool                                m_bExportMasked;
00236 
00237     std::string                     m_sId;
00238 
00239     BuddyPtr                            m_pController;
00240     bool                                m_bLocallyOwned;
00241 
00242     CommandLine *                       m_pCommandLine;
00243     bool                                m_bCloseNow;
00244 
00245     const AbstractChangeRecordSessionPacket* m_pActivePacket;
00246     bool                                m_bIsReverting;
00247 
00248     SessionRecorderInterface*           m_pRecorder;
00249 
00250     std::map<EV_Mouse*, UT_sint32>      m_mMouseListenerIds;
00251     bool                                m_bDoingMouseDrag;
00252 
00253     std::vector<std::pair<SessionPacket*,BuddyPtr> >
00254                                         m_vIncomingQueue;
00255 
00256 
00257     // session takeover functionality
00258     SessionTakeoverState                m_eTakeoveState;
00259     bool                                m_bProposedController;
00260     BuddyPtr                            m_pProposedController;
00261     std::map<std::string, bool>         m_vApprovedReconnectBuddies;
00262     std::map<BuddyPtr, bool>            m_mAckedSessionTakeoverBuddies; // only used by the session controller
00263     bool                                m_bSessionFlushed;
00264     SessionPacketVector                 m_vOutgoingQueue;
00265 };
00266 
00267 #endif /* ABI_COLLAB_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1