Skip to content

uorb:Added urob loop function module and supported epoll.#2604

Merged
xiaoxiang781216 merged 1 commit intoapache:masterfrom
Otpvondoiats:lk_loop
Sep 27, 2024
Merged

uorb:Added urob loop function module and supported epoll.#2604
xiaoxiang781216 merged 1 commit intoapache:masterfrom
Otpvondoiats:lk_loop

Conversation

@Otpvondoiats
Copy link
Copy Markdown
Contributor

@Otpvondoiats Otpvondoiats commented Sep 26, 2024

Summary

  1. Added urob loop function module and supported epoll.
struct orb_handle_s  g_handle;
struct orb_handle_s  g_handle1;
struct orb_loop_s    g_loop;
int count = 0;

void *test_loop(void *arg)
{
  struct orb_loop_s *loop = arg;

  if ( loop == NULL)
    {
      return ((void *)0);
    }

  if(orb_loop_run(loop) < 0)
    {
      syslog(1, "&&&& THREAD  error!\n");
    }
  syslog(1, "&&&& THREAD  exit !\n");
  return ((void *)0);
}

int print_accel(FAR struct orb_handle_s *handle, FAR void *arg)
{
  int ret;
  struct sensor_accel accel;
  pthread_t id = pthread_self();

  ret = orb_copy(ORB_ID(sensor_accel), handle->fd, &accel);
  if (ret == OK)
    {
      syslog(1, "data [%d] -> fd:%d, x:%f, y:%f, z:%f handle:%p, threadid:%d",
             (int)arg, handle->fd, accel.x, accel.y, accel.z, handle, id);
    }
    count++;
  return OK;
}

int flush_accel(FAR struct orb_handle_s *handle, FAR void *arg)
{
  int ret;
  struct sensor_accel accel;
  pthread_t id = pthread_self();

  ret = orb_copy(ORB_ID(sensor_accel), handle->fd, &accel);
  if (ret == OK)
    {
      syslog(1, "flush [%d] -> fd:%d, x:%f, y:%f, z:%f handle:%p, threadid:%d",
             (int)arg, handle->fd, accel.x, accel.y, accel.z, handle, id);
    }
  return OK;
}

int state_accel(FAR struct orb_handle_s *handle, FAR void *arg)
{
  int ret;
  struct orb_state state;
  pthread_t id = pthread_self();

  ret =  orb_get_state(handle->fd, &state);
  if (ret == OK)
    {
      syslog(1, "/// state [%d] -> fd:%d, max:%u, min:%u, que:%u nsu:%u, " \
             "gen:%lu, handle:%p, threadid:%d",
             (int)arg, handle->fd, state.max_frequency, state.min_batch_interval,
             state.queue_size, state.nsubscribers, state.generation, handle, id);
    }
  return OK;
}

int start_loop(void)
{
  pthread_t ntid;
  int err;
  int fd_handle;
  int fd_handle1;

  fd_handle = orb_subscribe_multi(ORB_ID(sensor_accel), 0);

  err = orb_loop_init(&g_loop, ORB_EPOLL_TYPE);
  if (err < 0)
    {
      syslog(1, "init g_loop error! error:%d\n", err);
    }

  err = orb_handle_init(&g_handle, fd_handle, EPOLLIN,
                        (FAR void *)0, print_accel, flush_accel,
                        state_accel);
  if (err < 0)
    {
      syslog(1, "init g_handle error! error:%d\n", err);
    }
  
  err = orb_handle_start(&g_loop, &g_handle);
  if (err < 0)
    {
      syslog(1, "initg_ handle start error! error:%d\n", err);
    }

  err = pthread_create(&ntid, NULL, test_loop, &g_loop);
  if (err != 0)
    {
      syslog(1, "can't create thread\n");
    }

  usleep(100000);

  /* add handle 1; */

  fd_handle1 = orb_subscribe_multi(ORB_ID(sensor_accel), 1);

  err = orb_handle_init(&g_handle1, fd_handle1, EPOLLIN,
                        (FAR void *)1, print_accel, flush_accel,
                        state_accel);
  if (err < 0)
    {
      syslog(1, "init g_handle error! error:%d\n", err);
    }
  
  err = orb_handle_start(&g_loop, &g_handle1);
  if (err < 0)
    {
      syslog(1, "initg_ handle start error! error:%d\n", err);
    }

  usleep(500000);

  while (1)
  {
    if( count < 200)
      {
        usleep(50000);
        continue;
      }

    err = orb_loop_deinit(&g_loop);
    if (err < 0)
      {
        syslog(1, "deinit loop error! error:%d\n", err);
      }
    break;
  }

  orb_unsubscribe(fd_handle);

  syslog(1, "main thread exit\n");

}

Impact

n/a

Testing

  • Environment:

OS and Version: Ubuntu 20.04.6 LTS x86_64
GCC Version: 13.1.0
SIM: ./tools/configure.sh sim:nsh

  • Order:

./nuttx

Signed-off-by: likun17 <likun17@xiaomi.com>
@nuttxpr
Copy link
Copy Markdown

nuttxpr commented Sep 26, 2024

[Experimental Bot, please feedback here]

The provided PR summary and information lack essential details to determine if it meets NuttX requirements.

Here's a breakdown of missing information and suggestions for improvement:

Summary:

  • Why is this change necessary? Clearly state the problem this module solves. Is it a common need in NuttX projects? Does it improve performance, add a missing functionality, etc.?
  • What functional part is changed? Be specific. Which directory is modified? Mention if this introduces a new API for other developers.
  • How does the change work? The code snippet is helpful, but a high-level explanation is crucial for reviewers. For example:
    • How does the urob_loop interact with the Orb?
    • How does epoll integration work?
    • What are the key data structures and their roles?
  • Issues/PRs: Provide links to related NuttX and NuttX Apps issues/PRs if applicable. This helps track the context and need for the change.

Impact:

  • It's highly unlikely that a change has no impact. Carefully consider each point:
    • New feature: Clearly state that a new feature is added.
    • User impact: Will users need to call new functions, change configurations, etc.?
    • Build impact: Are there new build options, dependencies to consider?
    • Hardware impact: Does this rely on specific hardware features?
    • Documentation: At the very least, the new module needs to be documented. Mention if you've updated the docs.
    • Security: Analyze for potential security implications. Even if there are none, state it explicitly.
    • Compatibility: Does this break existing code? Are there forward or backward compatibility concerns?

Testing:

  • Testing is insufficient.
    • Provide more descriptive logs demonstrating the functionality of the module.
    • Ideally, include test cases that cover different usage scenarios, error handling, etc.
    • Test on real hardware if possible, in addition to the simulator.

In summary, the PR needs significant improvements in clarity, completeness, and testing before it can be considered for merging.

Copy link
Copy Markdown
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Otpvondoiats :-)

@xiaoxiang781216 xiaoxiang781216 merged commit bccb6c6 into apache:master Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants