From c92b5b2a80b2040d6a4983c1cf00e77be36b2e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dauphin?= Date: Thu, 15 Jun 2017 19:18:25 +0200 Subject: [PATCH] added ndn_app_run_once --- app.c | 20 +++++++++++++++----- app.h | 13 +++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app.c b/app.c index e6d9c9b..b4c1ebe 100644 --- a/app.c +++ b/app.c @@ -22,6 +22,8 @@ #include "msg-type.h" #include "ndn.h" +#define ENABLE_DEBUG 1 + #include #include #include @@ -206,6 +208,18 @@ static int _sched_call_cb(ndn_app_t* handle, msg_t* msg) } int ndn_app_run(ndn_app_t* handle) +{ + while(1) { + int rc = ndn_app_run_once(handle); + if(rc != NDN_APP_CONTINUE) { + return rc; + } + thread_sleep(); + } + return NDN_APP_STOP; +} + +int ndn_app_run_once(ndn_app_t* handle) { if (handle == NULL) return NDN_APP_ERROR; @@ -215,9 +229,7 @@ int ndn_app_run(ndn_app_t* handle) reply.type = GNRC_NETAPI_MSG_TYPE_ACK; reply.content.value = (uint32_t)(-ENOTSUP); - while (1) { - msg_receive(&msg); - + while (msg_try_receive(&msg) == 1) { switch (msg.type) { case NDN_APP_MSG_TYPE_TERMINATE: DEBUG("ndn_app: TERMINATE msg received from thread %" @@ -612,8 +624,6 @@ int ndn_app_add_strategy(ndn_shared_block_t* prefix, reply.content.value = 1; msg_send_receive(&op, &reply, ndn_pid); if (reply.content.value != 0) { - DEBUG("ndn_app: cannot add forwarding strategy (pid=%" - PRIkernel_pid ")\n", handle->id); return -1; } return 0; diff --git a/app.h b/app.h index 6428921..8b37acf 100644 --- a/app.h +++ b/app.h @@ -139,6 +139,19 @@ ndn_app_t* ndn_app_create(void); */ int ndn_app_run(ndn_app_t* handle); +/** + * @brief Runs the event loop (non blocking) with the app handle. + * + * @details This function is reentrant and can be called from multiple threads. + * However, the same handle cannot be used twice by this function at + * the same time. + * + * @param[in] handle Handle of the app to run. + * + * @return One of the return codes for the callbacks. + */ +int ndn_app_run_once(ndn_app_t* handle); + /** * @brief Releases the app handle and all associated memory. */