| 1 |
/* Copyright (C) 2006 by Marc Maurer <[email protected]> |
| 2 |
* |
| 3 |
* This program is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU General Public License |
| 5 |
* as published by the Free Software Foundation; either version 2 |
| 6 |
* of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program; if not, write to the Free Software |
| 15 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 16 |
* 02110-1301 USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef __BUDDY_H__ |
| 20 |
#define __BUDDY_H__ |
| 21 |
|
| 22 |
#include <vector> |
| 23 |
#include <boost/shared_ptr.hpp> |
| 24 |
#include "ut_string_class.h" |
| 25 |
#include "ut_assert.h" |
| 26 |
#include "ut_debugmsg.h" |
| 27 |
#include "DocHandle.h" |
| 28 |
#include "DocTreeItem.h" |
| 29 |
|
| 30 |
class AccountHandler; |
| 31 |
|
| 32 |
class Buddy |
| 33 |
{ |
| 34 |
public: |
| 35 |
Buddy(AccountHandler* handler) |
| 36 |
: m_handler(handler), |
| 37 |
m_volatile(false) |
| 38 |
{ |
| 39 |
} |
| 40 |
virtual ~Buddy() {} |
| 41 |
|
| 42 |
/* |
| 43 |
* Buddy management |
| 44 |
*/ |
| 45 |
|
| 46 |
// Should be globally unique if possible, so it can be used to identify |
| 47 |
// authors when they reconnect or to allow sessions to be taken over. |
| 48 |
// Session takeover can NOT be enabled in the account handler if the buddy |
| 49 |
// descriptor is not globally unique. |
| 50 |
// When a buddy decriptor is not globally unique, then it must at least |
| 51 |
// uniquely identify a buddy within a collaboration session. |
| 52 |
// |
| 53 |
// When include_session_info is true, the descriptor should contain |
| 54 |
// all the information required to construct a buddy object from it for the |
| 55 |
// backends that support session takeover |
| 56 |
// When include_session_info is false, the descriptor only has to include the |
| 57 |
// information needed to *recognize* a particular author |
| 58 |
virtual UT_UTF8String getDescriptor(bool include_session_info = false) const = 0; |
| 59 |
|
| 60 |
virtual UT_UTF8String getDescription() const = 0; |
| 61 |
AccountHandler* getHandler() const |
| 62 |
{ return m_handler; } |
| 63 |
void setVolatile(bool _volatile) |
| 64 |
{ m_volatile = _volatile; } |
| 65 |
bool isVolatile() |
| 66 |
{ return m_volatile; } |
| 67 |
|
| 68 |
/* |
| 69 |
* Document management |
| 70 |
*/ |
| 71 |
virtual const DocTreeItem* getDocTreeItems() const = 0; |
| 72 |
void addDocHandle(DocHandle* pDocHandle); |
| 73 |
const std::vector<DocHandle*>& getDocHandles() const |
| 74 |
{ return m_docHandles; } |
| 75 |
DocHandle* getDocHandle(const UT_UTF8String& sSessionId) const |
| 76 |
{ |
| 77 |
for (std::vector<DocHandle*>::const_iterator cit = m_docHandles.begin(); cit != m_docHandles.end(); cit++) |
| 78 |
{ |
| 79 |
DocHandle* pHandle = *cit; |
| 80 |
if (pHandle->getSessionId() == sSessionId) |
| 81 |
return pHandle; |
| 82 |
} |
| 83 |
return NULL; |
| 84 |
} |
| 85 |
void destroyDocHandle(const UT_UTF8String& sSessionId) |
| 86 |
{ |
| 87 |
UT_DEBUGMSG(("Request to destroy dochandle %s\n", sSessionId.utf8_str())); |
| 88 |
for (std::vector<DocHandle*>::iterator it = m_docHandles.begin(); it != m_docHandles.end(); it++) |
| 89 |
{ |
| 90 |
DocHandle* pCurHandle = *it; |
| 91 |
UT_DEBUGMSG(("Comparing with dochandle: %s\n", pCurHandle->getSessionId().utf8_str())); |
| 92 |
if (pCurHandle && pCurHandle->getSessionId() == sSessionId) |
| 93 |
{ |
| 94 |
UT_DEBUGMSG(("Destroying document handle: %s\n", pCurHandle->getSessionId().utf8_str())); |
| 95 |
m_docHandles.erase(it); |
| 96 |
DELETEP(pCurHandle); |
| 97 |
return; |
| 98 |
} |
| 99 |
} |
| 100 |
UT_ASSERT(UT_NOT_REACHED); |
| 101 |
} |
| 102 |
|
| 103 |
private: |
| 104 |
AccountHandler* m_handler; |
| 105 |
UT_UTF8String m_descriptor; |
| 106 |
std::vector<DocHandle*> m_docHandles; |
| 107 |
bool m_volatile; |
| 108 |
}; |
| 109 |
|
| 110 |
typedef boost::shared_ptr<Buddy> BuddyPtr; |
| 111 |
|
| 112 |
#endif /* BUDDY_H */ |