Logo ROOT   6.14/05
Reference Guide
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 
21 
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 
33 {
34  if (LockValid(lock) && fLock == kUnlocked) {
35  fLock = lock;
36  if (gDebug>3) {
37  Info("TGLLockable::TakeLock", "'%s' took %s",
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 
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 
86 {
87  switch(lock) {
88  case kDrawLock:
89  case kSelectLock:
90  case kModifyLock:
91  return kTRUE;
92  default:
93  return kFALSE;
94  }
95 }
Bool_t ReleaseLock(ELock lock) const
Release current lock, make sure it the same as the &#39;lock&#39; argument.
Definition: TGLLockable.cxx:51
bool Bool_t
Definition: RtypesCore.h:59
static Bool_t LockValid(ELock lock)
Test if lock is a valid type to take/release.
Definition: TGLLockable.cxx:85
virtual const char * LockIdStr() const
Definition: TGLLockable.h:56
void Info(const char *location, const char *msgfmt,...)
void Error(const char *location, const char *msgfmt,...)
ELock fLock
Definition: TGLLockable.h:32
const Bool_t kFALSE
Definition: RtypesCore.h:88
static const char * LockName(ELock lock)
Return name-string for given lock-type.
Definition: TGLLockable.cxx:69
#define ClassImp(name)
Definition: Rtypes.h:359
R__EXTERN Int_t gDebug
Definition: Rtypes.h:86
Bool_t TakeLock(ELock lock) const
Lock the object in mode &#39;lock&#39;.
Definition: TGLLockable.cxx:32
Simple locking interface used by viewer and scene.
Definition: TGLLockable.h:17
const Bool_t kTRUE
Definition: RtypesCore.h:87