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

Buddy.h

Go to the documentation of this file.
00001 /* Copyright (C) 2006 by Marc Maurer <uwog@uwog.net>
00002  *
00003  * This program is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU General Public License
00005  * as published by the Free Software Foundation; either version 2
00006  * of the License, or (at your option) any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016  * 02110-1301 USA.
00017  */
00018 
00019 #ifndef __BUDDY_H__
00020 #define __BUDDY_H__
00021 
00022 #include <vector>
00023 #include <boost/shared_ptr.hpp>
00024 #include "ut_string_class.h"
00025 #include "ut_assert.h"
00026 #include "ut_debugmsg.h"
00027 #include "DocHandle.h"
00028 #include "DocTreeItem.h"
00029 
00030 class AccountHandler;
00031 
00032 class Buddy
00033 {
00034 public:
00035     Buddy(AccountHandler* handler)
00036         : m_handler(handler),
00037         m_volatile(false)
00038     {
00039     }
00040     virtual ~Buddy() {}
00041 
00042     /*
00043      * Buddy management
00044      */
00045 
00046     // Should be globally unique if possible, so it can be used to identify
00047     // authors when they reconnect or to allow sessions to be taken over.
00048     // Session takeover can NOT be enabled in the account handler if the buddy
00049     // descriptor is not globally unique.
00050     // When a buddy decriptor is not globally unique, then it must at least
00051     // uniquely identify a buddy within a collaboration session.
00052     //
00053     // When include_session_info is true, the descriptor should contain
00054     // all the information required to construct a buddy object from it for the
00055     // backends that support session takeover
00056     // When include_session_info is false, the descriptor only has to include the
00057     // information needed to *recognize* a particular author
00058     virtual UT_UTF8String          getDescriptor(bool include_session_info = false) const = 0;
00059 
00060     virtual UT_UTF8String           getDescription() const = 0;
00061     AccountHandler*                 getHandler() const
00062         { return m_handler; }
00063     void                            setVolatile(bool _volatile)
00064         { m_volatile = _volatile; }
00065     bool                            isVolatile()
00066         { return m_volatile; }
00067 
00068     /*
00069      * Document management
00070      */
00071     virtual const DocTreeItem*      getDocTreeItems() const = 0;
00072     void                            addDocHandle(DocHandle* pDocHandle);
00073     const std::vector<DocHandle*>&      getDocHandles() const
00074         { return m_docHandles; }
00075     DocHandle*                      getDocHandle(const std::string& sSessionId) const
00076     {
00077         for (std::vector<DocHandle*>::const_iterator cit = m_docHandles.begin(); cit != m_docHandles.end(); cit++)
00078         {
00079             DocHandle* pHandle = *cit;
00080             if (pHandle->getSessionId() == sSessionId)
00081                 return pHandle;
00082         }
00083         return NULL;
00084     }
00085     void                            destroyDocHandle(const std::string& sSessionId)
00086     {
00087         UT_DEBUGMSG(("Request to destroy dochandle %s\n", sSessionId.c_str()));
00088         for (std::vector<DocHandle*>::iterator it = m_docHandles.begin(); it != m_docHandles.end(); it++)
00089         {
00090             DocHandle* pCurHandle = *it;
00091             UT_DEBUGMSG(("Comparing with dochandle: %s\n", pCurHandle->getSessionId().c_str()));
00092             if (pCurHandle && pCurHandle->getSessionId() == sSessionId)
00093             {
00094                 UT_DEBUGMSG(("Destroying document handle: %s\n", pCurHandle->getSessionId().c_str()));
00095                 m_docHandles.erase(it);
00096                 DELETEP(pCurHandle);
00097                 return;
00098             }
00099         }
00100         UT_ASSERT(UT_NOT_REACHED);
00101     }
00102 
00103 private:
00104     AccountHandler*             m_handler;
00105     UT_UTF8String               m_descriptor;
00106     std::vector<DocHandle*>         m_docHandles;
00107     bool                        m_volatile;
00108 };
00109 
00110 typedef boost::shared_ptr<Buddy> BuddyPtr;
00111 
00112 #endif /* BUDDY_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1