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
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) {
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
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}
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:220
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
Int_t gDebug
Definition TROOT.cxx:592
Simple locking interface used by viewer and scene.
Definition TGLLockable.h:18
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.