ROOT logo
// @(#)root/gl:$Id$
// Author:  Matevz Tadel, Feb 2007

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TGLLockable.h"
#include <TError.h>

//______________________________________________________________________
// TGLLockable
//
// Simple locking interface used by viewer and scene.


ClassImp(TGLLockable);

TGLLockable::TGLLockable() :
   fLock      (kUnlocked)
{
   // Constructor
}

//______________________________________________________________________________
Bool_t TGLLockable::TakeLock(ELock lock) const
{
   // Lock the object in mode 'lock'. Return TRUE if successful, FALSE
   // if the object is already locked.

   if (LockValid(lock) && fLock == kUnlocked) {
      fLock = lock;
      if (gDebug>3) {
         Info("TGLLockable::TakeLock", "'%s' took %s",
              LockIdStr(), LockName(fLock));
      }
      return kTRUE;
   }
   Error("TGLLockable::TakeLock", "'%s' unable to take %s, already %s",
         LockIdStr(), LockName(lock), LockName(fLock));
   return kFALSE;
}

//______________________________________________________________________________
Bool_t TGLLockable::ReleaseLock(ELock lock) const
{
   // Release current lock, make sure it the same as the 'lock' argument.
   // Returns TRUE on success, FALSE on failure.

   if (LockValid(lock) && fLock == lock) {
      fLock = kUnlocked;
      if (gDebug>3) {
         Info("TGLLockable::ReleaseLock", "'%s' released %s",
              LockIdStr(), LockName(lock));
      }
      return kTRUE;
   }
   Error("TGLLockable::ReleaseLock", "'%s' unable to release %s, is %s",
         LockIdStr(), LockName(lock), LockName(fLock));
   return kFALSE;
}

//______________________________________________________________________________
const char* TGLLockable::LockName(ELock lock)
{
   // Return name-string for given lock-type.

   static const char* names[] =
      { "Unlocked", "DrawLock", "SelectLock", "ModifyLock" };

   if (lock <= kModifyLock) {
      return names[lock];
   } else {
      return "<unknown-lock>";
   }
}

//______________________________________________________________________________
Bool_t TGLLockable::LockValid(ELock lock)
{
   // Test if lock is a valid type to take/release.
   // kUnlocked is never valid in these cases.

   switch(lock) {
      case kDrawLock:
      case kSelectLock:
      case kModifyLock:
         return kTRUE;
      default:
         return kFALSE;
   }
}
 TGLLockable.cxx:1
 TGLLockable.cxx:2
 TGLLockable.cxx:3
 TGLLockable.cxx:4
 TGLLockable.cxx:5
 TGLLockable.cxx:6
 TGLLockable.cxx:7
 TGLLockable.cxx:8
 TGLLockable.cxx:9
 TGLLockable.cxx:10
 TGLLockable.cxx:11
 TGLLockable.cxx:12
 TGLLockable.cxx:13
 TGLLockable.cxx:14
 TGLLockable.cxx:15
 TGLLockable.cxx:16
 TGLLockable.cxx:17
 TGLLockable.cxx:18
 TGLLockable.cxx:19
 TGLLockable.cxx:20
 TGLLockable.cxx:21
 TGLLockable.cxx:22
 TGLLockable.cxx:23
 TGLLockable.cxx:24
 TGLLockable.cxx:25
 TGLLockable.cxx:26
 TGLLockable.cxx:27
 TGLLockable.cxx:28
 TGLLockable.cxx:29
 TGLLockable.cxx:30
 TGLLockable.cxx:31
 TGLLockable.cxx:32
 TGLLockable.cxx:33
 TGLLockable.cxx:34
 TGLLockable.cxx:35
 TGLLockable.cxx:36
 TGLLockable.cxx:37
 TGLLockable.cxx:38
 TGLLockable.cxx:39
 TGLLockable.cxx:40
 TGLLockable.cxx:41
 TGLLockable.cxx:42
 TGLLockable.cxx:43
 TGLLockable.cxx:44
 TGLLockable.cxx:45
 TGLLockable.cxx:46
 TGLLockable.cxx:47
 TGLLockable.cxx:48
 TGLLockable.cxx:49
 TGLLockable.cxx:50
 TGLLockable.cxx:51
 TGLLockable.cxx:52
 TGLLockable.cxx:53
 TGLLockable.cxx:54
 TGLLockable.cxx:55
 TGLLockable.cxx:56
 TGLLockable.cxx:57
 TGLLockable.cxx:58
 TGLLockable.cxx:59
 TGLLockable.cxx:60
 TGLLockable.cxx:61
 TGLLockable.cxx:62
 TGLLockable.cxx:63
 TGLLockable.cxx:64
 TGLLockable.cxx:65
 TGLLockable.cxx:66
 TGLLockable.cxx:67
 TGLLockable.cxx:68
 TGLLockable.cxx:69
 TGLLockable.cxx:70
 TGLLockable.cxx:71
 TGLLockable.cxx:72
 TGLLockable.cxx:73
 TGLLockable.cxx:74
 TGLLockable.cxx:75
 TGLLockable.cxx:76
 TGLLockable.cxx:77
 TGLLockable.cxx:78
 TGLLockable.cxx:79
 TGLLockable.cxx:80
 TGLLockable.cxx:81
 TGLLockable.cxx:82
 TGLLockable.cxx:83
 TGLLockable.cxx:84
 TGLLockable.cxx:85
 TGLLockable.cxx:86
 TGLLockable.cxx:87
 TGLLockable.cxx:88
 TGLLockable.cxx:89
 TGLLockable.cxx:90
 TGLLockable.cxx:91
 TGLLockable.cxx:92
 TGLLockable.cxx:93
 TGLLockable.cxx:94
 TGLLockable.cxx:95
 TGLLockable.cxx:96