Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
17Simple locking interface used by viewer and scene.
18*/
19
20
22 fLock (kUnlocked)
23{
24 // Constructor
25}
26
27////////////////////////////////////////////////////////////////////////////////
28/// Lock the object in mode 'lock'. Return TRUE if successful, FALSE
29/// if the object is already locked.
30
32{
33 if (LockValid(lock) && fLock == kUnlocked) {
34 fLock = lock;
35 if (gDebug>3) {
36 Info("TGLLockable::TakeLock", "'%s' took %s",
38 }
39 return kTRUE;
40 }
41 Error("TGLLockable::TakeLock", "'%s' unable to take %s, already %s",
42 LockIdStr(), LockName(lock), LockName(fLock));
43 return kFALSE;
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Release current lock, make sure it the same as the 'lock' argument.
48/// Returns TRUE on success, FALSE on failure.
49
51{
52 if (LockValid(lock) && fLock == lock) {
54 if (gDebug>3) {
55 Info("TGLLockable::ReleaseLock", "'%s' released %s",
56 LockIdStr(), LockName(lock));
57 }
58 return kTRUE;
59 }
60 Error("TGLLockable::ReleaseLock", "'%s' unable to release %s, is %s",
61 LockIdStr(), LockName(lock), LockName(fLock));
62 return kFALSE;
63}
64
65////////////////////////////////////////////////////////////////////////////////
66/// Return name-string for given lock-type.
67
69{
70 static const char* names[] =
71 { "Unlocked", "DrawLock", "SelectLock", "ModifyLock" };
72
73 if (lock <= kModifyLock) {
74 return names[lock];
75 } else {
76 return "<unknown-lock>";
77 }
78}
79
80////////////////////////////////////////////////////////////////////////////////
81/// Test if lock is a valid type to take/release.
82/// kUnlocked is never valid in these cases.
83
85{
86 switch(lock) {
87 case kDrawLock:
88 case kSelectLock:
89 case kModifyLock:
90 return kTRUE;
91 default:
92 return kFALSE;
93 }
94}
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:627
Bool_t TakeLock(ELock lock) const
Lock the object in mode 'lock'.
Bool_t ReleaseLock(ELock lock) const
Release current lock, make sure it the same as the 'lock' argument.
static const char * LockName(ELock lock)
Return name-string for given lock-type.
virtual const char * LockIdStr() const
Definition TGLLockable.h:56
static Bool_t LockValid(ELock lock)
Test if lock is a valid type to take/release.