ccc.cpp

Go to the documentation of this file.
00001 // $Id: ccc.cpp 751 2006-03-31 15:43:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // Implementation file for the ConcurrencyController
00099 
00100 #include "camtypes.h"
00101 #include "ccc.h"
00102 #include "gdrawasm.h"
00103 
00104 // Place any IMPLEMENT type statements here
00105 
00106 CC_IMPLEMENT_MEMDUMP(ConcurrencyController, CC_CLASS_MEMDUMP)
00107 //CC_IMPLEMENT_MEMDUMP(CriticalSection, CC_CLASS_MEMDUMP)
00108 
00109 // We want better memory tracking
00110 #define new CAM_DEBUG_NEW
00111 
00112 // Change this so TRACEUSERs work for you
00113 #define ME  "Colin"
00114 
00115 // Ooh Er! Static Members
00116 
00117 ConcurrencyController::UserID ConcurrencyController::s_NextFreeUserID = 0;
00118 ConcurrencyController::UserID ConcurrencyController::s_OneAndOnlyUser = 0;
00119 UINT32 ConcurrencyController::s_NumberOfUsers = 0;
00120 
00121 UINT32 ConcurrencyController::s_NumberOfActiveOperations = 0;
00122 const Operation* ConcurrencyController::s_pTheActiveOperation = NULL;
00123 
00124 // Functions follow
00125 
00126 
00127 
00128 /********************************************************************************************
00129 
00130 >   ConcurrencyController::ConcurrencyController() 
00131 
00132     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00133     Created:    11/03/97
00134 
00135     Purpose:    Default constructor for the ConcurrencyController
00136 
00137 ********************************************************************************************/
00138 ConcurrencyController::ConcurrencyController() 
00139 {
00140 }
00141 
00142 BOOL ConcurrencyController::Init()
00143 {
00144 //  CriticalSection::Init();
00145 
00146     return TRUE;
00147 }
00148 
00149 /********************************************************************************************
00150 
00151 >   ConcurrencyController::~ConcurrencyController() 
00152 
00153     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00154     Created:    11/03/97
00155 
00156     Purpose:    Default destructor for the ConcurrencyController
00157 
00158 ********************************************************************************************/
00159 ConcurrencyController::~ConcurrencyController() 
00160 {
00161     if (s_NumberOfUsers > 1)
00162     {
00163         TRACEUSER( ME, _T("ConcurrencyController: Users still active\n"));
00164     }
00165 //  CriticalSection::DeInit();
00166 }
00167 
00168 
00169 /********************************************************************************************
00170 
00171 >   ConcurrencyController::RESULT ConcurrencyController::StartUser(UserID* pNewUserID)
00172 
00173     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00174     Created:    11/03/97
00175 
00176     Purpose:    Default destructor for the ConcurrencyController
00177 
00178 ********************************************************************************************/
00179 ConcurrencyController::RESULT ConcurrencyController::StartUser(UserID* pNewUserID)
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 }
00207 
00208     
00209 /********************************************************************************************
00210 
00211 >   ConcurrencyController::RESULT ConcurrencyController::EndUser(UserID UserWhosDone)
00212 
00213     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00214     Created:    11/03/97
00215 
00216     Purpose:    Default destructor for the ConcurrencyController
00217 
00218 ********************************************************************************************/
00219 ConcurrencyController::RESULT ConcurrencyController::EndUser(UserID UserWhosDone)
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 }
00240 
00241 
00242 /********************************************************************************************
00243 
00244 >   ConcurrencyController::RESULT ConcurrencyController::PrepareForOperation(
00245                                                             const Operation* const pOperation)
00246 
00247     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00248     Created:    11/03/97
00249 
00250     Purpose:    Allows or disallows access to Operations.
00251 
00252     Notes:      En ce moment only one op is allowed per application (static scope)
00253 
00254 ********************************************************************************************/
00255 ConcurrencyController::RESULT ConcurrencyController::PrepareForOperation(
00256                                                         const Operation* const pOperation)
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 }
00278 
00279 
00280 /********************************************************************************************
00281 
00282 >   ConcurrencyController::RESULT ConcurrencyController::FinalizeOperation(
00283                                                         const Operation* const pOperation)
00284 
00285     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00286     Created:    11/03/97
00287 
00288     Purpose:    Default destructor for the ConcurrencyController
00289 
00290 ********************************************************************************************/
00291 ConcurrencyController::RESULT ConcurrencyController::FinalizeOperation(
00292                                                         const Operation* const pOperation)
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 }
00312 
00313 
00314 /*********************************************************************************************
00315            
00316 >   ConcurrencyController::RESULT ConcurrencyController::PrepareNodeForUpdate(Node* const pNode)
00317 
00318     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00319     Created:    25/02/97
00320 
00321     Inputs:     pNode:  The node to be updated
00322     Returns:    TRUE if the node can be updated
00323         FALSE otherwise
00324     Purpose:    Before updating a node, call this function to ensure the integrity of the 
00325         document tree.
00326         This call should be accompanied by a subsequent call to FinalizeNodeUpdate().
00327         The results of the update are undefined if not.
00328     See Also:   PrepareNodeForRead()
00329     
00330 **********************************************************************************************/  
00331 ConcurrencyController::RESULT ConcurrencyController::PrepareNodeForUpdate(Node* const pNode);
00332 
00333 
00334 /*********************************************************************************************
00335            
00336 >   ConcurrencyController::RESULT ConcurrencyController::FinalizeNodeUpdate(Node* const pNode)
00337 
00338     Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00339     Created:    25/02/97
00340 
00341     Inputs: pNode:  The node passed in a prior call to PrepareNodeForUpdate()
00342     Returns:    TRUE if the node was successfully updated
00343         FALSE otherwise
00344     Purpose:    Once the given node has been updated in the tree call this function to ensure
00345         its update is complete.
00346         This call should be accompanied by a prior call to PrepareForNodeUpdate(). The
00347         results of the update are undefined if not.
00348     See Also:   FinalizeNodeRead()
00349     
00350 **********************************************************************************************/  
00351 ConcurrencyController::RESULT ConcurrencyController::FinalizeNodeUpdate(Node* const pNode);
00352 
00353 
00354 /*********************************************************************************************
00355            
00356 >   ConcurrencyController::RESULT ConcurrencyController::PrepareNodeForRead(Node* const pNode)
00357 
00358     Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00359     Created:    25/02/97
00360 
00361     Inputs: pNode:  The node to be read
00362     Returns:    TRUE if the node can be read
00363         FALSE otherwise
00364     Purpose:    Before reading data in a node or passing it as a parameter to a function,
00365         call this function to ensure the integrity of the document tree.
00366         This call should be accompanied by a subsequent call to FinalizeNodeRead().
00367         The results of the read are undefined if not.
00368     See Also:   PrepareNodeForUpdate()
00369     
00370 **********************************************************************************************/  
00371 ConcurrencyController::RESULT ConcurrencyController::PrepareNodeForRead(Node* const pNode);
00372 
00373 
00374 /*********************************************************************************************
00375            
00376 >   ConcurrencyController::RESULT ConcurrencyController::FinalizeNodeRead(Node* const pNode)
00377 
00378     Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00379     Created:    25/02/97
00380 
00381     Inputs: pNode:  The node that was passed in a previous call to PrepareNodeForRead()
00382     Returns:    TRUE if the node can be read or updated again.
00383         FALSE otherwise
00384     Purpose:    Once the given node has been read or passed as a parameter, call this function 
00385         to free it for updates.
00386         This call should be accompanied by a prior call to PrepareNodeForRead(). The
00387         results of the read are undefined if not.
00388     See Also:   FinalizeNodeUpdate()
00389     
00390 **********************************************************************************************/  
00391 ConcurrencyController::RESULT ConcurrencyController::FinalizeNodeRead(Node* const pNode);
00392 
00393 
00394 /********************************************************************************************
00395 
00396 >   UserID ConcurrencyController::GetNewUserID()
00397 
00398     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00399     Created:    11/03/97
00400 
00401     Purpose:    Support function to provide a new user id
00402 
00403     Notes:      Assumes thread-safe access to static members
00404 
00405 ********************************************************************************************/
00406 ConcurrencyController::UserID ConcurrencyController::GetNewUserID()
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 }
00417 
00418 

Generated on Sat Nov 10 03:44:38 2007 for Camelot by  doxygen 1.4.4