ConcurrencyController Class Reference

Ensures no update conflicts with concurrent users to Camelot. More...

#include <ccc.h>

List of all members.

Public Types

typedef UINT32 UserID
enum  RESULT {
  CCR_OK = 0, CCR_INTERNAL_ERROR = 1, CCR_INVALID_ARGUMENT = 10, CCR_TOO_MANY_USERS = 100,
  CCR_INVALID_USER = 101
}

Public Member Functions

 ConcurrencyController ()
 Default constructor for the ConcurrencyController.
BOOL Init ()
virtual ~ConcurrencyController ()
 Default destructor for the ConcurrencyController.
RESULT StartUser (UserID *pNewUserID)
 Default destructor for the ConcurrencyController.
RESULT EndUser (UserID UserWhosDone)
 Default destructor for the ConcurrencyController.
RESULT PrepareForOperation (const Operation *const pOperation)
 Allows or disallows access to Operations.
RESULT FinalizeOperation (const Operation *const pOperation)
 Default destructor for the ConcurrencyController.
RESULT PrepareNodeForRead (Node *const pNode)
 Before reading data in a node or passing it as a parameter to a function, call this function to ensure the integrity of the document tree. This call should be accompanied by a subsequent call to FinalizeNodeRead(). The results of the read are undefined if not. See Also: PrepareNodeForUpdate().
RESULT FinalizeNodeRead (Node *const pNode)
 Once the given node has been read or passed as a parameter, call this function to free it for updates. This call should be accompanied by a prior call to PrepareNodeForRead(). The results of the read are undefined if not. See Also: FinalizeNodeUpdate().
RESULT PrepareNodeForUpdate (Node *const pNode)
 Before updating a node, call this function to ensure the integrity of the document tree. This call should be accompanied by a subsequent call to FinalizeNodeUpdate(). The results of the update are undefined if not. See Also: PrepareNodeForRead().
RESULT FinalizeNodeUpdate (Node *const pNode)
 Once the given node has been updated in the tree call this function to ensure its update is complete. This call should be accompanied by a prior call to PrepareForNodeUpdate(). The results of the update are undefined if not. See Also: FinalizeNodeRead().

Protected Member Functions

UserID GetNewUserID ()
 Support function to provide a new user id.

Private Member Functions

 CC_DECLARE_MEMDUMP (ConcurrencyController)

Static Private Attributes

static UserID s_NextFreeUserID = 0
static UserID s_OneAndOnlyUser = 0
static UINT32 s_NumberOfUsers = 0
static UINT32 s_NumberOfActiveOperations = 0
static const Operations_pTheActiveOperation = NULL


Detailed Description

Ensures no update conflicts with concurrent users to Camelot.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
09/03/97

Definition at line 115 of file ccc.h.


Member Typedef Documentation

typedef UINT32 ConcurrencyController::UserID
 

Definition at line 127 of file ccc.h.


Member Enumeration Documentation

enum ConcurrencyController::RESULT
 

Enumerator:
CCR_OK 
CCR_INTERNAL_ERROR 
CCR_INVALID_ARGUMENT 
CCR_TOO_MANY_USERS 
CCR_INVALID_USER 

Definition at line 128 of file ccc.h.

00129     {
00130         CCR_OK = 0,
00131         CCR_INTERNAL_ERROR = 1,
00132         CCR_INVALID_ARGUMENT = 10,
00133         CCR_TOO_MANY_USERS = 100,
00134         CCR_INVALID_USER = 101
00135     } RESULT;


Constructor & Destructor Documentation

ConcurrencyController::ConcurrencyController  ) 
 

Default constructor for the ConcurrencyController.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/03/97

Definition at line 138 of file ccc.cpp.

00139 {
00140 }

ConcurrencyController::~ConcurrencyController  )  [virtual]
 

Default destructor for the ConcurrencyController.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/03/97

Definition at line 159 of file ccc.cpp.

00160 {
00161     if (s_NumberOfUsers > 1)
00162     {
00163         TRACEUSER( ME, _T("ConcurrencyController: Users still active\n"));
00164     }
00165 //  CriticalSection::DeInit();
00166 }


Member Function Documentation

ConcurrencyController::CC_DECLARE_MEMDUMP ConcurrencyController   )  [private]
 

ConcurrencyController::RESULT ConcurrencyController::EndUser UserID  UserWhosDone  ) 
 

Default destructor for the ConcurrencyController.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/03/97

Definition at line 219 of file ccc.cpp.

00220 {
00221     RESULT Result = CCR_OK;
00222 
00223     CriticalSection UpdateUserID;
00224 //  UpdateUserID.Start();
00225 
00226     if (UserWhosDone == s_OneAndOnlyUser)
00227     {
00228         s_OneAndOnlyUser = NULL;
00229         --s_NumberOfUsers;
00230     }
00231     else
00232     {
00233         Result = CCR_INVALID_USER;
00234     }
00235 
00236 //  UpdateUserID.End();
00237 
00238     return Result;
00239 }

ConcurrencyController::RESULT ConcurrencyController::FinalizeNodeRead Node *const   pNode  ) 
 

Once the given node has been read or passed as a parameter, call this function to free it for updates. This call should be accompanied by a prior call to PrepareNodeForRead(). The results of the read are undefined if not. See Also: FinalizeNodeUpdate().

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/02/97
Parameters:
pNode,: The node that was passed in a previous call to PrepareNodeForRead() [INPUTS]
Returns:
TRUE if the node can be read or updated again. FALSE otherwise

ConcurrencyController::RESULT ConcurrencyController::FinalizeNodeUpdate Node *const   pNode  ) 
 

