Skip to content

Commit

Permalink
added ndn_app_run_once
Browse files Browse the repository at this point in the history
  • Loading branch information
astralien3000 committed Jun 16, 2017
1 parent 8fbcc73 commit c92b5b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
20 changes: 15 additions & 5 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "msg-type.h"
#include "ndn.h"

#define ENABLE_DEBUG 1

#include <debug.h>
#include <msg.h>
#include <thread.h>
Expand Down Expand Up @@ -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;

Expand All @@ -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 %"
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit c92b5b2

Please sign in to comment.