Skip to content

Commit

Permalink
Change MessageSendDestination into a type-safe Variant
Browse files Browse the repository at this point in the history
  • Loading branch information
kghost committed May 21, 2021
1 parent 06eb0eb commit b49ae9a
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 172 deletions.
3 changes: 2 additions & 1 deletion src/app/clusters/ias-zone-client/ias-zone-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ static void removeServer(uint8_t * ieeeAddress)
static EmberStatus sendCommand(EmberNodeId destAddress)
{
emberAfSetCommandEndpoints(myEndpoint, emberAfIasZoneClientKnownServers[currentIndex].endpoint);
EmberStatus status = emberAfSendCommandUnicast(EMBER_OUTGOING_DIRECT, destAddress);
MessageSendDestination destination = MessageSendDestination(MessageSendDestination::OutGoingDirect(destAddress));
EmberStatus status = emberAfSendCommandUnicast(destination);
emberAfIasZoneClusterPrintln("Sent IAS Zone Client Command to 0x%2X (%d -> %d) status: 0x%X", destAddress, myEndpoint,
emberAfIasZoneClientKnownServers[currentIndex].endpoint, status);
if (status != EMBER_SUCCESS)
Expand Down
5 changes: 2 additions & 3 deletions src/app/clusters/ias-zone-server/ias-zone-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,9 +762,8 @@ void emberAfPluginIasZoneServerPrintQueueConfig(void)
// destination when the destination is the only router the node is joined to.
// In that case, the command will never have been sent, as the device will have
// had no router by which to send the command.
void emberAfIasZoneClusterServerMessageSentCallback(EmberOutgoingMessageType type, MessageSendDestination destination,
EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message,
EmberStatus status)
void emberAfIasZoneClusterServerMessageSentCallback(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t msgLen,
uint8_t * message, EmberStatus status)
{
#if defined(EMBER_AF_PLUGIN_IAS_ZONE_SERVER_ENABLE_QUEUE)
uint8_t frameControl;
Expand Down
5 changes: 3 additions & 2 deletions src/app/clusters/messaging-client/messaging-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ EmberAfStatus emberAfPluginMessagingClientConfirmMessage(EndpointId endpoint)
emberAfGetCurrentTime(), 0x00, "");
// The source and destination are reversed for the confirmation.
emberAfSetCommandEndpoints(messageTable[ep].clientEndpoint, esiEntry->endpoint);
status = ((emberAfSendCommandUnicast(EMBER_OUTGOING_DIRECT, nodeId) == EMBER_SUCCESS) ? EMBER_ZCL_STATUS_SUCCESS
: EMBER_ZCL_STATUS_FAILURE);
MessageSendDestination destination = MessageSendDestination(MessageSendDestination::OutGoingDirect(nodeId));
status =
((emberAfSendCommandUnicast(destination) == EMBER_SUCCESS) ? EMBER_ZCL_STATUS_SUCCESS : EMBER_ZCL_STATUS_FAILURE);
}
}
else
Expand Down
6 changes: 4 additions & 2 deletions src/app/clusters/messaging-server/messaging-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ void emberAfPluginMessagingServerDisplayMessage(EmberNodeId nodeId, uint8_t srcE
message.startTime, message.durationInMinutes, message.message, message.extendedMessageControl);
emberAfSetCommandEndpoints(srcEndpoint, dstEndpoint);
emberAfGetCommandApsFrame()->options |= EMBER_APS_OPTION_SOURCE_EUI64;
status = emberAfSendCommandUnicast(EMBER_OUTGOING_DIRECT, nodeId);
MessageSendDestination destination = MessageSendDestination(MessageSendDestination::OutGoingDirect(nodeId));
status = emberAfSendCommandUnicast(destination);
if (status != EMBER_SUCCESS)
{
emberAfMessagingClusterPrintln("Error in display %x", status);
Expand All @@ -248,7 +249,8 @@ void emberAfPluginMessagingServerCancelMessage(EmberNodeId nodeId, uint8_t srcEn
ZCL_CANCEL_MESSAGE_COMMAND_ID, "wu", message.messageId, message.messageControl);
emberAfSetCommandEndpoints(srcEndpoint, dstEndpoint);
emberAfGetCommandApsFrame()->options |= EMBER_APS_OPTION_SOURCE_EUI64;
status = emberAfSendCommandUnicast(EMBER_OUTGOING_DIRECT, nodeId);
MessageSendDestination destination = MessageSendDestination(MessageSendDestination::OutGoingDirect(nodeId));
status = emberAfSendCommandUnicast(destination);
if (status != EMBER_SUCCESS)
{
emberAfMessagingClusterPrintln("Error in cancel %x", status);
Expand Down
10 changes: 5 additions & 5 deletions src/app/reporting/reporting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static void removeConfigurationAndScheduleTick(uint8_t index);
static EmberAfStatus configureReceivedAttribute(const EmberAfClusterCommand * cmd, AttributeId attributeId, uint8_t mask,
uint16_t timeout);
static void putReportableChangeInResp(const EmberAfPluginReportingEntry * entry, EmberAfAttributeType dataType);
static void retrySendReport(EmberOutgoingMessageType type, MessageSendDestination destination, EmberApsFrame * apsFrame,
uint16_t msgLen, uint8_t * message, EmberStatus status);
static void retrySendReport(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message,
EmberStatus status);
static uint32_t computeStringHash(uint8_t * data, uint8_t length);

EmberEventControl emberAfPluginReportingTickEventControl;
Expand All @@ -100,13 +100,13 @@ EmberAfStatus emberAfPluginReportingConfiguredCallback(const EmberAfPluginReport
return EMBER_ZCL_STATUS_SUCCESS;
}

static void retrySendReport(EmberOutgoingMessageType type, MessageSendDestination destination, EmberApsFrame * apsFrame,
uint16_t msgLen, uint8_t * message, EmberStatus status)
static void retrySendReport(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t msgLen, uint8_t * message,
EmberStatus status)
{
// Retry once, and do so by unicasting without a pointer to this callback
if (status != EMBER_SUCCESS)
{
emberAfSendUnicast(type, destination, apsFrame, msgLen, message);
emberAfSendUnicast(destination, apsFrame, msgLen, message);
}
}

Expand Down
94 changes: 48 additions & 46 deletions src/app/util/af-main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ void emAfInitializeMessageSentCallbackArray(void)
}
}

