Code Monkey home page Code Monkey logo

octopos's Introduction

Build Status codecov License: AGPL v3 release

OctopOS

A simple data bus for subsystem communication.

Introduction

OctopOS is a data bus designed to make subsystem inter communications as easy as possible. It exposes a publisher subscriber model, however it's tentacles can be extended as needed to include other communication methods.

If you are working on a subsystem for SPACE HAUC then most of the information you will need can be found in the Basic Usage section of this readme.

Contents

  • Basic Usage
    • Includes
    • Publisher
    • Subscriber
  • Advanced Topics
    • Calling Modules
    • Control Flow
    • Shared Memory Segment
    • Communication Protocal
  • Further Documentation

Basic Usage

The basic usage of octopOS is ment to make inter system communication as easy as possible! This section is designed to show you what you can do.

To compile and install run mkdir build && cd build && cmake .. && make && sudo make install

Includes and Linking

OctopOS provides a few libraries. The main ones you will be using are the publiher and subscriber libraries. All includes follow the format:

#include<OctopOS/{lib}.h>

i.e

#include<OctopOS/subscriber.h>

Publisher

If you would like to publish data from your subsystem for others to read this is the section for you. To create a publisher you only need to construct an instance of the class:

publisher<T> pub("topic_name", argv[0]);

Since publisher is a templated class T should be they type of data you are trying to publish. This include custome classes and structs.

The first parameter is also important as that is the name of the topic you wish to publis to. you can have multiple publishers to a single topic if you want. The name can not contain spaces.

If you would like to learn more about the argv[0] part refer to the Calling Modules section of this readme. A sample usage would be:

publisher<int> pub("test", argv[0]);

Now that we have a publisher to publish data all we have to do is:

int data = 5;
pub.publish(data);

That is all there is to it! Don't forget to include publisher.h

Subscriber

Ihis section gives instructions on how to read data from a topic using a subscriber. Due to there implementation subscribers require a bit more setup than publishers.

First you will want to create a thread that listens for events from octopOS. YOU ONLY NEED ONE OF THESE THREADS FOR ALL SUBSCRIBERS IN THE PROCESS! This is done by:

pthread_t wait_for_subscrber_event;

if (pthread_create(&wait_for_subscrber_event, NULL, subscriber_manager::wait_for_data, NULL)) {
    exit(-1);  // or handle the error as you see fit (this is almost always terminal)
}

Do not wait for this thread to join as it never will. Once this is complete we can set up our subscribers just like out publishers. First create an instance of the class with:

subscriber<T> sub("topic_name", argv[0]);

Again this is very similar to publiser where T is the type of data, and the first paramater is the topic name you would like to get data from. If we wanted to subscribe to our topic from the publisher section it would look like:

subscriber<int> sub("test", argv[0]);

Once we have created a subscriber to get data we simple do:

int x = sub.get_data();

A note is that this call WILL BLOCK your thread if there is no data to be had. It will unblock once data is available, but is advisable to read data from a secondaty thread so your main thread can continue execution.

Remember to include subscriber.h

Advanced Topics

This section is for those who want to understand how octopOS works under the hood. If you just want to use octopOS see the above Basic Usage section.

Calling Modules

When a module is created registered with octopOS, it forks and execs the independant binary of that module. It passes the message key that it expects the module to communicate on as argv[0], that is why you pass argv[0] to the constructor of classes inherited from tentical as it constructs itself on top of this message bus.

All modules, and the number of modules need to be known befor runtime as it stands right now. These are defined in utility.h and compiled into the main executable. In the future we hope to eliminate this need.

Control Flow

This section aims to talk through the basic flow of the lifetime of a octopOS topic.

Shared Memory Segment

Communication Protocal

Full Documentation

Full documentation is available here

octopos's People

Contributors

joshuahassler avatar jacobhempel avatar llazarek avatar kodycode avatar

Stargazers

Diar Shukor avatar Eric O'Donnell avatar Thomas Love avatar  avatar

Watchers

James Cloos avatar Daniel Santos avatar  avatar  avatar  avatar Thomas Love avatar

Forkers

djbaumann

octopos's Issues

OctopOS main program

The main program needs to be written for octopOS. It should:

  1. Setup an instance of octopOS
  2. Fork and exec each module
    • Each module needs to have its MSGKEY passed as argv[0]
  3. Create a tentacle and a thread for each child that listens for messages
  4. Register a handler for SIGCHLD, this will be expanded on with issue #4

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.