• 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., 59 Temple Place - Suite 330, Boston, MA
00021  * 02111-1307, USA.
00022  */
00023 
00024 #ifndef ABI_COLLAB_H
00025 #define ABI_COLLAB_H
00026 
00027 #include <map>
00028 #include <vector>
00029 #include "ev_EditBits.h"
00030 #include "ev_MouseListener.h"
00031 #include "ut_types.h"
00032 #include "pt_Types.h"
00033 #include "px_ChangeRecord.h"
00034 #include "stdio.h"
00035 #include "xav_Listener.h"
00036 #include "pl_Listener.h"
00037 #include "ut_string_class.h"
00038 #include "ut_uuid.h"
00039 
00040 #include <account/xp/Buddy.h>
00041 #include <packet/xp/AbiCollab_Packet.h>
00042 #include <session/xp/AbiCollab_Import.h>
00043 #include <session/xp/AbiCollab_Export.h>
00044 
00045 class FL_DocLayout;
00046 class PD_Document;
00047 class PX_ChangeRecord;
00048 class CommandLine;
00049 class Buddy;
00050 class AccountHandler;
00051 
00052 enum SessionTakeoverState
00053 {
00054     STS_NONE,
00055     STS_SENT_TAKEOVER_REQUEST,
00056     STS_SENT_TAKEOVER_ACK,
00057     STS_SENT_SESSION_RECONNECT_REQUEST
00058 };
00059 
00060 class ChangeAdjust
00061 {
00062 friend class AbiCollab_ImportRuleSet;
00063 
00064 public:
00065     ChangeAdjust(const AbstractChangeRecordSessionPacket& packet, PT_DocPosition iOrigDocPos, const UT_UTF8String& sRemoteDocUUID);
00066     ~ChangeAdjust();
00067 
00068     PT_DocPosition              getLocalPos() const { return m_iLocalPos; }
00069     void                        setLocalPos(PT_DocPosition iLocalPos) { m_iLocalPos = iLocalPos; }
00070     UT_sint32                   getLocalLength() const { return m_pPacket->getLength(); }
00071     UT_sint32                   getLocalAdjust() const { return m_pPacket->getAdjust(); }
00072     UT_sint32                   getLocalRev() const { return m_pPacket->getRev(); }
00073 
00074     PT_DocPosition              getRemoteDocPos() const { return m_iRemoteDocPos; }
00075     const UT_UTF8String&        getRemoteDocUUID() const { return m_sRemoteDocUUID; }
00076 
00077 private:
00078     // locally generated data (possibly in response to remotely generated data)
00079     const AbstractChangeRecordSessionPacket*    m_pPacket;
00080     PT_DocPosition                              m_iLocalPos;
00081 
00082     // remotely generated data
00083     PT_DocPosition                              m_iRemoteDocPos;
00084     UT_UTF8String                               m_sRemoteDocUUID;
00085 };
00086 
00087 class AbiCollab;
00088 class SessionRecorderInterface
00089 {
00090 public:
00091     SessionRecorderInterface( AbiCollab* Session ) : m_pAbiCollab(Session) {}
00092     virtual ~SessionRecorderInterface() {}
00093     virtual void storeOutgoing(const Packet* pPacket ) = 0;
00094     virtual void storeOutgoing(const Packet* pPacket, BuddyPtr toBuddy) = 0;
00095     virtual void storeIncoming(const Packet* pPacket, BuddyPtr fromBuddy) = 0;
00096 protected:
00097     AbiCollab*      m_pAbiCollab;
00098 };
00099 
00100 class AbiCollab : public EV_MouseListener
00101 {
00102     friend class ABI_Collab_Export;
00103 
00104 public:
00105     // master constructor
00106     AbiCollab(PD_Document* pDoc,
00107                     const UT_UTF8String& sSessionId,
00108                     AccountHandler* pAclAccount,
00109                     bool bLocallyOwned);
00110 
00111     // slave constructor
00112     AbiCollab(const UT_UTF8String& sSessionId,
00113                     PD_Document* pDoc,
00114                     const UT_UTF8String& docUUID,
00115                     UT_sint32 iRev,
00116                     BuddyPtr pControler,
00117                     AccountHandler* pAclAccount,
00118                     bool m_bLocallyOwned);
00119 
00120     virtual ~AbiCollab();
00121 
00122     // collaborator management
00123     void                                addCollaborator(BuddyPtr pCollaborator);
00124     void                                removeCollaborator(BuddyPtr pCollaborator);
00125     const std::map<BuddyPtr, std::string>&      getCollaborators() const
00126         { return m_vCollaborators; }
00127     bool                                isController(BuddyPtr pCollaborator) const
00128         { return m_pController == pCollaborator; }
00129     bool                                isLocallyOwned() const
00130         { return m_bLocallyOwned; }
00131     const std::vector<std::string>&     getAcl()
00132         { return m_vAcl; }
00133     AccountHandler*                     getAclAccount()
00134         { return m_pAclAccount; }
00135     void                                setAcl(const std::vector<std::string> vAcl);
00136     void                                appendAcl(const std::string& sBuddyDescriptor);
00137 
00138 
00139     // import/export management
00140     ABI_Collab_Import*                  getImport(void)
00141         { return &m_Import; }
00142     ABI_Collab_Export*                  getExport(void)
00143         { return &m_Export; }
00144     void                                push(SessionPacket* pPacket);
00145     bool                                push(SessionPacket* pPacket, BuddyPtr collaborator);
00146     void                                maskExport();
00147     virtual const std::vector<SessionPacket*>&  unmaskExport();
00148     bool                                isExportMasked(void) const
00149         { return m_bExportMasked; }
00150     void                                import(SessionPacket* pPacket, BuddyPtr collaborator);
00151     void                                addChangeAdjust(ChangeAdjust* pAdjust);
00152     const AbstractChangeRecordSessionPacket* getActivePacket() const
00153         { return m_pActivePacket; }
00154 
00155     // document management
00156     PD_Document*                        getDocument(void) const
00157         { return m_pDoc; }
00158 
00159     const UT_UTF8String                 getSessionId() const
00160         { return m_sId; }
00161     bool                                isLocallyControlled() const
00162         { return m_pController == NULL; }
00163 
00164     void                                setIsReverting(bool bIsReverting)
00165         { m_bIsReverting = bIsReverting; }
00166 
00167     // session takeover
00168     void                                initiateSessionTakeover(BuddyPtr pNewMaster);
00169 
00170     // session recording functionality
00171     bool                                isRecording()
00172         { return m_pRecorder != NULL; }
00173     void                                startRecording(SessionRecorderInterface* pRecorder);
00174     void                                stopRecording();
00175 
00176     // mouse listener functionality
00177     virtual void                        signalMouse(EV_EditBits eb, UT_sint32 xPos, UT_sint32 yPos);
00178     virtual void                        removeMouse(EV_Mouse* pMouse);
00179 
00180 protected:
00181     // TODO: make all Packets shared pointers, so this isn't needed anymore
00182     class SessionPacketVector : public std::vector<SessionPacket*>
00183     {
00184     public:
00185         ~SessionPacketVector() { clear(); } // so it's autocleaned on destroy!
00186         void clear()
00187         {
00188             for (size_t i=0; i<size(); ++i)
00189             {
00190                 DELETEP((*this)[i]);
00191             }
00192             std::vector<SessionPacket*>::clear();
00193         };
00194     } m_vecMaskedPackets; // packets that are generated during the import of a packet
00195 
00196 private:
00197     // collaborator management
00198     void                                _removeCollaborator(BuddyPtr pCollaborator, const std::string& docUUID);
00199     void                                _checkRevokeAccess(BuddyPtr pCollaborator);
00200 
00201 
00202     // document management
00203     void                                _setDocument(PD_Document* pDoc);
00204     void                                _setDocListenerId(UT_uint32 iDocListenerId)
00205         { m_iDocListenerId = iDocListenerId; }
00206 
00207     void                                _fillRemoteRev(Packet* pPacket, BuddyPtr pBuddy);
00208 
00209     // mouse listener functionality
00210     void                                _releaseMouseDrag();
00211 
00212     // session takeover
00213     bool                                _handleSessionTakeover(AbstractSessionTakeoverPacket* pPacket, BuddyPtr collaborator);
00214     bool                                _hasAckedSessionTakeover(BuddyPtr collaborator);
00215     bool                                _allSlavesAckedSessionTakeover();
00216     void                                _switchMaster();
00217     void                                _becomeMaster();
00218     bool                                _restartAsSlave(const UT_UTF8String& sDocUUID, UT_sint32 iRev);
00219     void                                _shutdownAsMaster();
00220     bool                                _allSlavesReconnected();
00221     void                                _checkRestartAsMaster();
00222     void                                _restartAsMaster();
00223     void                                _pushOutgoingQueue();
00224 
00225     PD_Document *                       m_pDoc;
00226     ABI_Collab_Import                   m_Import;
00227     ABI_Collab_Export                   m_Export;
00228 
00229     // buddy <-> remote document UUID mapping
00230     std::map<BuddyPtr, std::string>     m_vCollaborators;
00231     std::vector<std::string>            m_vAcl;
00232     AccountHandler*                     m_pAclAccount;
00233     UT_uint32                           m_iDocListenerId;
00234     bool                                m_bExportMasked;
00235 
00236     UT_UTF8String                       m_sId;
00237 
00238     BuddyPtr                            m_pController;
00239     bool                                m_bLocallyOwned;
00240 
00241     CommandLine *                       m_pCommandLine;
00242     bool                                m_bCloseNow;
00243 
00244     const AbstractChangeRecordSessionPacket* m_pActivePacket;
00245     bool                                m_bIsReverting;
00246 
00247     SessionRecorderInterface*           m_pRecorder;
00248 
00249     std::map<EV_Mouse*, UT_sint32>      m_mMouseListenerIds;
00250     bool                                m_bDoingMouseDrag;
00251 
00252     std::vector<std::pair<SessionPacket*,BuddyPtr> >
00253                                         m_vIncomingQueue;
00254 
00255 
00256     // session takeover functionality
00257     SessionTakeoverState                m_eTakeoveState;
00258     bool                                m_bProposedController;
00259     BuddyPtr                            m_pProposedController;
00260     std::map<std::string, bool>         m_vApprovedReconnectBuddies;
00261     std::map<BuddyPtr, bool>            m_mAckedSessionTakeoverBuddies; // only used by the session controller
00262     bool                                m_bSessionFlushed;
00263     SessionPacketVector                 m_vOutgoingQueue;
00264 };
00265 
00266 #endif /* ABI_COLLAB_H */

Generated on Sat May 26 2012 for AbiWord by  doxygen 1.7.1