All Projects → FedeDP → Libmodule

FedeDP / Libmodule

Licence: mit
C simple and elegant implementation of an actor library

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Libmodule

Unifiedtransform
A school management Software
Stars: ✭ 2,248 (+1805.08%)
Mutual labels:  library, oop
InitKit
Neo-InitWare is a modular, cross-platform reimplementation of the systemd init system. It is experimental.
Stars: ✭ 364 (+208.47%)
Mutual labels:  modular, bsd
Pencil.js
✏️ Nice modular interactive 2D drawing library
Stars: ✭ 204 (+72.88%)
Mutual labels:  modular, oop
the movie app open source
🎬 an app that lists movies in theaters and that will be released, and their respective actors using the api of the movie database, made with Flutter using Modular and MobX
Stars: ✭ 29 (-75.42%)
Mutual labels:  modular, actors
Casadi
CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave.
Stars: ✭ 714 (+505.08%)
Mutual labels:  library, modular
Hazelcast Cpp Client
Hazelcast IMDG C++ Client
Stars: ✭ 67 (-43.22%)
Mutual labels:  library, osx
Swiftyvk
Easy and powerful way to interact with VK API for iOS and macOS
Stars: ✭ 247 (+109.32%)
Mutual labels:  library, osx
Ecominit
eComInit is a free init system and service manager designed to scale from lightweight desktops to web-scale cloud deployments. It aims to offer feature-parity with systemd but with a modular, portable architecture compliant with software engineering best-practice.
Stars: ✭ 352 (+198.31%)
Mutual labels:  modular, bsd
Dynamix
🍥 A new take on polymorphism in C++
Stars: ✭ 504 (+327.12%)
Mutual labels:  library, oop
Csspin
CSS Spinners and Loaders - Modular, Customizable and Single HTML Element Code for Pure CSS Loader and Spinner
Stars: ✭ 1,019 (+763.56%)
Mutual labels:  library, modular
Miniaudio
Single file audio playback and capture library written in C.
Stars: ✭ 1,889 (+1500.85%)
Mutual labels:  osx, bsd
Openbsm
OpenBSM open audit implementation
Stars: ✭ 116 (-1.69%)
Mutual labels:  osx
Swiftfortunewheel
The ultimate spinning wheel view that supports dynamic content and rich customization.
Stars: ✭ 114 (-3.39%)
Mutual labels:  osx
Wasmcloud
wasmCloud is a universal host runtime for actors built with WebAssembly and capability providers
Stars: ✭ 116 (-1.69%)
Mutual labels:  actors
Libaudiodecoder
The Cross-Platform Audio Decoder API
Stars: ✭ 114 (-3.39%)
Mutual labels:  library
Typescript Hapi Starter
🚀 Starter for building APIs with Hapi + Typescript!
Stars: ✭ 117 (-0.85%)
Mutual labels:  library
Folding Cell
📃 FoldingCell is an expanding content cell with animation made by @Ramotion
Stars: ✭ 10,035 (+8404.24%)
Mutual labels:  library
Uppy Server
[DEPRECATED] 'Uppy Server' was renamed to 'Companion' and lives inside the Uppy repo no
Stars: ✭ 115 (-2.54%)
Mutual labels:  modular
Vusikview
Android library to make notes drop animation for music players
Stars: ✭ 115 (-2.54%)
Mutual labels:  library
Finish
A non-intrusive library adding a graceful shutdown to Go HTTP servers.
Stars: ✭ 115 (-2.54%)
Mutual labels:  library

Libmodule

builds.sr.ht status Documentation Status License: MIT

What is this?

Libmodule offers a small and simple C implementation of an actor library that aims to let developers easily create modular C projects in a way which is both simple and elegant.
Indeed, libmodule was heavily inspired by my own actor library experience with akka for its API.

What is a module, anyway?

Unsurprisingly, module is the core concept of libmodule architecture.
A module is an Actor that can listen on socket events too.
Frankly speaking, it is denoted by a MODULE() macro plus a bunch of mandatory callbacks, eg:

#include <module/module_easy.h>
#include <module/modules_easy.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>

MODULE("Pippo");

static void init(void) {
    /* Register STDIN fd, without autoclosing it at the end */
    m_register_fd(STDIN_FILENO, false, NULL);
}

static bool check(void) {
    /* Should module be registered? */
    return true;
}

static bool evaluate(void) {
    /* Should module be started? */
    return true;
}

static void destroy(void) {
    
}

static void receive(const msg_t *msg, const void *userdata) {
    if (!msg->is_pubsub) {
        char c;
        read(msg->fd_msg->fd, &c, sizeof(char));
        switch (tolower(c)) {
            case 'q':
                m_log("Leaving...\n");
                m_tell_str(self(), "ByeBye");
                break;
            default:
                if (c != ' ' && c != '\n') {
                    m_log("Pressed %c\n", c);
                }
                break;
        }
    } else if (msg->pubsub_msg->type == USER && 
        !strcmp((char *)msg->pubsub_msg->message, "ByeBye")) {
            
        modules_quit(0);
    }
}

In this example, a "Pippo" module is created and will read chars from stdin until 'q' is pressed.
Note that it does not even need a main function, as libmodule already provides a default one as a weak, thus overridable, symbol.

Is it portable?

Yes, it is. Non-portable code is actually compile-time-plugins based.
On linux, libmodule's internal loop will use epoll, while on BSD and MacOS it will use kqueue.
On other OS, cmake will fallback at looking for libkqueue, a drop-in replacement for kqueue.
Unfortunately, I am not able to test builds on other OS: I could only check that libmodule can be built on Linux through libkqueue.

Finally, it heavily relies upon gcc attributes that may or may not be available for your compiler.

Is there any documentation?

Yes, it is availabe at readthedocs.
You have some simple examples too, check Samples folder.
To see a real project using libmodule, check Clightd.

CI

Libmodule, samples and tests builds are tested on builds.sr.ht on archlinux, ubuntu, fedora and freebsd.
Moreover, tests are executed and valgrind checked too.

But...why?

We all know OOP is not a solution to every problem and C is still a beautiful and much used language.
Still, I admit to love code modularity that OOP enforces; moreover, I realized that I was using same code abstractions over and over in my C projects (both side projects and at my job).
So I thought that writing a library to achieve those same abstractions in a cleaner and simpler way was the right thing to do and could help some other dev.

Build dep and how to build

You only need cmake to build libmodule on Linux and BSD/osx; it does not depend upon external software.
On other platforms, you will need libkqueue too.
To build, you only need to issue:

$ mkdir build
$ cd build
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib ../
$ make

Note that libmodule can also be built as static library, by passing -DSTATIC_MODULE=true parameter to cmake.

Installation - Generic OS

# make install

Installation - Red Hat

$ cpack -G RPM

And finally install generated RPM package.

Installation - Debian

$ cpack -G DEB

And finally install generated DEB package.

Libmodule will install a pkg-config script too: use it to link libmodule in your projects, or use "-lmodule" linker flag.
Please note that in order to test examples, there is no need to install the library.

For Archlinux users, Libmodule is available on AUR.

License

Libmodule is made available with a MIT license to encourage people to actually try it out and maybe use it inside their project, no matter if open or closed source.

Are you using libmodule in your project? Please let me know and I will gladly list it here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].