• 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., 59 Temple Place - Suite 330, Boston, MA
00016  * 02111-1307, 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 using std::vector;
00033 
00034 class Buddy
00035 {
00036 public:
00037     Buddy(AccountHandler* handler)
00038         : m_handler(handler),
00039         m_volatile(false)
00040     {
00041     }
00042     virtual ~Buddy() {}
00043 
00044     /*
00045      * Buddy management
00046      */
00047 
00048     // Should be globally unique if possible, so it can be used to identify
00049     // authors when they reconnect or to allow sessions to be taken over.
00050     // Session takeover can NOT be enabled in the account handler if the buddy
00051     // descriptor is not globally unique.
00052     // When a buddy decriptor is not globally unique, then it must at least
00053     // uniquely identify a buddy within a collaboration session.
00054     //
00055     // When include_session_info is true, the descriptor should contain
00056     // all the information required to construct a buddy object from it for the
00057     // backends that support session takeover
00058     // When include_session_info is false, the descriptor only has to include the
00059     // information needed to *recognize* a particular author
00060     virtual UT_UTF8String          getDescriptor(bool include_session_info = false) const = 0;
00061 
00062     virtual UT_UTF8String           getDescription() const = 0;
00063     AccountHandler*                 getHandler() const
00064         { return m_handler; }
00065     void                            setVolatile(bool _volatile)
00066         { m_volatile = _volatile; }
00067     bool                            isVolatile()
00068         { return m_volatile; }
00069 
00070     /*
00071      * Document management
00072      */
00073     virtual const DocTreeItem*      getDocTreeItems() const = 0;
00074     void                            addDocHandle(DocHandle* pDocHandle);
00075     const vector<DocHandle*>&       getDocHandles() const
00076         { return m_docHandles; }
00077     DocHandle*                      getDocHandle(const UT_UTF8String& sSessionId) const
00078     {
00079         for (std::vector<DocHandle*>::const_iterator cit = m_docHandles.begin(); cit != m_docHandles.end(); cit++)
00080         {
00081             DocHandle* pHandle = *cit;
00082             if (pHandle->getSessionId() == sSessionId)
00083                 return pHandle;
00084         }
00085         return NULL;
00086     }
00087     void                            destroyDocHandle(const UT_UTF8String& sSessionId)
00088     {
00089         UT_DEBUGMSG(("Request to destroy dochandle %s\n", sSessionId.utf8_str()));
00090         for (std::vector<DocHandle*>::iterator it = m_docHandles.begin(); it != m_docHandles.end(); it++)
00091         {
00092             DocHandle* pCurHandle = *it;
00093             UT_DEBUGMSG(("Comparing with dochandle: %s\n", pCurHandle->getSessionId().utf8_str()));
00094             if (pCurHandle && pCurHandle->getSessionId() == sSessionId)
00095             {
00096                 UT_DEBUGMSG(("Destroying document handle: %s\n", pCurHandle->getSessionId().utf8_str()));
00097                 m_docHandles.erase(it);
00098                 DELETEP(pCurHandle);
00099                 return;
00100             }
00101         }
00102         UT_ASSERT(UT_NOT_REACHED);
00103     }
00104 
00105 private:
00106     AccountHandler*             m_handler;
00107     UT_UTF8String               m_descriptor;
00108     vector<DocHandle*>          m_docHandles;
00109     bool                        m_volatile;
00110 };
00111 
00112 typedef boost::shared_ptr<Buddy> BuddyPtr;
00113 
00114 #endif /* BUDDY_H */

Generated on Sat May 26 2012 for AbiWord by  doxygen 1.7.1