mirror of
https://github.com/espressif/openthread.git
synced 2026-08-11 05:07:47 +00:00
[udp] expose UDP receiver API (#3477)
This commit is contained in:
@@ -73,6 +73,30 @@ typedef struct otUdpReceiver
|
||||
void * mContext; ///< A pointer to application-specific context.
|
||||
} otUdpReceiver;
|
||||
|
||||
/**
|
||||
* This function adds a UDP receiver.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aUdpReceiver A pointer to the UDP receiver.
|
||||
*
|
||||
* @retval OT_ERROR_NONE The receiver is successfully added.
|
||||
* @retval OT_ERROR_ALREADY The UDP receiver was already added.
|
||||
*
|
||||
*/
|
||||
otError otUdpAddReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver);
|
||||
|
||||
/**
|
||||
* This function removes a UDP receiver.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aUdpReceiver A pointer to the UDP receiver.
|
||||
*
|
||||
* @retval OT_ERROR_NONE The receiver is successfully removed.
|
||||
* @retval OT_ERROR_NOT_FOUND The UDP receiver was not added.
|
||||
*
|
||||
*/
|
||||
otError otUdpRemoveReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver);
|
||||
|
||||
/**
|
||||
* This callback allows OpenThread to inform the application of a received UDP message.
|
||||
*
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
|
||||
#include "common/instance.hpp"
|
||||
#include "common/new.hpp"
|
||||
#include "net/udp6.hpp"
|
||||
|
||||
using namespace ot;
|
||||
|
||||
@@ -136,3 +137,17 @@ otUdpSocket *otUdpGetSockets(otInstance *aInstance)
|
||||
return instance.Get<Ip6::Ip6>().GetUdp().GetUdpSockets();
|
||||
}
|
||||
#endif
|
||||
|
||||
otError otUdpAddReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.GetIp6().GetUdp().AddReceiver(*static_cast<Ip6::UdpReceiver *>(aUdpReceiver));
|
||||
}
|
||||
|
||||
otError otUdpRemoveReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
return instance.GetIp6().GetUdp().RemoveReceiver(*static_cast<Ip6::UdpReceiver *>(aUdpReceiver));
|
||||
}
|
||||
|
||||
+11
-5
@@ -209,11 +209,13 @@ Udp::Udp(Instance &aInstance)
|
||||
|
||||
otError Udp::AddReceiver(UdpReceiver &aReceiver)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
for (UdpReceiver *cur = mReceivers; cur; cur = cur->GetNext())
|
||||
{
|
||||
if (cur == &aReceiver)
|
||||
{
|
||||
ExitNow();
|
||||
ExitNow(error = OT_ERROR_ALREADY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,14 +223,18 @@ otError Udp::AddReceiver(UdpReceiver &aReceiver)
|
||||
mReceivers = &aReceiver;
|
||||
|
||||
exit:
|
||||
return OT_ERROR_NONE;
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Udp::RemoveReceiver(UdpReceiver &aReceiver)
|
||||
{
|
||||
otError error = OT_ERROR_NOT_FOUND;
|
||||
|
||||
if (mReceivers == &aReceiver)
|
||||
{
|
||||
mReceivers = mReceivers->GetNext();
|
||||
aReceiver.SetNext(NULL);
|
||||
error = OT_ERROR_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -237,14 +243,14 @@ otError Udp::RemoveReceiver(UdpReceiver &aReceiver)
|
||||
if (handler->GetNext() == &aReceiver)
|
||||
{
|
||||
handler->SetNext(aReceiver.GetNext());
|
||||
aReceiver.SetNext(NULL);
|
||||
error = OT_ERROR_NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aReceiver.SetNext(NULL);
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
return error;
|
||||
}
|
||||
|
||||
otError Udp::AddSocket(UdpSocket &aSocket)
|
||||
|
||||
@@ -226,7 +226,8 @@ public:
|
||||
*
|
||||
* @param[in] aReceiver A reference to the UDP receiver.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully added the UDP receiver.
|
||||
* @retval OT_ERROR_NONE Successfully added the UDP receiver.
|
||||
* @retval OT_ERROR_ALREADY The UDP receiver was already added.
|
||||
*
|
||||
*/
|
||||
otError AddReceiver(UdpReceiver &aReceiver);
|
||||
@@ -236,7 +237,8 @@ public:
|
||||
*
|
||||
* @param[in] aReceiver A reference to the UDP receiver.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully removed the UDP receiver.
|
||||
* @retval OT_ERROR_NONE Successfully removed the UDP receiver.
|
||||
* @retval OT_ERROR_NOT_FOUND The UDP receiver was not added.
|
||||
*
|
||||
*/
|
||||
otError RemoveReceiver(UdpReceiver &aReceiver);
|
||||
|
||||
Reference in New Issue
Block a user