Skip to content

Commit 631e87f

Browse files
committed
Populate ntca::SendContext to inform the user how compression was applied during send operation
1 parent 0a829cf commit 631e87f

14 files changed

+887
-270
lines changed

groups/ntc/ntca/ntca_sendcontext.cpp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,38 @@ namespace ntca {
2525

2626
bool SendContext::equals(const SendContext& other) const
2727
{
28-
return (d_error == other.d_error);
28+
return (d_token == other.d_token &&
29+
d_compressionType == other.d_compressionType &&
30+
d_compressionRatio == other.d_compressionRatio &&
31+
d_error == other.d_error);
2932
}
3033

3134
bool SendContext::less(const SendContext& other) const
3235
{
36+
if (d_token < other.d_token) {
37+
return true;
38+
}
39+
40+
if (other.d_token < d_token) {
41+
return false;
42+
}
43+
44+
if (d_compressionType < other.d_compressionType) {
45+
return true;
46+
}
47+
48+
if (other.d_compressionType < d_compressionType) {
49+
return false;
50+
}
51+
52+
if (d_compressionRatio < other.d_compressionRatio) {
53+
return true;
54+
}
55+
56+
if (other.d_compressionRatio < d_compressionRatio) {
57+
return false;
58+
}
59+
3360
return d_error < other.d_error;
3461
}
3562

@@ -39,7 +66,29 @@ bsl::ostream& SendContext::print(bsl::ostream& stream,
3966
{
4067
bslim::Printer printer(&stream, level, spacesPerLevel);
4168
printer.start();
42-
printer.printAttribute("error", d_error);
69+
70+
if (d_token.has_value()) {
71+
printer.printAttribute("token", d_token.value());
72+
}
73+
74+
if (d_compressionType.has_value()) {
75+
printer.printAttribute("compressionType", d_compressionType.value());
76+
}
77+
78+
if (d_compressionRatio.has_value()) {
79+
80+
bsl::ostringstream ss;
81+
ss << bsl::setprecision(2);
82+
ss << bsl::fixed;
83+
ss << d_compressionRatio.value() * 100;
84+
85+
printer.printAttribute("compressionRatio", ss.str());
86+
}
87+
88+
if (d_error) {
89+
printer.printAttribute("error", d_error);
90+
}
91+
4392
printer.end();
4493
return stream;
4594
}

groups/ntc/ntca/ntca_sendcontext.h

Lines changed: 124 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
#include <bsls_ident.h>
2020
BSLS_IDENT("$Id: $")
2121

22+
#include <ntca_compressiontype.h>
23+
#include <ntca_sendtoken.h>
2224
#include <ntccfg_platform.h>
2325
#include <ntcscm_version.h>
2426
#include <ntsa_error.h>
27+
#include <bdlb_nullablevalue.h>
2528
#include <bslh_hash.h>
2629
#include <bsl_iosfwd.h>
2730

@@ -33,6 +36,23 @@ namespace ntca {
3336
/// @par Attributes
3437
/// This class is composed of the following attributes.
3538
///
39+
/// @li @b token:
40+
/// The token used to cancel the operation. This token matches the token
41+
/// specified in the corresponding send options, if any.
42+
///
43+
/// @li @b compressionType:
44+
/// The compression algorithm used to deflate the user's data before
45+
/// transmission, if any. If unspecified, no compression was performed.
46+
///
47+
/// @li @b compressionRatio:
48+
/// The ratio of deflated size of the data actually transmitted to the size of
49+
/// the original data desired to be sent. Note that value may be greater than
50+
/// one in the case of poorly-compressible data. If unspecified, no compression
51+
/// was performed.
52+
///
53+
/// @li @b error:
54+
/// The error detected when performing the operation.
55+
///
3656
/// @li @b error:
3757
/// The error detected when performing the operation.
3858
///
@@ -42,7 +62,10 @@ namespace ntca {
4262
/// @ingroup module_ntci_operation_send
4363
class SendContext
4464
{
45-
ntsa::Error d_error;
65+
bdlb::NullableValue<ntca::SendToken> d_token;
66+
bdlb::NullableValue<ntca::CompressionType::Value> d_compressionType;
67+
bdlb::NullableValue<double> d_compressionRatio;
68+
ntsa::Error d_error;
4669

4770
public:
4871
/// Create a new send context having the default value.
@@ -55,40 +78,61 @@ class SendContext
5578
/// Destroy this object.
5679
~SendContext();
5780

58-
/// Assign the value of the specified 'other' object to this object.
59-
/// Return a reference to this modifiable object.
81+
/// Assign the value of the specified 'other' object to this object. Return
82+
/// a reference to this modifiable object.
6083
SendContext& operator=(const SendContext& other);
6184

62-
/// Reset the value of this object to its value upon default
63-
/// construction.
85+
/// Reset the value of this object to its value upon default construction.
6486
void reset();
6587

66-
/// Set the error detected when performing the operation to the
67-
/// specified 'value'.
88+
/// Set the token used to cancel the operation to the specified 'value'.
89+
void setToken(const ntca::SendToken& value);
90+
91+
/// Set the compression algorithm compression algorithm used to deflate the
92+
/// user's data before transmission to the specified 'value'.
93+
void setCompressionType(ntca::CompressionType::Value value);
94+
95+
/// Set the ratio of deflated size of the data actually transmitted to the
96+
/// size of the original data desired to be sent to the specified 'value'.
97+
void setCompressionRatio(double value);
98+
99+
/// Set the error detected when performing the operation to the specified
100+
/// 'value'.
68101
void setError(const ntsa::Error& value);
69102

103+
/// Return the token used to cancel the operation.
104+
const bdlb::NullableValue<ntca::SendToken>& token() const;
105+
106+
/// Return the compression algorithm compression algorithm used to deflate
107+
/// the user's data before transmission.
108+
const bdlb::NullableValue<ntca::CompressionType::Value>&
109+
compressionType() const;
110+
111+
/// Return the ratio of deflated size of the data actually transmitted to
112+
/// the size of the original data desired to be sent.
113+
const bdlb::NullableValue<double>& compressionRatio() const;
114+
70115
/// Return the error detected when performing the operation.
71116
const ntsa::Error& error() const;
72117

73-
/// Return true if this object has the same value as the specified
74-
/// 'other' object, otherwise return false.
118+
/// Return true if this object has the same value as the specified 'other'
119+
/// object, otherwise return false.
75120
bool equals(const SendContext& other) const;
76121

77-
/// Return true if the value of this object is less than the value of
78-
/// the specified 'other' object, otherwise return false.
122+
/// Return true if the value of this object is less than the value of the
123+
/// specified 'other' object, otherwise return false.
79124
bool less(const SendContext& other) const;
80125

81-
/// Format this object to the specified output 'stream' at the
82-
/// optionally specified indentation 'level' and return a reference to
83-
/// the modifiable 'stream'. If 'level' is specified, optionally
84-
/// specify 'spacesPerLevel', the number of spaces per indentation level
85-
/// for this and all of its nested objects. Each line is indented by
86-
/// the absolute value of 'level * spacesPerLevel'. If 'level' is
87-
/// negative, suppress indentation of the first line. If
88-
/// 'spacesPerLevel' is negative, suppress line breaks and format the
89-
/// entire output on one line. If 'stream' is initially invalid, this
90-
/// operation has no effect. Note that a trailing newline is provided
91-
/// in multiline mode only.
126+
/// Format this object to the specified output 'stream' at the optionally
127+
/// specified indentation 'level' and return a reference to the modifiable
128+
/// 'stream'. If 'level' is specified, optionally specify
129+
/// 'spacesPerLevel', the number of spaces per indentation level for this
130+
/// and all of its nested objects. Each line is indented by the absolute
131+
/// value of 'level * spacesPerLevel'. If 'level' is negative, suppress
132+
/// indentation of the first line. If 'spacesPerLevel' is negative,
133+
/// suppress line breaks and format the entire output on one line. If
134+
/// 'stream' is initially invalid, this operation has no effect. Note that
135+
/// a trailing newline is provided in multiline mode only.
92136
bsl::ostream& print(bsl::ostream& stream,
93137
int level = 0,
94138
int spacesPerLevel = 4) const;
@@ -137,13 +181,19 @@ void hashAppend(HASH_ALGORITHM& algorithm, const SendContext& value);
137181

138182
NTCCFG_INLINE
139183
SendContext::SendContext()
140-
: d_error()
184+
: d_token()
185+
, d_compressionType()
186+
, d_compressionRatio()
187+
, d_error()
141188
{
142189
}
143190

144191
NTCCFG_INLINE
145192
SendContext::SendContext(const SendContext& original)
146-
: d_error(original.d_error)
193+
: d_token(original.d_token)
194+
, d_compressionType(original.d_compressionType)
195+
, d_compressionRatio(original.d_compressionRatio)
196+
, d_error(original.d_error)
147197
{
148198
}
149199

@@ -155,22 +205,68 @@ SendContext::~SendContext()
155205
NTCCFG_INLINE
156206
SendContext& SendContext::operator=(const SendContext& other)
157207
{
158-
d_error = other.d_error;
208+
if (this != &other) {
209+
d_token = other.d_token;
210+
d_compressionType = other.d_compressionType;
211+
d_compressionRatio = other.d_compressionRatio;
212+
d_error = other.d_error;
213+
}
214+
159215
return *this;
160216
}
161217

162218
NTCCFG_INLINE
163219
void SendContext::reset()
164220
{
221+
d_token.reset();
222+
d_compressionType.reset();
223+
d_compressionRatio.reset();
165224
d_error = ntsa::Error();
166225
}
167226

227+
NTCCFG_INLINE
228+
void SendContext::setToken(const ntca::SendToken& value)
229+
{
230+
d_token = value;
231+
}
232+
233+
NTCCFG_INLINE
234+
void SendContext::setCompressionType(ntca::CompressionType::Value value)
235+
{
236+
d_compressionType = value;
237+
}
238+
239+
NTCCFG_INLINE
240+
void SendContext::setCompressionRatio(double value)
241+
{
242+
d_compressionRatio = value;
243+
}
244+
168245
NTCCFG_INLINE
169246
void SendContext::setError(const ntsa::Error& value)
170247
{
171248
d_error = value;
172249
}
173250

251+
NTCCFG_INLINE
252+
const bdlb::NullableValue<ntca::SendToken>& SendContext::token() const
253+
{
254+
return d_token;
255+
}
256+
257+
NTCCFG_INLINE
258+
const bdlb::NullableValue<ntca::CompressionType::Value>&
259+
SendContext::compressionType() const
260+
{
261+
return d_compressionType;
262+
}
263+
264+
NTCCFG_INLINE
265+
const bdlb::NullableValue<double>& SendContext::compressionRatio() const
266+
{
267+
return d_compressionRatio;
268+
}
269+
174270
NTCCFG_INLINE
175271
const ntsa::Error& SendContext::error() const
176272
{
@@ -206,6 +302,9 @@ void hashAppend(HASH_ALGORITHM& algorithm, const SendContext& value)
206302
{
207303
using bslh::hashAppend;
208304

305+
hashAppend(algorithm, value.token());
306+
hashAppend(algorithm, value.compressionType());
307+
hashAppend(algorithm, value.compressionRatio());
209308
hashAppend(algorithm, value.error());
210309
}
211310

groups/ntc/ntcf/ntcf_system.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ ntsa::Error System::initialize()
309309
ntcs::MonitorableUtil::initialize();
310310
ntcs::Plugin::initialize();
311311
ntcs::Global::initialize();
312+
ntctlc::Plugin::initialize();
312313

313314
// We use a new delete allocator instead of the global allocator here
314315
// because we want prevent a visible "memory leak" if the global
@@ -1405,8 +1406,6 @@ ntsa::Error System::createCompression(
14051406
error = ntcf::System::initialize();
14061407
BSLS_ASSERT_OPT(!error);
14071408

1408-
ntctlc::Plugin::initialize();
1409-
14101409
bsl::shared_ptr<ntci::CompressionDriver> compressionDriver;
14111410
error = ntcs::Plugin::lookupCompressionDriver(&compressionDriver);
14121411
if (error) {

0 commit comments

Comments
 (0)