TGLLockable.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLLockable.cxx 32040 2010-01-18 13:56:00Z matevz $
00002 // Author:  Matevz Tadel, Feb 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGLLockable.h"
00013 #include <TError.h>
00014 
00015 //______________________________________________________________________
00016 // TGLLockable
00017 //
00018 // Simple locking interface used by viewer and scene.
00019 
00020 
00021 ClassImp(TGLLockable);
00022 
00023 TGLLockable::TGLLockable() :
00024    fLock      (kUnlocked)
00025 {
00026    // Constructor
00027 }
00028 
00029 //______________________________________________________________________________
00030 Bool_t TGLLockable::TakeLock(ELock lock) const
00031 {
00032    // Lock the object in mode 'lock'. Return TRUE if successful, FALSE
00033    // if the object is already locked.
00034 
00035    if (LockValid(lock) && fLock == kUnlocked) {
00036       fLock = lock;
00037       if (gDebug>3) {
00038          Info("TGLLockable::TakeLock", "'%s' took %s",
00039               LockIdStr(), LockName(fLock));
00040       }
00041       return kTRUE;
00042    }
00043    Error("TGLLockable::TakeLock", "'%s' unable to take %s, already %s",
00044          LockIdStr(), LockName(lock), LockName(fLock));
00045    return kFALSE;
00046 }
00047 
00048 //______________________________________________________________________________
00049 Bool_t TGLLockable::ReleaseLock(ELock lock) const
00050 {
00051    // Release current lock, make sure it the same as the 'lock' argument.
00052    // Returns TRUE on success, FALSE on failure.
00053 
00054    if (LockValid(lock) && fLock == lock) {
00055       fLock = kUnlocked;
00056       if (gDebug>3) {
00057          Info("TGLLockable::ReleaseLock", "'%s' released %s",
00058               LockIdStr(), LockName(lock));
00059       }
00060       return kTRUE;
00061    }
00062    Error("TGLLockable::ReleaseLock", "'%s' unable to release %s, is %s",
00063          LockIdStr(), LockName(lock), LockName(fLock));
00064    return kFALSE;
00065 }
00066 
00067 //______________________________________________________________________________
00068 const char* TGLLockable::LockName(ELock lock)
00069 {
00070    // Return name-string for given lock-type.
00071 
00072    static const char* names[] =
00073       { "Unlocked", "DrawLock", "SelectLock", "ModifyLock" };
00074 
00075    if (lock <= kModifyLock) {
00076       return names[lock];
00077    } else {
00078       return "<unknown-lock>";
00079    }
00080 }
00081 
00082 //______________________________________________________________________________
00083 Bool_t TGLLockable::LockValid(ELock lock)
00084 {
00085    // Test if lock is a valid type to take/release.
00086    // kUnlocked is never valid in these cases.
00087 
00088    switch(lock) {
00089       case kDrawLock:
00090       case kSelectLock:
00091       case kModifyLock:
00092          return kTRUE;
00093       default:
00094          return kFALSE;
00095    }
00096 }

Generated on Tue Jul 5 14:18:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1