Skip to content

Commit 3d62aa0

Browse files
committed
Add topic argument to publish callback in request-response stream client
1 parent 8785a93 commit 3d62aa0

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

include/aws/iot/MqttRequestResponseClient.h

+26-2
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,28 @@ namespace Aws
121121
/**
122122
* Default constructor
123123
*/
124-
IncomingPublishEvent() : m_payload() { AWS_ZERO_STRUCT(m_payload); }
124+
IncomingPublishEvent() : m_topic(), m_payload()
125+
{
126+
AWS_ZERO_STRUCT(m_topic);
127+
AWS_ZERO_STRUCT(m_payload);
128+
}
129+
130+
/**
131+
* Sets the message response topic associated with this event. The event does not own this topic.
132+
*
133+
* @param topic the message response topic associated with this event
134+
* @return reference to this
135+
*/
136+
IncomingPublishEvent &WithTopic(Aws::Crt::ByteCursor topic)
137+
{
138+
m_topic = topic;
139+
return *this;
140+
}
125141

126142
/**
127143
* Sets the message payload associated with this event. The event does not own this payload.
128144
*
129-
* @param payload he message payload associated with this event
145+
* @param payload the message payload associated with this event
130146
* @return reference to this
131147
*/
132148
IncomingPublishEvent &WithPayload(Aws::Crt::ByteCursor payload)
@@ -135,6 +151,13 @@ namespace Aws
135151
return *this;
136152
}
137153

154+
/**
155+
* Gets the message response topic associated with this event.
156+
*
157+
* @return the message response topic associated with this event
158+
*/
159+
Aws::Crt::ByteCursor GetTopic() const { return m_topic; }
160+
138161
/**
139162
* Gets the message payload associated with this event.
140163
*
@@ -143,6 +166,7 @@ namespace Aws
143166
Aws::Crt::ByteCursor GetPayload() const { return m_payload; }
144167

145168
private:
169+
Aws::Crt::ByteCursor m_topic;
146170
Aws::Crt::ByteCursor m_payload;
147171
};
148172

source/iot/MqttRequestResponseClient.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ namespace Aws
8989
int error_code,
9090
void *user_data);
9191

92-
static void OnIncomingPublishCallback(struct aws_byte_cursor payload, void *user_data);
92+
static void OnIncomingPublishCallback(
93+
struct aws_byte_cursor response_topic,
94+
struct aws_byte_cursor payload,
95+
void *user_data);
9396

9497
static void OnTerminatedCallback(void *user_data);
9598

@@ -187,7 +190,10 @@ namespace Aws
187190
}
188191
}
189192

190-
void StreamingOperationImpl::OnIncomingPublishCallback(struct aws_byte_cursor payload, void *user_data)
193+
void StreamingOperationImpl::OnIncomingPublishCallback(
194+
struct aws_byte_cursor topic,
195+
struct aws_byte_cursor payload,
196+
void *user_data)
191197
{
192198
auto *handle = static_cast<StreamingOperationImplHandle *>(user_data);
193199
StreamingOperationImpl *impl = handle->m_impl.get();
@@ -198,7 +204,7 @@ namespace Aws
198204
if (!impl->m_closed && impl->m_config.incomingPublishEventHandler)
199205
{
200206
IncomingPublishEvent event;
201-
event.WithPayload(payload);
207+
event.WithTopic(topic).WithPayload(payload);
202208

203209
impl->m_config.incomingPublishEventHandler(std::move(event));
204210
}

0 commit comments

Comments
 (0)