00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef ABICOLLABSESSIONMANAGER_H
00022 #define ABICOLLABSESSIONMANAGER_H
00023
00024 #include <map>
00025 #include <string>
00026 #include <vector>
00027 #include "ut_types.h"
00028 #include "pt_Types.h"
00029 #include "stdio.h"
00030 #include "ut_string_class.h"
00031 #include "xap_Dialog_Id.h"
00032 #include "xap_Types.h"
00033 #include "ie_imp.h"
00034 #include <account/xp/AccountHandler.h>
00035 #include <libxml/tree.h>
00036
00037 #ifdef WIN32
00038 #define WIN32_LEAN_AND_MEAN
00039 #include <windows.h>
00040 #endif
00041
00042 class AbiCollab;
00043 class Event;
00044 class EventListener;
00045
00046 class AbiCollabSessionManager
00047 {
00048 public:
00049 static AbiCollabSessionManager* getManager();
00050
00051 virtual ~AbiCollabSessionManager(void);
00052
00053
00054 static UT_Error serializeDocument(const PD_Document* pDoc, std::string& document, bool encodeBase64=true );
00055 static UT_Error deserializeDocument(PD_Document** pDoc, const std::string& document, bool isEncodedBase64=true);
00056
00057
00058 bool registerDialogs(void);
00059 bool unregisterDialogs(void);
00060 XAP_Dialog_Id getDialogShareId()
00061 { return m_iDialogShare; }
00062 XAP_Dialog_Id getDialogJoinId()
00063 { return m_iDialogJoin; }
00064 XAP_Dialog_Id getDialogAccountsId()
00065 { return m_iDialogAccounts; }
00066 XAP_Dialog_Id getDialogAddAccountId()
00067 { return m_iDialogAddAccount; }
00068 XAP_Dialog_Id getDialogAddBuddyId()
00069 { return m_iDialogAddBuddy; }
00070
00071 #ifdef WIN32
00072
00073 void setInstance(HINSTANCE hModule)
00074 { m_hModule = hModule; }
00075 HINSTANCE getInstance()
00076 { return m_hModule; }
00077
00078 #endif
00079
00080
00081 void loadProfile();
00082 void storeProfile();
00083
00084
00085 bool destroySession(PD_Document* pDoc);
00086 bool destroySession(AbiCollab* pSession);
00087 void disconnectSession(AbiCollab* pSession);
00088 void disconnectSessions();
00089 AbiCollab* getSession(PD_Document* pDoc);
00090 AbiCollab* getSessionFromDocumentId(const UT_UTF8String& sDocumentId);
00091 AbiCollab* getSessionFromSessionId(const UT_UTF8String& sSessionId);
00092 const UT_GenericVector<AbiCollab *>& getSessions(void) const
00093 { return m_vecSessions;}
00094 AbiCollab* startSession(PD_Document* pDoc, UT_UTF8String& sNewSessionId, AccountHandler* pAclAccount,
00095 bool bLocallyOwned, XAP_Frame* pFrame, const UT_UTF8String& masterDescriptor);
00096 void closeSession(AbiCollab* pSession, bool canConfirm);
00097 void closeSessions();
00098 void joinSessionInitiate(BuddyPtr pBuddy, DocHandle* pDocHandle);
00099 void joinSession(const UT_UTF8String& sSessionId, PD_Document* pDoc,
00100 const UT_UTF8String& docUUID, UT_sint32 iRev, UT_sint32 iAuthorId,
00101 BuddyPtr pCollaborator, AccountHandler* pAclAccount, bool bLocallyOwned,
00102 XAP_Frame *pFrame);
00103 void joinSession(AbiCollab* pSession, BuddyPtr pCollaborator);
00104 void disjoinSession(const UT_UTF8String& sSessionId);
00105 bool isLocallyControlled(PD_Document* pDoc);
00106 bool isInSession(PD_Document* pDoc);
00107 bool isActive(const UT_UTF8String& sSessionId);
00108 void removeBuddy(BuddyPtr pBuddy, bool graceful = true);
00109 void updateAcl(AbiCollab* pSession, AccountHandler* pAccount, const std::vector<std::string> acl);
00110 XAP_Frame* findFrameForSession(AbiCollab* pSession);
00111
00112
00113 bool registerAccountHandlers(void);
00114 bool unregisterAccountHandlers(void);
00115 const std::map<UT_UTF8String, AccountHandlerConstructor>&
00116 getRegisteredAccountHandlers(void)
00117 { return m_regAccountHandlers; }
00118 bool addAccount(AccountHandler* pHandler);
00119 const std::vector<AccountHandler *>& getAccounts() const
00120 { return m_vecAccounts; }
00121 void destroyAccounts();
00122 bool destroyAccount(AccountHandler* pHandler);
00123 void setDocumentHandles(BuddyPtr buddy, const UT_GenericVector<DocHandle*>& vDocHandle);
00124 BuddyPtr constructBuddy(const std::string& identifier, BuddyPtr pBuddy);
00125
00126
00127 bool processPacket(AccountHandler& handler, Packet* pPacket, BuddyPtr buddy);
00128
00129
00130 void registerEventListener(EventListener* pListener);
00131 void unregisterEventListener(EventListener* pListener);
00132 void signal(const Event& event, BuddyPtr pSource = BuddyPtr());
00133
00134
00135 void beginAsyncOperation(AbiCollab* pSession);
00136 void endAsyncOperation(AbiCollab* pSession);
00137 void beginAsyncOperation(AccountHandler* pSession);
00138 void endAsyncOperation(AccountHandler* pSession);
00139
00140
00141 void unregisterSniffers(void);
00142
00143 AbiCollabSessionManager(void);
00144
00145 private:
00146 bool _setupFrame(XAP_Frame** pFrame, PD_Document* pDoc);
00147
00148
00149 void _deleteSession(AbiCollab* pSession);
00150 void _deleteAccount(AccountHandler* pHandler);
00151 bool _nullUpdate();
00152
00153
00154 bool _canInitiateSessionTakeover(AbiCollab* pSession);
00155
00156 static AbiCollabSessionManager* m_pManager;
00157
00158
00159 XAP_Dialog_Id m_iDialogShare;
00160 XAP_Dialog_Id m_iDialogJoin;
00161 XAP_Dialog_Id m_iDialogAccounts;
00162 XAP_Dialog_Id m_iDialogAddAccount;
00163 XAP_Dialog_Id m_iDialogAddBuddy;
00164
00165 #ifdef WIN32
00166 HINSTANCE m_hModule;
00167 #endif
00168
00169
00170 UT_GenericVector<AbiCollab *> m_vecSessions;
00171
00172
00173 std::map<UT_UTF8String, AccountHandlerConstructor> m_regAccountHandlers;
00174 std::vector<AccountHandler *> m_vecAccounts;
00175 UT_GenericVector<EventListener *> m_vecEventListeners;
00176
00177
00178 std::map<AbiCollab*, int> m_asyncSessionOps;
00179 std::map<AccountHandler*, int> m_asyncAccountOps;
00180
00181
00182 std::vector<IE_ImpSniffer*> m_vImpSniffers;
00183 };
00184
00185 #endif