Skip to content

Commit

Permalink
coremqtt-agent: Improve subscription_manager.c
Browse files Browse the repository at this point in the history
Previously, removeSubscription did not produce any output, nor return a
value if it failed to remove a subscription (e.g. if the subscription
did not exist).
This commit makes removeSubscription return true if successful,
and false otherwise. This commit also documents this change.

Signed-off-by: Reuben Cartwright <[email protected]>
  • Loading branch information
RC-Repositories authored and aggarg committed Sep 25, 2024
1 parent f1b7c0c commit 29944b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ bool addSubscription( const char * pcTopicFilterString,
* @param[in] pxSubscriptionList The pointer to the subscription list array.
* @param[in] pcTopicFilterString Topic filter of subscription.
* @param[in] usTopicFilterLength Length of topic filter.
*
* @return `true` if subscription has been removed, `false` if the subscription
* does not exist or deletion failed.
*/
void removeSubscription( const char * pcTopicFilterString,
bool removeSubscription( const char * pcTopicFilterString,
uint16_t usTopicFilterLength );

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ bool addSubscription( const char * pcTopicFilterString,

/*-----------------------------------------------------------*/

void removeSubscription( const char * pcTopicFilterString,
bool removeSubscription( const char * pcTopicFilterString,
uint16_t usTopicFilterLength )
{
bool found = false;

if( ( pcTopicFilterString == NULL ) ||
( usTopicFilterLength == 0U ) )
{
Expand All @@ -142,11 +144,14 @@ void removeSubscription( const char * pcTopicFilterString,
{
if( strncmp( xGlobalSubscriptionList[ lIndex ].pcSubscriptionFilterString, pcTopicFilterString, usTopicFilterLength ) == 0 )
{
found = true;
memset( &( xGlobalSubscriptionList[ lIndex ] ), 0x00, sizeof( SubscriptionElement_t ) );
}
}
}
}

return found;
}

/*-----------------------------------------------------------*/
Expand Down

0 comments on commit 29944b8

Please sign in to comment.