BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball_transmission.h
Go to the documentation of this file.
1/// @file ball_transmission.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// ball_transmission.h -*-C++-*-
8#ifndef INCLUDED_BALL_TRANSMISSION
9#define INCLUDED_BALL_TRANSMISSION
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup ball_transmission ball_transmission
15/// @brief Enumerate the set of states for log record transmission.
16/// @addtogroup bal
17/// @{
18/// @addtogroup ball
19/// @{
20/// @addtogroup ball_transmission
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#ball_transmission-purpose"> Purpose</a>
25/// * <a href="#ball_transmission-classes"> Classes </a>
26/// * <a href="#ball_transmission-description"> Description </a>
27/// * <a href="#ball_transmission-usage"> Usage </a>
28/// * <a href="#ball_transmission-example-1-syntax"> Example 1: Syntax </a>
29/// * <a href="#ball_transmission-example-2-logging"> Example 2: Logging </a>
30///
31/// # Purpose {#ball_transmission-purpose}
32/// Enumerate the set of states for log record transmission.
33///
34/// # Classes {#ball_transmission-classes}
35///
36/// - ball::Transmission: namespace for log record transmission states
37///
38/// @see ball_context, ball_observer
39///
40/// # Description {#ball_transmission-description}
41/// This component provides a namespace, `ball::Transmission`, for
42/// the `enum` type `ball::Transmission::Cause`. `Cause` enumerates the list of
43/// conditions (or states) that can cause a log record to be transmitted. In
44/// addition, this component supports functions that convert the `Cause`
45/// enumerators to a well-defined ASCII representation.
46///
47/// ## Usage {#ball_transmission-usage}
48///
49///
50/// This section illustrates intended use of this component.
51///
52/// ### Example 1: Syntax {#ball_transmission-example-1-syntax}
53///
54///
55/// The following snippets of code provide a simple illustration of
56/// `ball::Transmission` usage.
57///
58/// First create a variable `cause` of type `ball::Transmission::Cause` and
59/// initialize it to the value `ball::Transmission::e_TRIGGER_ALL`:
60/// @code
61/// ball::Transmission::Cause cause = ball::Transmission::e_TRIGGER_ALL;
62/// @endcode
63/// Next, store a pointer to its ASCII representation in a variable `asciiCause`
64/// of type `const char *`:
65/// @code
66/// const char *asciiCause = ball::Transmission::toAscii(cause);
67/// assert(0 == strcmp(asciiCause, "TRIGGER_ALL"));
68/// @endcode
69/// Finally, print the value of `cause` to `bsl::cout`.
70/// @code
71/// bsl::cout << cause << bsl::endl;
72/// @endcode
73/// This statement produces the following output on `stdout`:
74/// @code
75/// TRIGGER_ALL
76/// @endcode
77///
78/// ### Example 2: Logging {#ball_transmission-example-2-logging}
79///
80///
81/// The `Cause` enumeration defined in this component allows a logging system
82/// to describe the condition causing the publication of a log message. One
83/// possible interpretation of three of these conditions is as follows:
84///
85/// `e_PASSTHROUGH`:
86/// indicate that a message is being output as a stand-alone message.
87///
88/// `e_TRIGGER`:
89/// indicate that a message is being output as part of a dump of all
90/// messages archived for the current thread.
91///
92/// `e_TRIGGER_ALL`:
93/// indicate that a message is being output as part of a dump of all
94/// messages archived for *all* threads.
95///
96/// This example illustrates the use of `ball::Transmission::Cause` by a
97/// hypothetical logging system.
98///
99/// We define a simple logger class named `my_Logger`. Assume that `my_Logger`
100/// accepts messages from clients (e.g., the threads in a multi-threaded
101/// application) and archives them in-core. Further assume that the message
102/// archive is bounded in size in which case `my_Logger` removes older messages
103/// to make room for newer ones as the need arises. When a thread encounters
104/// an unusual, unexpected, or undesirable condition that it wishes to bring to
105/// the attention of an operator (say, sitting at a console terminal), it
106/// "publishes" the message. That is the role of the `publish` method in the
107/// interface of `my_Logger`:
108/// @code
109/// // my_logger.h
110///
111/// class my_Logger {
112/// // ...
113/// public:
114/// my_Logger();
115/// ~my_Logger();
116/// void publish(const char *message, ball::Transmission::Cause cause);
117/// // ...
118/// };
119/// @endcode
120/// The `publish` method, defined in the following, shows the different actions
121/// that are taken for the three distinct causes of log message publication:
122/// @code
123/// // my_logger.cpp
124///
125/// my_Logger::my_Logger() { }
126///
127/// my_Logger::~my_Logger() { }
128///
129/// void my_Logger::publish(const char *message,
130/// ball::Transmission::Cause cause)
131/// {
132/// using namespace std;
133/// switch (cause) {
134/// case ball::Transmission::e_PASSTHROUGH: {
135/// cout << ball::Transmission::toAscii(cause) << ":\t" << message
136/// << endl;
137/// } break;
138/// case ball::Transmission::e_TRIGGER: {
139/// cout << ball::Transmission::toAscii(cause) << ":\t" << message
140/// << endl;
141/// cout << "\t[ dump all messages archived for current thread ]"
142/// << endl;
143/// } break;
144/// case ball::Transmission::e_TRIGGER_ALL: {
145/// cout << ball::Transmission::toAscii(cause) << ":\t" << message
146/// << endl;
147/// cout << "\t[ dump all messages archived for *all* threads ]"
148/// << endl;
149/// } break;
150/// default: {
151/// cout << "***ERROR*** Unsupported Message Cause: " << message
152/// << endl;
153/// return;
154/// } break;
155/// }
156/// }
157///
158/// // ...
159/// @endcode
160/// Finally, we create a `my_Logger` object and `publish` three (simplistic)
161/// messages, each with a different cause:
162/// @code
163/// my_Logger logger;
164///
165/// const char *MSG_PASSTHROUGH = "report relatively minor problem";
166/// const char *MSG_TRIGGER = "report serious thread-specific problem";
167/// const char *MSG_TRIGGER_ALL = "report process-impacting problem";
168///
169/// logger.publish(MSG_PASSTHROUGH, ball::Transmission::e_PASSTHROUGH);
170/// logger.publish(MSG_TRIGGER, ball::Transmission::e_TRIGGER);
171/// logger.publish(MSG_TRIGGER_ALL, ball::Transmission::e_TRIGGER_ALL);
172/// @endcode
173/// The following output is produced on `stdout`:
174/// @code
175/// PASSTHROUGH: report relatively minor problem
176/// TRIGGER: report serious thread-specific problem
177/// [ dump all messages archived for current thread ]
178/// TRIGGER_ALL: report process-impacting problem
179/// [ dump all messages archived for *all* threads ]
180/// @endcode
181/// @}
182/** @} */
183/** @} */
184
185/** @addtogroup bal
186 * @{
187 */
188/** @addtogroup ball
189 * @{
190 */
191/** @addtogroup ball_transmission
192 * @{
193 */
194
195#include <balscm_version.h>
196
197#include <bsl_iosfwd.h>
198
199
200namespace ball {
201
202 // ===================
203 // struct Transmission
204 // ===================
205
206/// This struct provides a namespace for enumerating the causes of the
207/// transmission of a log record.
209
210 public:
211 // TYPES
212
213 enum Cause {
214 e_PASSTHROUGH = 0, // single record emitted; caused locally
215 e_TRIGGER = 1, // all records emitted; caused locally
216 e_TRIGGER_ALL = 2, // all records emitted; caused remotely
217 e_MANUAL_PUBLISH = 3, // manually publish a single record
218 e_MANUAL_PUBLISH_ALL = 4, // manually publish all records
219 e_END = 5 // not supported, do not use
220 };
221
222 /// Define `LENGTH` to be the number of consecutively-valued enumerators
223 /// in the range `[ e_PASSTHROUGH .. e_MANUAL_PUBLISH_ALL ]`.
224 enum {
226 };
227
228 private:
229 // PRIVATE CLASS METHODS
230
231 /// Write to the specified `stream` the string representation of the
232 /// specified enumeration `value`.
233 static void print(bsl::ostream& stream, Transmission::Cause value);
234
235 public:
236 // CLASS METHODS
237
238 /// Format the specified `value` to the specified output `stream` and
239 /// return a reference to the modifiable `stream`.
240 static bsl::ostream& streamOut(bsl::ostream& stream,
241 Transmission::Cause value);
242
243 /// Return the string representation exactly matching the enumerator
244 /// name corresponding to the specified enumeration `value`.
245 static const char *toAscii(Transmission::Cause value);
246};
247
248// FREE OPERATORS
249
250/// Format the specified `rhs` to the specified output `stream` and return a
251/// reference to the modifiable `stream`.
252bsl::ostream& operator<<(bsl::ostream& stream, Transmission::Cause rhs);
253
254// ============================================================================
255// INLINE DEFINITIONS
256// ============================================================================
257
258 // -------------------
259 // struct Transmission
260 // -------------------
261
262// CLASS METHODS
263inline
264bsl::ostream& Transmission::streamOut(bsl::ostream& stream,
266{
267 print(stream, value);
268 return stream;
269}
270
271} // close package namespace
272
273// FREE OPERATORS
274inline
275bsl::ostream& ball::operator<<(bsl::ostream& stream, Transmission::Cause rhs)
276{
277 return Transmission::streamOut(stream, rhs);
278}
279
280
281
282#endif
283
284// ----------------------------------------------------------------------------
285// Copyright 2015 Bloomberg Finance L.P.
286//
287// Licensed under the Apache License, Version 2.0 (the "License");
288// you may not use this file except in compliance with the License.
289// You may obtain a copy of the License at
290//
291// http://www.apache.org/licenses/LICENSE-2.0
292//
293// Unless required by applicable law or agreed to in writing, software
294// distributed under the License is distributed on an "AS IS" BASIS,
295// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
296// See the License for the specific language governing permissions and
297// limitations under the License.
298// ----------------------------- END-OF-FILE ----------------------------------
299
300/** @} */
301/** @} */
302/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition ball_administration.h:214
bsl::ostream & operator<<(bsl::ostream &output, const Attribute &attribute)
Definition ball_transmission.h:208
Cause
Definition ball_transmission.h:213
@ e_END
Definition ball_transmission.h:219
@ e_MANUAL_PUBLISH
Definition ball_transmission.h:217
@ e_PASSTHROUGH
Definition ball_transmission.h:214
@ e_TRIGGER
Definition ball_transmission.h:215
@ e_TRIGGER_ALL
Definition ball_transmission.h:216
@ e_MANUAL_PUBLISH_ALL
Definition ball_transmission.h:218
@ e_LENGTH
Definition ball_transmission.h:225
static bsl::ostream & streamOut(bsl::ostream &stream, Transmission::Cause value)
Definition ball_transmission.h:264
static const char * toAscii(Transmission::Cause value)