Code Monkey home page Code Monkey logo

inside-job's Introduction

Inside Job

"Inside Job" is a package that manages the transfer of messages within a single process between threads using pointers and callbacks, enabling efficient and lightweight communication between the threads. It utilizes an MQTT-like approach, utilizing publish/subscribe patterns to transfer data through callbacks.

Installation

To install the Inside Job package, simply clone the repository and build the project.

$ git clone https://github.com/ishay320/inside-job
$ cd inside-job
$ mkdir build
$ cmake ..
$ sudo make install

The default queue of broker is 4096 messages but can be change in compilation using $ cmake -DBROKER_QUEUE_SIZE=<queue-size> ..

Usage

The Inside Job package provides a simple API to use for message transfer between threads. The main component of the API is the Broker class. The messaging api is using the publish and subscribe classes.

Broker

The Broker class is responsible for managing connections and facilitating message transfer. To create a Broker object, simply instantiate it using the constructor and start its thread.

#include "broker.h"

insideJob::Broker broker();
broker.start();

Then pass the broker to all the threads by pointer, reference or make it global.

In order to stop the broker call broker.stop() or let it destruct at the end of the scope.

Subscribe

To subscribe to the Broker, create a Subscriber object by calling its constructor and passing the main Broker as an argument.

#include "subscriber.h"

insideJob::Subscriber sub{broker};

To subscribe to a topic, use the subscribe method. You can subscribe to as many topics as you need.

std::string topic{"/base/some1"};
sub.subscribe(topic);

You can check if messages have been received or determine the number of received messages using the queueSize() and queueEmpty() methods.

To retrieve the data, use the popData() method.

Publish

To publish messages to the Broker, create a Publisher object by calling its constructor and passing the main Broker as an argument.

#include "publisher.h"

insideJob::Publisher pub{broker};

To publish a message, use the publish() method, providing the topic and the data.

Data packet{.num = 12, .str = "test"};
pub.publish(topic, (void*)&packet, 64);

inside-job's People

Contributors

ishay320 avatar

Watchers

 avatar

inside-job's Issues

add support for ipc, udp, tcp etc...

the idea is that i call generic callback, so i can use any sending method that i want, but i need to setup some kind of adapter in order to receive data.

  1. check how to receive date.
  2. add callbacks
  • maybe some kind of add-on system that allows me to add function read that gives me the published data, and remove/add subscriber. use the dynamic linking at runtime to get new options

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.