Skip to content

package for inter-thread communication using pointers and callbacks in a pub/sub fashion.

License

Notifications You must be signed in to change notification settings

ishay320/inside-job

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

package for inter-thread communication using pointers and callbacks in a pub/sub fashion.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published