Git Product home page Git Product logo

cdipc's Introduction

CDIPC

CDIPC is an Inter-Process Communication (IPC) mechanism and library. It is uniquely suited for coordinating perception, control drivers, and algorithms in real-time systems that sample data from physical processes.

CDIPC is similar to the ACH IPC library, but eliminates memory copy to improve efficiency. Other differences:

  • CDIPC support both Topic and Service similar to ROS;
  • Unlike the ACH and ROS Topic, if any of the subscriber's queue is full and the need_wait flag is true, the publisher will block.

Channel Data Structure

Data is shared between processes through shared memory.

The data structure is same for Topic and Service, the gray part is service only.

The publisher (/requester) and subscriber (/replier) are initialled statictly, we could support dynamic registration, but it is not implemented for the moment because it is not commonly used.

The max data size of each node in each channel are the same.

Currently we use a single conditional variable instead of semaphores for simplification.

Core Procedures

Topic

  1. The publisher request a free node at begining, then fill data to the node at any time.
  2. The publisher append the same node to all subscriber's node_head, and set the node reference map corresponding bits. If any subscriber's nodes amount equal to it's max_len before append new node to anyone: wait until not equal if need_wait is true; or clear the reference map bit of the oldest node, then free or drop it.
  3. The subscriber pick up a node, then use it at any time (read only).
  4. After use, clear the reference map bit and release the node if the map become zero (or drop if not zero).

Service

For use as service, only one replier is allowed.

  1. The requester request a free node (as same as topic).
  2. The requester append the node to replier's node_head (as same as topic, without clear pub reference).
  3. The replier pick up a node.
  4. The replier return data to requester (by simply clear reference map bit).
  5. The requester free the node after read return data.

Other Consideration

  • We could traversal all nodes to recover lost nodes depend on pub and sub reference, e.g. process exist on error.
  • Because we use PI-futex instead of pthread mutex, so communication between user and kernel space is possible.
  • We could use different daemon application to export Topic and Service channel to different interface protocol, e.g. websocket (already support), TCP/UDP socket, unix socket.

Logging

We can simply add one or more subscriber to each topic and service dedicated for logging.

Note: The log subscriber in service nerver replier to requester.

Install

make && sudo make install

Example

There is a command line tool for test purpose, type cdipc --help for more details, or read the help message at the beginning of tools/cli_tool/cdipc_tool.c.

Example for topic (run put command in another terminal):
  cdipc create --name test   # create a topic with 2 pub and 2 sub
                             # 5 nodes of 256 bytes by default
  cdipc pend-cfg --name test # change max_len to 2 for first sub
                             # max_len is 0 and need_wait is false after create
  cdipc get --name test      # wait on sub id 0
  cdipc put --name test      # publish string "test msg" to the topic

Notes:
  default values can override by arguments
...

License

The MIT License (MIT)
https://rem.mit-license.org

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.