static EmberStatus send(EmberOutgoingMessageType type, MessageSendDestination destination, EmberApsFrame * apsFrame,
uint16_t messageLength, uint8_t * message, bool broadcast, EmberNodeId alias, uint8_t sequence,
EmberAfMessageSentFunction callback)
static EmberStatus send(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message,
bool broadcast, EmberNodeId alias, uint8_t sequence, EmberAfMessageSentFunction callback)
{
EmberStatus status;
uint8_t index;
Expand Down Expand Up @@ -268,7 +267,7 @@ static EmberStatus send(EmberOutgoingMessageType type, MessageSendDestination de

{
EmberAfMessageStruct messageStruct = {
callback, apsFrame, message, destination, messageLength, type, broadcast,
callback, apsFrame, message, destination, messageLength, broadcast,
};
// Called prior to fragmentation in case the mesasge does not go out over the
// Zigbee radio, and instead goes to some other transport that does not require
Expand All @@ -285,7 +284,7 @@ static EmberStatus send(EmberOutgoingMessageType type, MessageSendDestination de

if (messageLength <= EMBER_AF_MAXIMUM_SEND_PAYLOAD_LENGTH)
{
status = emAfSend(type, destination, apsFrame, (uint8_t) messageLength, message, &messageTag, alias, sequence);
status = emAfSend(destination, apsFrame, (uint8_t) messageLength, message, &messageTag, alias, sequence);
}
else
{
Expand All @@ -297,7 +296,7 @@ static EmberStatus send(EmberOutgoingMessageType type, MessageSendDestination de
if ((status != EMBER_SUCCESS) &&
(callback == emberAfPluginCriticalMessageQueueEnqueueCallback || callback == emAfPluginCriticalMessageQueueRetryCallback))
{
callback(type, destination, apsFrame, messageLength, message, status);
callback(destination, apsFrame, messageLength, message, status);
}
#endif // EMBER_AF_PLUGIN_CRITICAL_MESSAGE_QUEUE

Expand Down Expand Up @@ -331,17 +330,19 @@ EmberStatus emberAfSendMulticastWithAliasWithCallback(GroupId multicastId, Ember
uint8_t * message, EmberNodeId alias, uint8_t sequence,
EmberAfMessageSentFunction callback)
{
apsFrame->groupId = multicastId;
return send(EMBER_OUTGOING_MULTICAST_WITH_ALIAS, MessageSendDestination(multicastId), apsFrame, messageLength, message,
apsFrame->groupId = multicastId;
MessageSendDestination destination = MessageSendDestination(MessageSendDestination::OutGoingMulticast(multicastId));
return send(destination, apsFrame, messageLength, message,
true, // broadcast
alias, sequence, callback);
}

EmberStatus emberAfSendMulticastWithCallback(GroupId multicastId, EmberApsFrame * apsFrame, uint16_t messageLength,
uint8_t * message, EmberAfMessageSentFunction callback)
{
apsFrame->groupId = multicastId;
return send(EMBER_OUTGOING_MULTICAST, MessageSendDestination(multicastId), apsFrame, messageLength, message,
apsFrame->groupId = multicastId;
MessageSendDestination destination = MessageSendDestination(MessageSendDestination::OutGoingMulticast(multicastId));
return send(destination, apsFrame, messageLength, message,
true, // broadcast?
0, // alias
0, // sequence
Expand Down Expand Up @@ -422,39 +423,38 @@ EmberStatus emberAfSendMulticastToBindings(EmberApsFrame * apsFrame, uint16_t me
// return emberAfSendBroadcastWithCallback(destination, apsFrame, messageLength, message, NULL);
//}

EmberStatus emberAfSendUnicastWithCallback(EmberOutgoingMessageType type, MessageSendDestination destination,
EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message,
EmberAfMessageSentFunction callback)
EmberStatus emberAfSendUnicastWithCallback(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength,
uint8_t * message, EmberAfMessageSentFunction callback)
{
// The source endpoint in the APS frame MAY NOT be valid at this point if the
// outgoing type is "via binding."
if (type == EMBER_OUTGOING_VIA_BINDING)
if (destination.Is<MessageSendDestination::OutGoingBinding>())
{
// If using binding, set the endpoints based on those in the binding. The
// cluster in the binding is not used because bindings can be used to send
// messages with any cluster id, not just the one set in the binding.
EmberBindingTableEntry binding;
// TODO: This cast should go away once
// https://github.com/project-chip/connectedhomeip/issues/3584 is fixed.
EmberStatus status = emberGetBinding(destination.mBindingIndex, &binding);
EmberStatus status = emberGetBinding(destination.Get<MessageSendDestination::OutGoingBinding>().mBindingIndex, &binding);
if (status != EMBER_SUCCESS)
{
return status;
}
apsFrame->sourceEndpoint = binding.local;
apsFrame->destinationEndpoint = binding.remote;
}
return send(type, destination, apsFrame, messageLength, message,
return send(destination, apsFrame, messageLength, message,
false, // broadcast?
0, // alias
0, // sequence
callback);
}

EmberStatus emberAfSendUnicast(EmberOutgoingMessageType type, MessageSendDestination destination, EmberApsFrame * apsFrame,
uint16_t messageLength, uint8_t * message)
EmberStatus emberAfSendUnicast(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint16_t messageLength,
uint8_t * message)
{
return emberAfSendUnicastWithCallback(type, destination, apsFrame, messageLength, message, NULL);
return emberAfSendUnicastWithCallback(destination, apsFrame, messageLength, message, NULL);
}

EmberStatus emberAfSendUnicastToBindingsWithCallback(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * message,
Expand All @@ -474,8 +474,9 @@ EmberStatus emberAfSendUnicastToBindingsWithCallback(EmberApsFrame * apsFrame, u
if (binding.type == EMBER_UNICAST_BINDING && binding.local == apsFrame->sourceEndpoint &&
binding.clusterId == apsFrame->clusterId)
{
apsFrame->destinationEndpoint = binding.remote;
status = send(EMBER_OUTGOING_VIA_BINDING, MessageSendDestination(i), apsFrame, messageLength, message,
apsFrame->destinationEndpoint = binding.remote;
MessageSendDestination destination = MessageSendDestination(MessageSendDestination::OutGoingBinding(i));
status = send(destination, apsFrame, messageLength, message,
false, // broadcast?
0, // alias
0, // sequence
Expand Down Expand Up @@ -547,7 +548,7 @@ void emAfPrintStatus(const char * task, EmberStatus status)
// Functions called by the Serial Command Line Interface (CLI)
// ******************************************************************

static void printMessage(EmberIncomingMessageType type, EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * messageContents)
static void printMessage(EmberApsFrame * apsFrame, uint16_t messageLength, uint8_t * messageContents)
{
emberAfAppPrint("Cluster: 0x%2X, %d bytes,", apsFrame->clusterId, messageLength);
if (messageLength >= 3)
Expand All @@ -558,14 +559,14 @@ static void printMessage(EmberIncomingMessageType type, EmberApsFrame * apsFrame
emberAfAppPrintln("");
}

void emAfMessageSentHandler(EmberOutgoingMessageType type, MessageSendDestination destination, EmberApsFrame * apsFrame,
EmberStatus status, uint16_t messageLength, uint8_t * messageContents, uint8_t messageTag)
void emAfMessageSentHandler(MessageSendDestination & destination, EmberApsFrame * apsFrame, EmberStatus status,
uint16_t messageLength, uint8_t * messageContents, uint8_t messageTag)
{
EmberAfMessageSentFunction callback;
if (status != EMBER_SUCCESS)
{
emberAfAppPrint("%ptx %x, ", "ERROR: ", status);
printMessage(type, apsFrame, messageLength, messageContents);
printMessage(apsFrame, messageLength, messageContents);
}

callback = getMessageSentCallback(messageTag);
Expand All @@ -576,7 +577,7 @@ void emAfMessageSentHandler(EmberOutgoingMessageType type, MessageSendDestinatio
if (messageContents != NULL && messageContents[0] & ZCL_CLUSTER_SPECIFIC_COMMAND)
{
emberAfClusterMessageSentWithMfgCodeCallback(
type, destination, apsFrame, messageLength, messageContents, status,
destination, apsFrame, messageLength, messageContents, status,
// If the manufacturer specific flag is set
// get read it as next part of message
// else use null code.
Expand All @@ -587,33 +588,32 @@ void emAfMessageSentHandler(EmberOutgoingMessageType type, MessageSendDestinatio

if (callback != NULL)
{
(*callback)(type, destination, apsFrame, messageLength, messageContents, status);
(*callback)(destination, apsFrame, messageLength, messageContents, status);
}

#ifdef EMBER_AF_GENERATED_PLUGIN_MESSAGE_SENT_FUNCTION_CALLS
EMBER_AF_GENERATED_PLUGIN_MESSAGE_SENT_FUNCTION_CALLS
#endif

emberAfMessageSentCallback(type, destination, apsFrame, messageLength, messageContents, status);
emberAfMessageSentCallback(destination, apsFrame, messageLength, messageContents, status);
}

#ifdef EMBER_AF_PLUGIN_FRAGMENTATION
void emAfFragmentationMessageSentHandler(EmberOutgoingMessageType type, MessageSendDestination destination,
EmberApsFrame * apsFrame, uint8_t * buffer, uint16_t bufLen, EmberStatus status,
uint8_t messageTag)
void emAfFragmentationMessageSentHandler(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint8_t * buffer,
uint16_t bufLen, EmberStatus status, uint8_t messageTag)
{
// the fragmented message is no longer in process
emberAfDebugPrintln("%pend.", "Fragmentation:");
emAfMessageSentHandler(type, destination, apsFrame, status, bufLen, buffer, messageTag);
emAfMessageSentHandler(destination, apsFrame, status, bufLen, buffer, messageTag);

// EMZIGBEE-4437: setting back the buffers to the original in case someone set
// that to something else.
emberAfSetExternalBuffer(appResponseData, EMBER_AF_RESPONSE_BUFFER_LEN, &appResponseLength, &emberAfResponseApsFrame);
}
#endif // EMBER_AF_PLUGIN_FRAGMENTATION

EmberStatus emAfSend(EmberOutgoingMessageType type, MessageSendDestination destination, EmberApsFrame * apsFrame,
uint8_t messageLength, uint8_t * message, uint8_t * messageTag, EmberNodeId alias, uint8_t sequence)
EmberStatus emAfSend(MessageSendDestination & destination, EmberApsFrame * apsFrame, uint8_t messageLength, uint8_t * message,
uint8_t * messageTag, EmberNodeId alias, uint8_t sequence)
{
// TODO: There's an impedance mismatch here in a few ways:
// 1) The caller expects to get a messageTag out that will identify this
Expand All @@ -630,11 +630,11 @@ EmberStatus emAfSend(EmberOutgoingMessageType type, MessageSendDestination desti
// tracks this.
*messageTag = INVALID_MESSAGE_TAG;
EmberStatus status = EMBER_SUCCESS;
switch (type)
switch (destination.GetType())
{
case EMBER_OUTGOING_VIA_BINDING: {
case MessageSendDestination::OutGoingBinding::VariantId: {
EmberBindingTableEntry binding;
status = emberGetBinding(destination.mBindingIndex, &binding);
status = emberGetBinding(destination.Get<MessageSendDestination::OutGoingBinding>().mBindingIndex, &binding);
if (status != EMBER_SUCCESS)
{
break;
Expand All @@ -647,31 +647,33 @@ EmberStatus emAfSend(EmberOutgoingMessageType type, MessageSendDestination desti
status = chipSendUnicast(binding.nodeId, apsFrame, messageLength, message);
break;
}
case EMBER_OUTGOING_VIA_ADDRESS_TABLE:
case MessageSendDestination::OutGoingAddressTable::VariantId:
// No implementation yet.
status = EMBER_ERR_FATAL;
break;
case EMBER_OUTGOING_DIRECT:
status = chipSendUnicast(destination.mNodeId, apsFrame, messageLength, message);
case MessageSendDestination::OutGoingDirect::VariantId:
status =
chipSendUnicast(destination.Get<MessageSendDestination::OutGoingDirect>().mNodeId, apsFrame, messageLength, message);
break;
case EMBER_OUTGOING_MULTICAST:
case MessageSendDestination::OutGoingMulticast::VariantId:
// No implementation yet.
status = EMBER_ERR_FATAL;
break;
case EMBER_OUTGOING_MULTICAST_WITH_ALIAS:
case MessageSendDestination::OutGoingMulticastWithAlias::VariantId:
// No implementation yet.
status = EMBER_ERR_FATAL;
break;
case EMBER_OUTGOING_BROADCAST:
case MessageSendDestination::OutGoingBroadcast::VariantId:
// No implementation yet.
status = EMBER_ERR_FATAL;
break;
case EMBER_OUTGOING_BROADCAST_WITH_ALIAS:
case MessageSendDestination::OutGoingBroadcastWithAlias::VariantId:
// No implementation yet.
status = EMBER_ERR_FATAL;
break;
case EMBER_OUTGOING_VIA_EXCHANGE:
status = chipSendUnicast(destination.mExchangeContext, apsFrame, messageLength, message);
case MessageSendDestination::OutGoingExchange::VariantId:
status = chipSendUnicast(destination.Get<MessageSendDestination::OutGoingExchange>().mExchangeContext, apsFrame,
messageLength, message);
break;
default:
status = EMBER_BAD_ARGUMENT;
Expand Down
Loading

0 comments on commit b49ae9a

Please sign in to comment.