Once the given node has been updated in the tree call this function to ensure its update is complete. This call should be accompanied by a prior call to PrepareForNodeUpdate(). The results of the update are undefined if not. See Also: FinalizeNodeRead().

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/02/97
Parameters:
pNode,: The node passed in a prior call to PrepareNodeForUpdate() [INPUTS]
Returns:
TRUE if the node was successfully updated FALSE otherwise

ConcurrencyController::RESULT ConcurrencyController::FinalizeOperation const Operation *const   pOperation  ) 
 

Default destructor for the ConcurrencyController.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/03/97

Definition at line 291 of file ccc.cpp.

00293 {
00294     RESULT Result = CCR_OK;
00295 
00296     CriticalSection UpdateOpTable;
00297 
00298     if (pOperation == s_pTheActiveOperation)
00299     {
00300         ERROR2IF(s_NumberOfActiveOperations != 1, CCR_INTERNAL_ERROR, "ActiveOps not Unity");
00301 
00302         s_pTheActiveOperation = NULL;
00303         --s_NumberOfActiveOperations;
00304     }
00305     else
00306     {
00307         Result = CCR_INVALID_ARGUMENT;
00308     }
00309 
00310     return Result;
00311 }

ConcurrencyController::UserID ConcurrencyController::GetNewUserID  )  [protected]
 

Support function to provide a new user id.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/03/97
Notes: Assumes thread-safe access to static members

Definition at line 406 of file ccc.cpp.

00407 {
00408     UserID NextID = ++s_NextFreeUserID;
00409 
00410     // if the NextID is zero, fail it always
00411     if (NextID == 0)
00412     {
00413         --s_NextFreeUserID;
00414     }
00415     return NextID;
00416 }

BOOL ConcurrencyController::Init  ) 
 

Definition at line 142 of file ccc.cpp.

00143 {
00144 //  CriticalSection::Init();
00145 
00146     return TRUE;
00147 }

ConcurrencyController::RESULT ConcurrencyController::PrepareForOperation const Operation *const   pOperation  ) 
 

Allows or disallows access to Operations.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/03/97
Notes: En ce moment only one op is allowed per application (static scope)

Definition at line 255 of file ccc.cpp.

00257 {
00258     RESULT Result = CCR_OK;
00259 
00260     CriticalSection UpdateOpTable;
00261 //  UpdateOpTable.Start();
00262 
00263     if (s_NumberOfActiveOperations == 0)
00264     {
00265         ERROR2IF(s_pTheActiveOperation != NULL, CCR_INTERNAL_ERROR, "ActiveOp not NULL");
00266         
00267         s_pTheActiveOperation = pOperation;
00268         ++s_NumberOfActiveOperations;
00269     }
00270     else
00271     {
00272         Result = CCR_TOO_MANY_USERS;
00273     }
00274 //  UpdateOpTable.End();
00275 
00276     return Result;
00277 }

ConcurrencyController::RESULT ConcurrencyController::PrepareNodeForRead Node *const   pNode  ) 
 

Before reading data in a node or passing it as a parameter to a function, call this function to ensure the integrity of the document tree. This call should be accompanied by a subsequent call to FinalizeNodeRead(). The results of the read are undefined if not. See Also: PrepareNodeForUpdate().

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/02/97
Parameters:
pNode,: The node to be read [INPUTS]
Returns:
TRUE if the node can be read FALSE otherwise

ConcurrencyController::RESULT ConcurrencyController::PrepareNodeForUpdate Node *const   pNode  ) 
 

Before updating a node, call this function to ensure the integrity of the document tree. This call should be accompanied by a subsequent call to FinalizeNodeUpdate(). The results of the update are undefined if not. See Also: PrepareNodeForRead().

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
25/02/97
Parameters:
pNode,: The node to be updated [INPUTS]
Returns:
TRUE if the node can be updated FALSE otherwise

ConcurrencyController::RESULT ConcurrencyController::StartUser UserID pNewUserID  ) 
 

Default destructor for the ConcurrencyController.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/03/97

Definition at line 179 of file ccc.cpp.

00180 {
00181     RESULT Result = CCR_OK;
00182 
00183     CriticalSection UpdateUserID;
00184 //  UpdateUserID.Start();
00185 
00186     if (s_NumberOfUsers == 0)
00187     {
00188         UserID NewUserID = GetNewUserID();
00189         if (NewUserID != NULL)
00190         {
00191             ++s_NumberOfUsers;
00192         }
00193         else
00194         {
00195             Result = CCR_TOO_MANY_USERS;
00196         }
00197         *pNewUserID = NewUserID;
00198     }
00199     else
00200     {
00201         Result = CCR_TOO_MANY_USERS;
00202     }
00203 //  UpdateUserID.End();
00204 
00205     return Result;
00206 }


Member Data Documentation

ConcurrencyController::UserID ConcurrencyController::s_NextFreeUserID = 0 [static, private]
 

Definition at line 158 of file ccc.h.

UINT32 ConcurrencyController::s_NumberOfActiveOperations = 0 [static, private]
 

Definition at line 163 of file ccc.h.

UINT32 ConcurrencyController::s_NumberOfUsers = 0 [static, private]
 

Definition at line 160 of file ccc.h.

ConcurrencyController::UserID ConcurrencyController::s_OneAndOnlyUser = 0 [static, private]
 

Definition at line 159 of file ccc.h.

const Operation * ConcurrencyController::s_pTheActiveOperation = NULL [static, private]
 

Definition at line 164 of file ccc.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:53:04 2007 for Camelot by  doxygen 1.4.4