Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

class_channel.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2000 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_CLASS_CHANNEL_H
19 #define LIBCWD_CLASS_CHANNEL_H
20 
21 #ifndef LIBCWD_CONFIG_H
22 #include <libcwd/config.h>
23 #endif
24 #ifndef LIBCWD_MAX_LABEL_LEN_H
25 #include <libcwd/max_label_len.h>
26 #endif
27 #ifndef LIBCWD_CONTROL_FLAG_H
28 #include <libcwd/control_flag.h>
29 #endif
30 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
32 #endif
33 
34 namespace libcwd {
35 
82 class channel_ct {
83 private:
84 #if LIBCWD_THREAD_SAFE
85  int WNS_index;
86  // A unique id that is used as index into the TSD array `off_cnt_array'.
87 #else // !LIBCWD_THREAD_SAFE
88  int off_cnt;
89  // A counter of the nested calls to off().
90  // The channel is turned off when the value of `off' is larger or equal then zero
91  // and `on' when it has the value -1.
92 #endif // !LIBCWD_THREAD_SAFE
93 
94  char WNS_label[max_label_len_c + 1]; // +1 for zero termination.
95  // A reference name for the represented debug channel
96  // This label will be printed in front of each output written to
97  // this debug channel.
98 
99  bool WNS_initialized;
100  // Set to true when initialized.
101 
102  static channel_ct const off_channel;
103  // Channel that is always off.
104 
105 public:
106  //---------------------------------------------------------------------------
107  // Constructor
108  //
109 
110  // MT: All channel objects must be global so that `WNS_initialized' is false
111  // at the start of the program and initialization occurs before other threads
112  // share the object.
113  explicit channel_ct(char const* label, bool add_to_channel_list = true);
114 
115  // MT: May only be called from the constructors of global objects (or single threaded functions).
116  void NS_initialize(char const* label LIBCWD_COMMA_TSD_PARAM, bool add_to_channel_list);
117  // Force initialization in case the constructor of this global object
118  // wasn't called yet. Does nothing when the object was already initialized.
119 
120 public:
121  //---------------------------------------------------------------------------
122  // Manipulators
123  //
124 
125  void off(void);
126  void on(void);
127 
128  struct OnOffState {
129  int off_cnt;
130  };
131 
132  void force_on(OnOffState& state, char const* label);
133  void restore(OnOffState const& state);
134 
135  channel_ct const& operator()(bool cond) const { return cond ? *this : off_channel; }
136 
137 public:
138  //---------------------------------------------------------------------------
139  // Accessors
140  //
141 
142  char const* get_label(void) const;
143  bool is_on(void) const;
144 #if LIBCWD_THREAD_SAFE
145  bool is_on(LIBCWD_TSD_PARAM) const;
146 #endif
147 };
148 
149 } // namespace libcwd
150 
151 #endif // LIBCWD_CLASS_CHANNEL_H
152 
void off(void)
Turn this channel off.
Definition: debug.cc:1773
char const * get_label(void) const
Pointer to the label of the debug channel.
Definition: class_channel.inl:71
channel_ct(char const *label, bool add_to_channel_list=true)
Construct a new debug channel with name label.
Definition: class_channel.inl:35
bool is_on(void) const
Returns `true' if the channel is active.
Definition: class_channel.inl:56
void on(void)
Cancel one call to `off()'.
Definition: debug.cc:1788
unsigned short const max_label_len_c
The maximum number of characters that are allowed in a debug channel label.
Definition: max_label_len.h:24
This object represents a debug channel, it has a fixed label. A debug channel can be viewed upon as a...
Definition: class_channel.h:82
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.