Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLLockable.cxx
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Matevz Tadel, Feb 2007
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TGLLockable.h"
13 #include <TError.h>
14 
15 /** \class TGLLockable
16 \ingroup opengl
17 Simple locking interface used by viewer and scene.
18 */
19 
20 ClassImp(TGLLockable);
21 
22 TGLLockable::TGLLockable() :
23  fLock (kUnlocked)
24 {
25  // Constructor
26 }
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// Lock the object in mode 'lock'. Return TRUE if successful, FALSE
30 /// if the object is already locked.
31 
32 Bool_t TGLLockable::TakeLock(ELock lock) const
33 {
34  if (LockValid(lock) && fLock == kUnlocked) {
35  fLock = lock;
36  if (gDebug>3) {
37  Info("TGLLockable::TakeLock", "'%s' took %s",
38  LockIdStr(), LockName(fLock));
39  }
40  return kTRUE;
41  }
42  Error("TGLLockable::TakeLock", "'%s' unable to take %s, already %s",
43  LockIdStr(), LockName(lock), LockName(fLock));
44  return kFALSE;
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Release current lock, make sure it the same as the 'lock' argument.
49 /// Returns TRUE on success, FALSE on failure.
50 
51 Bool_t TGLLockable::ReleaseLock(ELock lock) const
52 {
53  if (LockValid(lock) && fLock == lock) {
54  fLock = kUnlocked;
55  if (gDebug>3) {
56  Info("TGLLockable::ReleaseLock", "'%s' released %s",
57  LockIdStr(), LockName(lock));
58  }
59  return kTRUE;
60  }
61  Error("TGLLockable::ReleaseLock", "'%s' unable to release %s, is %s",
62  LockIdStr(), LockName(lock), LockName(fLock));
63  return kFALSE;
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Return name-string for given lock-type.
68 
69 const char* TGLLockable::LockName(ELock lock)
70 {
71  static const char* names[] =
72  { "Unlocked", "DrawLock", "SelectLock", "ModifyLock" };
73 
74  if (lock <= kModifyLock) {
75  return names[lock];
76  } else {
77  return "<unknown-lock>";
78  }
79 }
80 
81 ////////////////////////////////////////////////////////////////////////////////
82 /// Test if lock is a valid type to take/release.
83 /// kUnlocked is never valid in these cases.
84 
85 Bool_t TGLLockable::LockValid(ELock lock)
86 {
87  switch(lock) {
88  case kDrawLock:
89  case kSelectLock:
90  case kModifyLock:
91  return kTRUE;
92  default:
93  return kFALSE;
94  }
95 }