Skip to content

Commit

Permalink
eclipse-paho#266 Copy/move properties in will_options copy and move c…
Browse files Browse the repository at this point in the history
…onstructors and assignment operators. Also added parameter for properties in all the will_options constructors.
  • Loading branch information
fpagliughi committed Dec 27, 2020
1 parent 84b060e commit 3b400b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
14 changes: 10 additions & 4 deletions src/mqtt/will_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class will_options
* The properties for the LWT message.
* Strangely, in the C lib, the will properties are not in the
* willOptions struct, but are rather in the connectOptions.
* So we keep the cached properties here, but need to transfer them to
* the connect_options when we're added to that struct.
*/
properties props_;

Expand Down Expand Up @@ -115,7 +117,8 @@ class will_options
* subscribers.
*/
will_options(string_ref top, const void *payload, size_t payload_len,
int qos=DFLT_QOS, bool retained=DFLT_RETAINED);
int qos=DFLT_QOS, bool retained=DFLT_RETAINED,
const properties& props=properties());
/**
* Sets the "Last Will and Testament" (LWT) for the connection.
* @param top The LWT message is published to the this topic.
Expand All @@ -126,7 +129,8 @@ class will_options
* subscribers.
*/
will_options(const topic& top, const void *payload, size_t payload_len,
int qos=DFLT_QOS, bool retained=DFLT_RETAINED);
int qos=DFLT_QOS, bool retained=DFLT_RETAINED,
const properties& props=properties());
/**
* Sets the "Last Will and Testament" (LWT) for the connection.
* @param top The LWT message is published to the this topic.
Expand All @@ -137,7 +141,8 @@ class will_options
* subscribers.
*/
will_options(string_ref top, binary_ref payload,
int qos=DFLT_QOS, bool retained=DFLT_RETAINED);
int qos=DFLT_QOS, bool retained=DFLT_RETAINED,
const properties& props=properties());
/**
* Sets the "Last Will and Testament" (LWT) for the connection.
* @param top The LWT message is published to the this topic.
Expand All @@ -148,7 +153,8 @@ class will_options
* subscribers.
*/
will_options(string_ref top, const string& payload,
int qos=DFLT_QOS, bool retained=DFLT_QOS);
int qos=DFLT_QOS, bool retained=DFLT_QOS,
const properties& props=properties());
/**
* Sets the "Last Will and Testament" (LWT) for the connection.
* @param msg The message that is published to the Will Topic.
Expand Down
42 changes: 25 additions & 17 deletions src/will_options.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017-2020 Frank Pagliughi <[email protected]>
* Copyright (c) 2016 Guilherme M. Ferreira <[email protected]>
*
* All rights reserved. This program and the accompanying materials
Expand Down Expand Up @@ -33,13 +34,13 @@ const MQTTAsync_willOptions will_options::DFLT_C_STRUCT = MQTTAsync_willOptions_
will_options::will_options() : opts_(DFLT_C_STRUCT)
{
set_topic(string());
// set_payload(binary_ref());
}

will_options::will_options(string_ref top,
const void *payload, size_t payloadlen,
int qos, bool retained)
: opts_(DFLT_C_STRUCT)
int qos, bool retained,
const properties& props /*=properties()*/)
: opts_(DFLT_C_STRUCT), props_(props)
{
opts_.qos = qos;
opts_.retained = retained;
Expand All @@ -49,15 +50,16 @@ will_options::will_options(string_ref top,

will_options::will_options(const topic& top,
const void *payload, size_t payloadlen,
int qos, bool retained)
: will_options(top.get_name(), payload, payloadlen, qos, retained)
int qos, bool retained,
const properties& props /*=properties()*/)
: will_options(top.get_name(), payload, payloadlen, qos, retained, props)
{
}


will_options::will_options(string_ref top, binary_ref payload,
int qos, bool retained)
: opts_(DFLT_C_STRUCT)
int qos, bool retained,
const properties& props /*=properties()*/)
: opts_(DFLT_C_STRUCT), props_(props)
{
opts_.qos = qos;
opts_.retained = retained;
Expand All @@ -66,8 +68,9 @@ will_options::will_options(string_ref top, binary_ref payload,
}

will_options::will_options(string_ref top, const string& payload,
int qos, bool retained)
: opts_(DFLT_C_STRUCT)
int qos, bool retained,
const properties& props /*=properties()*/)
: opts_(DFLT_C_STRUCT), props_(props)
{
opts_.qos = qos;
opts_.retained = retained;
Expand All @@ -76,17 +79,20 @@ will_options::will_options(string_ref top, const string& payload,
}

will_options::will_options(const message& msg)
: will_options(msg.get_topic(), msg.get_payload(), msg.get_qos(), msg.is_retained())
: will_options(msg.get_topic(), msg.get_payload(), msg.get_qos(),
msg.is_retained(), msg.get_properties())
{
}

will_options::will_options(const will_options& opt) : opts_(opt.opts_)
will_options::will_options(const will_options& other)
: opts_(other.opts_), props_(other.props_)
{
set_topic(opt.topic_);
set_payload(opt.payload_);
set_topic(other.topic_);
set_payload(other.payload_);
}

will_options::will_options(will_options&& other) : opts_(other.opts_)
will_options::will_options(will_options&& other)
: opts_(other.opts_), props_(std::move(other.props_))
{
set_topic(std::move(other.topic_));
set_payload(std::move(other.payload_));
Expand All @@ -98,6 +104,7 @@ will_options& will_options::operator=(const will_options& rhs)
opts_ = rhs.opts_;
set_topic(rhs.topic_);
set_payload(rhs.payload_);
props_ = rhs.props_;
}
return *this;
}
Expand All @@ -108,6 +115,7 @@ will_options& will_options::operator=(will_options&& rhs)
opts_ = rhs.opts_;
set_topic(std::move(rhs.topic_));
set_payload(std::move(rhs.payload_));
props_ = std::move(rhs.props_);
}
return *this;
}
Expand All @@ -128,6 +136,6 @@ void will_options::set_payload(binary_ref msg)
}

/////////////////////////////////////////////////////////////////////////////

} // end namespace mqtt
// end namespace mqtt
}

0 comments on commit 3b400b5

Please sign in to comment.